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 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 OptionsUniverseSelectionModel import OptionsUniverseSelectionModel from universe import getUniverse class MultidimensionalVerticalShield(QCAlgorithm): def Initialize(self): self.SetStartDate(2019, 3, 22) # Set Start Date self.SetEndDate(2019, 3, 29) self.SetCash(100000) # Set Strategy Cash self.consolidators = {} self.SetUniverseSelection(OptionsUniverseSelectionModel(self.SelectOptionsSymbols)) self.Schedule.On( self.DateRules.EveryDay(), self.TimeRules.Every(timedelta(minutes=120)), self.sellOptions) def SelectOptionsSymbols(self, utcTime): symbols = [ Symbol.Create(ticker, SecurityType.Option, Market.USA, f"?{ticker}") for ticker in getUniverse() ] self.Log(f'{self.Time}' + ' ,'.join([str(x) for x in symbols])) return symbols def sellOptions(self): chains = self.CurrentSlice.OptionChains for kvp in chains: symbol = kvp.Key.Underlying chain = kvp.Value #self.Log(f'{self.Time} :: Process {symbol}') def OnSecuritiesChanged(self, changes) : for security in changes.RemovedSecurities: symbol = security.Symbol self.Liquidate(symbol) consolidator = self.consolidators.pop(symbol, None) if consolidator is not None: self.SubscriptionManager.RemoveConsolidator(symbol, consolidator) for security in changes.AddedSecurities: symbol = security.Symbol if not symbol in self.consolidators and security.Type == SecurityType.Option: consolidator = self.Consolidate(symbol, Resolution.Daily, self.OnOptionConsolidated) self.consolidators[symbol] = consolidator def OnOptionConsolidated(self, bar): self.Log(f'{self.Time} :: {bar.Symbol.Value} - {bar}')
from Selection.OptionUniverseSelectionModel import OptionUniverseSelectionModel from datetime import date, timedelta class OptionsUniverseSelectionModel(OptionUniverseSelectionModel): def __init__(self, select_option_chain_symbols): super().__init__(timedelta(1), select_option_chain_symbols) def Filter(self, filter): ## Define options filter -- strikes +/- 3 and expiry between 0 and 180 days away return (filter.Strikes(-20, +20) .Expiration(timedelta(0), timedelta(30)))
def getUniverse(): #return ['SPY','AAPL','NFLX','GOOG','WMT', 'BABA','FB']#,'UVXY'] return [ 'SPY' ] # Your New Python File