Dollar cost average with ruby on historical data

Now that almost all the markets and cryptos are red, I thought let's write an article about Dollar Cost Average as a strategy to reduce risk and still have the benefits of investing... and most importantly, continue investing without stress.

So if you don't know what DCA is, it's a simple investing strategy where you put money regularly in an asset no matter of it's price. As a result, it reduces significantly the risk and some times it may also gives you better results. How often or how much to invest though, is a good question and it depends on many factors. I am not a financial advisor, I am only writing about the idea of analysing historical data for DCA vs invest all the money from the beginning and hodl.

Dollar cost average script in ruby

So, I wanted to know based on some historical data, how would it be the final result on each case. What would happened if I was doing just a simple DCA instead of investing all-in and wait (given the fact that I had the cap from the beginning). So I wrote a simple script to measure it:

Script explanation

The script is a bit of a hack 'n' slash code. As you can see, if you have invested consistently with DCA, 30 dollars on Monero, you would have gained more money than if you had invested all the money one time at the beginning and waiting. Well, of course I chose Monero and this historical data set because it is one of the exceptions. Most of the time you would have gained less money with DCA than if you had invested all from the beginning. DCA main advantage in my opinion is that you can avoid taking the risk. One nice addition would be to see how many times each strategy went negative or lost more money than the total investment.
So, give it a try, you can find historical data everywhere on the internet, both on stocks and cryptos. I got the above from Coinmarketcap. Do your own research, take this script or write your own and run it on your historical data. I tried it on many assets and stocks and I can say that I prefer to go with DCA for my investments.

Last words and next articles

This is just a warmup, in the next article I am going to write how I am using DCA to invest automatically a specific amount of money on crypto without thinking or worrying too much. I'll add the automation and how it can be achieved through Binance and Kraken. Oh and as you may read this article in the future where everything will be super green and everyone will look exceptionally greedy, let's see how red is the crypto market now.
I got the first 1000 cryptos and counted the positives and the negatives.
As you see, the last 24 hours, there are 37 positive cryptos out of 1000 and 963 negative cryptos. I am using this kind of information for many things in an algo-trading bot I have. I may show in a future article how I am fetching it and other useful ways of thinking and using it.
Tags: ruby
Max one mail per week.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.