Overall Statistics
Total Trades
390
Average Win
1.74%
Average Loss
-1.75%
Compounding Annual Return
0.468%
Drawdown
13.500%
Expectancy
0.028
Net Profit
3.888%
Sharpe Ratio
0.096
Probabilistic Sharpe Ratio
0.088%
Loss Rate
48%
Win Rate
52%
Profit-Loss Ratio
0.99
Alpha
0
Beta
0
Annual Standard Deviation
0.043
Annual Variance
0.002
Information Ratio
0.096
Tracking Error
0.043
Treynor Ratio
0
Total Fees
$20046.90
Estimated Strategy Capacity
$23000.00
Lowest Capacity Asset
UNL UHQJ0EDGU6HX
#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(2025, 3, 1)     #Set End Date
        self.SetCash(1000000)            #Set Strategy Cash
        self.position = self.AddEquity("BOIL", Resolution.Minute).Symbol
        self.position2 = self.AddEquity("UNL", Resolution.Minute).Symbol
        self.spy = self.AddEquity("SPY", Resolution.Minute).Symbol
        
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
        #monthly
                # self.Schedule.On(self.DateRules.MonthEnd("SPY", 1),
        self.Schedule.On(self.DateRules.MonthEnd("SPY",1), self.TimeRules.AfterMarketOpen("SPY", 5), self.enter)
        self.Schedule.On(self.DateRules.MonthEnd("SPY", 1), self.TimeRules.AfterMarketOpen("SPY", 4), self.exit)

        # self.Schedule.On(self.DateRules.EveryDay(self.spy), self.TimeRules.BeforeMarketClose("SPY", 15), self.enter)
        # self.Schedule.On(self.DateRules.EveryDay(self.spy), self.TimeRules.AfterMarketOpen("SPY", 0), self.exit)


    def enter(self):
        if not self.Portfolio.Invested:
            # self.SetHoldings(self.spy, 1)
            self.SetHoldings(self.position, -.1)
            self.SetHoldings(self.position2, .2)

    def exit(self):
        if self.Portfolio.Invested:
            self.Liquidate()

    def OnData(self, data):
        pass