Overall Statistics
Total Orders
2509
Average Win
0.42%
Average Loss
-0.46%
Compounding Annual Return
7.411%
Drawdown
19.200%
Expectancy
0.066
Start Equity
100000
End Equity
142986.26
Net Profit
42.986%
Sharpe Ratio
0.219
Sortino Ratio
0.23
Probabilistic Sharpe Ratio
16.494%
Loss Rate
44%
Win Rate
56%
Profit-Loss Ratio
0.91
Alpha
0
Beta
0
Annual Standard Deviation
0.083
Annual Variance
0.007
Information Ratio
0.652
Tracking Error
0.083
Treynor Ratio
0
Total Fees
$3143.30
Estimated Strategy Capacity
$430000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
136.79%
Drawdown Recovery
961
#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(self.end_date - timedelta(5*365))
        self.set_cash(100000)
        self.set_brokerage_model(BrokerageName.INTERACTIVE_BROKERS_BROKERAGE)
        self.settings.seed_initial_prices = True
        self._spy = self.add_equity("SPY")
        
        date_rule = self.date_rules.every_day(self._spy)
        # Buy at market close.
        self.schedule.on(
            date_rule, 
            self.time_rules.before_market_close(self._spy, 20), 
            lambda: self.market_on_close_order(self._spy, self.calculate_order_quantity(self._spy, 1.0))
        )
        # Liquidate at market open.
        self.schedule.on(
            date_rule, 
            self.time_rules.before_market_open(self._spy, 10), 
            self._liquidate
        )
    
    def _liquidate(self):
        if self._spy.holdings.invested:
            self.market_on_open_order(self._spy, -self._spy.holdings.quantity)