Hi, guys,
I found
Portfolio[spySymbol].LastTradeProfit
can read the profts you made from last trade. But, how can I get current trade profts..
QUANTCONNECT COMMUNITY
Hi, guys,
I found
Portfolio[spySymbol].LastTradeProfit
can read the profts you made from last trade. But, how can I get current trade profts..
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.
Alexandre Catarino
For current profit/loss of a trading security, please use:
// Current profit [$] var profitDollarValue = Portfolio[symbol].UnrealizedProfit; // Current profit [%] var profitPercentage = Portfolio[symbol].UnrealizedProfitPercent;
Please checkout the documentation under the Securities and Portfolio section for more information.
Ariel Silahian
I'm having hard time to get the same for options. This is getting me always 0
decimal uPnl = Portfolio[OptionSymbol].UnrealizedProfitPercent
Jing Wu
Hi Ariel, UnrealizedProfit only includes open trades (e.g you Buy 1 share of SPY, price moves and your *unrealized* profit/loss moves with it. After you liquidate everything (i.e. close all open positions), Unrealized profit goes to zero.
Sean Larsgard
Is there an easy way to liquidate an open position when the UnrealizedProfit is ≥ x? (Using python)
Fred Painchaud
Hi Sean,
Yes. Something like this, depending where exactly you are trying to code the logic:
Fred
Sean Larsgard
Thanks Fred! I will give it a run and see how this works. Thank you!
Greg Kendall
Can we just liquidate everything at the end of the algorithm? This way anything remaining unrealized will be sold … right??? Is there something I don't understand about doing that?
Fred Painchaud
Hi Greg,
You can do it for sure. But my understanding of Sean's question was that he wanted to liquidate not at the end of the backtest but when the unrealized profit was above a certain threshold. Basically, a take profit.
When live trading, liquidating “at the end” is not something recommended 😊.
Fred
Axist
Can you do something like this as well?
if self.Portfolio[EntirePortfolio].UnrealizedProfit >= x:
self.Liquidate(EntirePortfolio)
What would the syntax be
Vladimir
Axist,
--> What would the syntax be
It may be like in "Stocks-Bond Portfolio with Take Profit".
Lifan
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!