Overall Statistics |
Total Trades 3854 Average Win 0.05% Average Loss -0.02% Compounding Annual Return 7.796% Drawdown 1.000% Expectancy 0.795 Net Profit 86.811% Sharpe Ratio 5.477 Probabilistic Sharpe Ratio 100% Loss Rate 43% Win Rate 57% Profit-Loss Ratio 2.14 Alpha 0.074 Beta 0.024 Annual Standard Deviation 0.014 Annual Variance 0 Information Ratio -0.515 Tracking Error 0.167 Treynor Ratio 3.308 Total Fees $4363.34 |
########################################## ###Combinatorial Portfolio Optimization### #Kamer Ali Yuksel, Principal AI Architect# ########################################## import numpy as np syms = ['ENSG', 'MLR', 'WTM', 'IAC', 'ROK', 'EGOV', 'PLCE', 'BECN', 'MSA', 'HRI', 'MKTX', 'PRU', 'ODFL', 'TER', 'PODD', 'VVI', 'CALM', 'IEX', 'TGT', 'PZZA', 'CLAR', 'WSO', 'LUV', 'GATX', 'ITW', 'PBCT', 'RS', 'TDY', 'XEL', 'HST', 'PVH', 'LCII', 'NUS', 'GBCI', 'NOC', 'CASH', 'HIFS', 'RGR', 'CMI', 'GPI', 'DAR', 'AFG', 'COO', 'SIG', 'LLY', 'PKG', 'AGX', 'CRVL', 'HRL', 'ATRI', 'KO', 'EXR', 'ISBC', 'KDP', 'PRSC', 'PKBK', 'MLM', 'TROW', 'MCD', 'XPO', 'EVR', 'UBA', 'GENC', 'LDOS', 'WTS', 'EGBN', 'COP', 'TILE', 'MPWR', 'PLUS', 'DDS', 'CTO', 'SAIA', 'WAL', 'CDNS', 'DFS', 'NI', 'NEE', 'VGR', 'DPZ', 'MNR', 'HD', 'ABR', 'JBSS', 'SNX', 'PBIP', 'AGNC', 'LII', 'ABCB', 'LSI', 'MPW', 'GCBC', 'TRTN', 'CLCT', 'O', 'EEFT', 'THG', 'TKR', 'SUI', 'OKE', 'CVCY', 'GL', 'GSBC', 'HOFT', 'SBNY', 'GS', 'AOS', 'STE', 'CMS', 'ETN', 'WINA', 'UTHR', 'NYMT', 'JKHY', 'GABC', 'HSKA', 'CORE', 'FCX', 'TCX', 'RPT', 'SMG', 'SLM', 'IDXX', 'KR', 'GRMN', 'BMY', 'PRIM', 'CSV', 'INTC', 'COHR', 'TCBK', 'FIZZ', 'CMCSA', 'EVI', 'PNC', 'LBC', 'TRN', 'CR', 'HAL', 'SFST', 'EIX', 'WHR', 'TYL', 'EMN', 'TJX', 'AME', 'HT', 'DLR', 'CI', 'LKFN', 'KALU', 'CNS', 'DISCA', 'ELS', 'KFRC', 'LDL', 'ROST', 'CVGW', 'CHH', 'EW', 'CMA', 'NEU', 'F', 'HI', 'DVA', 'SPG', 'MLAB', 'SCI', 'HBNC', 'CAT', 'BFC', 'HSY', 'QRTEA', 'AIR', 'CTAS', 'RGCO', 'NYT', 'MYRG', 'DE', 'MNRO', 'WST', 'DHIL', 'AEP', 'CACC', 'AMT', 'STL', 'UHAL', 'QCRH', 'CPRT', 'CBRL', 'AIV', 'ABC', 'COKE', 'MCBC', 'HP', 'RGS', 'WEC', 'BRKL', 'FFIV', 'ALG', 'SLP', 'DTE', 'ORLY', 'NATH', 'AWK', 'RMD', 'ACNB', 'SBAC', 'AMKR', 'NRIM', 'TT', 'ERIE', 'HCI', 'WLK', 'POL', 'UDR', 'FFIN', 'CPT', 'AAPL', 'TSN', 'SIVB', 'MSTR', 'TDG', 'GRIF', 'CCL', 'GHM', 'TDW', 'PBH', 'FCAP', 'GLRE', 'ADS', 'NTUS', 'ETR', 'CUZ', 'GIS', 'GPC', 'GHL', 'NUE', 'EXC', 'BDC', 'APA', 'CBT', 'REG', 'OFC', 'ZIXI', 'WFC', 'Y', 'OVBC', 'SLGN', 'DGX', 'NWN', 'SCOR', 'BSX', 'DSPG', 'BXS', 'INVA', 'GD', 'SPR', 'J', 'HAFC', 'SO', 'TRV', 'LMNR', 'C', 'FE', 'MCO', 'BBBY', 'PCAR', 'PBI', 'HPQ', 'NCMI', 'ECOL', 'PCG', 'ATLO', 'MTW', 'ADP', 'FICO', 'TRST', 'HBI', 'MWA', 'EQIX', 'SRCL', 'EXP', 'JNPR', 'FISV', 'WERN', 'CXW', 'TPX', 'ATI', 'JNJ', 'JEF', 'FSTR', 'OXY', 'BELFB', 'CCRN', 'PGC', 'HOG', 'DVN', 'XRX', 'ASB', 'AVT', 'CPF', 'UMH', 'INGR', 'POWL', 'TAP', 'DHC', 'L', 'CUB', 'VMC', 'CPSI', 'LOW', 'CMCO', 'WHG', 'FIS', 'ECL', 'HUBG', 'NXGN', 'MDP', 'PNM', 'IRET', 'DEI', 'USD', 'BUSE', 'NEOG', 'MEI', 'FCBC', 'CYH', 'CLX', 'NWLI', 'STFC', 'MHK', 'GBL', 'FSP', 'RL', 'BWA', 'D', 'GPS', 'ALCO', 'CUBE', 'KRG', 'AMZN', 'TOL', 'SYKE', 'VNO', 'ITT', 'EME', 'R', 'TXT', 'TCBI', 'NDAQ', 'WRI', 'AJG', 'MRO', 'MGEE', 'CBZ', 'HOLX', 'SWK', 'YUM', 'WEYS', 'VMW', 'NJR', 'ES', 'OC', 'LKQ', 'PSA', 'IBM', 'CL', 'MKC', 'TTEK', 'BFIN', 'SLB', 'K', 'EGLE', 'IDCC', 'AWR', 'HXL', 'CVS', 'GTS', 'LECO', 'WWD', 'CHS', 'PNR', 'SR', 'HTZ', 'RWT', 'KNX', 'SIGI', 'BEN', 'FDP', 'COWN', 'TGTX', 'BFS', 'PTVCB', 'FORM', 'NUAN', 'SVRA', 'HRB', 'VLO', 'ACC', 'MANT', 'LMNX', 'CLI', 'RNST', 'MDT', 'CDZI', 'MSFT', 'IVZ', 'FARM', 'UNM', 'VRTX', 'JCOM', 'EPC', 'TDS', 'HTLD', 'PPG', 'KMB', 'AAL', 'TRC', 'CNR', 'ATGE', 'ZION', 'MDLZ', 'CPB', 'CW', 'THS', 'DISH', 'MAT', 'TGI', 'FCN', 'TR', 'FRBK', 'HBMD', 'MGM', 'CSX'] class MultidimensionalModulatedRegulators(QCAlgorithm): def Initialize(self): self.SetStartDate(2009, 1, 1) self.SetEndDate(2017, 4, 27) #self.SetStartDate(2017, 4, 29) self.SetCash(1000000) self.SetExecution(VolumeWeightedAveragePriceExecutionModel()) self.symbols = [] for i in range(len(syms)): self.symbols.append(Symbol.Create(syms[i], SecurityType.Equity, Market.USA)) self.Debug(syms[i]) self.SetUniverseSelection(ManualUniverseSelectionModel(self.symbols) ) self.UniverseSettings.Resolution = Resolution.Hour self.AddEquity('SPY', Resolution.Hour) self.SetBenchmark('SPY') self.SetBrokerageModel(AlphaStreamsBrokerageModel()) self.constant_weights = np.array([3.3417e-03, 3.8028e-03, 1.4059e-03, 3.4104e-03, 3.9302e-03, 9.9260e-04, 1.0612e-03, 2.0523e-04, 3.5471e-03, 2.9257e-03, 3.1664e-03, 2.1936e-03, 1.6552e-03, 2.3495e-03, 1.2242e-03, 3.6865e-03, 1.0618e-03, 1.7877e-03, 3.1107e-03, 1.1763e-03, 3.4327e-04, 1.5801e-03, 2.8545e-03, 2.6894e-05, 5.1181e-04, 5.7672e-04, 2.1206e-04, 2.5516e-03, 3.0639e-03, 8.2794e-04, 2.5007e-03, 2.7412e-03, 2.1178e-03, 6.3320e-03, 4.0600e-03, 1.1722e-03, 2.7766e-03, 2.2327e-03, 2.9752e-03, 8.2105e-04, 4.1861e-03, 6.6802e-03, 3.2894e-03, 2.1772e-03, 3.7651e-03, 2.7335e-03, 9.4199e-04, 1.4910e-03, 2.2184e-03, 4.5235e-03, 2.8623e-03, 3.5650e-03, 2.9967e-03, 3.8449e-03, 1.8003e-03, 2.2331e-03, 5.7518e-04, 1.7696e-03, 1.0691e-03, 1.7870e-03, 2.7541e-03, 2.1565e-04, 1.5179e-04, 7.1908e-05, 4.3064e-04, 2.0322e-03, 5.2195e-03, 3.0573e-04, 4.0056e-03, 1.3818e-03, 1.8951e-03, 8.0042e-05, 4.0875e-03, 5.1223e-03, 3.3992e-03, 3.9272e-03, 6.4421e-03, 1.2183e-02, 3.2786e-03, 1.8064e-03, 4.3704e-03, 1.9794e-03, 1.0249e-03, 2.6482e-03, 3.6462e-03, 3.6295e-04, 4.0004e-03, 2.1801e-06, 2.3962e-03, 9.4415e-05, 4.4154e-03, 8.8089e-04, 4.6874e-04, 3.3055e-03, 5.4481e-05, 2.3258e-03, 9.6804e-05, 8.2183e-04, 4.5355e-03, 2.4202e-03, 4.9153e-04, 2.6664e-03, 1.9735e-03, 1.2649e-03, 2.0325e-03, 2.3987e-03, 2.2261e-03, 4.0274e-03, 1.0670e-02, 1.3903e-03, 2.9743e-03, 1.6101e-04, 3.0130e-03, 1.8604e-04, 4.0952e-03, 1.0987e-03, 6.9669e-04, 2.5876e-04, 2.3333e-03, 3.0450e-03, 2.7980e-03, 1.0243e-03, 7.2236e-04, 1.4133e-04, 1.1426e-03, 3.7609e-04, 3.1934e-03, 1.8178e-03, 4.7778e-03, 1.9916e-03, 1.3615e-03, 2.6158e-03, 1.4982e-03, 1.4080e-03, 2.8114e-03, 1.1357e-03, 1.9027e-03, 3.5936e-03, 7.5999e-04, 3.2905e-03, 6.2227e-03, 4.3929e-04, 1.9625e-03, 2.1627e-03, 4.3537e-03, 4.6764e-05, 1.5259e-03, 1.3931e-03, 1.3157e-03, 3.0629e-03, 1.0086e-03, 1.1564e-03, 3.2249e-03, 3.2685e-03, 1.8081e-03, 1.7189e-03, 8.2950e-04, 8.8513e-04, 3.3197e-03, 1.1809e-03, 4.3620e-03, 3.5139e-03, 3.7789e-03, 2.1409e-03, 9.7664e-04, 1.1641e-03, 8.5473e-04, 6.3883e-04, 5.5767e-03, 2.4796e-03, 1.9339e-03, 1.8126e-03, 1.7459e-03, 6.2430e-04, 1.2570e-04, 9.8235e-04, 1.8344e-03, 5.5949e-04, 2.7063e-03, 3.8196e-04, 2.0297e-03, 1.9005e-03, 3.1143e-03, 2.3321e-03, 1.3153e-03, 2.6558e-03, 3.8219e-03, 3.7341e-03, 2.5854e-03, 5.7557e-03, 6.8459e-04, 3.9895e-03, 7.6754e-04, 1.0856e-03, 3.6724e-03, 3.4355e-04, 1.5656e-03, 2.1307e-03, 2.9144e-05, 1.4048e-03, 1.5509e-03, 4.3498e-03, 1.8235e-03, 2.2557e-03, 9.4102e-03, 4.1529e-04, 2.4944e-03, 1.0605e-03, 2.8099e-04, 2.1333e-04, 4.2229e-03, 4.5367e-03, 2.2808e-03, 2.6972e-03, 2.7239e-03, 8.2795e-04, 3.4477e-03, 4.5486e-03, 5.3790e-03, 1.9238e-03, 3.2646e-03, 3.7267e-03, 5.8358e-03, -7.4541e-04, -1.9550e-03, -5.4310e-04, -3.5297e-03, -4.1548e-04, -4.4845e-05, -4.8579e-03, -1.2105e-03, -1.6814e-03, -9.9570e-03, -5.8453e-03, -1.3867e-03, -1.4691e-03, -1.5595e-03, -2.5582e-03, -5.0901e-03, -2.2385e-03, -5.6548e-04, -4.9504e-04, -3.7464e-03, -9.2950e-04, -1.6929e-03, -1.0829e-04, -6.0393e-03, -2.7448e-03, -1.2948e-03, -4.4644e-03, -4.2658e-03, -1.5402e-03, -2.1482e-03, -2.2050e-03, -3.6007e-03, -1.3042e-03, -4.9408e-03, -2.2361e-03, -1.1129e-03, -1.9575e-03, -9.7125e-04, -6.1710e-04, -2.2057e-03, -4.3421e-03, -7.5482e-03, -2.5225e-03, -1.8769e-04, -3.8479e-03, -1.5375e-03, -1.4706e-03, -1.8170e-03, -1.9682e-03, -5.5579e-03, -3.5518e-03, -3.2478e-03, -1.8794e-03, -4.1365e-06, -5.8630e-03, -2.3761e-04, -1.4231e-03, -2.0227e-04, -4.9978e-03, -6.0544e-04, -6.8808e-04, -1.9647e-03, -2.3390e-03, -1.9225e-03, -6.3816e-04, -7.8824e-04, -7.6184e-04, -3.7401e-03, -1.0051e-03, -9.0359e-04, -1.2177e-03, -3.0303e-03, -3.9736e-03, -1.8539e-03, -5.8832e-04, -1.0154e-03, -3.9670e-03, -6.1406e-03, -7.0706e-03, -2.3424e-03, -3.5818e-03, -2.3809e-03, -3.4336e-03, -1.7615e-03, -5.0180e-03, -2.4254e-03, -2.2886e-03, -1.3889e-03, -2.6840e-03, -1.4305e-03, -2.4484e-03, -1.1192e-03, -2.0609e-03, -2.9267e-03, -3.9610e-03, -1.0288e-04, -3.8108e-03, -2.4852e-03, -2.0814e-03, -3.6420e-03, -5.7204e-03, -9.6674e-04, -8.2790e-04, -2.6322e-03, -7.0549e-04, -3.5798e-05, -7.1118e-03, -2.6594e-03, -1.2827e-03, -1.6701e-03, -1.9564e-03, -2.6173e-03, -1.5608e-03, -5.1275e-03, -2.3575e-03, -1.1461e-03, -3.0101e-04, -3.4357e-03, -8.4539e-05, -9.2087e-04, -2.1546e-03, -7.2138e-04, -3.5606e-03, -1.5610e-03, -1.1768e-03, -2.1758e-03, -1.5611e-03, -2.9603e-03, -2.7771e-04, -1.5421e-03, -3.7582e-04, -1.4812e-03, -6.4536e-04, -8.1000e-04, -3.8451e-03, -5.3865e-03, -2.5691e-03, -1.2413e-03, -5.1832e-03, -1.9566e-03, -3.6770e-03, -3.1613e-03, -2.8377e-03, -1.2962e-03, -3.7973e-03, -9.9946e-05, -2.0366e-03, -2.3030e-03, -3.2982e-03, -2.5354e-03, -2.2130e-03, -9.6030e-05, -2.9495e-03, -3.5488e-03, -2.2169e-03, -4.8849e-04, -2.0825e-03, -6.2035e-04, -1.3114e-03, -3.6480e-03, -1.5889e-03, -3.1885e-03, -2.5954e-03, -7.7833e-04, -2.2452e-03, -3.5203e-03, -1.5312e-03, -4.3498e-04, -3.5858e-03, -1.1413e-04, -1.2579e-03, -1.5356e-03, -3.4629e-03, -2.1334e-03, -2.8755e-03, -2.1075e-03, -6.4503e-03, -1.1978e-03, -4.9033e-03, -1.4568e-03, -5.3000e-05, -2.0981e-03, -1.1097e-03, -5.1937e-04, -2.1546e-03, -2.4764e-03, -5.0490e-03, -8.1952e-04, -2.2383e-03, -1.5884e-03, -2.3170e-03, -2.6931e-03, -8.0503e-04, -7.2320e-04, -1.1855e-03, -2.6055e-03, -2.5952e-03, -3.7193e-03, -1.6228e-03, -1.9823e-03, -1.7266e-03, -1.7196e-04, -1.2466e-03, -1.1801e-03, -2.0928e-03, -1.7366e-03, -2.8059e-03, -3.2971e-03, -1.9594e-03, -2.3105e-03, -3.0076e-03, -4.5682e-04]) #self.constant_weights[-279:] = -1.0 self.constant_weights = self.constant_weights / np.sum(np.abs(self.constant_weights)) def OnData(self, data): 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.TotalPortfolioValue) diff = self.constant_weights[i] - curr total += np.abs(diff) if total > 0.25: rebalance = True if rebalance: for i, sym in enumerate(self.symbols): curr = (self.Securities[sym].Holdings.HoldingsValue/self.Portfolio.TotalPortfolioValue) if self.constant_weights[i] < curr: self.SetHoldings(sym, self.constant_weights[i]) for i, sym in enumerate(self.symbols): curr = (self.Securities[sym].Holdings.HoldingsValue/self.Portfolio.TotalPortfolioValue) if self.constant_weights[i] > curr: self.SetHoldings(sym, self.constant_weights[i]) else: for i, sym in enumerate(self.symbols): self.SetHoldings(sym, self.constant_weights[i])