| Overall Statistics |
|
Total Trades 7884 Average Win 0.12% Average Loss -0.11% Compounding Annual Return 34.258% Drawdown 39.400% Expectancy 0.662 Net Profit 2121.734% Sharpe Ratio 1.353 Probabilistic Sharpe Ratio 73.309% Loss Rate 20% Win Rate 80% Profit-Loss Ratio 1.08 Alpha 0.314 Beta -0.043 Annual Standard Deviation 0.228 Annual Variance 0.052 Information Ratio 0.632 Tracking Error 0.279 Treynor Ratio -7.162 Total Fees $13663.76 Estimated Strategy Capacity $1600000.00 Lowest Capacity Asset TMF UBTUG7D0B7TX |
class SleepyYellowBee(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2010, 12, 23)
self.SetCash(100000)
self.AddEquity("SPY", Resolution.Daily)
self.SetBenchmark("SPY")
# Variable to hold the last calculated benchmark value
self.lastBenchmarkValue = None
# Our inital benchmark value scaled to match our portfolio
self.BenchmarkPerformance = self.Portfolio.TotalPortfolioValue
#self.Float = self.GetParameter("self.Float")
self.Float = 0.01
self.non_float = 1 - self.Float
# target allocations
self.TQQQ_target = 0.20*self.non_float
self.UPRO_target = 0.20*self.non_float
self.TMF_target = 0.60*self.non_float
#import equities
self.AddEquity("TQQQ", Resolution.Daily)
self.AddEquity("UPRO", Resolution.Daily)
self.TMF = self.AddEquity("TMF", Resolution.Daily)
#EMAs for bear filter
self.ema_fast = self.EMA("SPY", 5)
self.ema_slow = self.EMA("SPY", 100)
self.rebalance_date = self.Time + timedelta(days = 100)
def OnData(self, data):
# when bull market
if self.ema_fast > self.ema_slow:
self.TQQQ_target = 0.30*self.non_float
self.UPRO_target = 0.30*self.non_float
self.TMF_target = 0.40*self.non_float
self.Log('Fuck yeah Bull market')
self.Plot("BULL - BEAR", "Bull", 1)
self.Plot("BULL - BEAR", "Bear", 0)
self.Rebalance(data)
# when bear market - ******* PLAYING WITH THESE ***********8
if self.ema_fast < self.ema_slow:
self.TQQQ_target = 0.15*self.non_float
self.UPRO_target = 0.15*self.non_float
self.TMF_target = 0.50*self.non_float
self.Log('Fuck no Bear market')
self.Plot("BULL - BEAR", "Bull", 0)
self.Plot("BULL - BEAR", "Bear", 1)
self.Rebalance(data)
# Plot EMAs
self.Plot("Benchmark", "Fast", self.ema_fast.Current.Value)
self.Plot("Benchmark", "Slow", self.ema_slow.Current.Value)
# Plot assets
self.Plot("Assets", "TMF", self.Securities["TMF"].Close)
self.Plot("Assets", "UPRO", self.Securities["UPRO"].Close)
self.Plot("Assets", "TQQQ", self.Securities["TQQQ"].Close)
# Check if we're not invested and then put portfolio 100% in the SPY ETF.
if not self.Portfolio.Invested:
self.SetHoldings("TQQQ", self.TQQQ_target)
self.SetHoldings("UPRO", self.UPRO_target)
self.SetHoldings("TMF", self.TMF_target)
#rebalance_date = self.Time + timedelta(days = 370)
if self.Time == self.rebalance_date:
self.Rebalance(data)
# store the current benchmark close price
benchmark = self.Securities["SPY"].Close
# enter our strategy
if not self.Portfolio.Invested:
self.Rebalance(data)
# Calculate the performance of our benchmark and update our benchmark value for plotting
if self.lastBenchmarkValue is not None:
self.BenchmarkPerformance = self.BenchmarkPerformance * (benchmark/self.lastBenchmarkValue)
# store today's benchmark close price for use tomorrow
self.lastBenchmarkValue = benchmark
# make our plots
self.Plot("Strategy vs Benchmark", "Portfolio Value", self.Portfolio.TotalPortfolioValue)
self.Plot("Strategy vs Benchmark", "Benchmark", self.BenchmarkPerformance)
def Rebalance(self, data):
self.SetHoldings("TQQQ", self.TQQQ_target)
self.SetHoldings("UPRO", self.UPRO_target)
self.SetHoldings("TMF", self.TMF_target)
self.rebalance_date = self.Time + timedelta(days = 100)
self.Log("Rebalanced")