Bitcoin Dollar Cost Average Calculator

Today, I decided to test my strategy of monthly bitcoin purchases to see how it stands up in a backtest environment using a simple python script. After gathering the bitcoin data csv from yahoo and proceeded to write a little bit of python code to project the gains of a potential dollar cost average strategy based on the historical values of the bitcoin cryptocurrency. I was able to obtain data from 2014 to 2022 and project what the potential earnings would be for a variety of timeframes and periodic purchases using a dollar cost average strategy. First, I will cover what dollar cost averaging is. Then, I will display the results of running my simple programmatic test.

What is dollar cost averaging (DCA)?

Dollar-cost averaging (DCA) is defined by investopedia as an investment strategy in which an investor divides up the total amount to be invested across periodic purchases of a target asset in an effort to reduce the impact of volatility on the overall purchase. The purchases occur regardless of the asset’s price and at regular intervals.

This strategy is useful for long term investors as it better insulates the investor from volatile market conditions through providing them with a consistently adaptive cost basis for their investment, thus allowing for a less rigid investment strategy.

Program to test hypothesis

So for this little hypothesis, I wrote a simple adaptable python program to predict different dollar amounts and time periods for Dollar Cost Averaging into the Bitcoin market.

First, we’ll look at dollar cost averaging $100 a month through different yearly periods

Mid-2014 to 2022 $100PM DCA
2017 – 2022 $100PM DCA
2019 – 2022 $100PM DCA
2021 – 2022 $100PM DCA

Examining these charts shows that with a dollar cost average strategy you almost always come out ahead on bitcoin. 2021 was one of the largest and most volatile years for bitcoin but the Dollar Cost Averaging strategy with a simple plan of purchasing $100 every month still managed to come out significantly ahead. This shows that dollar cost averaging is not only a viable, but a competitive strategy when investing in bitcoin. To obtain a scaled figure, you can multiply the values on each of the indicies by the desired value and obtain what the value would have been given that you invested more or less money. I have also included the python code in the bottom of the post so that the code savvy of you can run some simulations of your own!

Conclusion

This post shows that Dollar Cost Averaging is a legitimate and profitable strategy for cryptocurrency investing as well as providing real figures based on real numbers for the strategy. Feel free to join my discord in the title bar above in order to ask me more quesitons, comment on this post, or provide some ideas for other potential hypotheses

How do I dollar cost average into bitcoin or other crypto?

Coinbase has a method for purchasing cryptocurrency each month! You just need to set up a monthly buy for bitcoin in an amount that you are comfortable with and SHAZAM! set it and forget it.


import pandas as pd
import matplotlib.pyplot as plt
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    purchaseAmount = 100
    btcAmount = 0
    # Read Data
    BTC = pd.read_csv('data/BTC.csv')
    # Set dates to datetime
    BTC['Date'] = pd.to_datetime(BTC['Date'])
    # Set Index to date field
    BTC.set_index('Date', inplace=True)
    # Create a Day Column
    BTC['Day'] = BTC.index.day
    # Create a Month Column
    BTC['Month'] = BTC.index.month
    # Create a Year Column
    BTC['Year'] = BTC.index.year
    #Get purchase dates based on first day of months only
    purchaseDates = BTC.loc[BTC['Day'] == 1]
    #Get purchase dates based on year
    purchaseDates = purchaseDates.loc[purchaseDates['Year'] == (2021 or 2022)]

    dateList = []
    valueList = []
    btcPriceList = []
    investedAmount = 0
    investedAmountList = []
    for index, row in purchaseDates.iterrows():
        # Track amount of bitcoin owned
        btcAmount += purchaseAmount / row['Close']
        # Track value of current amount of crypto
        valueList.append(btcAmount * row['Close'])
        # Track Bitcoin's price
        btcPriceList.append(row['Close'])
        # Track Total amount invested
        investedAmount = investedAmount + purchaseAmount
        investedAmountList.append(investedAmount)
        # Track Date
        dateList.append(index)
    print(investedAmount)
    plt.plot(dateList, valueList, label='Value of portfolio')
    #plt.plot(dateList, btcPriceList, label='Price of Bitcoin')
    plt.plot(dateList, investedAmountList, label='Amount Invested')
    plt.legend(loc="upper left")
    plt.show()
    print(valueList)

Leave a Reply

Your email address will not be published. Required fields are marked *