[R-SIG-Finance] Position Limits

Ilya Kipnis ilya.kipnis at gmail.com
Fri May 27 22:52:48 CEST 2016


John,

It's generally a good idea to have an exit order, even if you're just
flipping the position. Quantstrat may take care of it for you, but it's
still good practice to have explicit exits IMO.

Regarding passing in a custom order sizing function, yes, you certainly
can. For instance, I have a position sizing function called osDollarATR in
my IKTrading package. See this post for some depth on it:
https://quantstrattrader.wordpress.com/2014/06/11/trend-vigor-part-iii-atr-position-sizing-annualized-sharpe-above-1-4-and-why-leverage-is-pointless/

-Ilya

On Fri, May 27, 2016 at 4:48 PM, John Klingensmith <johnsk00 at gmail.com>
wrote:

> Hi,
>  I am relatively new to R and QuantStrat, etc. I am playing with a real
> simple strategy that goes long when the market closes at its lowest close
> in 3 days and reverses the position when the market closes at its highest
> close in 3 day.  I am trying to limit the position size to 1 lot in either
> direction by using osMaxPos and addPosLimit, but for whatever reason the
> position limits are not getting imposed. I also read the "Long Enter
> Position do not "block" Short Enter Orders" question and tried making a
> custom function.
>
> My questions are as follows:
>
> 1) I currently have a long entry order and a short entry order - do I need
> to have dedicated exit orders? I am just looking to flip the position from
> long to short, and the strategy is in the market 100% of the time.
>
> 2) Why would it keep trading if I am using osMaxPos and addPosLimt, as
> follows:
>
> #Position Limits
> addPosLimit(portfolio.st, "GSPC", timestamp = initDate, maxpos = 1,
> longlevels = 1, minpos = -1, shortlevels = 1)
>
>
> #rules
> add.rule(strategy.st, name = "ruleSignal",
>          arguments = list(sigcol = "longSig",
>                           sigval=TRUE,
>                           ordertype = "market",
>                           orderside = "long",
>                           prefer="PST", # PST is just an adjusted price
> column i created
>                           replace = FALSE,
>                           orderqty = 1,
>                           osFun =  "osMaxPos"
>                           ),
>          type = "enter")
>
>
> add.rule(strategy.st, name = "ruleSignal",
>          arguments = list(sigcol = "shortSig",
>                           sigval=TRUE,
>                           ordertype = "market",
>                           orderside = "short",
>                           prefer="PST", # PST is just an adjusted price
> column i created
>                           replace = FALSE,
>                           orderqty = -1,
>                           osFun = "osMaxPos"
>                           ),
>         type = "enter")
>
> 3) Can I just create a custom function and pass it to add.rule as follows:
>
>
> #Custom Function
> osMaxPosMR = function(data, timestamp, orderqty, ordertype, ordersize,
> portfolio, symbol, ruletype, ...){
>   maxpos = osMaxPos(data, timestamp, orderqty, ordersize, portfolio,
> symbol, ruletype, ...)
>   curpos = getPosQty(portfolio, symbol, timestamp)
>
>   if(orderside == 'long' && curpos > 0)
>     maxpos = 0
>
>   if(orderside == 'short' && curpos < 0)
>     maxpos = 0
>
>   return(maxpos)
>   print(curpos)
> }
>
> add.rule(strategy.st, name = "ruleSignal",
>          arguments = list(sigcol = "longSig",
>                           sigval=TRUE,
>                           ordertype = "market",
>                           orderside = "long",
>                           prefer="PST",
>                           replace = FALSE,
>                           orderqty = 1,
>                           osFun = "osMaxPosMR"
>                           ),
>          type = "enter")
>
>
> add.rule(strategy.st, name = "ruleSignal",
>          arguments = list(sigcol = "shortSig",
>                           sigval=TRUE,
>                           ordertype = "market",
>                           orderside = "short",
>                           prefer="PST",
>                           replace = FALSE,
>                           orderqty = -1,
>                           osFun = "osMaxPosMR"
>                           ),
>         type = "enter")
>
> 4) I am using S&P index data; although you cannot actually trade the index,
> it is a good proxy for what I am trying to test. When I download the index
> data (symbol ^GSPC) the symbol stored is "GSPC" without the carrot;
> therefore, I cannot simply use "symbols <- "^GSPC" and reference "symbols"
> in my code as I would normally if it were an ETF. Can someone explain why
> this is?
>
> Thanks for any help.
> Best,
>  John
>
>         [[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.
>

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list