Overall Statistics
Total Trades
3047
Average Win
0.02%
Average Loss
0.00%
Compounding Annual Return
-0.364%
Drawdown
3.500%
Expectancy
-0.487
Net Profit
-1.808%
Sharpe Ratio
-0.309
Probabilistic Sharpe Ratio
0.022%
Loss Rate
95%
Win Rate
5%
Profit-Loss Ratio
9.17
Alpha
-0.002
Beta
-0.011
Annual Standard Deviation
0.008
Annual Variance
0
Information Ratio
-0.593
Tracking Error
0.111
Treynor Ratio
0.22
Total Fees
$9690.90
Estimated Strategy Capacity
$470000.00
Lowest Capacity Asset
SST V2245V5VOQQT
#region imports
from AlgorithmImports import *
#endregion

class UncorrelatedAssetsDemo(QCAlgorithm):
    
    def Initialize(self):
        #1. Required: Five years of backtest history
        self.SetStartDate(2014, 1, 1)
        self.SetEndDate(2019, 1, 1)
    
        #2. Required: Alpha Streams Models:
        self.SetBrokerageModel(BrokerageName.AlphaStreams)
    
        #3. Required: Significant AUM Capacity
        self.SetCash(1000000)
    
        #4. Required: Benchmark to SPY
        self.SetBenchmark("SPY")
        
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
    
        self.assets = ["SHY", "TLT", "IEI", "SHV", "TLH", "EDV", "BIL",
                        "SPTL", "TBT", "TMF", "TMV", "TBF", "VGSH", "VGIT",
                        "VGLT", "SCHO", "SCHR", "SPTS", "GOVT"]
        
        # Add Equity ------------------------------------------------ 
        for i in range(len(self.assets)):
            self.AddEquity(self.assets[i], Resolution.Minute)
        
        # Set Scheduled Event Method For Our Model. In this example, we'll rebalance every month.
        self.Schedule.On(self.DateRules.MonthStart(), 
            self.TimeRules.BeforeMarketClose("SHY", 5), 
            self.EveryDayBeforeMarketClose)
            
    def EveryDayBeforeMarketClose(self):
        qb = self
        # Fetch history on our universe
        history = qb.History(qb.Securities.Keys, 252*2, Resolution.Daily)
        if history.empty: return
    
        # Select the close column and then call the unstack method, then call pct_change to compute the daily return.
        returns = history['close'].unstack(level=0).pct_change().iloc[1:]
    
        # Get correlation
        correlation = returns.corr()
        
        # Find 5 assets with lowest absolute sum correlation
        selected = []
        for index, row in correlation.iteritems():
            corr_rank = row.abs().sum()
            selected.append((index, corr_rank))
    
        sort_ = sorted(selected, key = lambda x: x[1])
        selected = [x[0] for x in sort_[:5]]
    
        # ==============================
        
        insights = []
        
        for symbol in selected:
            insights.append( Insight.Price(symbol, Expiry.EndOfMonth, InsightDirection.Up) )
    
        self.EmitInsights(insights)