Overall Statistics
Total Trades
246
Average Win
0.71%
Average Loss
-0.07%
Compounding Annual Return
30.644%
Drawdown
32.900%
Expectancy
2.349
Net Profit
14.635%
Sharpe Ratio
1.019
Probabilistic Sharpe Ratio
46.026%
Loss Rate
71%
Win Rate
29%
Profit-Loss Ratio
10.67
Alpha
0.358
Beta
0.831
Annual Standard Deviation
0.4
Annual Variance
0.16
Information Ratio
2.203
Tracking Error
0.158
Treynor Ratio
0.491
Total Fees
$256.80
from Execution.ImmediateExecutionModel import ImmediateExecutionModel
#from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel
from EqualLeveragePortfolioConstructionModel import EqualLeveragePortfolioConstructionModel

class ParticleNadionReplicator(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 12, 19)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
        # self.AddEquity("SPY", Resolution.Minute)
        self.SetExecution(ImmediateExecutionModel())

        #self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetPortfolioConstruction(EqualLeveragePortfolioConstructionModel(None, 1.5)) #Rebalance Frequency, Leverage

    
        self.SetRiskManagement(MaximumUnrealizedProfitPercentPerSecurity(0.03))
        tickers = ["SPY", "QQQQ", "TLT"]
        self.UniverseSettings.Resolution = Resolution.Minute
        symbols = [ Symbol.Create(ticker, SecurityType.Equity, Market.USA)  for ticker in tickers]
        self.SetUniverseSelection( ManualUniverseSelectionModel(symbols) )
        self.SetBenchmark("SPY")
        self.SetSecurityInitializer(lambda x: x.SetDataNormalizationMode(DataNormalizationMode.Raw))
        
        self.alpha = MyAlphaModel()#leverage
        self.AddAlpha(self.alpha)

class MyAlphaModel(AlphaModel):
    def __init__(self):
        self.equities = []
        
    def OnSecuritiesChanged(self, algorithm, changes):
        for security in changes.AddedSecurities:
            if str(type(security)) == "<class 'QuantConnect.Securities.Equity.Equity'>":
                self.equities.append(security.Symbol)
                
        for security in changes.RemovedSecurities:
            symbol = security.Symbol
            if symbol in self.equities:
                self.equities.remove(symbol)
              
    def Update(self, algorithm, data):
        insights = []
        
        if algorithm.IsWarmingUp or algorithm.Portfolio.Invested:
            return insights
        
        for symbol in self.equities:
            insights.append(Insight.Price(symbol,timedelta(days=180), InsightDirection.Up))
        
        return insights