Overall Statistics
Total Trades
812
Average Win
0.09%
Average Loss
-0.06%
Compounding Annual Return
6.399%
Drawdown
40.800%
Expectancy
1.102
Net Profit
97.872%
Sharpe Ratio
0.456
Loss Rate
20%
Win Rate
80%
Profit-Loss Ratio
1.63
Alpha
0.125
Beta
-4.044
Annual Standard Deviation
0.129
Annual Variance
0.017
Information Ratio
0.33
Tracking Error
0.13
Treynor Ratio
-0.015
Total Fees
$814.83
from math import ceil,floor,isnan
from datetime import datetime
import pandas as pd
import numpy as np
from scipy.optimize import minimize



class AssetAllocationAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2007, 01, 01)  #Set Start Date
        self.SetEndDate(2018, 01, 01)    #Set End Date
        self.SetCash(100000)            #Set Strategy Cash

        tickers = [ "IEF", "TLT", "SPY", "EFA", "EEM", "JPXN", "VGT"]
        self.symbols = [] 
        for i in tickers:
            self.symbols.append(self.AddEquity(i, Resolution.Daily).Symbol)

        self.Schedule.On(self.DateRules.MonthStart("SPY"), self.TimeRules.AfterMarketOpen("SPY"), Action(self.Rebalancing))
       

    def OnData(self, data):
        pass
        
    def Rebalancing(self):
        
  
        for syl in self.symbols:
            # equally weighted
            self.SetHoldings(syl, 1.0/len(self.symbols))