I took a break from options algos to try my hand at crypto, and this BTC algo is the result.
It was fairly straightforward, using the same architecture patterns and logic I used for equities. There were some gaps in the BTC vendor data, but otherwise it was painless (gotta love LEAN). It took me a few minutes to set up a Coinbase API key, and I deployed live without any issues, on the first try. Gotta love QC!
I'm sharing the code here, fully commented in case others find it helpful. As always I'd appreciate any feedback on how I can optimize the code for performance and/or re-use.
Note: The indicator signals used in the backtest are not my actual live traded signals, feel free to replace them with your own.
Trent Ramirez
Not very familiar with bollinger bands, could you explain the different values that can be changed? or link me somewhere that can? really appreciate you sharing you code
.ekz.
Hi Trent,
The Bollinger bands consist of two 'bands' , that are above and below the price. Each band is offset from the 20-Period SMA, at a distance of 2 standard deviations.
You can change the period of the SMA, and change the # of standard deviations from the SMA.
This image should give you a good visual reference
This 5 minute video might also help (I only scrubbed through it briefly but it seems good)
https://www.youtube.com/watch?v=CSZEB20cGVoGrokpot
Hi .ekz., thanks for sharing - I like this sharing trend in the QC Community!
Something I've been doing in my projects is benchmarking against 1) lump sum deposit ("buy and hold"), and 2) daily purchases ("dollar cost averaging")
While your code is really nice and indeed pulls in a profit, I wonder how it would compare to these benchmarks?
Here's how I add the benchmarks:
def Initialize(self): self.startingCash = 10000 self.dailyCashDrawdown = self.startingCash / self.resolutionLookback self.benchmarkDailyShares = 0 self.benchmarkDailyValue = 0 self.benchmarkDailyCash = None self.benchmarkLongShares = 0 self.benchmarkLongValue = 0 self.SetBenchmark(self.btc.Symbol) ... def OnData(self, data): ... self.UpdateBenchmarkValue() def UpdateBenchmarkValue(self): """ https://www.quantconnect.com/forum/discussion/7947/a-little-trick-to-plot-the-benchmark """ currentPrice = self.Benchmark.Evaluate(self.Time) # Daily drawdown benchmark if self.benchmarkDailyCash is None: self.benchmarkDailyCash = self.startingCash self.benchmarkDailyShares += self.dailyCashDrawdown / currentPrice self.benchmarkDailyCash -= self.dailyCashDrawdown self.benchmarkDailyValue = (self.benchmarkDailyShares * currentPrice) + self.benchmarkDailyCash # Long benchmark if self.benchmarkLongShares == 0: self.benchmarkLongShares = self.startingCash / currentPrice self.benchmarkLongValue = self.benchmarkLongShares * currentPrice
I'm interested to see the result!
Best,
.ekz.
That's great, grokpot :-)
Please feel free to give it a try. I use a similar benchmark comparison method, but I didn't include that code.
Do keep in mind two things:
.ekz.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!