“BTC & ETH do seem high lol”

@elonmusk

As crypto markets start to move upwards once more I’ve been reading up on the concept of dollar-cost averaging. The idea of removing emotion from investment and damping some of crypto’s wilder oscillations is a tempting idea, even if studies show that with reduced risk comes reduced gains.

I pitched MintyFresh on the idea of modelling this strategy ourselves over a one day hackathon.

He agreed.

The Back End (local-optimum)

My role was to design and serve a new API that delivered a table of deposits and running portfolio values within a specified time period across a range of crypto and fiat currencies. I also decided to include a benchmark running total that modelled the user investing their total funds on day zero for comparison.

The code can be found here, but the tl;dr is:

def costAverageFunc(coin, deposit, currency, frequency, startdate):
    """function that takes the above strings as inputs, 
    converts them into an API query to coingecko
    then creates a dataframe of dollar cost averaging 
    returns vs a single bulk deposit"""

The output of this function is then wrapped in a flask app, the dataframe is jsonify’d and the resulting API is hosted on heroku. If you want to call the API yourself, simply append the following to the linked address

/dca/query?coin=INPUT&deposit=INPUT&currency=INPUT&frequency=INPUT&startdate=INPUT

Example here.

The Front End (MintyFresh)

As the interface designer, MintyFresh built a web app in JavaScript that allowed the user to choose the parameters for my costAverageFunc, call the API and return a simple Plotly visualisation of the returns over time. Have a go below!


You can also find his code here

Conclusions

Crypto in general has had such an astronomical rise in value over the last few years that any modelling that goes back more than 18 months generates significantly lower returns compared to going all in early.

However there are situations where dollar-cost averaging does come out on top, intuitively this is true when starting the model at one of the peaks (eg mid March 2021 where DCA actually generates a profit versus a 20% loss for those that buy only at the peak). In general losses are reduced as the market dips and the investor is getting more crypto for their money to compensate.

We must also consider that there are many situations where the recreational investor is only able to put money in periodically rather than all at once. In this case it may be reassuring to know that buying regularly rather than saving up for a “dip” may be a better strategy (the classic “time in the market is better than timing the market”), however I’m not confident our current visualisations can prove that assertion.

Next Steps

This project was my first experience creating APIs and using Flask so I’m sure there are some more elegant alternatives to my approach. However the real stretch goals for this project are in the visualisations, not just in opportunities to tidy up formatting but in how to clearly define and answer useful questions around DCA.

Comparing regular investment vs an initial bulk buy was the best we could think of within the time constraints. Going forward I would be interested in allowing users to hand pick buy-in points to simulate saving up to time the market or simply model their previous investment decisions.

If you have any ideas for visualisations or further expansion of this work please leave a comment on github.