Overall Statistics
Total Orders
4633
Average Win
0.64%
Average Loss
-0.70%
Compounding Annual Return
-1.422%
Drawdown
38.700%
Expectancy
-0.009
Start Equity
100000
End Equity
76797.02
Net Profit
-23.203%
Sharpe Ratio
-0.266
Sortino Ratio
-0.295
Probabilistic Sharpe Ratio
0.000%
Loss Rate
48%
Win Rate
52%
Profit-Loss Ratio
0.91
Alpha
0
Beta
0
Annual Standard Deviation
0.097
Annual Variance
0.009
Information Ratio
-0.053
Tracking Error
0.097
Treynor Ratio
0
Total Fees
$21348.82
Estimated Strategy Capacity
$89000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
68.65%
#region imports
from AlgorithmImports import *
#endregion
# https://quantpedia.com/Screener/Details/4
# buy SPY ETF at its closing price and sell it at the opening each day. 


class OvernightTradeAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2000, 1, 1)   #Set Start Date
        self.set_end_date(2018, 6, 1)     #Set End Date
        self.set_cash(100000)            #Set Strategy Cash
        self._spy = self.add_equity("SPY", Resolution.HOUR).symbol
        self.set_brokerage_model(BrokerageName.INTERACTIVE_BROKERS_BROKERAGE)
        date_rule = self.date_rules.every_day(self._spy)
        self.schedule.on(date_rule, self.time_rules.after_market_open("SPY", 0), self._every_day_after_market_open)
        self.schedule.on(date_rule, self.time_rules.before_market_close("SPY", 0), self._every_day_before_market_close)

    def _every_day_before_market_close(self):
        if not self.portfolio.invested:
            self.set_holdings(self._spy, 1)
    
    def _every_day_after_market_open(self):
        if self.portfolio.invested:
            self.liquidate()