[R-SIG-Finance] Generating a front month only Time Series for Futures Prices

G See gsee000 at gmail.com
Thu May 3 22:47:27 CEST 2012


note that if you adjust by adding back roll costs and then try to
calculate returns, your returns will be "off" (read:wrong)

On Thu, May 3, 2012 at 3:32 PM, G See <gsee000 at gmail.com> wrote:
> On Thu, May 3, 2012 at 3:28 PM, G See <gsee000 at gmail.com> wrote:
>> If you just want to combine 2 series together, no problem:  use rbind.
>>  But, then you'll have a gap in your data on the roll date, and you'll
>> be back asking how to adjust for it. ;-)  That's where the minefields
>> come into play.
>>
>> I look at roll cost like a dividend (which is often negative).  You
>> can adjust for it a couple different way.  You could add the roll
>> costs back to the series, which may mean negative prices in the past.
>> Or, you could multiply by an adjustment ratio (treat it like a split).
>>
>> If you don't adjust for the roll, you'll have big gaps in your data.
>> Imagine buying the front month VIX future and rolling it each month.
>> 10 years later, the VIX may still be at the same price, but you'll
>> likely have lost way more than you started with.
>>
>> If you do adjust for the roll, either the oldest prices or the newest
>> prices may not be reasonable.
>>
>> To get this back to R, let's get some code involved.
>> This is laying in the FinancialInstrument sandbox; I haven't
>> personally looked at it, so I don't know how it works.  Ditto for
>> FinancialInstrument:::slice and FinancialInstrument:::splooth
>> https://r-forge.r-project.org/scm/viewvc.php/pkg/FinancialInstrument/sandbox/continuousSeries.R?view=markup&root=blotter
>>
>> If you just want daily data that has already been adjusted for you,
>> look here for code to download data from trading blox (it has Heating
>> Oil.. not gasoil though):
>> https://r-forge.r-project.org/scm/viewvc.php/pkg/FinancialInstrument/inst/parser/download.tblox.R?view=markup&root=blotter
>>
>> I believe Trading Blox simply adds back the roll cost.  And, I think
>> they roll when Open Interest rolls.
>>
>> source("http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/FinancialInstrument/inst/parser/download.tblox.R?root=blotter")
>>
>
> # oops. forgot this line
> getSymbols("HO", src='tblox')
>
>> chartSeries(HO[, 8])  #unadjusted
>> addTA(HO[, 4], col='red', on=1) #adjusted
>>
>> Or, are you looking for code to calculate the expiration dates of instruments?
>>
>> What have you tried? ;-)
>>
>> Garrett
>>
>> On Thu, May 3, 2012 at 3:07 PM, gussinsky <sduve at hotmail.com> wrote:
>>> Hey Garrett,
>>>
>>> thank you for this, I had a read through this page in the book you
>>> referenced. And looking at Agricultural Commodities this makes a lot of
>>> sense. And if you look at Wheat and Corn on the CBOT, I think you only have
>>> 5 deliveries per year, hence the massive gaps when each contract rolls off.
>>> So here the interpolation makes sense, and I think one could approach this
>>> trade as a box.
>>>
>>> But lets consider for example heating oil again, here you have monthly
>>> deliveries, and the seasonality is far less nowadays, in Europe even less
>>> due to the increased Diesel consumption on the roads.
>>>
>>> But lets consider this:
>>>
>>> "Trading in a current month shall cease on the last business day of the
>>> month preceding the delivery month."
>>>
>>> This is the expiry rule for Heating Oil on the Nymex. I think this is
>>> codeable without minefields isn't it. It would be terrific if anyone could
>>> point me in the right direction on how to approach this.
>>>
>>> I think it wont be possible to download this with one simple function. I
>>> suspect one would have to store individual files for the respective expiry
>>> contracts, and perhaps index the file names. And then perhaps through a loop
>>> function could read out the corresponding 1:n values for each month, store
>>> them in an array, and then run the next month with the same rule, and store
>>> them again, etc....In the end one needs to connect all those arrays into one
>>> big time series.
>>>
>>> And here is my problem, I dont know how to code this, I know what I want....
>>>
>>> Many thanks for the advice so far....
>>>
>>>
>>> Best
>>>
>>>
>>> Gussinsky
>>>
>>>
>>> PS: Garrett, it is your Pair Trading code that brought this up my mind again
>>> :-)
>>>
>>> --
>>> View this message in context: http://r.789695.n4.nabble.com/Generating-a-front-month-only-Time-Series-for-Futures-Prices-tp4606794p4606979.html
>>> Sent from the Rmetrics mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> 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.



More information about the R-SIG-Finance mailing list