Hi all,
i would like to drilldown into the details on the backtesting result.
- my backtest is that i will pick some stocks from universe and buy it.
- i found that the result is not good and i would like to drill down to details to avoid losing too much money on individual trades
- I want to load the backtesting result to research environment ( i knew that i can use api backtestorder to do so)
- i want to find out top5 losing trade and further analysis it
- My question is, is there any way to find out pnl or each trade? It seems like i need to write my own code to match the sell order and calculate on my own. Is there any library to do so or if there is any code snippet it would be appreciated
Non Compete
i think you can download the backtest json directly from quant connect cloud. or if you run it locally it will be generated. order csv can be download from cloud backtest as well. not sure which has pnl per trade
Enjolras Leigh
Thx for reply, indeed, i am looking for the way to calculate pnl from trade
eg
i buy apple at 20230101 100 share $150
and then i sell
apple at 20230102 100 share $151
i want to know i earned $100 from this trade
below is some i can download
20230101,appl,100,150
20230102,appl,-100,151
but i want to find out i earned $100 from 20230101 purchase of appl
i knew that the code is not so complicated. but I don’t want to reinvent the wheel . hope that there is reuseable libraries or code for the purpose
Nico Xenox
Hey Enjolras Leigh
you could make a data frame adding the symbols and the last made profit and then import that dataframe via objectstore to your notebook.
This will only work if you buy into the up direction and sell to the down direction. If you also short stocks you might want to change the if statement. I also added time and quantity maybe it might help you.
At the end you have to add this:
and in the notebook you will have to access it like this:
Hope it helps!
Best,
Nico
Enjolras Leigh
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!