boring technical explanation of my automated market maker
Fbtc 669.792831 -> 663.814262, implied SBD 0.001506
Ebtc 657.785747 -> 663.809175, implied SBD 0.001506
Bsbd 0.001969 -> 0.001956 implied BTC 511.223381
Psbd 0.001946 -> 0.001957 implied BTC 511.028519
Bsteem 0.006473 -> 0.006490, implied SBD 4.310717 adjusted 3.317631
Psteem 0.006496 -> 0.006487, implied SBD 4.308849 adjusted 3.316194 3.316194
At the risk of divulging some info that allows someone to take advantage of it, I think it is better to explain how I calculate the quotes. I am thinking of open sourcing the market maker anyway, so wont make much difference in that case.
I put this together in a day, so its not like it is anything super complicated, but it does have some cross market and arbitrage logic in it, which is always a bit confusing. Especially with the introduction of the third market in poloniex, things got a lot more complicated than I expected when I said I would write it.
I used iguanacore as the basis as that has a lot of handy features built in, like a universal API for all the common exchanges (bittrex and poloniex included). I havent yet made a module for STEEM, but there is no reason I cant map the STEEM orderbook and ordering to the iguana API (http://docs.supernet.org)
The first thing I needed was the current prices for BTC/USD and STEEM/BTC as those are the big volume pairs and it is always best to anchor things to the highest volume items. For BTC/USD I chose bitfinex and btc-e as the reference exchanges as bitfinex usually trades at a bit of a premium and btc-e is almost always the most discounted. For STEEM/BTC (and SBD/BTC) clearly bittrex and poloniex prices are needed.
But what is the price? it is changing all the time and has different prices at the different exchanges. At first I just did a single cumulative decayed sum, ie X = (X + newX)/2; This ran into the problem where due to the price difference between the exchanges, it was jumping up and down. So I decided to do the cumulative decayed sum for each exchange/price and then calculate the average of both for each update. This solved the price jitter and created smooth price changes that didnt take long to adapt to new prices, but takes into account the recent price with the highest weight and still has a memory for the older prices.
Now comes the part that is not so obvious. What to do with these raw smoothed prices?
Fbtc 669.792831 -> 663.814262, implied SBD 0.001506
Ebtc 657.785747 -> 663.809175, implied SBD 0.001506
Fbtc is bitfinex and Ebtc is btc-e, so you can see the average is around $664 and it only changes by about half a penny with a new price coming in. The BTC/USD price directly creates the theoretical SBD price by taking its inverse. Now it is a theoretical ("implied") price as in reality it is acting as a floor and today we saw it trade at significant premium to this. The reason is explained in https://steemit.com/steem/@jl777/sbd-at-0025-btc-how-is-this-making-any-sense-i-explain-what-happened-with-the-pricings-today
Bsbd 0.001969 -> 0.001956 implied BTC 511.223381
Psbd 0.001946 -> 0.001957 implied BTC 511.028519
The above is the reverse of the BTC/USD. It is not quite as useful as it implies that BTC is $511, which if it was I would be buying it like crazy and selling it at market price!
So if the BTC/USD price gets us a theoretical floor value far far from reality and the real price in turn tells us BTC is at a much lower price, how can we come up with a reasonable price to use?
Bsteem 0.006473 -> 0.006490, implied SBD 4.310717 adjusted 3.317631
Psteem 0.006496 -> 0.006487, implied SBD 4.308849 adjusted 3.316194 3.316194
The answer is the STEEM/BTC price. Now we know it is around .0065 for now, but how to convert this to what the SBD/USD price should be? Turns out you can use the division to solve this type of problem. By writing trading pairs as X/Y to mean going from X to Y it actually lets you multiply and cancel out terms.
STEEM/BTC combined with BTC/USD is luckily the easiest case as we just need to multiply them:
(STEEM *BTC) / (BTC * USD) -> cancel out the BTC -> STEEM/USD
Now if one of the terms was upside down, we would need to take the reciprocal to get it lined up right before doing the multiply that cancels out the terms. With the above raw data, it comes up with a price of $4.31. As a sanity test, I check CMC and see that it is $4.32, which is almost too close, kind of spooky since CMC is a 24 hour trailing average. Coincidence I guess.
OK, so now we have arrived at the $4.32 price, but the internal market is around $3.15. Before you get all excited and try to make $1.15 per STEEM, the issue is that SBD is trading at a premium, so if you dont adjust for that you could end up losing money when you thought you were making money. Now whether SBD is trading at a premium because the internal market is at a discount or the internal market is at a discount because the SBD trades at a premium on the exchanges is exactly like the chicken and the egg problem. Which was first? It actually doesnt matter since everything tastes like chicken.
The final trick I do is to adjust the $4.31 price based on the premium of SBD on the external exchanges. This calculates the internal price that would be the breakeven price (assuming no slippage). This price ends up at $3.31, which is at a 15 cent premium and at the highest level I have seen it over the history of the market maker being live (4 hours), so it isnt really that much history but I think it indicates the price is reversing from its peak.
Over the next days we will see if the premium/discount the adjusted implied price is relative to the internal market is a leading or trailing indicator and which way is bullish or bearish or maybe it is purely random.
You get a silver star if you can figure out the equation to use to calculate the final $3.15 price using all three prices and a gold star if you can do it using only two of the prices. BTCUSD, STEEMBTC, SBDBTC
I'm just completely impressed and amazed at the technical skills you possess. This is way over my head, even though I've always been interested in these developments.
Boring or not it's always a good read coming from you.
Thanks for the some important information for me
Consider this bookmarked. I need to read this in full when I have a minute. Thank you.
keep it up @jl777 !
This post does deserve some upvotes.
thanks!