Hi All,
Is there any example for Options trading in c# that uses OptionChainProvider.GetOptionContractList ?
Thanks
Nik
QUANTCONNECT COMMUNITY
Hi All,
Is there any example for Options trading in c# that uses OptionChainProvider.GetOptionContractList ?
Thanks
Nik
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.
Michael Manus
you know the github project. There I found this
Nik milev
Thank you Michael and Gustavo!
Michael Manus
hehe :)
Artemiusgreat
Here is an example of selling Short Strangle (Call + Put) for premium. Options are monthly, Unfortunately, LEAN doesn't allow to get weekly and daily options.
There is also an implementation fir SetFilter, but OptionChainProvider seems more reliable.
Jared Broad
All the data is there =)
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.
Artemiusgreat
Weekly options in a Chain Provider would be a significant step forward. In the meantime, here are some other examples for C#. All examples are for MSFT and strike prices are pretty random, so strategies can definitely be optimized.
1. Long Strangle
http://www.theoptionsguide.com/long-strangle.aspx
Artemiusgreat
2. Long Straddle
http://www.theoptionsguide.com/long-straddle.aspx
Artemiusgreat
3. Short Strangle
http://www.theoptionsguide.com/short-strangle.aspx
Artemiusgreat
4. Short Straddle
http://www.theoptionsguide.com/short-straddle.aspx
Artemiusgreat
5. Bear Call Spread
http://www.theoptionsguide.com/bear-call-spread.aspx
Artemiusgreat
6. Bull Put Spread
http://www.theoptionsguide.com/bull-put-spread.aspx
Artemiusgreat
7. Long Condor
http://www.theoptionsguide.com/reverse-iron-condor.aspx
Artemiusgreat
8. Short Condor
http://www.theoptionsguide.com/iron-condor.aspx
Artemiusgreat
Some strategies are harder to implement, because I can't see how to compare Bid / Ask prices of options in a chain. For example, Risk Reversal - I found some Put option that I'd like to sell, so now I need to find Call option that costs less that my Put option. Something like this.Now we found Put option whose strike price is from -$0 to -$3 below underlying price
var atmPuts = from c in contracts where c.ID.OptionRight == OptionRight.Put where price - c.ID.StrikePrice < 3 && price - c.ID.StrikePrice >= 0 where (c.ID.Date - Time).TotalDays < 35 && (c.ID.Date - Time).TotalDays > 0 select c; var contractAtmPut = atmPuts .OrderBy(o => o.ID.Date) .ThenByDescending(o => price - o.ID.StrikePrice) .FirstOrDefault();
Now we have Put option that we want to sell and get its Premium. Let's assume Bid price of this option is 5.25, so we can get $525 by selling it. I'm neutral to bullish, and to increase probability of my trade I need to find Call option that can increase my profit but cost of that Call shouldn't exceed cost of the premium from my Put option, because I need this premium to compensate commission and possible market move against me, so I want to find Call option whose Ask price is not more than 4.25
var otmCalls =    from c in contracts   where c.ID.OptionRight == OptionRight.Call   where contractAtmPut.BidPrice - c.AskPrice <= 1.0 // difference should be more than $100   where (c.ID.Date - Time).TotalDays < 35 && (c.ID.Date - Time).TotalDays > 0   select c;
Question: how to get these Ask / Bid prices?
Michael Manus
nice stuff
Nikolay Chikhachev
The correct approach to building spreads is based on Deltas rather than prices.
Alexandre Catarino
Thank you artemiusgreat for the strategies in C#.
Jing Wu has made a tutorial series on options with examples in python.
Unfortunately, we cannot build spread based on deltas when we use OptionChainProvider at the moment.
Erik Balun
You can get spreads after using OptionChainProvider with a history call of the contracts in question.
When calling the History function with option contracts it returns a dataframe with Quotebars including ask and bid prices.
contractList = self.OptionChainProvider.GetOptionContractList(symbol, self.Time)
   Â
    # filter and sort contracts then grab best contract        Â
    contracts = [i for i in contractList if i.ID.OptionRight is OptionRight.Call and
                        i.ID.StrikePrice < (1 + self.OTM) * self.priceData[0] and
                        self.DTE - self.DTErange < (i.ID.Date - self.Time).days < self.DTE + self.DTErange]
   Â
    history = self.History(contracts, 1, Resolution.Minute)
    history['spread'] = history.askclose- history.bidclose
    for contract in contracts:
      contract.spread = history.loc(contract)['spread']
   Â
    if len(contracts) > 0:
      contract = sorted(contracts,key=lambda x: (x.spread, x.ID.StrikePrice, -(x.ID.Date - self.Time).days))[0]
Â
Nik milev
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!