| Overall Statistics |
|
Total Trades 2 Average Win 0% Average Loss -0.03% Compounding Annual Return 9.865% Drawdown 55.100% Expectancy -1 Net Profit 409.488% Sharpe Ratio 0.564 Probabilistic Sharpe Ratio 2.321% Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.099 Beta -0.089 Annual Standard Deviation 0.16 Annual Variance 0.026 Information Ratio -0.016 Tracking Error 0.237 Treynor Ratio -1.016 Total Fees $8.79 |
class VerticalQuantumAtmosphericScrubbers(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2002, 10, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.dict = {}
self.SetBrokerageModel(BrokerageName.AlphaStreams)
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.lowerBollingerFirstHit = False
self.lowerLow = 0.0
self.higherLow = 0.0
self.higherHigh = 1.0
self.lowerHigh = 1.0
self.tradeBuyReady = False
self.upperBollingerFirstHit = False
self.buyTradeActive = False
self.sellTradeActive = False
self.buyAndHold = True
def OnData(self, data):
#make sure our indicator is ready
if not self.bb.IsReady:
return
price = self.Securities["SPY"].Price
bollingerValue = (price - self.bb.LowerBand.Current.Value)/(self.bb.UpperBand.Current.Value - self.bb.LowerBand.Current.Value)
if self.buyAndHold is False:
#if the price is below 0% BB
if not self.Portfolio["SPY"].Invested:
if bollingerValue < 0.0 and bollingerValue<self.lowerLow and self.buyTradeActive is False:
#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 = bollingerValue
self.lowerBollingerFirstHit = True
self.buyTradeActive = False
elif bollingerValue >= 0.0 and bollingerValue > self.lowerLow and self.lowerBollingerFirstHit is True:
self.buyTradeActive = True
self.higherLow = bollingerValue
elif self.buyTradeActive is True and bollingerValue < self.higherLow and bollingerValue > self.lowerLow:
self.SetHoldings("SPY", 1)
self.buyPrice = price
self.buyTradeActive = False
self.lowerBollingerFirstHit = False
elif self.Portfolio["SPY"].Invested:
if price<self.buyPrice and ((self.buyPrice - price)/price)*100 > 6.66:
self.Liquidate()
elif bollingerValue > 1.0 and bollingerValue > self.higherHigh and self.sellTradeActive is False:
self.higherHigh = bollingerValue
self.upperBollingerFirstHit = True
elif bollingerValue <= 1.0 and bollingerValue < self.higherHigh and self.upperBollingerFirstHit is True:
self.sellTradeActive = True
self.lowerHigh = bollingerValue
elif self.sellTradeActive is True and bollingerValue > 1.0 and bollingerValue > self.lowerHigh:
self.Liquidate()
self.sellTradeActive = True
self.upperBollingerFirstHit = False
else:
self.SetHoldings("SPY", 1)