Overall Statistics
Total Orders
405
Average Win
0.02%
Average Loss
-0.03%
Compounding Annual Return
-0.313%
Drawdown
3.300%
Expectancy
-0.282
Start Equity
1000000
End Equity
984442.20
Net Profit
-1.556%
Sharpe Ratio
-1.885
Sortino Ratio
-1.4
Probabilistic Sharpe Ratio
0.033%
Loss Rate
59%
Win Rate
41%
Profit-Loss Ratio
0.77
Alpha
-0.015
Beta
-0.011
Annual Standard Deviation
0.008
Annual Variance
0
Information Ratio
-0.59
Tracking Error
0.111
Treynor Ratio
1.344
Total Fees
$7415.71
Estimated Strategy Capacity
$420000.00
Lowest Capacity Asset
SST V2245V5VOQQT
Portfolio Turnover
4.05%
#region imports
from AlgorithmImports import *
#endregion

class UncorrelatedAssetsDemo(QCAlgorithm):
    
    def initialize(self):
        #1. Required: Five years of backtest history
        self.set_start_date(2014, 1, 1)
        self.set_end_date(2019, 1, 1)
    
        #2. Required: Alpha Streams Models:
        self.set_brokerage_model(BrokerageName.ALPHA_STREAMS)
    
        #3. Required: Significant AUM Capacity
        self.set_cash(1000000)
    
        #4. Required: Benchmark to SPY
        self.set_benchmark("SPY")
        
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())
        self.set_execution(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.add_equity(self.assets[i], Resolution.MINUTE).symbol
        
        # Set Scheduled Event Method For Our Model. In this example, we'll rebalance every month.
        self.schedule.on(self.date_rules.month_start(), 
            self.time_rules.before_market_close("SHY", 5), 
            self.every_day_before_market_close)
            
    def every_day_before_market_close(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.iterrows():
            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.END_OF_MONTH, InsightDirection.UP) )
    
        self.emit_insights(insights)