In the last few months of 2020 and following into 2021, Bitcoin experienced a huge rise in price. Here’s its performance over the last 12 months:

In response to seeing this exponential rise in price, we sought to test different methods for entering a market that’s at all-time highs and experiencing large volatility. So in this episode of Idea Streams, the trading strategy that we’re going to be employing is dollar-cost averaging. The idea of dollar-cost averaging is to minimize the volatility and the impact of investing in assets such as Bitcoin by investing over a period of time.

Our Process

To observe the benefits of dollar-cost averaging, we created two different strategies. The first strategy simply buys $10 worth of Bitcoin every week. To deposit money into the portfolio each week, we created a Scheduled Event that executes every Monday at noon.

self.schedule.on(self.date_rules.every(DayOfWeek.monday), 
                 self.time_rules.at(12, 0), 
                 self.deposit)

When we’re buying $10 worth of Bitcoin every week, our Scheduled Event is defined to add $10 to the portfolio and convert all of the portfolio’s dollars into Bitcoin.

def deposit(self):
    self.portfolio.cash_book[‘USD’].add_amount(10)
    self.set_holdings(self.btc, 1)

The second strategy we created adds $10 to the investment portfolio every Monday, but only converts the portfolio’s dollars to Bitcoin if Bitcoin made a new 52-week high in the last 6 months.

if self.high < self.max.current.value:
    self.high = self.max.current.value
    self.stop_investing = self.time + timedelta(182)
If self.time < self.stop_investing: 
    self.set_holdings(self.btc, 1)

Results

To test our dollar-cost averaging strategies, we set the start of the backtests to January 1, 2017. Here is the equity curve of buying $10 worth of Bitcoin every week:

The equity curve of the second strategy is presented below. The diagonal black line represents the number of dollars deposited into the portfolio over time.

In the plot above, we can see that in February 2019, the value of the portfolio almost reached the nominal amount that was deposited into the portfolio. However, since we invest periodically, the nominal value of the investment builds up over time so we start seeing greater increases in the portfolio value as the price of Bitcoin rises later on.

With all of that in mind, we hope you now have a better idea of how to trade crypto, how to incorporate dollar-cost averaging into your strategies, and how to simulate depositing money into your trading account. To view the source code of this project, clone the backtest below.