Overall Statistics
Total Trades
738
Average Win
0.00%
Average Loss
0.00%
Compounding Annual Return
-56.302%
Drawdown
0.900%
Expectancy
-0.992
Net Profit
-0.903%
Sharpe Ratio
-10.613
Probabilistic Sharpe Ratio
0%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
1.82
Alpha
-0.064
Beta
-0.808
Annual Standard Deviation
0.05
Annual Variance
0.003
Information Ratio
-10.952
Tracking Error
0.102
Treynor Ratio
0.66
Total Fees
$738.00
Estimated Strategy Capacity
$4000.00
Lowest Capacity Asset
SGLBW WI3VVSA3AH5X
# region imports
from AlgorithmImports import *

# endregion

class CrawlingMagentaAlbatross(QCAlgorithm):

    def Initialize(self):
#        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Cash)
        self.SetStartDate(2022, 1, 1)  # Set Start Date
        self.SetEndDate(2022, 1, 4)
        self.SetCash(100000)  # Set Strategy Cash
        self.AddUniverse(self.SelectCoarse)
        self.AddEquity("SPY", Resolution.Minute)
        
        self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.AfterMarketOpen("SPY", 1), self.updateOpenPrice)
        self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.BeforeMarketClose("SPY", 10), self.onMarketClose)
        self.pause = False

        self.opening_price ={}
        self.symbols_below_k = []
        self.count = 0

    def SelectCoarse(self, coarse):
        allSymbols = sorted(coarse, key=lambda c:c.DollarVolume, reverse=True)

        self.symbols_below_k = [s.Symbol for s in allSymbols if s.Price < 1000]

        return self.symbols_below_k

    def OnSecuritiesChanged(self, changes: SecurityChanges):
        for security in changes.AddedSecurities:
            self.opening_price[security.Symbol] = {'MarketOpenPrice': 0.0}

    def OnData(self, data):
        if self.pause == True:
            return
        for x in self.opening_price:
            

            if self.opening_price[x]['MarketOpenPrice'] == 0.0:
                continue
            if float(self.Securities[x].Price) > 1.1 * float(self.opening_price[x]['MarketOpenPrice']) and not self.Securities[x].Invested:
                self.MarketOrder(x, 1)
                self.count += 1
                self.Debug("[{t}] {x}: openPrice: {o} buyingPrice: {b}".format(t=self.Time, x=x, o=self.opening_price[x]['MarketOpenPrice'], b=self.Securities[x].Price))
        invested = [x.Key for x in self.Portfolio if x.Value.Invested]
        self.Plot("Amount invested","stocks", len(invested))
        

    def onMarketClose(self):
        self.Log("End day. Liquidating!")
        self.pause = True
        self.Liquidate()
        

        
        self.Log("Count: {c}".format(c=self.count))

   

    def updateOpenPrice(self):
        self.pause = False
        for x in self.opening_price:
            self.opening_price[x] = {'MarketOpenPrice': float(self.Securities[x].Price)}