[R-SIG-Finance] Quantstrat - Triggering chain rule with lag period

Mayank Singhal msinghal_22 at yahoo.com
Tue Aug 2 07:14:35 CEST 2016


Sure, please find attached the sample case. 

    On Tuesday, August 2, 2016 9:13 AM, Ilya Kipnis <ilya.kipnis at gmail.com> wrote:
 

 You might want to send a minimum reproducible example.
On Mon, Aug 1, 2016 at 11:38 PM, Mayank Singhal via R-SIG-Finance <r-sig-finance at r-project.org> wrote:

Hello all,
Here is what i am trying to achieve : For every entry order (which gets filled, note that some might get rejected because of MaxPos criteria), i want to exit based on the exit rule (which is based on signal generation) or on a second exit rule (which is fixed no. of periods, "n",  from entry) depending upon whichever of these two exit criteria is met first.

The result i am getting is : exit rule 2 (fixed no. of periods) triggers off the following day from the entry rule and not after desired "n" periods. Please if someone can advise - if i am doing something wrong with the syntax here ? Below is the code snapshot of rules
**********************************************************************************eb3 = TRUE
#entry rulestrat.st <- add.rule(strat.st,name='ruleSignal',arguments = list( sigcol=c("signal4.gt.zero"),sigval=TRUE,orderqty=1,ordertype='market',orderside='long',prefer="Open",replace=FALSE,threshold=NULL,osFUN=osMaxPos),type='enter',label='enter_long_alpha5c',storefun=FALSE,enabled=eb3,path.dep = TRUE)
#exit rule 1strat.st <- add.rule(strat.st,name='ruleSignal',arguments = list( sigcol=c("signal4.lt.zero"), sigval=TRUE,orderqty='all',ordertype='market',orderside='long',prefer="Open",replace=FALSE,threshold=NULL,osFUN=osMaxPos,orderset='ocolong'),type='exit', label='exit_long_alpha5c',storefun=FALSE,enabled=eb3,path.dep = TRUE)
#exit rule 2 strat.st <- add.rule(strat.st,name='ruleSignal',arguments = list(sigcol=c("longExit"), sigval=TRUE,orderqty=-1,ordertype='market',orderside='long',prefer="Open",replace=FALSE, orderset='ocolong'), type='chain', parent='enter_long_alpha5c',label='Sqroff_LONG',enabled=eb3, path.dep = TRUE)
*********************************************************** Note that - in exit rule 2 , the sigcol "longexit" is just a "n" period lag on "signal4.gt.zero" column
Any guidance in this regard will be very helpful.
Regards,Mayank
        [[alternative HTML version deleted]]

_______________________________________________
R-SIG-Finance at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.



  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20160802/9b6314e3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo_msinghal.R
Type: application/octet-stream
Size: 3615 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20160802/9b6314e3/attachment.obj>


More information about the R-SIG-Finance mailing list