Back

Help with simple time-series momentum alpha framework

Hi there, 

So I've already used the framework for some investing strategies and now I'm trying to implement a simple time-series momentum swing trading strategy on commodity CFDs (Market.Oanda).

 

What I would like to happen is the following:

1) Minute/hourly resolution is used as the main data resolution (set in main.py) with multiple symbols.

2) In the AlphaModel, I would like to consolidate into Daily data and register an indicator to each symbol (example, Donchain Channel) with this consolidated data.

3) Each time (if and only if) a new daily data is consolidated (which should be at the close/open for 24/5 CFDs), check whether the close of that daily bar is higher/lower than the Donchian Channels.

4) Emit insights Up/Down for those symbols that have closed above/below the Channels. 

You can see my current progress in the attached code.

 

Problems:

1) Through Debugging, I have noticed that my current OnDataConsolidated is being called at different times (i.e. "Daily" bars are consolidating at different times). I have followed the trail and the indicators are being registered at the same time, and all contracts should open/close trading at the same time each trading day.

2) Furthermore, the "Daily bars" are all ending at "00:00:00" (bar.EndTime). This is not the "end of trading day close" that I'm after. In all cases, the "Daily bars" are giving an intra-day price (00:00:00) as the "Daily close". 

 

If someone could please help me figure out what is going wrong with my indicator + consolidator combo, and thus help me achieve the process initially outlined above, that would be very much appreciated! I'm not sure if I've explained things in the simplest manner, so please ask any further questions. 

Thanks in advance, 

Kayne.

Update Backtest








0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Kayne,

1. Market hours can vary for Cfds. You can find a list of market hours for each Cfd here. You can find the next market close for a security using

nextMarketClose = security.Exchange.Hours.GetNextMarketClose(security.LocalTime, false)

This and including the fact the your algorithm start date is a holiday explain why the first bar's consolidated time is different for each symbol. By removing self.print = False on line 79 in your AlphaModel, you can see that the consolidated times are more consistent after the first day.

2. Daily bars are created by consolidating intra-day data. These bars are emitted at the end of each day at midnight. This means even for equities, which close trading at 4 pm for non-extended hours, the daily bars are emitted at midnight.

If you have any further issues or concerns, please don't hesistate to reach out!

Best
Rahul

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Rahul, 

Thank you for your response. After evaluating what you've said, I still have some further questions.

 

I had not seen that part of the github, so thank you for showing it to me. I removed the print limit as you suggested, but I am still struggling to grasp some things. I will outline this below with a specific example using WTICOUSD.

This is the print statement from the OnDataCosolidated function:

2018-01-24 00:00:00 -- Data Consol. for WTICOUSD: 64.494, Ending: 2018-01-24 00:00:00

I have not changed the algorithm time, so the time is in UTC-4 (correct me if my understanding is wrong). 

So, firstly, on 2018-01-24 (a Wednesday), the session for WTICOUSD began at 18:00. The expected close price (close of 2018-01-23) I want to be receiving and evaluating is 64.514. 

You've mentioned that "daily" data/bars are consolidated at midnight (in the algorithm time). However, I would like to get and analyse a "daily" data/bar consolidated at the close of the previous trading session, which in this case, is not 00:00 but 18:00.

 

I can redefine what I am after in more specifics now:

1) Use a lower-than-daily resolution as the main data resolution.

2) In the AlphaModel, at the close of each security's session, receive that previous sessions' "daily" data/bar (which may not always be a 24h period as in the case of Sunday's & Friday's). This same "daily" data/bar should then also be passed into any indicators that need to update with this information.

3) Evaluate this "daily" data/bar alongside any indicators to make Insight decisions.

 

I am really struggling to implement part 2). Could you please help me understand specifically where my provided code is going wrong in achieving this? 

 

Many thanks, 

Kayne.

0

Hey Kayne,

If I understand you correctly, you want a bar for WTICOUSD which is data consolidated from the market open period, meaning a bar which starts at 18:00 Wednesday and closes at 17:00 Thursday, and so on. You can accomplish this using a custom Calendar consolidator. As examples of how Calendar consolidators work, you can see how the weekly and monthly calendar consolidators are created in Calendar.cs.

Best
Rahul

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed