Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
63.143%
Drawdown
2.600%
Expectancy
0
Net Profit
0%
Sharpe Ratio
3.863
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.039
Beta
0.982
Annual Standard Deviation
0.117
Annual Variance
0.014
Information Ratio
4.479
Tracking Error
0.007
Treynor Ratio
0.461
Total Fees
$3.20
from QuantConnect.Data.Market import TradeBar
from datetime import timedelta

class MyAlgorithm(QCAlgorithm):
    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
        # Find more symbols here: http://quantconnect.com/data
        self.AddEquity("SPY", Resolution.Second)

        consolidator = TradeBarConsolidator(timedelta(1))
        consolidator.DataConsolidated += self.OnDailyData
        self.SubscriptionManager.AddConsolidator("SPY", consolidator)

        self.daily = RollingWindow[TradeBar](2)
        self.window = RollingWindow[TradeBar](2)

    # Add daily bar to daily rolling window
    def OnDailyData(self, sender, bar):
        self.daily.Add(bar)


    # Add second bar to window rolling window
    def OnData(self, data):
        self.window.Add(data["SPY"])
        if not (self.window.IsReady and self.daily.IsReady): return
        currBar = self.window[0].Close
        yesterdayc = self.daily[1].Close
        if not self.Portfolio.Invested and currBar<yesterdayc:
            self.SetHoldings("SPY", 1)