| Overall Statistics |
|
Total Trades 390 Average Win 0.07% Average Loss -0.13% Compounding Annual Return -99.402% Drawdown 19.500% Expectancy -0.833 Net Profit -18.595% Sharpe Ratio -1.322 Probabilistic Sharpe Ratio 0.297% Loss Rate 89% Win Rate 11% Profit-Loss Ratio 0.55 Alpha 0.742 Beta -13.131 Annual Standard Deviation 0.73 Annual Variance 0.533 Information Ratio -1.46 Tracking Error 0.751 Treynor Ratio 0.074 Total Fees $5602.00 Estimated Strategy Capacity $21000000.00 Lowest Capacity Asset SPY WKNGGS989CCM|SPY R735QTJ8XC9X |
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from datetime import timedelta
import pandas as pd
class AlertFluorescentOrangeJackal(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017, 5, 1)
self.SetEndDate(2017, 5, 15)
self.SetCash(100000)
equity = self.AddEquity("SPY", Resolution.Minute)
equity.SetDataNormalizationMode(DataNormalizationMode.Raw)
self.equity = equity.Symbol
self.SetBenchmark(self.equity)
option = self.AddOption("SPY", Resolution.Minute)
self.symbol = option.Symbol
# set our strike/expiry filter for this option chain
option.SetFilter(-10, 10, timedelta(0), timedelta(100))
def OnData(self, data):
# check if we alreadz invested in option
option_invested = [x.Key for x in self.Portfolio if x.Value.Invested and x.Value.Type==SecurityType.Option]
# if option is invested and it is close to expiration (4 days till expiration), we close the position
if option_invested:
if self.Time + timedelta(4) > option_invested[0].ID.Date:
self.Liquidate(option_invested[0], "Too close to expiration")
return
# buy options LATER I CAN ADD CONDITION DEPENDING OIN SPY EQUITY
# if self.Securities[self.equity].Price >= self.high.Current.Value:
for i in data.OptionChains:
chains = i.Value
self.BuyVerticalSpread(chains)
def BuyVerticalSpread(self, chains):
expiry = sorted(chains, key = lambda x: x.Expiry)[0].Expiry
self.Debug(f"Today: {self.Time.date()}, expiry: {expiry}")
calls = [i for i in chains if i.Expiry == expiry and i.Right == OptionRight.Call] # we choose call option closest to 90 days
self.Debug(f"Today: {self.Time.date()}, calls: {calls}")
call_contracts = sorted(calls, key = lambda x: abs(x.Strike - x.UnderlyingLastPrice))
if len(call_contracts) == 0:
self.Debug("There are no option contracts for given criteria.")
return
self.call = call_contracts[0]
quantity = self.Portfolio.TotalPortfolioValue / self.call.AskPrice
quantity = int( 0.05 * quantity / 100 ) # we want to invest 5% of portfolio in out position
self.Buy(self.call.Symbol, quantity)
def OnOrderEvent(self, orderEvent):
self.Log(str(orderEvent))
def ClosePositions(self):
if self.Portfolio.Invested:
self.Liquidate()