Overall Statistics
Total Trades
12
Average Win
0.00%
Average Loss
0.00%
Compounding Annual Return
181.188%
Drawdown
0.100%
Expectancy
0.121
Net Profit
1.331%
Sharpe Ratio
22.43
Loss Rate
33%
Win Rate
67%
Profit-Loss Ratio
0.68
Alpha
0.734
Beta
0.127
Annual Standard Deviation
0.037
Annual Variance
0.001
Information Ratio
0.665
Tracking Error
0.067
Treynor Ratio
6.548
Total Fees
$12.00
#Multi-part algo template
import numpy as np
from algorithm1 import *

class Multialgorithm(QCAlgorithm):

    def Initialize(self):
        # Set the cash we'd like to use for our backtest
        # This is ignored in live trading 
        self.SetCash(100000)
        
        # Start and end dates for the backtest.
        # These are ignored in live trading.
        self.SetStartDate(2017,1,1)
        self.SetEndDate(2017,1,5)
        
        self.algorithm_list = []
        
        #call algorithms with self so that they get access to the main algorithm
        self.algorithm1 = Algo1(self)
        
        self.algorithm_list.append(self.algorithm1)
        
        self.securities = []
        
        #get all the stocks from each algorithm and append it to one security list, if your algorithms trade
        #the same stocks you will have duplicates, you should add some code to remove duplicates after this step
        for algorithm in self.algorithm_list:
            for stock in algorithm.stocks:
                self.securities.append(stock)
        
        # get the data from all the assets from all your algorithms
        for stock in self.securities:
            self.Debug(str(stock))
            self.AddEquity(stock, Resolution.Minute)
        

    def OnData(self, slice):
        
        # Simple buy and hold template
        for algorithm in self.algorithm_list:
            
            #compute each of your algorithms. This is a hack-job, you should have some separate code that computes
            #all of your algorithms in one step and combines the allocations into one master portfolio 
            #in a scheduled function.
            algorithm.compute_allocation()
            
            for stock in self.securities:
                self.SetHoldings(stock, algorithm.allocation[stock])
class Algo1(object):
    def __init__(self, data):
        
        # __init__ gets called with the "self" from the main algorithm, that data is assigned to a local variable
        # self.data which gets used whenever variables or history is needed from the main algorithm. example:
        # Debug("") is not availible to Algo1, it's part of the main QCAlgorithm so it's called with self.data.Debug("")
        
        self.data = data
        self.data.Debug("initialize algo1")
        
        # Add assets you'd like to use, these get added in main.py initialize
        self.stocks = [
                    "SPY",
                    "QQQ",
                    "TLT",
                    "TIP",
                    "AGG",
                    ]
                    
        # Set the allocation that can be called from whatever is executing your trades.
        self.allocation = {}
        
        # all local parameters for this algorithm go into __init__
        self.parameter = 10
    
    def compute_allocation(self):
        #self.data.Log("compute_allocation")
        
        prices = self.data.History(self.stocks, self.parameter, Resolution.Daily)['close']
        
        for sid in self.stocks:
            self.allocation[sid] = 1.0/len(self.stocks)