Hi all, I am trying to rbind monthly futures to a continuous time series to be run through an algo strategy. The problem here is that data is overlapping, i.e. my Feb contract trades for 6 weeks and when I rbind with my March data I get an overlap for last two weeks of Jan. How can I create a time series that is continuous, not overlapping and useable in quantstrat (i.e. XTS format)? I am not posting any code as it would be really one single rbind statement. Thanks Peter
rbind and duplicates in monthly futures
6 messages · Peter Neumaier, Joshua Ulrich, Brian G. Peterson
On Mon, Apr 4, 2016 at 7:24 AM, Peter Neumaier <peter.neumaier at gmail.com> wrote:
Hi all, I am trying to rbind monthly futures to a continuous time series to be run through an algo strategy. The problem here is that data is overlapping, i.e. my Feb contract trades for 6 weeks and when I rbind with my March data I get an overlap for last two weeks of Jan. How can I create a time series that is continuous, not overlapping and useable in quantstrat (i.e. XTS format)? I am not posting any code as it would be really one single rbind statement.
Even though the code may be simple, you still would be more likely to receive help if you provide a minimal reproducible example of the issue. In this case, the data are not simple, and most people will not take the time to construct sample data in order to attempt to reproduce the issue you describe.
Thanks
Peter
[[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.
Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2016 | www.rinfinance.com
1 day later
Hi all, in the interim I've managed to import the halfhourly data, cast to
a matrix, then rbind the two months
and convert to XTS for later use by my algo strategy.
I am wondering how the data overlap will be treated by the quantstrat
framework and how
it might be impacting the calculations (i.e. P&L during overlaps).
Below the files and the code I am using:
APR <-
as.matrix(read.zoo("NGF201404_6weeks30mins.csv",sep=",",tz="",header=T))
MAY <-
as.matrix(read.zoo("NGF201405_6weeks30mins.csv",sep=",",tz="",header=T))
APR_MAY <- as.xts(rbind(APR,MAY))
http://tempsend.com/BBA86DB4ED
http://tempsend.com/0EDA07753B
Thanks
Peter
On Mon, Apr 4, 2016 at 2:30 PM, Joshua Ulrich <josh.m.ulrich at gmail.com>
wrote:
On Mon, Apr 4, 2016 at 7:24 AM, Peter Neumaier <peter.neumaier at gmail.com> wrote:
Hi all, I am trying to rbind monthly futures to a continuous time series
to
be run through an algo strategy. The problem here is that data is overlapping, i.e. my Feb contract trades for 6 weeks and when I rbind
with
my March data I get an overlap for last two weeks of Jan. How can I create a time series that is continuous, not overlapping and useable in quantstrat (i.e. XTS format)? I am not posting any code as it would be really one single rbind statement.
Even though the code may be simple, you still would be more likely to receive help if you provide a minimal reproducible example of the issue. In this case, the data are not simple, and most people will not take the time to construct sample data in order to attempt to reproduce the issue you describe.
Thanks
Peter
[[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. -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2016 | www.rinfinance.com
1 day later
On Tue, Apr 5, 2016 at 3:06 PM, Peter Neumaier <peter.neumaier at gmail.com> wrote:
Hi all, in the interim I've managed to import the halfhourly data, cast to a matrix, then rbind the two months and convert to XTS for later use by my algo strategy. I am wondering how the data overlap will be treated by the quantstrat framework and how it might be impacting the calculations (i.e. P&L during overlaps).
It wasn't clear to me from your original question, but I can now see that you want to create a single continuous futures series using adjacent futures contracts. As you probably guessed, the overlap in data in your APR_MAY object would be very bad. There is not a single correct way to create a continuous futures series for every futures market. You could roll to the next contract when the current contract expires, when volume or open interest in the current contract drops below some threshold over the next contract's volume or open interest, etc. I realize this doesn't completely answer your question... because your question is not just about programming. It's also about the microstructure of the market you're researching. Searching for "continuous futures" or "futures roll" should help give you some ideas about how to solve the problem for this specific futures market.
Below the files and the code I am using:
APR <-
as.matrix(read.zoo("NGF201404_6weeks30mins.csv",sep=",",tz="",header=T))
MAY <-
as.matrix(read.zoo("NGF201405_6weeks30mins.csv",sep=",",tz="",header=T))
APR_MAY <- as.xts(rbind(APR,MAY))
http://tempsend.com/BBA86DB4ED
http://tempsend.com/0EDA07753B
Thanks
Peter
On Mon, Apr 4, 2016 at 2:30 PM, Joshua Ulrich <josh.m.ulrich at gmail.com>
wrote:
On Mon, Apr 4, 2016 at 7:24 AM, Peter Neumaier <peter.neumaier at gmail.com> wrote:
Hi all, I am trying to rbind monthly futures to a continuous time series to be run through an algo strategy. The problem here is that data is overlapping, i.e. my Feb contract trades for 6 weeks and when I rbind with my March data I get an overlap for last two weeks of Jan. How can I create a time series that is continuous, not overlapping and useable in quantstrat (i.e. XTS format)? I am not posting any code as it would be really one single rbind statement.
Even though the code may be simple, you still would be more likely to receive help if you provide a minimal reproducible example of the issue. In this case, the data are not simple, and most people will not take the time to construct sample data in order to attempt to reproduce the issue you describe.
Thanks
Peter
[[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.
-- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2016 | www.rinfinance.com
Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2016 | www.rinfinance.com
I agree, I could have been more explicit about the nature of my problem and the specific issue arising from the decision of when/how to roll futures contracts. However, I was hoping for a workaround within the quantstrat framework that might help me. My research shows that the last six weeks of my traded contract are the most liquid period over lifetime. As a result, I end up wth an overlap of two weeks, where in practical terms I would be trading two contracts: the actual frontmonth and the following month. Currently, I am backtesting each contract separately, ending up with monthly output, which is not 100% satisfying as I'd like to evaluate the yearly performance and not look into monthly output. Is there a way to overcome the issue of overlapping periods, i.e. run the data for the actual frontmonth (six weeks) and continue thereafter with the overlap period, essentially forcing sequential execution of the time series instead of merging the two months and mix the data during the overlap period? I hope I am not confusing you further. Thanks Peter On Thu, Apr 7, 2016 at 1:57 AM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
On Tue, Apr 5, 2016 at 3:06 PM, Peter Neumaier <peter.neumaier at gmail.com> wrote:
Hi all, in the interim I've managed to import the halfhourly data, cast
to a
matrix, then rbind the two months and convert to XTS for later use by my algo strategy. I am wondering how the data overlap will be treated by the quantstrat framework and how it might be impacting the calculations (i.e. P&L during overlaps).
It wasn't clear to me from your original question, but I can now see that you want to create a single continuous futures series using adjacent futures contracts. As you probably guessed, the overlap in data in your APR_MAY object would be very bad. There is not a single correct way to create a continuous futures series for every futures market. You could roll to the next contract when the current contract expires, when volume or open interest in the current contract drops below some threshold over the next contract's volume or open interest, etc. I realize this doesn't completely answer your question... because your question is not just about programming. It's also about the microstructure of the market you're researching. Searching for "continuous futures" or "futures roll" should help give you some ideas about how to solve the problem for this specific futures market.
Below the files and the code I am using:
APR <-
as.matrix(read.zoo("NGF201404_6weeks30mins.csv",sep=",",tz="",header=T))
MAY <-
as.matrix(read.zoo("NGF201405_6weeks30mins.csv",sep=",",tz="",header=T))
APR_MAY <- as.xts(rbind(APR,MAY))
http://tempsend.com/BBA86DB4ED
http://tempsend.com/0EDA07753B
Thanks
Peter
On Mon, Apr 4, 2016 at 2:30 PM, Joshua Ulrich <josh.m.ulrich at gmail.com>
wrote:
On Mon, Apr 4, 2016 at 7:24 AM, Peter Neumaier <
peter.neumaier at gmail.com>
wrote:
Hi all, I am trying to rbind monthly futures to a continuous time
series
to be run through an algo strategy. The problem here is that data is overlapping, i.e. my Feb contract trades for 6 weeks and when I rbind with my March data I get an overlap for last two weeks of Jan. How can I create a time series that is continuous, not overlapping and useable in quantstrat (i.e. XTS format)? I am not posting any code as
it
would be really one single rbind statement.
Even though the code may be simple, you still would be more likely to receive help if you provide a minimal reproducible example of the issue. In this case, the data are not simple, and most people will not take the time to construct sample data in order to attempt to reproduce the issue you describe.
Thanks
Peter
[[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.
-- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2016 | www.rinfinance.com
-- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com R/Finance 2016 | www.rinfinance.com
You need to decide how you want to roll. You're telling us that you'll trade two contracts simultaneously. That's different from all the standard roll algorithms. You've confirmed what Josh told you by saying you don't want to create a continuous series. You should subset your data over the periods you want to trade before calling quantstrat. quantstrat loops over instruments, so it will trade them when the data is available. I don't understand your query about summarizing results. If they are cash P&L recorded in the portfolio or account, they will be at whatever frequency you market the portfolio at, typically at least daily. You'll probably pull then using something like dailyEqPL or dailyTxnPL or dailyReturn or dailyStats. You can summarize and display your results however you like, and there are a host of tools in blotter for price/cash space and PerformanceAnalytics for %-returns space. Very few of them presume monthly summaries except for the few standardized fund returns tables. Regards, Brian
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock On Thu, 2016-04-07 at 12:25 +0100, Peter Neumaier wrote: > I agree, I could have been more explicit about the nature of my problem and > the specific issue arising from the decision of > when/how to roll futures contracts. > > However, I was hoping for a workaround within the quantstrat framework that > might help me. My research shows > that the last six weeks of my traded contract are the most liquid period > over lifetime. As a result, I end up wth an overlap of two > weeks, where in practical terms I would be trading two contracts: the > actual frontmonth and the following month. > > Currently, I am backtesting each contract separately, ending up with > monthly output, which is not 100% satisfying as I'd like to > evaluate the yearly performance and not look into monthly output. > > Is there a way to overcome the issue of overlapping periods, i.e. run the > data for the actual frontmonth (six weeks) and continue thereafter > with the overlap period, essentially forcing sequential execution of the > time series instead of merging the two months and mix > the data during the overlap period? I hope I am not confusing you further. > > Thanks > Peter > > > > On Thu, Apr 7, 2016 at 1:57 AM, Joshua Ulrich <josh.m.ulrich at gmail.com> > wrote: > > > On Tue, Apr 5, 2016 at 3:06 PM, Peter Neumaier <peter.neumaier at gmail.com> > > wrote: > > > Hi all, in the interim I've managed to import the halfhourly data, cast > > to a > > > matrix, then rbind the two months > > > and convert to XTS for later use by my algo strategy. > > > > > > I am wondering how the data overlap will be treated by the quantstrat > > > framework and how > > > it might be impacting the calculations (i.e. P&L during overlaps). > > > > > It wasn't clear to me from your original question, but I can now see > > that you want to create a single continuous futures series using > > adjacent futures contracts. As you probably guessed, the overlap in > > data in your APR_MAY object would be very bad. > > > > There is not a single correct way to create a continuous futures > > series for every futures market. You could roll to the next contract > > when the current contract expires, when volume or open interest in the > > current contract drops below some threshold over the next contract's > > volume or open interest, etc. > > > > I realize this doesn't completely answer your question... because your > > question is not just about programming. It's also about the > > microstructure of the market you're researching. Searching for > > "continuous futures" or "futures roll" should help give you some ideas > > about how to solve the problem for this specific futures market. > > > > > Below the files and the code I am using: > > > > > > APR <- > > > as.matrix(read.zoo("NGF201404_6weeks30mins.csv",sep=",",tz="",header=T)) > > > MAY <- > > > as.matrix(read.zoo("NGF201405_6weeks30mins.csv",sep=",",tz="",header=T)) > > > > > > APR_MAY <- as.xts(rbind(APR,MAY)) > > > > > > > > > http://tempsend.com/BBA86DB4ED > > > > > > http://tempsend.com/0EDA07753B > > > > > > Thanks > > > Peter > > > > > > On Mon, Apr 4, 2016 at 2:30 PM, Joshua Ulrich <josh.m.ulrich at gmail.com> > > > wrote: > > >> > > >> On Mon, Apr 4, 2016 at 7:24 AM, Peter Neumaier < > > peter.neumaier at gmail.com> > > >> wrote: > > >> > Hi all, I am trying to rbind monthly futures to a continuous time > > series > > >> > to > > >> > be run through an algo strategy. The problem here is that data is > > >> > overlapping, i.e. my Feb contract trades for 6 weeks and when I rbind > > >> > with > > >> > my March data I get an overlap for last two weeks of Jan. > > >> > > > >> > How can I create a time series that is continuous, not overlapping and > > >> > useable in quantstrat (i.e. XTS format)? I am not posting any code as > > it > > >> > would be really one single rbind statement. > > >> > > > >> Even though the code may be simple, you still would be more likely to > > >> receive help if you provide a minimal reproducible example of the > > >> issue. In this case, the data are not simple, and most people will > > >> not take the time to construct sample data in order to attempt to > > >> reproduce the issue you describe. > > >> > > >> > Thanks > > >> > Peter > > >> > > > >> > [[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. > > >> > > >> > > >> > > >> -- > > >> Joshua Ulrich | about.me/joshuaulrich > > >> FOSS Trading | www.fosstrading.com > > >> R/Finance 2016 | www.rinfinance.com > > > > > > > > > > > > > > -- > > Joshua Ulrich | about.me/joshuaulrich > > FOSS Trading | www.fosstrading.com > > R/Finance 2016 | www.rinfinance.com > > > > [[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.