| Overall Statistics |
|
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -8.164 Tracking Error 0.229 Treynor Ratio 0 Total Fees $0.00 |
from QuantConnect.Algorithm import *
from QuantConnect.Securities.Option import OptionPriceModels
class BasicTemplateOptionsFilterUniverseAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 1, 1)
self.SetEndDate(2019, 1, 15)
self.SetCash(100000)
self.option = self.AddOption("AAPL")
self.option.SetFilter(-3, +3, 0, 31)
self.optionCall = None
def OnData(self, data):
if self.optionCall is None:
self.TradeOptions(data)
else:
self.Plot("BidPrice", "Current", self.Securities[self.optionCall.Symbol].BidPrice)
self.Plot("BidPrice", "Original", self.optionCall.BidPrice)
def TradeOptions(self, data):
for symbol, chain in data.OptionChains.items():
# sorted the optionchain by expiration date and choose the furthest date
expiry = sorted(chain, key = lambda x: x.Expiry, reverse=True)[0].Expiry
# filter the call and put contract
call = [i for i in chain if i.Expiry == expiry and i.Right == OptionRight.Call]
# sorted the contracts according to their strike prices
call_contracts = sorted(call, key = lambda x: x.Strike)
if len(call_contracts) == 0: return
self.optionCall = call_contracts[0]