Overall Statistics
Total Trades
96
Average Win
0.37%
Average Loss
-0.78%
Compounding Annual Return
-14.504%
Drawdown
14.900%
Expectancy
-0.386
Net Profit
-13.619%
Sharpe Ratio
-1.658
Probabilistic Sharpe Ratio
0.000%
Loss Rate
58%
Win Rate
42%
Profit-Loss Ratio
0.47
Alpha
-0.101
Beta
-0
Annual Standard Deviation
0.061
Annual Variance
0.004
Information Ratio
0.012
Tracking Error
0.213
Treynor Ratio
425.859
Total Fees
$206.40
Estimated Strategy Capacity
$85000000.00
Lowest Capacity Asset
ES Y4D62XFM9IPT
# region imports
from AlgorithmImports import *
# endregion

class WeekendTradingWarrior(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2022, 1, 1)  # Set Start Date
        self.SetEndDate(2022, 12, 31)
        self.SetCash(100000)  # Set Strategy Cash
        self.SP500EMini_CC = self.AddFuture(Futures.Indices.SP500EMini, resolution=Resolution.Minute, extendedMarketHours=True) # SP500EMini Continious Contract
        self.SP500EMini_CC.SetFilter(0, 97)
        self.SP500EMini_PC = self.SP500EMini_FC = self.SP500EMini_NC = self.SP500EMini_CC

        self.Schedule.On(self.DateRules.WeekEnd(self.SP500EMini_CC.Symbol, 0),
                 self.TimeRules.BeforeMarketClose(self.SP500EMini_CC.Symbol, 1, extendedMarketClose=True),
                 self.before_market_close)

        self.Schedule.On(self.DateRules.WeekStart (self.SP500EMini_CC.Symbol, 0),
                 self.TimeRules.AfterMarketOpen(self.SP500EMini_CC.Symbol, 1, extendedMarketOpen=True),
                 self.after_market_opn)
    
    def get_current_contract(self):
        for chain in self.CurrentSlice.FutureChains:
            self.popularContracts = [contract for contract in chain.Value if contract.OpenInterest > 1000]
            if len(self.popularContracts) == 0:
                continue
            else:
                sortedByOIContracts = sorted(self.popularContracts, key=lambda k : k.OpenInterest, reverse=True)
                self.SP500EMini_NC = sortedByOIContracts[0]
                break

        # swap contracts when new front contract is found
        if self.SP500EMini_FC.Symbol != self.SP500EMini_NC.Symbol:
            self.Debug(f"{self.Time} new_contract found.. NewContractSymbol: {self.SP500EMini_NC.Symbol} {self.SP500EMini_NC.Expiry}" )
            self.SP500EMini_PC = self.SP500EMini_FC
            self.SP500EMini_FC = self.SP500EMini_NC

    def OnData(self, slice):
        self.get_current_contract()

    def before_market_close(self):
        self.Debug(f"{self.Time} before_market_close called.. FrontContractSymbol: {self.SP500EMini_FC.Symbol}")
        if not self.Portfolio.Invested:
            self.MarketOrder(self.SP500EMini_FC.Symbol, 1)

    def after_market_opn(self):
        self.Debug(f"{self.Time} after_market_open called.. FrontContractSymbol: {self.SP500EMini_FC.Symbol}")
        if self.Portfolio.Invested:
            self.Liquidate()