Hacker News new | past | comments | ask | show | jobs | submit login
Algo trading digital assets (johnmathews.eu)
167 points by mthwsjc_ on Oct 30, 2017 | hide | past | favorite | 53 comments



Although simulations will predict good profits, you will probably lose your money doing this due to counterparty risk. Counterparty risk is the risk that, between the time you click the 'sell' button and the time you actually get the money deposited in your bank account a few days later, the exchange goes insolvent.

When a given coin trades at different prices on two exchanges (which is what these arbitrage algorithms look for), it will try to buy that currency on the cheap one and sell on the expensive one.

The main reason coins have different prices (more than a few cents) on different exchanges is that people are worried about the exchange being insolvent.

For instance, during MtGox's slide into doom, Bitcoin was cheap there. So this algorithm would have been busily buying Bitcoin with USD on MtGox, then transferring the Bitcoin to another exchange to sell, so it could pump the USD back into MtGox. Since withdrawals from MtGox were throttled, you would have built up a large balance there. When they shut down, you would have lost bigly.

People do make money doing arbitrage between exchanges, but you need a sophisticated model that considers counterparty risk, which isn't something you can read from a price sheet.


As a former high-frequency (HF) equity derivatives trader, I'm skeptical of HF cryptocurrency trading. There's a reason few modern markets have HF trading, an activity which could be described as vacuuming up nickels in front of bulldozers. HF needs a stable, predictable environment to make the nickels worth collecting.

Risk management in HF is less about predicting what might go down than avoiding trading when liquidity dries up. This is why when markets get weird HF algos pull out: an unexpected one-minute trading stall can wipe out a quarter's profits.

In crypto, where the market is still learning lessons from the 1930s, the nickels are quarters but the bulldozers are tanks.


This comment is almost like a copy-paste every time some kind of crypto trading article is submitted. I might have missed something in the article / code but this isn't an arb strat? It is just using some moving averages to try to follow a perceived trend in different trading pairs on a single exchange.

Counterparty risk definitely still exists, but it is getting better very quickly with the growth of regulated US-based exchanges like gdax, gemini, and ledger x. In the altcoin world, Bittrex is in the process of fulfilling state-by-state requirements for regulatory approval. The crypto world is very different today from when MtGox dominated and getting even better.


You can still run an arbitration strategy even with one exchange, and the risk within that single exchange can be different between different coins. For example, if an exchange's Bitcoin balance is stolen but not their Litecoin, there might be a period during which you can withdraw in Litecoin but not Bitcoin. If the rumor mill works, that would be preceded by a change in the relative prices during which this algorithm would suggest buying Bitcoin.


You forgot the most infuential (and unscrupulous) crypto exchange in the cyptocoin ecosystem: Bitfinex. https://medium.com/@bitfinexed/latest


Yes, very familiar with finex and the bitfinexed guy's warnings / rants / whatever you want to call them.

If counterparty risk is a top concern (and it probably should be) then don't trade on unlicensed exchanges... That rule is great to follow and I haven't even gotten into any usdt tether issues...


couldn't you trade on decentralised exchanges where counterparty risk isn't a thing? at least if you're only trading between crypto pairs


Yes, decentralized exchanges (dex) are coming and I'm very hopeful.

However, the ones I have looked at / tested so far just aren't ready for primetime. Slow transaction times, lackluster user experience, no liquidity.

But those are all problems that are to be expected for what are basically beta-status projects (at best) and I am excited to see where things go from here.


Is there arbitration in cryptocurrencies? Arent transactions really slow though?


I don't think you have read the article, traded digital assets or understand the current landscape of crypto.


Nice comment. How does that relate to the SMA visualizations discussed in the article?


You are correct re: exchange arb and gox, but it worked the other way around. Gox dollars were illiquid but BTC was liquid (until BTC withdrawals started failing just before collapse). So Gox had a higher BTC price than anywhere else.

Problem was, if you thought you were selling BTC -> USD you were wrong, you were selling for GOX-USD which were known to be worth much less than USD. In fact, they turned out to be worthless.


I don't think this analysis is about cross-exchange arbitrage


Since the history of markets there have been people who believed they could define a set of rules that would allow them to win more than they lose (reliably enough to make it worth the gamble).

There are many reasons why this is a fool's belief, at least with one strategy over a long term. As many people pointed out already, properly calculating risk is the usual failure. But even if you properly calculate risk, there are still possibilities (which you may deem unreasonably small to consider) which can happen. This is was the final straw that caused the 2007/8 failures. Any possibility greater than zero can happen. It doesn't matter what your models prepare you for. If that "virtually impossible" scenario occurs, you lose.

