|
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
|
|
Beware, this is a mine field! For example, one problem you will need
to deal with is that different commodities roll on different dates. Then there is the nightmare quagmire of back adjusting, which is best skipped altogether in my opinion. In short, there are many ways to get hurt here. There is a large literature on the topic, starting with W. D. Gann 80+ years ago. The writings of Bob Pelletier of CSI are a good trail-head. John On Thu, May 3, 2012 at 11:44 AM, gussinsky <[hidden email]> wrote: > Hello All, > > I am struggeling to find a method which would enable me to generate a > historical time series which only contains a commodities front month price, > and after expiry automatically rolls over to the next month. > > I suspect one has to code the roll over rule from the respective exchange > into a function, and supply the function with the respective expired > historical data. > > My aim is to backtest those data for delta 1 strategies, but also for > cointegration. One example would be heating oil futures vs. gasoil futures. _______________________________________________ [hidden email] 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. |
|
Gussinsky,
Since you are looking to test for cointegration, and you say you're looking at energy products (which have liquidity in more than just the front contract), I'd suggest creating a constant maturity future (CMF) that is the interpolated price between the 2 lead contracts (see Carol Alexander's stuff for more info). CMFs don't require any back adjusting, they just require that you partially roll your position every day. HTH, Garrett On Thu, May 3, 2012 at 2:02 PM, BBands <[hidden email]> wrote: > Beware, this is a mine field! For example, one problem you will need > to deal with is that different commodities roll on different dates. > Then there is the nightmare quagmire of back adjusting, which is best > skipped altogether in my opinion. In short, there are many ways to get > hurt here. There is a large literature on the topic, starting with W. > D. Gann 80+ years ago. The writings of Bob Pelletier of CSI are a good > trail-head. > > John > > On Thu, May 3, 2012 at 11:44 AM, gussinsky <[hidden email]> wrote: >> Hello All, >> >> I am struggeling to find a method which would enable me to generate a >> historical time series which only contains a commodities front month price, >> and after expiry automatically rolls over to the next month. >> >> I suspect one has to code the roll over rule from the respective exchange >> into a function, and supply the function with the respective expired >> historical data. >> >> My aim is to backtest those data for delta 1 strategies, but also for >> cointegration. One example would be heating oil futures vs. gasoil futures. > > _______________________________________________ > [hidden email] 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. _______________________________________________ [hidden email] 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. |
|
I'm not sure if this link will work; if not, I'm trying to point you
to page 75 of "Market Risk Analysis: Pricing, Hedging and Trading Financial Instruments" http://books.google.com/books?id=3Xg4pO1PEpUC&pg=PR13&lpg=PR13&dq=carol+alexander+constant+maturity+future&source=bl&ots=ArlAbn7XPW&sig=1WGn8vNIVRy-FEYFhNyncd_WVU0&hl=en&sa=X&ei=O92iT46KEYPO9QTry7jeCA&ved=0CDkQ6AEwBA#v=onepage&q=constant%20maturity&f=false Garrett On Thu, May 3, 2012 at 2:28 PM, G See <[hidden email]> wrote: > Gussinsky, > > Since you are looking to test for cointegration, and you say you're > looking at energy products (which have liquidity in more than just the > front contract), I'd suggest creating a constant maturity future (CMF) > that is the interpolated price between the 2 lead contracts (see Carol > Alexander's stuff for more info). CMFs don't require any back > adjusting, they just require that you partially roll your position > every day. > > HTH, > Garrett > > On Thu, May 3, 2012 at 2:02 PM, BBands <[hidden email]> wrote: >> Beware, this is a mine field! For example, one problem you will need >> to deal with is that different commodities roll on different dates. >> Then there is the nightmare quagmire of back adjusting, which is best >> skipped altogether in my opinion. In short, there are many ways to get >> hurt here. There is a large literature on the topic, starting with W. >> D. Gann 80+ years ago. The writings of Bob Pelletier of CSI are a good >> trail-head. >> >> John >> >> On Thu, May 3, 2012 at 11:44 AM, gussinsky <[hidden email]> wrote: >>> Hello All, >>> >>> I am struggeling to find a method which would enable me to generate a >>> historical time series which only contains a commodities front month price, >>> and after expiry automatically rolls over to the next month. >>> >>> I suspect one has to code the roll over rule from the respective exchange >>> into a function, and supply the function with the respective expired >>> historical data. >>> >>> My aim is to backtest those data for delta 1 strategies, but also for >>> cointegration. One example would be heating oil futures vs. gasoil futures. >> >> _______________________________________________ >> [hidden email] 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. _______________________________________________ [hidden email] 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. |
|
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
|
|
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") 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 <[hidden email]> 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. > > _______________________________________________ > [hidden email] 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. _______________________________________________ [hidden email] 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. |
|
On Thu, May 3, 2012 at 3:28 PM, G See <[hidden email]> 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 <[hidden email]> 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. >> >> _______________________________________________ >> [hidden email] 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. _______________________________________________ [hidden email] 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. |
|
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 <[hidden email]> wrote: > On Thu, May 3, 2012 at 3:28 PM, G See <[hidden email]> 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 <[hidden email]> 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. >>> >>> _______________________________________________ >>> [hidden email] 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. _______________________________________________ [hidden email] 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. |
|
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
|
|
On Fri, May 4, 2012 at 3:27 AM, gussinsky <[hidden email]> wrote:
> Hey Garrett, > > I think the ContinousSeriesCreator, is probably exactly what I am looking > for. Thanks, and how did you find this function?? No special search skills, I just try to keep track of what code is in packages I maintain. ;-) _______________________________________________ [hidden email] 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. |
|
John,
I think you probably meant to send this to the list instead of just me; apologies if not. I agree that when possible, you should avoid building continuous series. Nonetheless, that's what the OP asked for. Sometimes, there is value in analyzing a long history of data (for example when analyzing risk) and in such cases, a constant maturity future makes sense. Also, if your time-frame is short and you're careful about how you adjust and how you use the adjusted data, I think it can be useful. The OP wanted to combine and not adjust, which, IMO is more dangerous than combining and adjusting. If you're going to combine the price series of 2 different expiration months, then you have to adjust for the roll. Otherwise, you may see a trend or mean-reversion where there isn't one, or worse, the opposite is actually occurring. Your point about this being a difficult thing to generalize (e.g. different grades for different expirations, or first notice day being different than expiration, etc.) is valid. Regards, Garrett On Thu, May 10, 2012 at 12:48 PM, BBands <[hidden email]> wrote: > I feel that reiterating my prior warning is worthwhile. The proper way > to do this is to analyze the actual contracts and roll just as you > would have to if you were actually trading; exit the current contact > when the crowd moves enter the new actively-traded front month and > account for each separately. I coded this in Python and it works well, > but I have yet to tackle futures in R. Some problems: In some > commodities not all months actually trade actively. Backwardation and > contango can impact the rolls dramatically. While analyzing months in > delivery may seem OK, traders avoid them. None of the shortcuts that I > know of comes even close to approximating the realities of the > marketplace. Most analysts (including most of the tblox crowd) simply > ignore these problems, analyze continuous contracts and are burned > when they enter the marketable. > > Current example problem: Different crude contracts track different > delivery venues and are priced differently. Think WTI versus Brent, > spread truculently running tin the $10 range, which not too long ago > was thought 'impossible". > > This is a very deep well. > > Best, > > John _______________________________________________ [hidden email] 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. |
|
In reply to this post by gsee
I feel that reiterating my prior warning is worthwhile. The proper way
to do this is to analyze the actual contracts and roll just as you would have to if you were actually trading; exit the current contact when the crowd moves enter the new actively-traded front month and account for each separately. I coded this in Python and it works well, but I have yet to tackle futures in R. Some problems: In some commodities not all months actually trade actively. Backwardation and contango can impact the rolls dramatically. While analyzing months in delivery may seem OK, traders avoid them. None of the shortcuts that I know of comes even close to approximating the realities of the marketplace. Most analysts (including most of the tblox crowd) simply ignore these problems, analyze continuous contracts and are burned when they enter the marketable. Current example problem: Different crude contracts track different delivery venues and are priced differently. Think WTI versus Brent, spread truculently running tin the $10 range, which not too long ago was thought 'impossible". This is a very deep well. Best, John _______________________________________________ [hidden email] 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. |
|
repost for the archives:
I agree that when possible, you should avoid building continuous series. Nonetheless, that's what the OP asked for. Sometimes, there is value in analyzing a long history of data (for example when analyzing risk) and in such cases, a constant maturity future makes sense. Also, if your time-frame is short and you're careful about how you adjust and how you use the adjusted data, I think it can be useful. The OP wanted to combine and not adjust, which, IMO is more dangerous than combining and adjusting. If you're going to combine the price series of 2 different expiration months, then you have to adjust for the roll. Otherwise, you may see a trend or mean-reversion where there isn't one, or worse, the opposite is actually occurring. Your point about this being a difficult thing to generalize (e.g. different grades for different expirations, or first notice day being different than expiration, etc.) is valid. Regards, Garrett _______________________________________________ [hidden email] 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. |
| Powered by Nabble | Edit this page |
