Overall Statistics
Total Trades
5
Average Win
0%
Average Loss
0%
Compounding Annual Return
3.703%
Drawdown
0.300%
Expectancy
0
Net Profit
0.319%
Sharpe Ratio
1.292
Probabilistic Sharpe Ratio
54.366%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.036
Beta
-0.025
Annual Standard Deviation
0.02
Annual Variance
0
Information Ratio
-3.21
Tracking Error
0.11
Treynor Ratio
-1.067
Total Fees
$9.76
Estimated Strategy Capacity
$470000000.00
Lowest Capacity Asset
AMZN R735QTJ8XC9X
Portfolio Turnover
1.54%
#region imports
from AlgorithmImports import *
#endregion
from QuantConnect.Data.Market import TradeBar

class RollingWindowAlgorithm(QCAlgorithm):
    '''Basic template algorithm simply initializes the date range and cash'''

    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
        
        self.SetStartDate(2013,10,1)   # Set Start Date
        self.SetEndDate(2013,11,1)     # Set End Date
        self.SetCash(100000)           # Set Strategy Cash
        self.AddEquity("QQQ", Resolution.Daily)
        self.symbols = ["AAPL", "GOOGL", "FB", "AMZN", "QQQ"]

        
		# Creates a Rolling Window indicator to keep the 2 TradeBar
        self.window = {}
        for symbol in self.symbols:
            self.AddEquity(symbol, Resolution.Daily)
            self.window[symbol] = RollingWindow[TradeBar](5) 

    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
        
        for symbol in self.symbols:
            # Add TradeBar for each stock in rolling window
            self.window[symbol].Add(data[symbol])



        # Wait for window to be ready: needs two additions
            if not self.window[symbol].IsReady: return


            currBar = self.window[symbol][0]                     # Current bar had index zero.
            pastBar = self.window[symbol][1]                     # Past bar has index one.


        # Remember: avoid logging prices
        self.Log("{0} -> {1} ... {2} -> {3}".format(pastBar.Time, pastBar.Close, currBar.Time, currBar.Close))

        for symbol in self.symbols:
            if not self.Portfolio.Invested and currBar.Close < pastBar.Close:
                self.SetHoldings(symbol, .1)