Overall Statistics Total Trades1Average Win0%Average Loss0%Compounding Annual Return-0.364%Drawdown0.000%Expectancy0Net Profit-0.010%Sharpe Ratio-5.604Probabilistic Sharpe Ratio0.923%Loss Rate0%Win Rate0%Profit-Loss Ratio0Alpha-0.002Beta-0.001Annual Standard Deviation0.001Annual Variance0Information Ratio-7.968Tracking Error0.131Treynor Ratio3.079Total Fees\$1.00
# https://seekingalpha.com/article/4299701-leveraged-etfs-for-long-term-investing
# https://www.quantconnect.com/forum/discussion/7708/using-levered-etfs-in-ira-10-years-24-cagr-1-56-sharpe/p1
# with some extra symbols.

import pandas as pd
import numpy as np

class MultidimensionalTransdimensionalPrism(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2020, 7, 7)  # Set Start Date
self.SetCash(10000)  # Set Strategy Cash
self.SetEndDate(2020, 7, 16)

# create a dictionary to store momentum indicators for all symbols
self.mom = {}
self.rsi = {}
self.momp = {}

#MOM period
period = 21*4
#rsi period
period2 = 10
#MOMP period
period3 = 44

self.SetRiskManagement(TrailingStopRiskManagementModel(0.25))

# warm up the MOM indicator
self.SetWarmUp(period)
self.symbols = []
tickers = ["TQQQ", "UBT", "TECL","UGLD","TYD"]
for ticker in tickers:
self.symbols.append(symbol)
self.mom[symbol] = self.MOM(symbol, period, Resolution.Hour)
self.rsi[symbol] = self.RSI(symbol, period2, Resolution.Daily)
self.momp[symbol] = self.MOMP(symbol, period3, Resolution.Daily)

self.Schedule.On(self.DateRules.Every(DayOfWeek.Wednesday), \
self.TimeRules.At(15, 30), \
self.Rebalance)

def Rebalance(self):
if self.IsWarmingUp: return

alldata = pd.DataFrame({'momp':[self.mom[symbol].Current.Value for symbol in self.symbols],
'rsi': [self.rsi[symbol].Current.Value for symbol in self.symbols]})
highest_rsi = alldata[alldata['rsi'] > 80]
top3 = highest_rsi.sort_values(by='momp', ascending = False)[:3]
top3_symbols = [self.symbols[i] for i in top3.index]

for kvp in self.Portfolio:
security_hold = kvp.Value
if security_hold.Invested and (security_hold.Symbol not in top3_symbols):
self.Liquidate(security_hold.Symbol)

self.SetHoldings(added, 1/len(added_symbols))