Create your Bitcoin dollar cost average(DCA) Calculator in python

Mustafa Alahmid
2 min readAug 11, 2022

--

Image source

Dollar cost average is a practice of investing a fixed dollar amount on a regular basis, regardless of the share price, its basically means that you buy a bit every day or week or month and this way you can get an average price so you can be sure that you didn’t buy the top only but you buy also the bottom

In bitcoin its common to hear people say keep stacking Sats and DCA is the best practice for stacking Sats and accumulate Bitcoin

Today we will implement that in python in a simple way
we will start to import the libraries :

1- Yahoo finance API
2- pandas
3- numpy

next is to download daily data of the bitcoin using yahoo finance API

what we need from the user is the starting date, ending date and the amount of money to buy every day

1- so we will make a list of amount Bitcoin stacked every time and a variable to calculate the total spent money.
2- we will create a loop to buy every day from starting date until ending date.
3- calculating how much Sats we will buy.
4- add this amount of Bitcoin to the list we created.
5- add the amount of money spent to the total spent.
6- Calculate the total average.
7- Calculate how much the total stacked would cost at the price of today.
8- Calculate profits and losses

Here is the full code and example

here we see if we have put 10$ everyday in bitcoin from 2016–1–16 till 2022–03–05 we would have spent 22,450$ and we would have made it 418318$

--

--

Mustafa Alahmid

Master degree in CS, interested in Machine learning and deep learning