Overall Statistics
Total Trades
537
Average Win
0.16%
Average Loss
-0.14%
Compounding Annual Return
5.118%
Drawdown
26.400%
Expectancy
0.949
Net Profit
64.586%
Sharpe Ratio
0.451
Probabilistic Sharpe Ratio
2.813%
Loss Rate
10%
Win Rate
90%
Profit-Loss Ratio
1.16
Alpha
0.055
Beta
-0.069
Annual Standard Deviation
0.106
Annual Variance
0.011
Information Ratio
-0.304
Tracking Error
0.198
Treynor Ratio
-0.695
Total Fees
$547.16
'''An implementation of Meb Faber's basic Global Tactical Asset Allocation model (GTAA)(5) 
B&H portfolio with monthly rebalancing, as found in the following paper: 
"A Quantitative Approach to Tactical Asset Allocation" published May 2006.
'''
class GlobalTacticalAssetAllocationBase(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(datetime.now() - timedelta(365*10))
        self.SetEndDate(datetime.now() - timedelta(5))
        self.SetCash(100000) 
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
        self.UniverseSettings.Resolution = Resolution.Daily
        symbols = [ Symbol.Create("SPY", SecurityType.Equity, Market.USA), #US Large Cap
                    Symbol.Create("VEA", SecurityType.Equity, Market.USA), #Developed Foreign Stocks (2007/8)
                    Symbol.Create("IEF", SecurityType.Equity, Market.USA), #US 10Y Gov.Bonds
                    Symbol.Create("DBC", SecurityType.Equity, Market.USA), #GSCI Commodities (2006/3)
                    Symbol.Create("VNQ", SecurityType.Equity, Market.USA)  #US RealEstate
                    ]
        self.AddUniverseSelection(ManualUniverseSelectionModel(symbols))
        self.AddAlpha(ConstantAlphaModel(InsightType.Price, InsightDirection.Up, timedelta(days = 20*365), None, None))
        self.Settings.RebalancePortfolioOnInsightChanges = False
        self.Settings.RebalancePortfolioOnSecurityChanges = False
        self.SetPortfolioConstruction( EqualWeightingPortfolioConstructionModel(self.DateRules.MonthStart()) )
        self.SetExecution( ImmediateExecutionModel() ) 
        self.AddRiskManagement( NullRiskManagementModel() )
        
        # 1) Setting a Benchmark to plot with equity
        self.benchmarkTicker = 'SPY'
        self.SetBenchmark(self.benchmarkTicker)
        self.initBenchmarkPrice = None
    
    
    def UpdateBenchmarkValue(self):
        ''' Simulate buy and hold the Benchmark '''
        if self.initBenchmarkPrice is None:
            self.initBenchmarkCash = self.Portfolio.Cash
            self.initBenchmarkPrice = self.Benchmark.Evaluate(self.Time)
            self.benchmarkValue = self.initBenchmarkCash
        else:
            currentBenchmarkPrice = self.Benchmark.Evaluate(self.Time)
            self.benchmarkValue = (currentBenchmarkPrice / self.initBenchmarkPrice) * self.initBenchmarkCash    
            
            
    def OnData(self, data):
        # 2) simulate buy and hold the benchmark and plot its daily value as we are using daily data.
        # Otherwise schedule when to call this function!
        self.UpdateBenchmarkValue()
        self.Plot('Strategy Equity', self.benchmarkTicker, self.benchmarkValue)