Overall Statistics |
Total Trades 395 Average Win 0.00% Average Loss 0.00% Compounding Annual Return 1.229% Drawdown 0.400% Expectancy 15.805 Net Profit 6.332% Sharpe Ratio 2.905 Probabilistic Sharpe Ratio 99.998% Loss Rate 20% Win Rate 80% Profit-Loss Ratio 20.03 Alpha 0.011 Beta 0.007 Annual Standard Deviation 0.004 Annual Variance 0 Information Ratio -0.862 Tracking Error 0.132 Treynor Ratio 1.778 Total Fees $445.55 |
import numpy as np syms = ['IEI', 'ERX', 'XLB', 'XLE', 'GDX', 'XLU', 'FDN', 'TLT', 'XES', 'BIL', 'SLV', 'TBT', 'IAU', 'VDE', 'UNG', 'XLK', 'TECL', 'XLV', 'XLP', 'XOP', 'SHV', 'ICLN', 'XLI', 'UCO', 'ERY', 'SPTL', 'AGQ', 'SCO', 'QQQ', 'XLF', 'GLD', 'IGV', 'FXL', 'IEF', 'SHY', 'QTEC', 'USO', 'TLH', 'TAN', 'TECS'] static_weights = [9.34755988e-03, 3.81794689e-06, 2.73189398e-05, 3.73349467e-05, 6.17753358e-06, 1.13753122e-04, 4.86071862e-04, 2.15727603e-04, 1.12426060e-05, 3.03697258e-01, 8.25903226e-06, 4.41784832e-05, 6.33423188e-05, 3.29151699e-05, 1.04393821e-05, 1.05330686e-03, 2.23151346e-06, 6.45845709e-03, 7.63766002e-03, 1.47287337e-05, 3.30812722e-01, 8.52190078e-06, 1.35812705e-04, 7.23709218e-06, 1.28564043e-05, 7.77560694e-04, 1.58797218e-06, 1.00353282e-05, 3.67849553e-03, 2.23107927e-05, 6.87888314e-05, 2.34894051e-05, 3.30419498e-05, 2.45390972e-03, 3.31439734e-01, 3.45058681e-04, 2.07255653e-05, 8.54378450e-04, 6.37257517e-06, 1.55947491e-05] class MultidimensionalModulatedRegulators(QCAlgorithm): def Initialize(self): self.SetStartDate(2015, 1, 16) # Set Start Date self.SetCash(1000000) # Set Strategy Cash self.SetExecution(VolumeWeightedAveragePriceExecutionModel()) self.symbols = [] for i in range(len(syms)): #if static_weights[i] < 0: syms[i] = neg_syms[i] self.symbols.append(Symbol.Create(syms[i], SecurityType.Equity, Market.USA)) #static_weights[i] = np.abs(static_weights[i]) #self.Debug(syms[i]) self.SetUniverseSelection( ManualUniverseSelectionModel(self.symbols) ) self.UniverseSettings.Resolution = Resolution.Hour self.AddEquity('SPY') self.SetBenchmark('SPY') self.SetBrokerageModel(AlphaStreamsBrokerageModel()) # Schedule the rebalance function to execute at the begining of each month #self.Schedule.On(self.DateRules.MonthStart(self.spy), #self.TimeRules.BeforeMarketClose(self.spy, 30), Action(self.rebalance)) def OnData(self, data): self.constant_weights = np.abs([9.34755988e-03, 3.81794689e-06, 2.73189398e-05, 3.73349467e-05, 6.17753358e-06, 1.13753122e-04, 4.86071862e-04, 2.15727603e-04, 1.12426060e-05, 3.03697258e-01, 8.25903226e-06, 4.41784832e-05, 6.33423188e-05, 3.29151699e-05, 1.04393821e-05, 1.05330686e-03, 2.23151346e-06, 6.45845709e-03, 7.63766002e-03, 1.47287337e-05, 3.30812722e-01, 8.52190078e-06, 1.35812705e-04, 7.23709218e-06, 1.28564043e-05, 7.77560694e-04, 1.58797218e-06, 1.00353282e-05, 3.67849553e-03, 2.23107927e-05, 6.87888314e-05, 2.34894051e-05, 3.30419498e-05, 2.45390972e-03, 3.31439734e-01, 3.45058681e-04, 2.07255653e-05, 8.54378450e-04, 6.37257517e-06, 1.55947491e-05]) #for i in range(len(self.constant_weights)): # if np.abs(self.constant_weights[i]) < 0.0005: self.constant_weights[i] = 0 self.constant_weights /= np.sum(self.constant_weights) #if (not self.Portfolio.Invested): # for i, sym in enumerate(self.symbols): # if self.constant_weights[i] != 0: # self.SetHoldings(sym, self.constant_weights[i]) insights = [] rebalance = False if self.Portfolio.TotalHoldingsValue > 0: total = 0.0 for i, sym in enumerate(self.symbols): curr = (self.Securities[sym].Holdings.HoldingsValue/self.Portfolio.TotalHoldingsValue) diff = self.constant_weights[i] - curr total += np.abs(diff) #if diff > 0: # insights.append(Insight.Price(sym, timedelta(days = 26), InsightDirection.Up)) #elif diff < 0: # insights.append(Insight.Price(sym, timedelta(days = 26), InsightDirection.Down)) if total > 0.0025: #self.Debug(total) rebalance = True if rebalance or (not self.Portfolio.Invested): for i, sym in enumerate(self.symbols): if self.constant_weights[i] != 0: self.SetHoldings(sym, self.constant_weights[i]) ''' #if self.rebalance: self.EmitInsights(insights) if self.rebalance: for i, sym in enumerate(self.symbols): oq = self.CalculateOrderQuantity(sym, self.constant_weights[i]) lp = self.Securities[sym].BidPrice if oq < 0: lp = self.Securities[sym].AskPrice if oq != 0: self.Transactions.CancelOpenOrders(sym) self.LimitOrder(sym, oq, lp) '''