| Overall Statistics |
|
Total Trades 123 Average Win 18.25% Average Loss -3.06% Compounding Annual Return 26.787% Drawdown 49.700% Expectancy 1.500 Net Profit 1432.841% Sharpe Ratio 0.864 Probabilistic Sharpe Ratio 19.092% Loss Rate 64% Win Rate 36% Profit-Loss Ratio 5.96 Alpha 0.283 Beta 0.01 Annual Standard Deviation 0.329 Annual Variance 0.109 Information Ratio 0.418 Tracking Error 0.364 Treynor Ratio 27.847 Total Fees $5823.63 Estimated Strategy Capacity $9300000.00 Lowest Capacity Asset UPRO UDQRQQYTO12D |
'''
SPY 1x = 8/13 = 0.61
SPY 2x = 17/28 = 0.68
QQQ 1x - 15/10 = 1.50
QQQ 2x - 31/19 = 1.63
TQQQ 1x - 38/33 = 1.15
TQQQ 2x - 73/57 = 1.28
'''
Res = Resolution.Daily
# Res = Resolution.Hour
roc_period = adx_period = 20
adx_filter = 30
leverage = 2
S = 'UPRO'
class Algo(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2010, 1, 1)
# self.SetEndDate(2010, 12, 31)
self.SetCash(100000)
self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
self.AddEquity('QQQ', Res)
self.AddEquity('TQQQ', Res)
self.AddEquity('SPY', Res)
self.AddEquity('UPRO', Res)
self.AddEquity('TMF', Res)
self.AddEquity('TLT', Res)
self.ma = self.SMA('SPY', 200, Res)
self.roc = self.ROC(S, roc_period, Res)
self.adx = self.ADX(S, adx_period, Res)
self.Schedule.On(self.DateRules.EveryDay('SPY'), self.TimeRules.AfterMarketOpen('SPY'), self.Trade)
self.SetWarmUp(roc_period, Res)
self.SetBenchmark('SPY')
# def OnData(self, data):
# if self.IsWarmingUp: return
# self.Trade()
# def OnEndOfDay(self):
# self.Trade()
def Trade(self):
if self.Securities['SPY'].Close > self.ma.Current.Value:
self.SetHoldings('UPRO', 1, True)
else:
self.SetHoldings('TLT', 1, True)
# if self.roc.Current.Value < 0 or self.adx.Current.Value > adx_filter:
# # self.SetHoldings(S, 0.40)
# self.SetHoldings('TMF', 1, True)
# if self.roc.Current.Value > 0 and self.adx.Current.Value < adx_filter:
# self.SetHoldings(S, 1, True)
# # self.SetHoldings('TMF', 0.40)