Analyzing the crypto market with Python

in #python7 years ago

I am currently on a trip trough Europe, and I have met some interesting individuals whom have recently realized large gains in crypto. I've decided to spend the weekend writing some code to help me learn a bit more about investing/trading in this space. As a bonus, I have also hacked together a simple trading strategy.

Requirements

What if I invested $100 in every top coin a year ago?

I would have about $140,000+ right now. That is an insanely good 14x yearly gain, most of which has been materialized in the past 2 months.
top100.png

What if I invested in 10 random coins a year ago?

Picking top coins has some survivor bias built in, so I've wondered about how the random portfolios would do (think Dr. Malkiel's Monkeys experiment). Here is an example of 15 portfolios comprised of 10 random coins, yielding $30,000 to $400,000 in returns.
random_portfolio.png
Feel free to tweak the params and generate more portfolios on your own.

Which coins did the best?

The variance on returns of different coins can be quite large, for example, here are returns on some top coins for the past 30 days.

Screen Shot 2017-06-12 at 8.53.40 PM.png

To deepen my understanding of variance and correlations, I've built some interactive charts to display returns from different coins, as well as normalized returns versus an arbitrary benchmark (ie BTC).

newplot (2).png

Please, feel free expand the size of the universe, and play with the chart interactively in your notebook.

newplot (3).png

Simple momentum strategy

The idea behind this strategy is simple - we want to buy the coins that are rising in value, and drop the coins that are not doing so well. I have picked the parameters haphazardly and I've avoided optimization to avoid the risk of curve-fitting.

Spec

We rebalance our portfolio weekly.

Rules:

  • we can not initially buy more than 10,000 worth of coins
  • with each sell/trade, we re-calculate balance
  • no trade can be bigger than 1000 USD

Strategy:

  • if a coin goes up 30% or more in a week, buy it
  • if coin goes up 100% from last trade, sell half
  • if coin goes down by 50% in a week, sell all

Filters:

  • can't be top 10
  • must be in top 130
  • must have at least 1MM mkt cap

The whole strategy can be succinctly described using a few helper functions.

Screen Shot 2017-06-12 at 9.02.46 PM.png

Results

Before I go any further, I should mention that this strategy is very simplistic, and it suffers from serious biases/flaws. It is in my opinion not suitable for real-money trading, and I should explain why, and work on improvements for my next post.

The results on trades from 2017 look promising, as the backtest of this system yields $73,815 in value (7x gain in less than 6 months).

It would be good to know how does this strategy compare to buy-and-hold and random buy-and-hold strategies above. Well, it totally bombs, as we go nearly broke ($3438 of initial $10000). Maybe our strategy is only suitable for the recent market, or perhaps I have bugs in my code.

To be continued...


Source

Source code for data gathering/cleanup, analysis and the trading strategy is available here. Use at own risk (see disclaimer).

Disclaimer

This project is for educational purposes only. The code provided is not suitable for real-money trading, and comes with absolutely no warranty.

Sort:  

You should havea look at www.bittwenty.com.

It's a crypto currency index fund of the top 20 crypto. The index have a monthly revison, you will probably enjoy the information ;)

This took me several days but I was able to calculate the top performers by market cap over the last year. small cap crushed it!!

Thank you for your insight on portfolio management!
Best,
Isaac

Really interesting.

Certainly!

For someone not understanding how blockchain technology works, this might seem like navel-gazing and building a "useless tool" and investing in "useless coins", just for the sake of it.

Where does the value come from, right?

For someone understanding what blockchain innovation means, it shows how 'permisionless innovation' is also coming to the world of finance.

Interesting times ahead!

Where does the value come from? Haha! I love that one.

I think nowadays people that ask me that question I'll ask them where does the value of money that government print and can print as much as they like, where does the value of this enchanted paper comes from?

It's so good to be part of this cryptocurrency revolution. It's so freeing.

Thanks @teamsteem, let's keep pooling the wealth of knowledge together!

This is by far one of the best analysis posts out there for the cryptocurrency community. Right on brother time to execute your random coin strategy. Even if the market tanks in the long term this is typical buffet style buy and hold, absent the inside info and the massive leverage haha

Nice, you are right and the small cap coins still do. If you have the data can simulate it with crystal ball, and lets see.

Regards

I agree - small cap crushes it. Well done @furion on a great post.

This post got me thinking What happens if you invest $1000 into crypto and leave it for 1 year? It's easy enough to find out. I'd love to hear others thoughts on their top choices over the next 365 days.

Hey Isaac! Awesome presentation here and very good insight. Lately, I had been thinking there has to be a sweet spot for coin market cap and it looks like it is clearly 10-100mm. May I ask where you got your data? I'd love to take a look at this myself? Thanks!

