Hey everyone!
I wanted to make an announcement that we have officially merged an update to Leans sampling and statistics implementation. This PR brings improvements to our sampling and statistics building in Lean to more accurately reflect the daily performance values for algorithms of all resolutions.
Specifically we now sample as a scheduled event attached to the algorithm at 12AM each day only storing one value a day for performance and benchmark values. Then later in the statistics builder we take the benchmark values and generate a percentage difference between each day. Then when generating our statistics that take daily portfolio performance and benchmark performance into account we have a perfectly aligned set of samples to compare.
This brings a significant change to our regressions algorithms, which you can see in the PR details (165 files changed total) but this is expected. A great highlight of this improvement would be to look at a basic buy and hold algorithm of a security with the same security as the benchmark. What we would expect is the benchmark performance and daily performance to line up almost perfectly, this would result in a Beta value of ~1.
Below I will post a set of Backtests using different resolutions of this exact scenario using SPY.
Colton Sellers
Daily Resolution (Beta = 0.994)
Colton Sellers
Hour Resolution (Beta = 0.997)
Colton Sellers
Minute Resolution (Beta = 0.995)
Laurent Crouzet
Hey Colton Sellers
Thanks for these explanations.
Is it the same during a LIVE simulation (for both long and short positions)? The discrepancy generated by different ex-dividend dates and pay dates used to generate different results previously.
Colton Sellers
Hey Laurent Crouzet,
Of course!
Thanks for looking deeper into these cases, I'm glad its consistent.
As for your question, I'm not certain on the affect it would have in Live on those types of cases. 🤔 I will say that in general this change should be more accurate all around. I am curious though, I was not aware of those types of discrepancies.
Laurent Crouzet
Colton Sellers
Thanks for your message.
The discrepancy I was referring to above is the fact that:
- for backtests, the dividends are simulated to be delivered on the ex-dividend date, even if, in the real world, the dividends are not received on the ex-dividend date
- during live (for instance in Alphas), as ex-dividend dates and pay dates are NOT the same, there were some pretty big discrepancies when there are dividend payments.
I proposed, as is done by Interactivebrokers which add “dividend receivables” to the real account as soon as the ex-dividend date, to do the same in live trading, even if the CASH dividend has not been really received, so that the returns (and Beta, and correlations…) are the same for at time the backtests AND live trading.
Colton Sellers
Ah I see,
These particular changes were focused on correcting some issues with our sampling period and collection of values for our statistics and did not touch anything related to dividend application to the portfolio, but that is a very interesting issue. I'll have to look and see if we have an issue for that open on our Github. Sounds like it may be difficult to reproduce 🤔
Laurent Crouzet
Thanks for your interest.
To reproduce the issue, you can check the dividend calendar and open a new position the day before the ex-dividend date (for instance, COP or FRC yesterday) and check what happens in “live” (or paper) trading (no dividend added).
Then a couple of days later, you can BACKTEST (with “adjusted” prices) the same investment on the same dates, and the returns will not be the same, as the backtest will simulate receiving the dividend by adjusting the price.
You can also check the same investment's discrepancy for shorts (in the real world, having a short position means paying the “short dividend”)
If I may help you for anything, please just let me know.
Laurent Crouzet
https://marketchameleon.com/Calendar/Dividend
Colton Sellers
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!