| Overall Statistics |
|
Total Trades 9 Average Win 6.79% Average Loss 0% Compounding Annual Return 12.285% Drawdown 7.800% Expectancy 0 Net Profit 24.966% Sharpe Ratio 1.163 Probabilistic Sharpe Ratio 57.736% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.022 Beta 0.254 Annual Standard Deviation 0.074 Annual Variance 0.006 Information Ratio -1.33 Tracking Error 0.127 Treynor Ratio 0.341 Total Fees $12.91 Estimated Strategy Capacity $2400000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X |
class VerticalQuantumAtmosphericScrubbers(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 4, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.dict = {}
self.AddEquity("SPY", Resolution.Daily)
#define our bb indicator for SPY
self.bb = self.BB("SPY", 20, 2, MovingAverageType.Simple, Resolution.Daily);
#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