| Overall Statistics |
|
Total Trades 193 Average Win 2.34% Average Loss -3.80% Compounding Annual Return 14.621% Drawdown 30.800% Expectancy 0.212 Net Profit 98.137% Sharpe Ratio 0.746 Probabilistic Sharpe Ratio 24.314% Loss Rate 25% Win Rate 75% Profit-Loss Ratio 0.62 Alpha 0 Beta 0.922 Annual Standard Deviation 0.242 Annual Variance 0.059 Information Ratio -0.086 Tracking Error 0.171 Treynor Ratio 0.196 Total Fees $263.64 Estimated Strategy Capacity $290000000.00 Lowest Capacity Asset AAPL R735QTJ8XC9X |
from QuantConnect.Indicators import *
import decimal as d
### <summary>
### In this example we are looking for price to breakout above the bollinger bands
### and look to buy when we see that. We hold our position until price touches the
### middle band of the bollinger bands.
###
class BollingerBreakoutAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2016, 9, 22) #Set Start Date
self.SetCash(10000) #Set Strategy Cash
#self.SetBrokerageModel(BrokerageName.GDAX)
self.target_stock = "AAPL"
self.AddEquity(self.target_stock, Resolution.Hour)
# create a bollinger band
self.Bolband = self.BB(self.target_stock, 20, 2, MovingAverageType.Simple, Resolution.Hour);
# Plot Bollinger band
self.PlotIndicator(
"Indicators",
self.Bolband.LowerBand,
self.Bolband.MiddleBand,
self.Bolband.UpperBand
)
# set warmup period
self.SetWarmUp(20)
def OnData(self, data):
holdings = self.Portfolio[self.target_stock].Quantity
price = self.Securities[self.target_stock].Close
self.Plot("Indicators", "Close", price);
# buy if price closes above upper bollinger band
if holdings <= 0:
if price < self.Bolband.LowerBand.Current.Value:
self.SetHoldings(self.target_stock, 1.0)
# sell if price closes below middle bollinger band
if holdings > 0 and price > self.Bolband.UpperBand.Current.Value:
self.Liquidate()