Moving average of a Portfolio derive value

Back

Hello,

In the backtest attached, I have used the starting cash and Portfolio.TotalPortfolioValue property to calculate the Portfolio Drawdown overtime and plot it (lines 54-70).

I have also used an ExponentialMovingAverage (line 25) which I update manually in the OnData block with the calculated Drawdown value (line 64).

However, the value of the EMA(30) seems way to close to the calculated Drawdown value when looking at the plot. The plot makes more sense when I significantly increase the period of the EMA (e.g. 250). I suspect this is an issue with the resolution of the EMA which is not in synch with the rest of the algo (consolidated 24 hourly bars for that example), but I cannot figure out how to fix it. Can somebody help?

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 Pi..R,

The EMA of the portfolio drawdown is so similiar to the portfolio drawdown because of how the algorithm updates the EMA. In the algorithm published above, the portfolio drawdown is calculated in OnData during each loop through our `DataDico` dictionary, then it updates the drawdown EMA with this portfolio drawdown. As a result, the portfolio drawdown EMA is updated several times for each call to OnData. To fix this issue, we just need to move the portfolio calculations outside the for-loop in OnData.

See the attached backtest for the full solution file.

Best,
Derek Melchin

1

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.


Argh, over a year that I have started coding and still making some basic mistakes, sorry about that. Thanks a lot Derek!

0

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