[R-SIG-Finance] Dealing with the futures roll in quantstrat and blotter
Brian G. Peterson
brian at braverock.com
Mon Mar 14 18:06:14 CET 2011
On 03/14/2011 10:56 AM, Gei Lin wrote:
> My issue with one continuous series is that the spliced series does not
> reflect actual performance on the roll date. There is an inherent drop in
> price from one contract to the next that if the strategy holds over the
> roll. What's need is a rolled performance series, and but in that case,
> rolled performance is what is being traded and not prices, resulting in an
> orderBook this can't be directly piped to or compared to a real life order
> management system.
> I would like to actually simulate trading the roll within the blotter rather
> than mask it away with a shortcut. I suppose this can be done by setting up
> different portfolios with the set of tradeable symbols for each time frame
> and lopping calls to applyStrategy for each portfolio?
Sorry, I didn't understand what you were getting at, specifically.
Yes. You've got the right idea. You don't need to separate them into
different portfolios if you subset your price data first, wince
quantstrat will loop over symbols anyway.
I'd probably do something like this:
- create all the future_series instruments
- create a portfolio with all these instruments in it,
in order of expiration
- construct your roll calendar
- subset your data for each instrument based on the roll calendar
- build your strategy
- make sure the strategy knows to 'get flat' on
the last day of the data series for each instrument
- call applyStrategy
There are other ways to do this, but this seems the simplest, and
doesn't require any code changes.
> On Mon, Mar 14, 2011 at 11:35 AM, Brian G. Peterson<brian at braverock.com>wrote:
>> On 03/14/2011 10:02 AM, Gei Lin wrote:
>>> Has anyone dealt with rolling futures in the quantstrat and blotter
>> Yes, we roll products manually.
>> The 'best' approach is probably to construct some sort of continuous series
>> that implements whatever rules you use (roll calendar, volume cross,
>> Robert Sams wrote splicing functions, but they assume univariate data, and
>> have not been ported to handle multi-column data (e.g. OHLC or TBBO data)
>> for each instrument.
>> Any assistance or contributions on the splicing front would be gladly
>> I am working on an event based strategy -- the eventIndicators function
>>> returns a whole list of events in xts format (values = 1) that coincide
>>> the index datetimes of the mktdata
>>> # add the event indicators
>>> stratEvent<- add.indicator(strategy = stratEvent, name =
>>> arguments = list(price = quote(getPrice(mktdata))))
>>> I then add rules for entry and exit based on the event column being true:
>>> stratEvent<- add.rule(stratEvent, name='ruleSignal', arguments =
>>> list(sigcol="MEm1"),sigval=TRUE, orderqty=100, ordertype= 'market',
>>> orderside=NULL, threshold=NULL),type='enter')
>>> I would like to have this strategy applied to a futures contract based on
>>> specified rolling convention (e.g. if< 2 days before first notice of
>>> delivery, trade the 2nd contract, otherwise trade the 1st e.g. TY2 Comdty
>>> versus TY1 Comdty).
>>> I would like to apply this strategy to 1 portfolio covering multiple
>>> of data of closing price data with the whole futures chain. I'm not sure
>>> how to call applyStrategy to get the result I want when the instrument the
>>> strategy is trading changes over time.
>> I would construct a continuous series first, then add an instrument for
>> that continuous series to your portfolio, and test your strategy using the
>> continuous series information.
>> - Brian
>> Brian G. Peterson
>> IM: bgpbraverock
>> R-SIG-Finance at r-project.org mailing list
>> -- 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]]
> R-SIG-Finance at r-project.org mailing list
> -- 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.
Brian G. Peterson
More information about the R-SIG-Finance