I am looking to access the realized profit/loss during the day. When backtesting, how do we get the realized profit at any instant for that day alone? thanks.
I am looking to access the realized profit/loss during the day. When backtesting, how do we get the realized profit at any instant for that day alone? thanks.
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 Ags,
To calculate the daily realized profit/loss, we can add some properties in Initialize
self.yesterday_total_profit = 0
self.yesterday_total_fees = 0
To calculated the daily realized profit and loss intraday, we can call
def get_daily_realized_pnl(self):
daily_gross_profit = self.Portfolio.TotalProfit - self.yesterday_total_profit
daily_fees = self.Portfolio.TotalFees - self.yesterday_total_fees
return daily_gross_profit - daily_fees
We just need to ensure we update the `yesterday` values at the end of each day
def OnEndOfDay(self):
self.yesterday_total_profit = self.Portfolio.TotalProfit
self.yesterday_total_fees = self.Portfolio.TotalFees
See the attached backtest for reference.
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.
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!