paint-brush
Why I Built A Historical Cryptocurrency Trade Simulator (which you can use too)by@raudaschl
3,642 reads
3,642 reads

Why I Built A Historical Cryptocurrency Trade Simulator (which you can use too)

by Adrian H. RaudaschlJanuary 11th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

I got into trading <a href="https://hackernoon.com/tagged/crypto" target="_blank">crypto</a> around May 2017 after about a year of regular <a href="https://hackernoon.com/tagged/investing" target="_blank">investing</a> in a range of peer2peer (P2P) systems, commodities and stocks. My strategy was simple — every month I would invest 20% of my total income (or as much as I could afford) before tax into a range of investments, then regularly reinvest the dividends generated from interest into more investments.

Coins Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Why I Built A Historical Cryptocurrency Trade Simulator (which you can use too)
Adrian H. Raudaschl HackerNoon profile picture

I got into trading crypto around May 2017 after about a year of regular investing in a range of peer2peer (P2P) systems, commodities and stocks. My strategy was simple — every month I would invest 20% of my total income (or as much as I could afford) before tax into a range of investments, then regularly reinvest the dividends generated from interest into more investments.

The first part of this strategy came from a book called the The Richest Man in Babylon, and second from general modern economic thinking. The combination of the two proved quite effective and allowed me to diversify my portfolio and reduce risk over time.

With the growing excitement around cryptocurrencies I thought I would give it a go while leveraging the same strategy. Every month I would invest about 5% of my total 20% into a range of cryptocurriencies — primarily bitcoin, etherium, litecoin, dash and a few altcoins. Overall this performed well (especially with the massive rise in value in the second half of 2017). However, recenly I could not help but think my simple strategy was not as effecient as it could be.

Being the start of 2018 I thought I would put my theory to the test and try some different trading strategies on historical cryptocurrency data. I couldn’t find anything that really suited my needs online, or didn't seem to require a subscription to buy so I build something myself with python.

The result of the project is git repo you can try for yourself (python 3)-https://github.com/Raudaschl/historical_crypto_trade_simulator

Steps

Requires pandas and python 3

Install Pandas

pip install pandas

Step 1

Download historical data python download.py To download the prices for different cryptocurrencies for the last 300 days as a csv file curtesy of the cryptocompare.com API. You can edit the coin types in the download.py file.

Step 2

Run the script python trader.py This will produce the following outputs:

Original Value — The current value of your investments assuming no trade strategy has been applied apart from holding onto your investments

Original Dividends — The total dividends based from your initial investments

Final Dividends — The total dividends based on original and new investments

Original Investments Value — The total value of your original investments after the strategy is applied

New Investments Value — The total value of new investments made based on your strategy

Final Total Value — The total value of your investments and any dividends taken

Step 3 — Customise

Set Orders

bitCoinOrders array is filled with cyptocoin different orders — example:

bitCoinOrders.append({“coin”: “btc”, “buyPrice”: 2690, “coins”: 0.0782, “date”: “2017–05–27”})

coin: set the currency symbol (needs to be one of the currencies downloaded before) buyPrice: original buy price ($) coins: number of coins bought date: date purchased

Calculate Function

Function

The calculate function takes an array of orders and examines their value from the point of purchase. During this iteration I have set up trading strategy which aims to sell 40% of the coins from a single order when that order has increased in value by 300%. That 40% is then reinvested by buying other cryptocurrencies which is in the dfAdditionalOrders array. If the value of the 40% sell is less than $40 then I will sell all the coins outright and claim that amount for myself as dividends.

Variables

profitFactor — Set the % value where you will take profit. Setting 3 for example will automatically trigger a sell at 300% reinvest

Percentage — the percentage of the total value of the order when the profit factor is reached to reinvest.

minimumSellValue — Sell all coins of this specific order when the value hits the profitFactor and the value of the reinvestment is less than this value.

BuyWeightsBuild Function

Function

This function sets the coins to buy from the profits of any sell (see above). They exclude the coin that was originally sold so for example if bitcoin turned a profit and was sold it would not buy more bitcoin with the profits.

Variables

buyWeights.append({“coin”: “btc”, “weight”: 0.25})

coin — the symbol of the currency you want to buy (must be one of the currencies downloaded)

weight — this is an indicator to how much you want to buy of one currency compared to another. The total value of all weights should add up to 1.

Conclusions

So there you have it. In my experiments I found I could only really increase my overall value by less than 1% over the last year so perhaps the simpler model is still the best one for me. Maybe you will have better luck. 💰 💸

Git Repo — https://github.com/Raudaschl/historical_crypto_trade_simulator

PS: I’m not a programmer, so please go easy on me with the code 😃