Hey Folks:
These days some posts were about the problem of analyzing the backtests results, and the need of more log.
After thinking about it I realized that the engine already gives us all the information we need to fully analyze the backtest in the downloadable trades log. But that data need to be processed in order to obtain valuable information.
What can be considered valuable information? To begin, just the basics: the daily algorithm equity curve, the daily volume traded by stock, the daily result by stock. Maybe you can help me naming some others?
I see two options to extract the information from the trades data:
- Make a program to process the trades data.
- Make the engine generate the info and make it available just like the trades data: I think this is a better option because the engine already estimates those values through the rolling statistics. Or, at least, the info is easily available from Transaction and Trade QCAlgorithm properties.
So, what do you think?
I’m available to help in the development of this issue.
Jared Broad
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.
JayJayD
Jared Broad
var resultJsonString = File.ReadAllText("my-backtest-result.json"); var results = JsonConvert.DeserializeObject(resultJsonString);
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.
JayJayD
var dailyStatisticsByStock = TradeBuilder.ClosedTrades .GroupBy(trades => trades.Symbol, (symbol, trades) => new { ticket = symbol, dailyValues = trades .GroupBy(trade => trade.ExitTime.Date, (day, trade) => new { index = day.Date, profit = trade.Sum(t => t.ProfitLoss), volShares = trade.Sum(t => t.Quantity), volDollars = trade.Sum(t => t.Quantity * (t.ExitPrice + t.EntryPrice)) // Any other daily statistic by stock. } ) });
Is pretty ugly, and I'm not sure if the volume is correctly estimated, but is a first working draft. Some of you will note the Pandas Panel way of thinking, i.e. there is a DataFrame for each symbol with the daily statistics. As you can see only needs the TradeBuilder, so as far I understand, it can be called from anywhere in the engine. I'll research how to correctly make the volume estimations the and how to serialize this object to JSON. Cheers, JJJared Broad
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.
JayJayD
Bruce Vanstone
Can you please give a python example of how to do this... and what the name of the backtest object is after I have run a backtest.
I am quite happy to contibute time to developing advanced analytics, but it is unclear how to obtain the data to start with,
cheers,
Bruce
Derek Melchin
Hi Bruce,
To get the backtest results into the research environment, we can use
backtest = api.ReadBacktest(projectId, backtestId)
We are working on tools to help process the `backtest` result object. For now, we can access the Sharpe ratio for example with
backtest.Result.TotalPerformance.PortfolioStatistics.SharpeRatio
See the attached research notebook for an example.
The backtestId can be seen under the "Share" tab of the backtest results page
Best,
Derek Melchin
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.
Tzuo Hann Law
Hi I just tried to replicate this, but it did not work. Can someone confirm that this is functional please?
Arthur Asenheimer
It didn't work for me, too.
The commands api.Connected and backtest = api.ReadBacktest(projectId, backtestId) were successful, but backtest.Result yields a NoneType object.
Erol Aspromatis
I'm getting the same error, the API is not finding my backtest and retuirning it, rather it is creating a empty object.
AttributeError Traceback (most recent call last) <ipython-input-15-b8bc2d3efee3> in <module> ----> 1 backtest.Result.TotalPerformance.PortfolioStatistics.SharpeRatio AttributeError: 'NoneType' object has no attribute 'TotalPerformance'Jared Broad
Sorry about we made some fast-breaking changes before the holiday weekend and will push the fixes for them today. We move quickly and there will always be bugs in complex software. Microsoft is still patching Windows since 1989 =). But please respect the forum etiquette and not post bug reports to the forum -- please submit all bug reports to support@quantconnect.com so we can keep the forum focused on algorithm development.
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.
JayJayD
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!