Overall Statistics
Total Trades
327
Average Win
0.23%
Average Loss
-0.06%
Compounding Annual Return
15.697%
Drawdown
31.600%
Expectancy
2.943
Net Profit
55.282%
Sharpe Ratio
0.545
Probabilistic Sharpe Ratio
15.304%
Loss Rate
17%
Win Rate
83%
Profit-Loss Ratio
3.74
Alpha
0.039
Beta
0.995
Annual Standard Deviation
0.27
Annual Variance
0.073
Information Ratio
0.849
Tracking Error
0.045
Treynor Ratio
0.148
Total Fees
$327.64
Estimated Strategy Capacity
$25000000.00
Lowest Capacity Asset
AHA R735QTJ8XC9X
##########################################
#Kamer Ali Yuksel linkedin.com/in/kyuksel#
##########################################
from AlgorithmImports import *
import numpy as np

syms = ['MSFT', 'AAPL', 'TXN', 'ASML', 'ADBE', 'CRM', 'SBUX', 'MCHP', 'MA', 'ADI', 'SWKS', 'SNPS', 'KLAC']

class MultidimensionalModulatedRegulators(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetCash(100000)
        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('VGT', Resolution.Hour)
        self.SetBenchmark('VGT')
        self.SetBrokerageModel(AlphaStreamsBrokerageModel())

        self.constant_weights = np.array([0.28535828, 0.23993727, 0.12635303, 0.05360154, 0.04681825, 0.04518177, 0.04505873, 0.04194283, 0.03757035, 0.03131177, 0.02168459, 0.0151392 , 0.01004238])
        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.05: 
                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])