Hello all!
I have been stuck for a while trying to figure out how to track the live bid or ask price of my purchased option contract in the OnData() method. When I purchase the contract, it is in its own BuyCall()/BuyPut() method, however, I want to access the live price from the OnData() in order to track % gain or loss to make sell decisions. The issue is that the contract is in another method and I can't figure out how to either pass the contract back to OnData() or access the live price through a qc function call. I have tried using Securities, but again I dont have the contract information in the OnData method to use that. I have also tried using the different Portfolio SecurityHolding calls from the following page, but to no avail. Below is a code snippet where it prints that we are invested, but then gives 0.0 for both. Is it because it is looking for holdings of shares and not contracts? What is the best way to track live option prices in OnData() if you buy the contract in a method that is not OnData()?
if self.Portfolio:
self.Debug("We are invested!")
self.Debug(str(self.security_holding.UnrealizedProfitPercent))
self.Debug(str(self.security_holding.HoldingsValue
Jclute17
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!