As the title mentions; is there a way to retain the runtime statistics? (i.e Net Profit)
QUANTCONNECT COMMUNITY
As the title mentions; is there a way to retain the runtime statistics? (i.e Net Profit)
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.
Mia Alissi
Yes, you can retain the runtime statistics such as 'Net Profit' by using the
SetRuntimeStatistic
method in your algorithm. This method allows you to set a runtime statistic for the algorithm which can be a string or a number.Here is how you can do it in Python:
Replace
value
with the calculated net profit.Please note that if you stop and redeploy a live algorithm, the runtime statistics are reset.
For more details, you can refer to the QuantConnect Documentation.
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.
Muhammad Yusuf Bin Salleh
Thanks again Mia Alissi . You're awesome!
Muhammad Yusuf Bin Salleh
Mia Alissi My apologies, where should i put that code in again? under def Initialize(self)?
I tried to re-deploy though, but it still shows “0”
Mia Alissi
The
SetRuntimeStatistic
method can be used in any part of your algorithm where you calculate the net profit and want to set it as a runtime statistic. It doesn't necessarily have to be in theInitialize
method.However, please note that the
SetRuntimeStatistic
method only sets the value of the statistic at the moment it is called. If you want to continuously update the net profit statistic, you should call this method each time the net profit changes, for example, after a trade.Here is an example of how you might use it:
In this example, the 'Net Profit' statistic is updated each time a trade is closed.
If it still shows "0", it might be because the
value
you are setting is actually zero, or the method is not being called. Make sure the code section withSetRuntimeStatistic
is actually being executed.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.
Muhammad Yusuf Bin Salleh
I've redeployed it and it still shows “0”.
I've added both under onTrade; when it checks if i'm invested or not. It still shows “0”
Mia Alissi
Your code seems correct in terms of setting the 'Net Profit' runtime statistic. The
SetRuntimeStatistic
method is being called in the right places. However, if it's still showing "0", it might be because theself.Portfolio.TotalProfit
is actually zero at the times whenSetRuntimeStatistic
is being called.Remember that
self.Portfolio.TotalProfit
gives the total profit of your portfolio at the moment it is called. If no trades have been made or if the net profit from trades is zero, thenself.Portfolio.TotalProfit
will be zero.If you expect
self.Portfolio.TotalProfit
to be non-zero and it's still showing "0", you might want to add some logging to your algorithm to check the values ofself.Portfolio.TotalProfit
at the times when you are callingSetRuntimeStatistic
. For example:This will print the total profit to the console, which can help you debug why it's showing "0".
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.
Muhammad Yusuf Bin Salleh
It doesnt get the information from my ibkr account? I assume it will since the algo is being fed with the information.
Mia Alissi
QuantConnect does indeed connect to your Interactive Brokers (IBKR) account for live trading and can access real-time data from your account. However, the
self.Portfolio.TotalProfit
in your algorithm refers to the total profit made by the trades executed by the algorithm itself, not the total profit of your entire IBKR account.If you want to access account-specific information from your IBKR account, you might need to use the brokerage-specific functionalities provided by the LEAN engine. However, the specifics of how to do this are not provided in the information extracts given.
For more details, you can refer to the QuantConnect Documentation.
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.
Muhammad Yusuf Bin Salleh
Thats unfortunate. Redeploying is required every weekend in regards to 2FA, does that mean that the runtime statistics will keep resetting everytime? There is no way we can keep track of the Net Profit of our algo trading? Is there a way for a workaround on this? Jared Broad Mia Alissi .
Whats the purpose of this being algo/automatic trading if i can even monitor my profit and loss of my trades. Very disappointing.
Jared Broad
The IBGateway connection restarts every week - but it doesn't shut down the algorithm. However, restarts happen and you have to plan for them.
The best way to track total profit long term is “ending - starting equity” balances. Assuming you started with $12,345 you could do: self.Portfolio.TotalPortfolioValue - 12345
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.
Muhammad Yusuf Bin Salleh
Thanks Jared Broad ! That will work, appreciate your reply
Muhammad Yusuf Bin Salleh
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!