| Overall Statistics |
|
Total Trades 13 Average Win 1.53% Average Loss 0% Compounding Annual Return 35.234% Drawdown 3.500% Expectancy 0 Net Profit 10.311% Sharpe Ratio 3.769 Probabilistic Sharpe Ratio 88.530% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.142 Beta 0.754 Annual Standard Deviation 0.094 Annual Variance 0.009 Information Ratio 1.345 Tracking Error 0.055 Treynor Ratio 0.468 Total Fees $13.00 Estimated Strategy Capacity $240000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X |
class VerticalQuantumAtmosphericScrubbers(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 5, 1) # Set Start Date
self.SetCash(5000) # Set Strategy Cash
self.dict = {}
self.AddEquity("SPY", Resolution.Hour)
#define our bb indicator for SPY
self.bb = self.BB("SPY", 20, 2, MovingAverageType.Simple, Resolution.Hour);
#tradelock keeps track of whether our entry conditions have been met
# if trade lock is true, entry conditions are not yet met, we cannot enter a trade
# if trade lock is false, entry conditions have been met and we can now enter a trade
# when available
self.loweBollingerFirstHit = False
self.lowerLow = 0.0
self.tradeBuyReady = False
self.upperBollingerFirstHit = False
self.tradeSellReady = False
self.buyPrice = 0
def OnData(self, data):
#make sure our indicator is ready
if not self.bb.IsReady:
return
price = self.Securities["SPY"].Price
#if the price is below 0% BB
if price < self.bb.LowerBand.Current.Value and self.Portfolio["SPY"].Invested is False and self.bb.LowerBand.Current.Value < self.lowerLow:
#if we are already in a long position, we liquidate and cut our losses
#if self.Portfolio["SPY"].Invested:
#self.Liquidate()
#we set trade lock to false, allowing us to enter a trade next time price crosses above 0% BB
self.lowerLow = self.bb.LowerBand.Current.Value
if price > self.bb.LowerBand.Current.Value and self.Portfolio["SPY"].Invested is False and self.tradeBuyReady is False:
self.tradeBuyReady = True
#if the price is above 0% BB and also trade lock is false
if price <= self.bb.LowerBand.Current.Value and self.tradeBuyReady is True and self.bb.LowerBand.Current.Value > self.lowerLow and self.Portfolio["SPY"].Invested is False:
#we enter a long position
self.SetHoldings("SPY", 1)
self.buyPrice = price
self.watchOut = False
self.tradeBuyReady = False
self.lowerLow = 0
if price >= self.bb.UpperBand.Current.Value and self.Portfolio["SPY"].Invested and self.upperBollingerFirstHit is False and price > self.buyPrice:
#if the price crosses the upperband and we have a long position
#we liquidate for profit
#self.upperBollingerFirstHit = True
self.Liquidate()
if price < self.bb.UpperBand.Current.Value and self.upperBollingerFirstHit is True and self.tradeSellReady is False and price > self.buyPrice:
self.tradeSellReady = True
if price >= self.bb.UpperBand.Current.Value and self.tradeSellReady is True and price > self.buyPrice:
self.Liquidate()
self.tradeSellReady = False
self.upperBollingerFirstHit = False