Overall Statistics
Total Trades
130
Average Win
0.93%
Average Loss
-1.06%
Compounding Annual Return
1.961%
Drawdown
24.700%
Expectancy
0.132
Net Profit
11.030%
Sharpe Ratio
0.199
Probabilistic Sharpe Ratio
2.074%
Loss Rate
40%
Win Rate
60%
Profit-Loss Ratio
0.88
Alpha
0.029
Beta
-0.073
Annual Standard Deviation
0.115
Annual Variance
0.013
Information Ratio
-0.316
Tracking Error
0.213
Treynor Ratio
-0.314
Total Fees
$187.73
## 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(2015, 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', 'VEU', 'IEF'] #for plotting
        us_equity = Symbol.Create('SPY', SecurityType.Equity, Market.USA)
        foreign_equity = Symbol.Create('VEU', SecurityType.Equity, Market.USA)
        bond = Symbol.Create('IEF', 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)