Hello! I wonder if it's possible to capture any custom analytical data series during backtest, such that the data would appear in the backtest logs and could then be applied for later analysis of performance during backtest?
In the simplest case, I'd like to be able to capture the data being produced by indicators during backtest, in order to review the performance of each indicator.
In MetaTrader4 for example, this would generally be possible with the chart series produced in each MT4 backtest, such that the chart would contain both the visual representation of each indicator and the actual data series as produced by each indicator.
As a feature, I think that this could be of some help when developing any number of custom indicators. Personally, I'd like to take a look at the DSP-oriented technical analysis methods published by John F. Ehlers.
Previously, I've been able to port a rendition of John F. Ehlers' SuperSmoother from TradeStation EasyLanguage to Cython/Python, along with a visual representation in pyqtgraph. Perhaps it could be of use for an indicator towards algorithmic trading. However, I believe that I'd need to be able to review how the indicator implementation would be performing under each backtest.
After some local backtests with quantconnect's lean tooling, I wasn't able to locate any of the indicator data under the backtest/**/*.json files.
Mia Alissi
To capture and analyze custom analytical data series during a backtest in QuantConnect, you can use the following methods and properties from the
QCAlgorithm
class:Initialize Indicators: In your algorithm's
initialize
method, set up the indicators you want to track. Ensure they are registered with the appropriate symbols and resolutions using theregister_indicator
method.Use the
record
Method: Utilize therecord
method within theon_data
method to log the values of your indicators. This method allows you to plot a chart using a string series name and a decimal value. It is an alias for theplot
method.Create Custom Charts: Define custom charts and series in the
initialize
method to visualize the indicator data. Use theadd_chart
andadd_series
methods to set up these visualizations.Log Indicator Values: Within the
on_data
method, continuously update the custom charts with the current values of your indicators using theplot
method.Store Data for Analysis: If you need to analyze the data post-backtest, consider using the Object Store to save the indicator values for later retrieval and analysis. You can use the
object_store
property to save and retrieve data.Here's a basic example to illustrate these steps:
This setup allows you to capture and visualize the performance of your indicators during a backtest. You can review the charts in the backtest results and use the Object Store to save data for further analysis.
Sources: Custom Charting Algorithm, Results - QuantConnect.com, Custom Indicator Algorithm, Debugging Tools - QuantConnect.com, Indicator Suite Algorithm
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.
Sean Champ
Thanks! I'll take a look at the examples.
In fact, I was already using the plot() method, however the plot data was not appearing in the local backtest logs.
Maybe the object store could be of use here? I hope it produces something under the local backtest, thanks!
Sean Champ
This seems to have worked out, using an object store and a JSON dump of a Pandas dataframe from the indicator history. The data is then available locally under ‘<cloud_root>/storage/backtest/**/local/**'
This uses a 'params' mapping created under ‘__init__’ to store the indicator and the primary symbol for the indicator when created under initialize()
It seems that the timestamp in the file path may be aligned to a historical timestamp in backtest quote series.
Health, all!
Sean Champ
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!