The more commonly successful approach to algo trading is to identify an inefficiency in the market and capitalize on that. But that is a limited time opportunity. You either eat up all the inefficiency yourself (if you're lucky), or other people catch on and help you make the market properly efficient. Then you're on to the next game. And in many cases, the inefficiency you are capitalizing on is due to a lack of capability of your broker(s). And brokers don't like when you cost them money repeatedly. Eventually they catch on, and they shut you down. So you trade your time for money by way of constantly searching for new brokers and gaining access to a market only so you can profit your way right out of that market.

Summary: create value to win. Any other method of profit is an eventual failure.


You mean how companies like Renaissance Technologies are obviously flawed since they only rely on mathematical models and are thus doomed to fail?


it's ok, it was amusing to see the Nassim taleb meme still going strong.


I have a strong suspicion that Renaissance has some (illegal) advantage that almost nobody else is aware of. They are notorious for isolating information within their own organization, and that could help them keep secrets regarding their edge.

Nobody produces results like they do over such a long period, and it's exceedingly unlikely that they are so much smarter than everyone else. Whether from insider information or market manipulation, their success smells too strongly.


This is a decent first-steps guide into analyzing historical trading data. With resources like Quandl, QuantConnect, etc continuing to improve, hopefully we will see more and more people diving into the data.

That being said, the "todos" at the end of this article kind of understate just how much work is left to be done before a strategy like this could be put into production. Ignoring the actual viability of a simple moving average cross signal, you could have the best strategy out there but would never stand a chance without significant time and effort committed to the execution and risk management sides of automated trading.

If building trading systems in the crypto world is something that interests you feel free to reach out to me, company / contact info is in my HN profile.


Here's a question I've had for a while regarding trading systems in the cryptocurrency world --

What's the end goal? Would a perfect trading system fully automate the trading process to maximize returns, or is the goal to develop the best tool to assist a trader?

I'm curious what you, as someone in the field of developing these systems, see as the "ideal product".

As a follow up question, what would happen to a market that is 100% traded automatically (assuming thats possible and the end-goal) - would become stagnant?

Forgive my ignorance if any of this is obvious, my econ/trading knowledge is next to 0.


I'm not exactly sure what you're asking. What's the goal of building a trading system?

As someone who's worked on trading systems in a professional setting I'll give some thoughts.

First and foremost the goal is to make money. I guess some people build these systems for fun/hobby or for the challenge/educational value. But huge amounts of money are spent on trading systems, with the goal that they increase profitability. Sometimes that means maximizing returns, sometimes that means assisting traders. This is a very large market, with very diverse types of end-users. I believe crypto is similar, but a microcosm of the broader trading environment (with some of its own cyrpto-specific idiosyncrasies). You have some "HFT" traders, "institutional", HODLERs, etc... Each has different objectives and skill sets. A trading system has a different value proposition for each trader's needs and objectives.

In terms of a 100% automated market, that's an interesting question. The biggest world markets are very highly automated, such as the equities market. Google "hft percentage of volume" and you'll find various sources claiming up to 70% of the equities volume is HFT. Since HFT trades complete in micro-seconds, this is fully automated trading. The Flash crash was partially blamed on a high-level of automation, were a trader was trying to game the response to large orders[1]. I think a 100% automated market would collapse. Even the 70% automated market of equities has shown some scary positive feedback loops that need human intervention.

1 - https://www.bloomberg.com/view/articles/2015-04-21/guy-tradi...


HFT strategies are of course secret but aren't they really taking advantage of:

1. Faster speed to market. Basically, front running 2. Extremely low transaction costs. Not available to the retail trader or even electronic mkt makers. 3. Extremely low time in each trade - when you dispense with bell curve predicting - risk becomes only the time you are not flat.

These are NOT prediction of future price. HFT don't make money 'predicting' the market - they are too sophisticated as traders to believe that's reliably possible. It is to some extent, but its very hard and theirs is a better play.


> Faster speed to market. Basically, front running

No, this is not basically front running. Front running has a very specific meaning. High frequency trading is not front running.


1 - being faster isn't front running. Nobody can hop in front of orders that are already visible on the lit market.

2 - The electronic market makers ARE mostly hft and generally get the best transaction costs and other privileges excluding taker-maker exchanges. Take NYSE parity or CME mass quotes for example

3 - Somewhat true but not in general. Becomes a murkier quality when hft is combined with longer term signals

> These are NOT prediction of future price. HFT don't make money 'predicting' the market - they are too sophisticated as traders to believe that's reliably possible. It is to some extent, but its very hard and theirs is a better play.

This is completely wrong. Plenty of HFTs do prediction to varying degrees, one of the biggest HFTs almost exclusively trades on price prediction. Other don't very much but hedge in very sophisticated manners. The smallest group is those who just use speed and fee structure to make money. There are certainly benefits to speed however (fill rate at the very least) and the market leaders are both intelligent AND fast.


1) yes, if a large order has to be fulfilled across multiple exchanges then there’s a race which HF can win


Nobody knows about a large order being filled cross multiple exchanges, at most they see a price level get filled at one exchange and take from that what they want. The majority of large cross-exchange orders are done via ISO orders which bypass routing mechanisms and exist for the sole purpose of executing large cross-exchange orders. Even if one doesn't want to lift the price, people trying to fill a large order generally route multiple orders to different exchanges.

An HFT might see one price level go away before another even with the ISO mechanism, but it's far too late to act on that information by the time it's visible on the lit markets.


But front-running has a very narrow regulatory / legal definition, which isn't met by latency arbitrage. Maybe you don't like what's going on, but to use the name of a crime to describe perfectly legal latency arbitrage is hyperbolic and/or ignorant.


