Overall Statistics
Total Trades
13
Average Win
0.80%
Average Loss
-0.65%
Compounding Annual Return
12.518%
Drawdown
2.200%
Expectancy
0.117
Net Profit
0.508%
Sharpe Ratio
0.909
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
1.23
Alpha
0.198
Beta
-3.903
Annual Standard Deviation
0.137
Annual Variance
0.019
Information Ratio
0.772
Tracking Error
0.137
Treynor Ratio
-0.032
Total Fees
$24.05
from datetime import timedelta
import math

class TachyonOptimizedCoil(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2018, 11, 15)  # Set Start Date
        self.SetEndDate(2018,11,30) # Set End Date
        self.SetCash(100000)  # Set Strategy Cash
        
        # subscribe SPY with minute level resolution
        self.AddEquity("SPY", Resolution.Minute)
        
        # consolidate data into 1-day bar
        oneDayConsolidator = TradeBarConsolidator(timedelta(1))
        oneDayConsolidator.DataConsolidated += self.OneDayBarHandler
        self.SubscriptionManager.AddConsolidator("SPY", oneDayConsolidator)
        
        # store high from previous day
        self.previousHigh = -1


    def OnData(self, data):
        # On first day, do nothing
        if self.previousHigh < 0:
            return
        
        # place order only if we haven't made orders or fulfilled orders
        if not self.Portfolio.Invested and len(self.Transactions.GetOpenOrders()) == 0:
            quantity = math.floor(self.Portfolio.Cash / self.previousHigh)
            self.Log(f'limit order price: {self.previousHigh}')
            self.StopMarketOrder("SPY",quantity,self.previousHigh)
        
    def OneDayBarHandler(self, sender, bar):
        # update self.high
        self.previousHigh = bar.High
        
        # liquidate for new order on next day
        self.Liquidate()
        #self.Log(f'previous day high: {self.previousHigh}')
        
    def OnOrderEvent(self, orderEvent):
        self.Log(orderEvent)