| Overall Statistics |
|
Total Trades 10 Average Win 5.98% Average Loss -24.74% Compounding Annual Return -19.901% Drawdown 68.900% Expectancy -0.255 Net Profit -21.484% Sharpe Ratio 0.066 Probabilistic Sharpe Ratio 12.078% Loss Rate 40% Win Rate 60% Profit-Loss Ratio 0.24 Alpha 0.08 Beta -0.293 Annual Standard Deviation 0.608 Annual Variance 0.369 Information Ratio -0.138 Tracking Error 0.694 Treynor Ratio -0.137 Total Fees $15600.63 |
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")
AddReference("QuantConnect.Indicators")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Brokerages import *
from QuantConnect.Orders import *
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(2019, 6, 1) #Set Start Date
self.SetEndDate(2020, 7, 1) #Set End Date
self.SetCash('BTC', 100)
#self.SetBrokerageModel(BrokerageName.GDAX)
self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
# define crypto we want to trade on
# ETHUSD, LTCUSD or BTCUSD
self.target_crypto = "ETHBTC"
self.AddCrypto(self.target_crypto, Resolution.Daily)
# create a bollinger band
self.Bolband = self.BB(self.target_crypto, 20, 2, MovingAverageType.Simple, Resolution.Daily)
# Plot Bollinger band
self.PlotIndicator(
"Indicators",
self.Bolband.LowerBand,
self.Bolband.MiddleBand,
self.Bolband.UpperBand,
)
# create a momentum indicator over 3 days
self.mom = self.MOM(self.target_crypto, 5)
#self.mom = self.MOM(self.target_crypto, 3)
# Plot Momentum
self.PlotIndicator(
"Indicators",
self.mom
)
# set warmup period
self.SetWarmUp(20)
def OnData(self, data):
holdings = self.Portfolio[self.target_crypto].Quantity
price = self.Securities[self.target_crypto].Close
mom = self.mom.Current.Value
# buy if price closes above upper bollinger band
if holdings <= 0:
if price < self.Bolband.LowerBand.Current.Value:
numBtc = self.Portfolio.CashBook['BTC'].Amount
quantity = round(.97 * numBtc / self.Securities['ETHBTC'].Price, 2)
self.MarketOrder(self.target_crypto, quantity)
# sell if price closes below middle bollinger band
if holdings > 0 and price > self.Bolband.UpperBand.Current.Value:
self.Liquidate()