| Overall Statistics |
|
Total Trades 19 Average Win 1247.40% Average Loss -1.97% Compounding Annual Return 254.221% Drawdown 9.600% Expectancy 69.470 Net Profit 1157.630% Sharpe Ratio 10.198 Probabilistic Sharpe Ratio 7.959% Loss Rate 89% Win Rate 11% Profit-Loss Ratio 633.23 Alpha 76.713 Beta 0.352 Annual Standard Deviation 7.525 Annual Variance 56.629 Information Ratio 10.187 Tracking Error 7.526 Treynor Ratio 217.896 Total Fees $273727.50 Estimated Strategy Capacity $25000.00 Lowest Capacity Asset SPY 2ZE1VVCOOOW2U|SPY R735QTJ8XC9X |
class MuscularFluorescentYellowFox(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2011, 1, 1) # Set Start Date
self.SetEndDate(2012, 12, 31)
self.SetCash(1000000) # Set Strategy Cash
spy = self.AddEquity("SPY", Resolution.Minute)
spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
self.spy = spy.Symbol
self.Settings.FreePortfolioValuePercentage = 0.00
# schedule trading at end of every week
self.Schedule.On(self.DateRules.WeekEnd("SPY"), \
self.TimeRules.BeforeMarketClose("SPY", 10), \
self.Trade)
self.percentage = 0.98
# put option
self.OTM = 0.6
self.contract_n = None
self.threshold_time_n = 60
self.lower_thr = self.threshold_time_n * 2 - 10
self.upper_thr = self.threshold_time_n * 2 + 10
def Trade(self):
self.insurance_r(self.CurrentSlice)
def insurance_r(self, slice):
if self.contract_n is None:
self.contract_n = self.GetContract(slice, self.OTM, self.lower_thr, self.upper_thr)
elif self.contract_n:
if not self.Portfolio[self.contract_n].Invested:
self.SetHoldings(self.contract_n, (1 - self.percentage))
self.UnderlyingPrice = self.Portfolio[self.spy].Price
self.Log(str("CTR: [QTY_BUY, UnderlyingPrice, Option_Price, Strike] = ") + str(self.contract_n) + str(":") +
str([self.Portfolio[self.contract_n].Quantity, self.Portfolio[self.spy].Price, self.Portfolio[self.contract_n].Price,
self.contract_n.ID.StrikePrice]))
self.UnderlyingPrice = self.Portfolio[self.spy].Price
if (self.contract_n.ID.Date - self.Time).days < self.threshold_time_n:
quantity = self.Portfolio[self.contract_n].Quantity
self.Liquidate(self.contract_n)
self.Log(str("CTR: [LQD_ROLL, SPY_Price, Option_Price, Strike]: ") + str(self.contract_n) + str(":") +
str([quantity, self.Portfolio[self.spy].Price, self.Portfolio[self.contract_n].Price,
self.contract_n.ID.StrikePrice]))
self.RemoveSecurity(self.contract_n)
self.contract_n = None
self.contract_n = self.GetContract(slice, self.OTM, self.lower_thr, self.upper_thr)
def GetContract(self, slice, strike_OTM, lower_thr, upper_thr):
upperStrike = (slice[self.spy].Price * (1 - strike_OTM)) - (slice[self.spy].Price * (1 - strike_OTM))%5 + 10
lowerStrike = (slice[self.spy].Price * (1 - strike_OTM)) - (slice[self.spy].Price * (1 - strike_OTM))%5
contracts = self.OptionChainProvider.GetOptionContractList(self.spy, self.Time)
puts = [x for x in contracts if x.ID.OptionRight == OptionRight.Put]
puts = sorted (sorted(puts, key = lambda x: x.ID.Date, reverse = True), key = lambda x: x.ID.StrikePrice)
puts = [x for x in puts if lowerStrike <= x.ID.StrikePrice <= upperStrike]
puts = [x for x in puts if lower_thr < (x.ID.Date - self.Time).days <= upper_thr]
sort_strikes = sorted(puts, key = lambda x: x.ID.StrikePrice, reverse = False)
sorted_puts = sorted(sort_strikes, key = lambda x: (x.ID.Date - self.Time).days, reverse = True)
if len(sorted_puts) == 0:
return None
option = self.AddOptionContract(sorted_puts[0], Resolution.Minute)
option.PriceModel = OptionPriceModels.BinomialTian()
self.Log("Option_Put: [Symbol, Strike, Expiry, Right]" + str(option) + str([option.StrikePrice, option.Expiry, option.Right]))
return sorted_puts[0]