Overall Statistics
Total Trades
449
Average Win
1.00%
Average Loss
-0.86%
Compounding Annual Return
8.672%
Drawdown
23.100%
Expectancy
0.627
Net Profit
267.126%
Sharpe Ratio
0.658
Probabilistic Sharpe Ratio
5.689%
Loss Rate
25%
Win Rate
75%
Profit-Loss Ratio
1.17
Alpha
0.08
Beta
-0.016
Annual Standard Deviation
0.119
Annual Variance
0.014
Information Ratio
-0.052
Tracking Error
0.216
Treynor Ratio
-5.003
Total Fees
$1069.39
## A simple m odification to add leverage factor to the InsightWeightingPortfolioConstructionModel
class LeveragePCM(InsightWeightingPortfolioConstructionModel):
    
    leverage = 0.0
    
    def CreateTargets(self, algorithm, insights):
        
        targets = super().CreateTargets(algorithm, insights)
        
        return [PortfolioTarget(x.Symbol, x.Quantity*(1+self.leverage)) for x in targets]
''' An ensemble approach to GEM - Global Equities Momentum.
'''
from alpha_model import GEMEnsembleAlphaModel
from pcm import LeveragePCM

class GlobalTacticalAssetAllocation(QCAlgorithm):
    
    def Initialize(self):
         
        self.SetStartDate(2005, 1, 1)
        #self.SetEndDate(2020, 5, 20)
        self.SetCash(100000) 
        self.Settings.FreePortfolioValuePercentage = 0.02
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
        # PNQI, TLT
        tickers = ['SPY', 'EFA', 'TLT'] #for plotting
        us_equity = Symbol.Create('SPY', SecurityType.Equity, Market.USA)
        foreign_equity = Symbol.Create('EFA', SecurityType.Equity, Market.USA)
        bond = Symbol.Create('TLT', SecurityType.Equity, Market.USA)
        symbols = [us_equity, foreign_equity, bond]
   
        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddUniverseSelection( ManualUniverseSelectionModel(symbols) )

        self.AddAlpha( GEMEnsembleAlphaModel(us_equity, foreign_equity, bond) )
        self.Settings.RebalancePortfolioOnSecurityChanges = False
        self.Settings.RebalancePortfolioOnInsightChanges = False
        self.SetPortfolioConstruction(LeveragePCM(self.RebalanceFunction, PortfolioBias.Long))
        self.lastRebalanceTime = None
        
        self.SetExecution( ImmediateExecutionModel() ) 
        self.AddRiskManagement( NullRiskManagementModel() )
        
        # Initialise plot
        assetWeightsPlot = Chart('AssetWeights %')
        for ticker in tickers:
            assetWeightsPlot.AddSeries(Series(ticker, SeriesType.Line, f'{ticker}%')) 

    def RebalanceFunction(self, time):

        return Expiry.EndOfMonth(self.Time)
    
    def OnData(self, data):
        # Update Plot
        for kvp in self.Portfolio:
                symbol = kvp.Key
                holding = kvp.Value 
                self.Plot('AssetWeights %', f"{str(holding.Symbol)}%", holding.HoldingsValue/self.Portfolio.TotalPortfolioValue)