JavaScript Cryptocurrency Market Cap Weighted Algorithm

Claudio Atilano
SoFlo Tech
Published in
2 min readJan 4, 2019

--

After seeing the HODLbot market cap weighted algorithm written in Python I thought it would be good to have it in JavaScript.

This code first calculates the ratios of how much a certain cryptocurrency weighs on the top 20 cryptocurrencies, data provided by Coin Market Cap.

Then when we get those ratios we have to cap them out to diversify an investment portfolio. The example above uses 10% as a portfolio allocation cap. We see that this method gives us a portfolio of 10% BTC, ETH, XRP. Meaning these cryptocurrencies are capped and should not hold more stake of the portfolio or it will be too heavily weighted on large market cap cryptocurrencies.

For more information on market cap weighted algorithms read this.

To rebalance a portfolio using this algorithm will require you to plugin to an exchange’s API and measure out the change of allocation over time. I have seen that rebalancing daily or weekly produces the greatest returns. If you want to know more, read this.

Sample of portfolio allocation with Hodlbot

Some projects that do this are https://hodlbot.io and https://crypto20.com

If you are investing in high risk cryptocurrencies, be sure to take responsible actions.

JavaScript Developers

Feel free to use this algorithm for a portfolio project. I thought creating this would help you develop.

--

--

Claudio Atilano
SoFlo Tech

Creator of the Primal Trading Card Game | Front-end Software Engineer