QuantConnect’s built-in Return statistic is tied to the current live deployment. If you stop and redeploy an algorithm, its runtime statistics reset. This can make the displayed return misleading when an algorithm has been running across multiple deployments. QuantConnect confirms this behavior in its live-results documentation.
For example, my live node currently shows a built-in return of -1.7%, while the actual return measured from my original starting capital is +0.31%.
I wanted a simple dashboard statistic that always measures performance from the same original account value, regardless of how many times the algorithm is stopped and restarted.
from AlgorithmImports import *
from datetime import timedelta
class MyAlgorithm(QCAlgorithm):
def initialize(self):
self.absolute_return_starting_capital = 100000
self.set_cash(self.absolute_return_starting_capital)
self.schedule.on(
self.date_rules.every_day(),
self.time_rules.every(timedelta(minutes=1)),
self.update_absolute_return
)
self.update_absolute_return()
def update_absolute_return(self):
if self.absolute_return_starting_capital <= 0:
return
portfolio_value = float(
self.portfolio.total_portfolio_value
)
absolute_return = (
portfolio_value
/ self.absolute_return_starting_capital
- 1
)
self.set_runtime_statistic(
"AbsRet%",
f"{absolute_return:.2%}"
)Change this value to the portfolio value from which you want to measure performance:
self.absolute_return_starting_capital = 100000In a backtest, set_cash sets the simulated starting balance. In live trading, QuantConnect ignores set_cash and loads the actual balances from the brokerage. The separate absolute_return_starting_capital variable is therefore the fixed reference point used by this calculation. QuantConnect initialization documentation
When the algorithm restarts, the custom statistic is recreated from:
current portfolio value / original starting capital - 1It doesn’t depend on the previous deployment’s runtime statistics. As long as the same original starting-capital value remains in the code, the calculation continues from the same baseline.
The result appears as AbsRet% in the runtime-statistics banner and refreshes every minute. This has been much more useful to me than the deployment-specific Return figure because it shows the performance of the account from the point at which I originally started tracking it.
Martin
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!