Overall Statistics
Total Trades
3099
Average Win
0.12%
Average Loss
-0.15%
Compounding Annual Return
-22.733%
Drawdown
79.700%
Expectancy
-0.672
Net Profit
-79.627%
Sharpe Ratio
-6.393
Probabilistic Sharpe Ratio
0%
Loss Rate
82%
Win Rate
18%
Profit-Loss Ratio
0.81
Alpha
0
Beta
0
Annual Standard Deviation
0.025
Annual Variance
0.001
Information Ratio
-6.393
Tracking Error
0.025
Treynor Ratio
0
Total Fees
$3419.02
Estimated Strategy Capacity
$400000.00
Lowest Capacity Asset
BOIL V0IZ4MOFEHR9
#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. 
import numpy as np


class OvernightTradeAlgorithm(QCAlgorithm):

    def Initialize(self):

        self.SetStartDate(2015, 1, 1)   #Set Start Date
        self.SetEndDate(2021, 3, 1)     #Set End Date
        self.SetCash(100000)            #Set Strategy Cash
        self.boil = self.AddEquity("BOIL", Resolution.Minute).Symbol
        self.spy = self.AddEquity("SPY", Resolution.Minute).Symbol
        
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)

        self.Schedule.On(self.DateRules.EveryDay(self.spy), self.TimeRules.BeforeMarketClose("SPY", 15), self.EveryDayBeforeMarketClose)
        self.Schedule.On(self.DateRules.EveryDay(self.spy), self.TimeRules.AfterMarketOpen("SPY", 0), self.EveryDayAfterMarketOpen)


    def EveryDayBeforeMarketClose(self):
        if not self.Portfolio.Invested:
            # self.SetHoldings(self.spy, 1)
            self.SetHoldings(self.boil, -.5)
    
    def EveryDayAfterMarketOpen(self):
        if self.Portfolio.Invested:
            self.Liquidate()

    def OnData(self, data):
        pass