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:  
There are 4 pages
Pages

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.

What a super cool project you are on and I bet your trip only finds itself even more exciting by the results!?!

Thanks for sharing this knowledge with us, it is appreciated, Namaste :)

Interesting strategy. What is the annual turnover? I like the way you take proffit!

I have been really intrigued by the recent crypto market rise the past 2 months and I'm developing am interest to trade some on @poloniex and see if i can get a decent gain i will go in with just $10 for starters

I'm a simple minnow so i can't go all in on huge amount of money

Well, as you can see from the first chart, even small amounts invested in some of the top coins could be very profitable! Good luck! Don't put in anything you can't afford to lose.

What's also important is its current value in relation to the coin max supply. If a coin is relatively cheap, and I'm really talking about a coin under $1, while simultaneously having a low cap max supply, say under 100M coins, then that means you have a very good asymmetrical risk. You can buy a shitload of coins if they are under $1, while their potential is great. Low supply, high demand.

I love data, and enjoy the way you show it. Any chance on https://steemdata.com/charts we can have more chance to play with the charts and go back in time plus get the raw numbers (without being a coder)?

This post received a 50% upvote from @randowhale thanks to @furion! For more information, click here!

If we can get STEEM in the news, we can get it over $5 each.

Everyone should use this Media email list (3000+ contacts)
https://steemit.com/steem/@marsresident/how-you-can-help-get-steem-in-the-news-simply-using-your-email

And send them this:
http://www.reuters.com/article/us-currency-steem-idUSKCN0ZS2MF

And this:
https://coinmarketcap.com/currencies/steem/

Very interesting, cool stuff brother @furion thank you. We are involved in a space like no other. People are catching on this year more than ever.

Also, it's funny that you're not smart enough to know that your flags can't do shit to my comments. Dumbass!

Bring it on you fucking pussy! Just wait to see what happens to the rest of @krnel's posts!! I think you'll like my work!!!

Are you ready?? This is gonna be fun!

Don't worry, I'll get them just before payout. Keep wasting that voting power though.

This space is growing very fast and many people a missing a lot of opporunity. Do u imagine that 700$ invested in top 7 crypto-currencies in 2016 will be valued at 32 000$ today. Not trading a good way to win BIG in crypto. As a value investor, I do not trade and usually follow the legend Warren Buffet strategy. Best luck !

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

With the fees involved that would become very pricey,No?

Possibly. I don't know. I should be looking for integration with some more sophisticated backtesting / analysis framework, such as zipline.

Is 6 months worth of backtesting even a statistically significant span of time?

Great work and infos.
I'm a programmer, I appreciate double your work ;)

Jesus....as depressing as this is, it's really well done. I wish hindsight wasn't always 20/20!! haha. Cool article though!

Nice post my friend, I will test it in my conputer. Thanks for share.

Congratulations @furion!
Your post was mentioned in my hit parade in the following categories:

  • Upvotes - Ranked 5 with 889 upvotes
  • Comments - Ranked 9 with 143 comments
  • Pending payout - Ranked 3 with $ 1482,01

dont do buy and sell!! just DO buy HOLD and SELL soon
and buy good project not really promising but can solve a problem.
remember "SOLUTION TO A PROBLEM" are the best products/services in any successful business.

Expected it would've been lucrative, but this is very indepth! Thanks :)

Great post - I dev python. We should get together to do some machine learning and reinforcement learning applications with TensorFlow sometime.

Good POC. Though the approach is simplistic and may not be ready for real trading I think it would be great if you could create a website with a graph where we could track multiple currencies at once. It would be super cool if we could use it for all coins in our portfolio

IOTA coin in a matter of hours became the 6th biggest coin in market capitalization. Excellent investment opportunity like never before! And it is revolutionary because it is the first cryptocoin that does not use blockchain technology. http://coinmarketcap.com/currencies/iota/#charts

Heres a good article giving an overview of how IOTA aims to be different http://www.tangleblog.com/what-is-iota-what-is-the-tangle/

I think Byteball or digiball or something like that already uses a DAG, so IOTA isn't the first.

Nice write up! very Informative while staying visually stimulating!
DESPERATE PLEA 4 HELP!
I need some MINNOWS and WHALES to Help!
Lets prove my WIFE wrong! :)!
https://steemit.com/story/@justcallmemyth/lets-prove-my-wife-wrong-she-thinks-steemit-is-fake-minnows-and-whales-unite-plus-custom-gif-giveaway
Proud-Minnow.gif
(Like The Gif? View The Blog For More) (Free 2 Use)

With the <20% share of my crypto that I dare to keep on an exchange, I spread it somewhat equally over around 10 different currencies. Just buy and hold, some re-balancing every once in a while. In hindsight I would sure have done better if I had always just held onto things.

Same lol. Lesson learned: if selling, don't sell all of it, you never know what will happen!

Good info thank.

Very interesting strategy you have made. The thing is that the market changes rapidly and thus you have to develop the code and strategy to change with the market!

Great Write UP! Can't wait for more..
Got approved few hours ago, enjoying it already.

Pretty interesting Stuff , i am just getting into cryptocurrencies i am doing alot of research i have a couple of bitcoins to invest in alt coins(longterm) i am very optimistic about the future !

Oh cool! It looks like http://coinmarketcap.northpole.ro has historical data on all coins!

you're analyzing good, just don't neglect hat bitcoin currently has less than 10 million users so far. what does that tell you when you now? It means that the Federal Reserve is buying their product (actually selling, but at an expense) at $2, and selling those same bonds at 25 cents?

Can you fucken believe what they are doing to us while getting rich out of our nine to five routine? this is bullshit, and that's why I am on the front line fighting them today.

From which source did you got to know that there are 10 million users ?

Nice artice, I Have resteem it on my timeline. Take a look to my channel if you want;)

I like it i thing Dash or Lite coin doing best

Furion! Thank for posting!

This is a interesting post here!
Currently I am part time forex trader and hope to develop more automatic trading using codes.

I am sure I can learn some techniques regarding python code or trading idea.

Keep the hard works. Definitely will follow your posts.

This is a great project.

Thanks for sharing your insights @furion

Interesting analysis and strategy, looking forward to your next post covering it more in depth.

Good job, Very interesting. Still a good trip in europe:)

Sorry for somebody can help me I will be very grateful, after running my python code of a small project throws me this error and I do not know what it should be.

TypeError: 'NoneType' object has no attribute 'getitem'

This is an interesting project, a lot of insight. Not sure whether it would be good to diversify one's portfolio in multiple coins or simply stick to the big ones (BTC and ETH) and invest around $100 a month.

Awesome article, I follow you

There are 4 pages
Pages