Overall Statistics
Total Trades
12
Average Win
2.78%
Average Loss
-1.47%
Compounding Annual Return
53.431%
Drawdown
8.100%
Expectancy
0.446
Net Profit
3.824%
Sharpe Ratio
1.902
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
1.89
Alpha
0.611
Beta
-0.367
Annual Standard Deviation
0.186
Annual Variance
0.035
Information Ratio
-1.219
Tracking Error
0.282
Treynor Ratio
-0.966
Total Fees
$12.00
import numpy as np
import pandas as pd

class TachyonQuantumProcessor(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 1, 1)  # Set Start Date
        self.SetEndDate(2019,2,1)
        self.SetCash(10000)  # Set Strategy Cash
        
        self.symbols = ['AAPL','NFLX','NVDA','TSLA','SPY']
        for i in self.symbols:
            self.AddEquity(i,Resolution.Minute,Market.USA,True,1,True)
        
        self.openPrices = pd.DataFrame(columns=self.symbols)
        self.closePrices = pd.DataFrame(columns=self.symbols)
        self.gapPercentage = pd.DataFrame(columns=self.symbols)
        self.highestPrice = pd.DataFrame(columns=self.symbols)
        
        self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.At(9,30), self.EveryDayOpen)
        self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.At(12,30), self.EveryDayLiquidate)
        self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.At(15,30), self.EveryDayClose)
        
        self.stopMarketTicket = {}
        
    def EveryDayOpen(self):
        
        open = []
        
        for symbol in self.symbols:
            newOpen = self.dataPrice[symbol].Open
            open = np.append(open, newOpen)
            
        self.openPrices.loc[0,self.symbols] = open
        self.gapPercentage = (self.openPrices-self.closePrices)/self.closePrices
        openingPos = np.sum(np.sum(self.gapPercentage>0.03)+np.sum(self.gapPercentage<-0.03))
        
        for symbol in self.symbols:
            
            if self.gapPercentage[symbol].iloc[0] > 0.03:
                self.SetHoldings(symbol,1/openingPos)
                self.stopMarketTicket[symbol] = self.StopMarketOrder(symbol, -1*self.Portfolio[symbol].Quantity, self.Securities[symbol].Close*0.97)
                # self.stopMarketTicket = self.StopMarketOrder(symbol, -1*self.Portfolio[symbol].Quantity, self.Securities[symbol].Close*0.97)
                self.highestPrice[symbol] = self.Securities[symbol].Close
            elif self.gapPercentage[symbol].iloc[0] < -0.03:
                self.SetHoldings(symbol,-1/openingPos)
                self.stopMarketTicket[symbol] = self.StopMarketOrder(symbol, -1*self.Portfolio[symbol].Quantity, self.Securities[symbol].Close*1.03)
                # self.stopMarketTicket = self.StopMarketOrder(symbol, -1*self.Portfolio[symbol].Quantity, self.Securities[symbol].Close*1.03)
                self.highestPrice[symbol] = self.Securities[symbol].Close
        
        self.Log(f'{self.stopMarketTicket}')
                
    def EveryDayLiquidate(self):
        
        self.Liquidate()
                
    def EveryDayClose(self):
        
        self.Liquidate()
        
        close = []
        
        for symbol in self.symbols:
            newClose = self.dataPrice[symbol].Close
            close = np.append(close, newClose)
            
        self.closePrices.loc[0,self.symbols] = close

    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments:
                data: Slice object keyed by symbol containing the stock data
        '''
        
        self.dataPrice = data