| Overall Statistics |
|
Total Trades 55 Average Win 4.52% Average Loss -0.67% Compounding Annual Return 12.424% Drawdown 28.900% Expectancy 6.501 Net Profit 233.158% Sharpe Ratio 0.816 Probabilistic Sharpe Ratio 21.797% Loss Rate 4% Win Rate 96% Profit-Loss Ratio 6.79 Alpha 0.125 Beta -0.104 Annual Standard Deviation 0.137 Annual Variance 0.019 Information Ratio -0.085 Tracking Error 0.219 Treynor Ratio -1.071 Total Fees $55.00 Estimated Strategy Capacity $1000000000.00 |
class VerticalQuantumAtmosphericScrubbers(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2011, 1, 1) # Set Start Date
self.SetCash(5000) # 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