We're happy to announce a new feature in QuantConnect -- custom split and dividend handling! Currently all the dividend and splits are factored into the asset price. Starting today you can control how the algorithm models reality!
E.g. Do you want raw asset prices, with dividends paid as cash and splits adjusting the quantity of your holdings? This is the closest possible to reality, and can be achieved with the new setting: DataNormalizationMode.Raw
Would you prefer splits adjusted into the price, but dividends paid in cash? This is ideal for charting since the price is continuous, but the dividends are still paid in cash. You can use this mode with: DataNormalizationMode.SplitAdjusted
How about Total Return charting? Where dividends are added into the price of the asset, so the total asset price includes the sum of dividends? This is a popular technique to account for the receipt and reinvestment of dividends. You can access this mode with: DataNormalizationMode.TotalReturn
The current, default behavior of QuantConnect is to fully adjust for splits and dividends, giving you an adjusted price which always equals today's price. This is ideal for easy charting and simplified portfolio modeling. We kept this as the default since the stock plots rely on adjusted pricing.
To get started with customized price normalization, set the mode on the security during the Initialize() method: e.g.
Securities["MSFT"].SetDataNormalizationMode(DataNormalizationMode.TotalReturn);
You can also bind to Dividends and Splits events:
public void OnData(Splits split) {
split["MSFT"].SplitFactor
}
public void OnData(Dividends dividends) {
dividends["MSFT"].Distribution
}
Check out the QC University algorithm below as an example of how to get started!
Sameer Allidina
Hi Jared, wondering if this is done differently in the algorithm framework model -- I use ManualUniverseSelectionModel, and after this I check the Securities dictionary, and it has a count of 0 (there is 1 security in my ManualUniverseSelectionModel for which I want raw dividend mode).
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.
Sameer Allidina
I may have an answer to this for anyone with the same question:
it appears that you can do this by setting a custom security initializer via:
SetSecurityInitializer(mySecurityInitializer)
Then, in your custom security initializer (mySecurityInitializer), you will receive a callback for each security in your universe, and can call security.SetDataNormalizationMode(...)
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.
Levi Freedman
How do I access raw prices in Research?
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.
Shile Wen
Hi Levi,
Since History requests are based on the Data Normalization of the security, we can simply set the Data Normalization to raw before retrieving data with security.SetDataNormalizationMode(DataNormalizationMode.Raw). I've shown this in notebook of the attached backtest.
Best,
Shile Wen
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.
Levi Freedman
Perfect, thanks.
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.
Alexandre Catarino
Hi David Thielen ,
Splits and Dividends were incorporated into the Slice object.
However, they are still accessible via OnData(Splits) and OnData(Dividends), since we haven't deprecated those overloads.
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.
Sachin Kholamkar
How does DataNormalizationMode.TotalReturn mode handle splits? With quantity or price?
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.
Kevin Wheeler
“The current, default behavior of QuantConnect is to fully adjust for splits and dividends, giving you an adjusted price which always equals today's price. This is ideal for easy charting and simplified portfolio modeling. We kept this as the default since the stock plots rely on adjusted pricing.”
Is this equal to DataNormalizationMode.TotalReturn? Otherwise what does it mean to “fully adjust for splits and dividends"?
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.
Simone Pantaleoni
Here the framework algo
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.
Vladimir
Simone Pantaleoni,
Good idea and in line with my personal preferences.
Thank you for sharing.
Before we start to add on top of this framework we need to fix some existing problem.
1.Every line in orders log has Warning: fill at stale price.
Try to change resolution for stocks and bond from Daily to Hour.
And change
self.TimeRules.AfterMarketOpen("SPY")
to
self.TimeRules.AfterMarketOpen("SPY", 31)
This should solve the problem.
Good luck .
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.
Peter Guenther
Interesting project, looking forward to the discussion. Well done, Simone Pantaleoni and Strongs!
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.
Strongs
Hi all guys, this is just a base from which to start. The starting idea is to also exploit the concept of in & out and the intersection of ROC by Vladimir . The LEI could actually be exploited for a dynamic selection of ETFs, essentially identifying phases of the economic cycle and then selecting groups of ETFs that perform best in that specific phase of the cycle.
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.
Simone Pantaleoni
New version with the fixes from Vladimir 😊
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.
Vladimir
Simone Pantaleoni,
Completed as requested!
The second problem is that you have initialized the position in QQQ,
which is contrary to the main logic at the beginning of backtest.
To solve this. I define
To make self.mom visible on the chart changed self.MOM to self.MOMP
Here is "SIMON LesFlex" modified by Vladimir
with changes I mention above and some cosmetic changes.
Enjoy.
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.
Strongs
The idea would be to turn the indicator like that
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.
.ekz. INVESTOR
First of all, great work :)
I've had some time to look at this, and I want to be sure i'm interpreting it correctly...
Questions:
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.
Simone Pantaleoni
Hi .ekz. ! many thanks for appreciating it. :)
Let me try to answer your questions:
Questions:
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.
.ekz. INVESTOR
Perfect, Simone Pantaleoni. Thanks for this.
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.
Simone Pantaleoni
Hi guys!
As suggested, we have been working behind the scene on applying the concepts shared above about the different phases of the market. Based on that, we apply ETF-selection accordingly, out of a basket of sectorial ETFs (we kept a similar switch to shift to bond in case of possible market downturn using the leading indicator)
Some improvement on Total Return, sharpe and so on.
Feel free to work on this release, fix it in case I've made mistakes (here I rely on Vladimir as PeerReview :P ) and improve it (there's still something to optimize - but don't want to share all in once so… work on it and share your outcomes with us! :) )
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.
Strongs
Surely there is still a lot of work to be done, but this is definitely a great start. Levels for identifying the phases of the business cycle with associated ETF groups was presented. We await more ideas from you to improve it.
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.
Frank Giardina
Great stuff Guys thanks for sharing. I have a question and a comment. I have a Quandl free account have not used it much. I plugged in my key and started looking at the algo. My question is how does the self.history statement get the Quandl data to sync up with the start of the algo? i see the request for the 1400 bars, so does the Quandl request use the start date of the algo as it start retrieval date? I see the data frame adjusting to the different start dates I tried. Any clarification greatly appreciated.
My comment is i have been following a youtube channel Hedgeeye. The gentleman who runs the channel is an ex-Hedge fund manager who also uses a macro view of investing. He uses inflation and gdp rates of change for his strategy much like this algo uses the KEI data as leading indicators.. He uses ETFs like this algo but also uses different styles based on his macro view of 4 Quadrants. Depending on the Quads as he calls them he picks the ETFs and the investment style (Momentum, V:alue, High Beta, Low Beta etc.)
GrowthInflationQuad 1acceleratingslowingQuad 2acceleratingacceleratingQuad 3slowingacceleratingQuad 4slowingslowingA full explanation of his approach is on Hedgeeye.com, but here is a link to his strategy
https://app.hedgeye.com/insights/77156-chart-of-the-day-what-works-in-which-quad?type=macro
Frank
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.
Frank Giardina
Sorry, the grid got messed up when i pasted it
Quad 1 Growth accelerating Inflation slowing
Quad 2 Growth accelerating Inflation accelerating
Quad 3 Growth slowing Inflation accelerating
Quad 4 Growth slowing Inflation slowing
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.
Varad Kabade
Hi Frank,
History method takes the StartDate as the anchor retrieves data before it for the requested period. Refer to the following source code.
returns the last 1400 bars of history but we have the option to pass start and end dates to the History method.
returns the historical data for custom 90 day period.
Refer to the attached backtest, which demonstrates both approaches just comment out any one.
Best,
Varad Kabade
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.
Frank Giardina
Varad,
Thank you for the explanation now i understand
Frank
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.
Frank Schikarski
Hi there,
interesting stuff!!
Here are my 2 cents:
And the results using QQQ and TLT only:
Results using an amended version of Sector ETF's:
Results using an overfitted version of Sector ETF's:
Suggestions for the way forward:
Have fun,
Frank
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.
Tom Penrose
Expanding on Frank's work, I've added to the number of assets allocated depending on the regime.
I've attempted to replicate an asset allocation chart that I have which tells you where you should put your money depending on the trajectory of the economy.
For example, in a scenario of better than expected growth forecasted, it suggests allocating to 37% US equities, 18% non-US equities, 25% US-fixed income, 3% non-US fixed income, 13% alternative investments, and keeping 4% cash.
This doesn't translate perfectly to this strategy but I've done a crude implementation that follows more ETF's weighted based on this chart. For the US-equities component I've maintained the same sectors suggested in the previous version, only with different weighting.
The optimal implementation of this version of the strategy in my opinion would be to use universe selection to choose the best companies in each index, rather than following a whole sector. I think this would increase performance dramatically. Unfortunately, I'm not advanced enough to do this sort of dynamic universe selection.
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.
Simone Pantaleoni
Thanks to Frank Giardina and Tom Penrose for the good work and for moving the thread forward!
You're going on the exact direction I was meant to drive this discussion, when we've started it :)
I've been a bit busy lately on other projects, but next step will be exactly as Tom outlined, about stock-selection to pick up best 4-5 stocks for each sector.
Challenge there is to make the code decently quick, so I think a quite strict pre-selection of stocks will be needed
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.
Frank Giardina
I think we got the wrong Frank, I made some comments and certainly want to help but Frank Schikarski did more meaningful work with his post.
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!