<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hi all,<br>
    <br>
    here is an example code for a basic strategy on a synthetic asset.
    (with error <span class="moz-smiley-s2"><span> :-(  </span></span>)
    <br>
    Let us assume  I already calculated the synthetic asset.<br>
    You will find it attached.<br>
    <br>
    <font color="#3333ff">require(quantstrat)<br>
      <br>
      try(rm("order_book.testP",pos=.strategy),silent=TRUE)<br>
try(rm("account.testP","portfolio.testP",pos=.blotter),silent=TRUE)<br>
try(rm("account.st","portfolio.st","synth.str","stratComp","initDate","initEq",'start_t','end_t'),silent=TRUE)</font><br>
    <br>
    <br>
    <font color="#33cc00">### Here I prepare the asset####<br>
      <font color="#3366ff">synth.str='test'<br>
        testdata<-read.csv("test.csv",colClasses=c("character","numeric"),sep=";")  
        <br>
        test<-as.xts(testdata[,2],order.by=as.POSIXct(testdata[,1],format="%Y-%m-%d"),tzone="America/New_York",
        src="csv", updated=Sys.time())<br>
        colnames(test)<-"test"</font><br>
    </font><br>
    <font color="#33ff33">####Then I will define it####</font><br>
    <font color="#3366ff">currency('USD')<br>
      synthetic(synth.str,currency='USD',multiplier=1,tick_size=0.000001)
    </font><br>
    <font color="#33cc00"># BTW, I have to specify a multiplier and a
      tick_size otherwise there is an error</font><br>
    <br>
    <font color="#3366ff">initDate='2007-11-01'<br>
      initEq=1000000<br>
      portfolio.st='testP'<br>
      account.st='testP'<br>
      <br>
      initPortf(portfolio.st,symbols=synth.str, initDate=initDate)<br>
      initAcct(account.st,portfolios=portfolio.st, initDate=initDate)<br>
      initOrders(portfolio=portfolio.st,initDate=initDate)<br>
      <br>
      buyin=-1.5*sd(C15)<br>
      <br>
      <font color="#33cc00">#Define function stand</font><br>
      stand<-function(x)<br>
      {<br>
        t<-cbind(x,x)<br>
        colnames(t)<-c(colnames(x),"signal")<br>
        return(t)<br>
      }<br>
    </font><br>
    <br>
    <font color="#3366ff">stratComp <- strategy(portfolio.st)<br>
      <br>
      stratComp <- add.indicator(strategy = stratComp, name =
      "stand", arguments = list(x=quote(mktdata)) )<br>
      <br>
      stratComp <- add.signal(strategy =
      stratComp,name="sigThreshold",arguments =
list(column="signal",relationship="gt",threshold=buyin,cross=TRUE),label="signal.gt.buyin")<br>
      <br>
      #buy rule<br>
      stratComp <- add.rule(strategy = stratComp,name='ruleSignal',
      arguments = list(sigcol="signal.gt.buyin",sigval=TRUE, orderqty=1,
      ordertype='market', orderside='long',
      threshold=NULL),type='enter')<br>
      stratComp <- add.rule(strategy = stratComp,name='ruleSignal',
      arguments = list(sigcol="signal.gt.buyin",sigval=TRUE,
      orderqty=-1, ordertype='stoplimit', orderside='long',
      threshold=.90,tmult=TRUE),type='risk')<br>
      <br>
      out<-try(applyStrategy(strategy=stratComp ,
      portfolios=portfolio.st))</font><br>
    <br>
    I have then the following error<br>
    <br>
    <font color="#ff0000">Error in getPrice(x = data, prefer = prefer) :
      <br>
        subscript out of bounds, no price was discernible from the data<br>
      De plus : Message d'avis :<br>
      In max(i) : aucun argument pour max ; -Inf est renvoyé<br>
      Error in if (price == 0) stop("price", price, "must be positive or
      negative") : <br>
        valeur manquante là où TRUE / FALSE est requis</font><br>
    <br>
    I understand that the getPrice function works on OHLC prices.<br>
    the synthetic asset, as such, is just a one column price
    time-series.<br>
    <br>
    Is there a way to use the applyStrategy function on non-OHLC
    time-series?<br>
    <br>
    Thx in advance<br>
    <br>
    Anass<br>
  </body>
</html>