>I think a 100% automated market would collapse. Even the 70% automated market of equities has shown some scary positive feedback loops that need human intervention.

Which is because the automation isn't capable of fully gaming itself yet.

In game theory, you don't have to be the smartest person in the room, you just have to know what everyone else is going to do. In a ~100% automated market, whoever can identify the patterns emergent from the automated rules will be able to beat the automation.


What do you think of db's recent decision to open-source their trading platform? https://www.db.com/newsroom_news/2017/deutsche-bank-makes-it...


Just like in traditional markets there are all kinds of applications. Some devs might be building tools to assist human traders, some might be working on market making / liquidity providing, some might be working on execution algos for the various funds that have popped up. My ideal product is very different from someone else's, it just depends on what your business model is.

For the follow up question, I would suggest looking at the rise of automated trading in traditional markets. It is an overwhelmingly large % of trades and market activity these days, and I would call the largest financial markets in the world anything but stagnant.

The more players and liquidity in a market, the more efficient the price discovery can be, which I think would be a very good thing for the long term viability of crypto markets.

I guess to summarize, the crypto markets are not much different from traditional markets and getting more similar every day.


Summary: some code to calculate moving averages of crypto currency prices.


I am unable to see the charts.


Had the same problem, they showed up later. I guess HN effect is to blame.


I would guess using a charting SaaS that charges based on views is to blame


I'm seeing:

This embedded plot has reached the maximum allowable views given the owner's current subscription. Please visit the subscriptions page to learn more about upgrading.


During this summer I performed a similar analysis with SMA and variations from it. My initial explorations looked very promising so I started saving market data and build a Python back-tester to test it. Once I applied exchange fees, slippage and simulated over longer periods things changed. I was no longer able to create a profitable strategy that performed well in longer time-frames over multiple markets. However its something I still want to work with.


"Hello Hacker News! Thanks for all the views. Due to increased traffic, Plot.ly won’t serve any more plots until tomorrow. Come back then?"

A bit off-topic, but it teaches us a lesson about avoiding getting locked-in by too many services. If I'd use a plot in my blog post I'd like it to keep working even when I get more traffic than usual. Especially if my whole blog post is useless without it.


This is cool. If you want to go further, checkout a small tool I made that automates technical analysis for crypto markets with major price signals: https://github.com/AbenezerMamo/crypto-signal


I'm building a trading bot (ruby) that uses a collection of signals to trade. I have been working on the backtesting to do validation of different strategies across different pairs and intervals. The highest i've gotten it so far is 120X from start of LTC/BTC, but thats also on a fairly aggressive setting (and obviously idealistic);

SMA can work, but it can also bite you. I think using only 1 technical indicator is asking for trouble when determining entry. Use at least 2, but no more than 5 or 6.

As a software developer, its a cool field to tinker in. But theres lots of ignorance, hype, and crap.

For anyone who wants to build a simple bot, checkout gekko https://gekko.wizb.it


> The highest i've gotten it so far is 120X from start of LTC/BTC

120x sounds impressive (and overfitted), but if you compare this to a simple buy-and-hold strategy it is a rather depressing result.


Indeed; for crypto trading, your unit of account matters a lot. I'd recommend using BTC as the unit of account, so you aren't counting 100x+ USD increases.


Time in the market beats timing the market.


Can someone summarize the returns and risk-level of his strategy?


Trying to trade purely off technical analysis is a disaster waiting to happen. Have a look at the technical analysis of ETH/USD, for instance, they have absolutely no clue what's going on:

https://www.ethnews.com/analysis/10-30-2017-ethereum-forecas...

As to the linked article, the idea of SMA crossovers is nothing special: https://www.babypips.com/learn/forex/moving-average-crossove...

Take a look at their example. Say you sold at the peak, great. Then the currency drops and you buy at the bottom, great. But then the SMA crosses again and you sell - oops, look where the graph is going. You can't predict this stuff with technical indicators.


My opinion is that technical indicators can work well... when it's clearly a bull market (but then, so can every other strategy). They absolutely suck and can't predict when it's clearly going to crash. Which make technical indicators pretty much useless because you can easily lose all your gains when that happens.


> Trying to trade purely off technical analysis is a disaster waiting to happen.

Watching purely a leading indicator can get you in trouble with false positives; while a lagging one means missing some of the trend. Yes, you can take it too far, use too many indicators, or look for trends in ranging markets and other mistakes.


That ethnews article is bizarre


For this kind of simple SMA/EMA crossing strategies there is essentially only one tunable knob (minimum return on one trade pair) that controls both return and risk and main output of this kind of analysis is finding out setting of that knob which you are comfortable with.


I'm unable to see the charts:

    Refused to display 'https://plot.ly/~mthwsjc/69.embed' in a frame because it set 'X-Frame-Options' to 'sameorigin'.


Me too :/


me three


me fourth. See devTools console. Usual chrome on mac


how were you trying to view the page? mobile? which browser were you using?


Chrome@Android, Firefox@Android, Chrome@Windows - all fail for me.

Just look at the dev console.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: