I want to fetch the portoflio vlaues at the end of specific months (e.g. March, June, September and December) from a backtest (given project_Id and backtest_id).
However, when i follow the online doc on Meta Analysis/Backtest Analysis, the code doesnt work:
URL:
Code:
equity = equity_chart.series["Equity"].values
drawdown = drawdown_chart.series["Equity Drawdown"].values
benchmark = benchmark_chart.series["Benchmark"].values
equity = equity_chart.series["Equity"].values
drawdown = drawdown_chart.series["Equity Drawdown"].values
benchmark = benchmark_chart.series["Benchmark"].values
---------------------------------------------------------------------------
KeyNotFoundException Traceback (most recent call last)
Cell In[27], line 4
2 drawdown_chart = backtest.charts["Drawdown"]
3 benchmark_chart = backtest.charts["Benchmark"]
----> 4 equity = equity_chart.series["Equity"].values
5 drawdown = drawdown_chart.series["Equity Drawdown"].values
6 benchmark = benchmark_chart.series["Benchmark"].values
KeyNotFoundException: The given key 'Equity' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at InvokeStub_Dictionary`2.get_Item(Object, Span`1)
at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
Please advise.
Thanks,
Mia Alissi
Here’s how you can diagnose and resolve the issue with missing series keys in your backtest:
This inspection helps you handle cases where the series key ("Equity") might be missing or renamed.
Run this code in your environment to see exactly which charts and series your backtest contains. Once you know the right series key, you can proceed to extract and analyze the portfolio values, such as for end-of-quarter reporting. Let me know if you want code to extract and analyze the values once you have the correct key!
Sources: Backtest Analysis - QuantConnect.com, Live Analysis - QuantConnect.com, Can Crude Oil Predict Equity Returns
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.
Kubid
Louis Szeto
Hi Kubid
You can try the following code snippet for a completed backtest:
Best
Louis
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.
Kubid
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!