skies.dev

How I Built a Crypto Index Fund

3 min read

As per usual, this material should be used for educational purposes, not financial advice.

In a previous article, we built v1 of coinbase-pro-dca. I showed how to set up a GitHub Actions cron job to automatically buy cryptocurrency using the Coinbase Pro API.

In v1, you were required you to manually set your crypto portfolio allocation. For example, you would configure that you want to buy 50% Bitcoin, 40% Ethereum, etc each time the cron job ran.

In the v2 update, I remove the need to manually set your allocation. The tool now uses the CoinMarketCap API to create a capitalization-weighted index of the top cryptocurrencies.

Just like in v1, you still set how frequently you want the cron job to run and how much fiat you want to use each time the job is run. But now each time the job runs, the tool will:

  1. use the CoinMarketCap API to get the desired portfolio allocation
  2. use the Coinbase API to get your current portfolio allocation
  3. buy the cryptocurrencies that gets your current portfolio allocation as close as possible to the desired portfolio allocation.

How the index strategy works

For simplicity, suppose the market cap of all cryptocurrencies is

  • 50% BTC
  • 50% ETH

Now suppose you currently own $100 worth of BTC, and you've set up the job to buy $50 worth of crypto each time the job runs.

Next time the job runs, the job will buy $50 of ETH so that you have $100 worth of BTC and $50 of ETH i.e. 66% BTC and 33% ETH. This gets you as close as possible to the desired portfolio allocation of 50% BTC and 50% ETH without selling any crypto.

Then, next time the job is run, you'd again buy $50 worth of ETH. Now you'd have $100 worth of BTC and $100 worth of ETH i.e. 50% BTC and 50% ETH, which is the desired portfolio allocation.

Caveats

To make your taxes simpler, the tool only buys crypto, it does not attempt to re-balance your portfolio by selling crypto. Having the ability to sell crypto may still be useful to add in a future iteration.

The tool is also hard-coded to use a root market cap weighted strategy, which puts more emphasis on small-cap cryptocurrencies. It could be useful to switch between different weighting options.

I've also considered making a web UI that allows people to submit API keys, and I could manage all of this for a fee (e.g. a percentage of the fiat you put down). Would you use it?

If you have any ideas for how this tool can be improved, feel free to suggest on Twitter or open an issue.

(clap if you liked the article)

You might also like