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
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
from QuantConnect.Data.Market import *
from QuantConnect.Data.Consolidators import *
from datetime import *
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Securities.Option import OptionPriceModels
import decimal as d 
import operator

class BasicTemplateOptionsAlgorithm(QCAlgorithm):
                        
    def Initialize(self):   
        self.SetStartDate(2019, 1, 3)
        self.SetEndDate(2019, 1, 5)
        #self.SetCash(200000)
        self.symbolData = dict()
        self.symbols = []
        self.symbols_two =[]
        self.tr = dict()
        self.high = dict()
        self.low = dict()
        self.tickers_one = [
"AAPL", "FB", "TSLA", "AMD", "AMZN", "BABA", "BAC", "MSFT", "NFLX", "MU", "NVDA", "SNAP", "GE", "DIS", "T", "BA", "ROKU", "NIO",
 "CRM", "INTC", "X", "TWTR", "QCOM", "CSCO", "JPM", "CZR", "WDC", "JD", "GOOGL", "TEVA", "F", "WMT", "PCG", "C", "SQ", "FCX", "ADBE", "CGC"
]

        for ticker in self.tickers_one:
            option = self.AddOption(ticker)
            self.symbols.append(option.Symbol)
            option.SetFilter(-15, -1, timedelta(60), timedelta(90))
            self.Settings.DataSubscriptionLimit = 1000000
            option.PriceModel = OptionPriceModels.CrankNicolsonFD()
            
        self.equity_symbols = [x.Underlying for x in self.symbols]    
        history = self.History(self.equity_symbols, 90, Resolution.Daily).sort_values(by=["symbol", "high"], ascending=[1,0])
        for symbol in self.equity_symbols:
            self.high[symbol] = history.loc[str(symbol.ID)]["high"][0]
        history = history.sort_values(by=["symbol", "low"], ascending=[1,1])
        for symbol in self.equity_symbols:
            self.low[symbol] = history.loc[str(symbol.ID)]["low"][0]
            self.tr[symbol] = self.high[symbol] - self.low[symbol]
            
        self.AddEquity("SPY")
        self.Schedule.On(self.DateRules.EveryDay("SPY"),
                        self.TimeRules.At(12,40),
                        self.OnceADay)
                        
                        
        
        self.Log("initialize")
        self.slice = None
        
    def OnceADay(self):
        
            
            
            self.Log("before")
            for security in self.ActiveSecurities.Keys:
                self.Log(f'Security in Universe: {security.Value}')

            for security in self.ActiveSecurities.Keys:
                self.RemoveSecurity(security)
                
            self.Log("after")
            for security in self.ActiveSecurities.Keys:
                self.Log(f'Security in Universe: {security.Value}')
                
            tickers_two = ["EXAS", "ARQL", "PVTL", "LUV", "UAA", "BBT", "AMC", "OC", "GIS", "HSY", "FSLR", "CBAY", "OLED", "AKS", "HPQ", "EROS", "KL", "NVTA", "CYBR",
 "PXD", "PSTG", "CECE", "CRC", "AMT", "FTR", "TLRD", "EOG", "PAYS", "ANET", "WB", "DVN", "ERI", "IRBT", "JBLU", "AMTD", "KMB", "CNTY",
 "MOMO", "PVG", "ETSY", "MT", "DG", "TTWO", "SVRA", "KEM", "YETI", "WHR", "NLSN", "CBS", "BBY", "WMB", "STM", "CDE", "YUM", "TRGP",
 "HST", "DOW", "COUP", "ZUO", "LYB", "EPD", "RAD", "ANTM", "HGV", "ALGN", "FAST", "FEYE", "ADM", "MOS", "MDLZ", "DOMO", "GT", "CMI", "AMBA"

]
            for ticker in tickers_two:
                option = self.AddOption(ticker)
                self.symbols_two.append(option.Symbol)
                option.SetFilter(-15, -1, timedelta(60), timedelta(90))
                self.Settings.DataSubscriptionLimit = 1000000
                option.PriceModel = OptionPriceModels.CrankNicolsonFD()
                
            self.equity_symbols = [x.Underlying for x in self.symbols]    
            history = self.History(self.equity_symbols, 90, Resolution.Daily).sort_values(by=["symbol", "high"], ascending=[1,0])
            for symbol in self.equity_symbols:
                self.high[symbol] = history.loc[str(symbol.ID)]["high"][0]
            history = history.sort_values(by=["symbol", "low"], ascending=[1,1])
            for symbol in self.equity_symbols:
                self.low[symbol] = history.loc[str(symbol.ID)]["low"][0]
                self.tr[symbol] = self.high[symbol] - self.low[symbol]