Sure thing I used the historical snapshots on Coinmarketcap.com and then went to work crunching it if different ways to get the results I wanted.

I'm gonna have a go at this!!

That looks very nice, something I've been thinking of doing with market cap info from coinmarketcap. Have you finished the spreadsheet. Any chance we can take a look at the whole sheet. Thank You!

I could email it if you want a copy. This is what I am doing full time now having turned down my job out of college. So I need to find fair ways to get compensated for the work I do hope you understand. If anyone wants to send 1 SP or SBD with their email in the memo I would be happy to email them my sheets of excel research.
Best,
Isaac

very very interesting. when you invest, do you normally buy and hold or do you trade? if you trade, do you use any anomaly detection algorithm that classifies the detected anomaly into a buy or sell signal? Great stuff - keep your posts coming Isaac

How can I increase your picture so I can see details I just see a small pic but it's not large enough for me to look at details. Thanks.

I am not sure on the esteem app is one way it show up better so you can read it

thanks for the post,

I have been doing similar experiments. This momentum strategy can work as long as there is inward capital flow. which we could expect for a while because people are still learning about block chain.

yes the experiment of top coins with "survivor bias" does not mean anything. but random portfolios are very interesting and tells us some things..

I did paper trade a momentum strategy for 3 weeks.

1st week high cap coins did well. low cap was around -10%
2nd week all the portfolios generated more than 50%
3rd week which was just 1 week before until today, (I also do rebalancing during tuesdays) low caps profited around 10%, high caps were around -5%.

which means yes low caps can return more.

I was thinking about publishing results and live trade it some day. as far as I know I can share my own positions and that would not constitute as trading advise. I got 30x and 6x in my experiements with different cap sizes.

lastly, I would be also very interested to see how the "buy low, sell high" strategy works.

Interesting strategy findings. I'd love to learn more. But just a simple strategy of buying and holding seems to prove a really good return in a year for those who don't have the time to stay on top of trading. I really like the back history comparisons of what could have been if you had done BLANK.

This is a very interesting project. Developing trading strategies is a lot of work, especially back-testing, thanks for posting your findings.

In your last two charts, it definitely looks like Steem is the only coin that hasn't gone totally parabolic yet; it's sitting at the BTC line. I hope that means there's plenty of room for it to run.

Your strategies seem to be following the trends. It would be interesting to test 'buy the dip' strategies, eg:

Strat 1

Filter: Top 30 coin over last 26 weeks (i.e. quality)
Action: Sell when price rises 20% above average price movement of all other quality coins.
Buy when price falls 20% below average price movement of all other quality coins.

Strat 2:

Filter: Randomly choose 20 coins from top 100
Action: Same as strat 1 (to test difference)

I think trading volumes for the top 100 alt coins whether they are gainers or losers give a good indication of potential. I agree with you

Every strategy is going to work in the market that you made a strategy for, now once the market changes you will have to develop a ​strategy for that market, it is never ending circle.

Indeed. I think the trick is in building a portfolio of robust strategies that can adhere to different market conditions.

So you're actually talking about some sort of AI portfolio :)

It is an interesting idea and it is already being done by many investors in other markets and possibly in crypto as well. But it is really a neverending cycle of upgrades and adjustments.

I really like your recreation of the monkey experiment. It shows the enormous deviation in returns in such a short period of time. (And the recent bull trend, every portfolio has positive returns?!)

I'm not a fan of market timing, especially with backtesting. At first glance, it always seems that a 'golden rule' or 'perfect trading strategy' exists. But when you backtest on a different time period, it suddenly doesn't work. However, I'm often tempted to try to time the market, so every once in a while I like to go back to Vanguards investing guide: https://personal.vanguard.com/us/insights/investingtruths/investing-truth-about-emotion
If you play around with the interactive chart you can see that small changes have a big effect and that overall, it's hard to beat the market.

Don't think that I didn't like your project though! Love it, just don't like market timing. ;)

I think that's the beauty in price point smoothing (aka buying incrementally over time), and finding low cost options with baskets of securities

Another reason why letting the Winklevii get their ETF would have been a helpful investment vehicle

Thank you for that Vanguard link, a great read right there.

Do you think that your model would benefit from incorporating some qualitative factors in to its framework. IE the history of the founders, their success on other projects ? The educational background of the founders and so on. At this point any crack pot who knows how to copy and paste can create their own crypto currency, with that being said, the ones that are most likely to succeed will be the ones who invest heavily into intellectual resources and human capital.

loving this stuff

push! such a great article!!

Always nice to see visuals of what could have happened.