Bitcoin Algorithmic Trading with CoinTrader and R
Tom Johnson, PhDBitcoin SF Dev Group
6-23-2014
Bitcoin Algo Trading DevelopmentObjective:
Make Money, Help Bitcoin,
Have Fun
Why focus on Price rather than Pipes?
Price Volatility Big deterrent to public acceptance
Smooth rise good for all!
Big Opportunities for:Products - Derivatives, Transaction infoServices - Price guides, Block executionTrading/Arb - Hedging, Funds, Day-tradeCoins - Medium of xchg vs Store of value
What does R have to contribute?
R is Open Source, Global, Data ScienceR script - Interactive, Algo development,
Prototyping, Live control, Easy to migratePackages - 5800, 120k functionsCommunity - Statistics & Machine LearningPros - Stable, fast math, answers/resourcesCons - Single threaded, in-memory, silosR tools well matched to Bitcoin challenges So are others like Python and ?
So how volatile is Bitcoin?Compared with EURUSD?
Compared with Gold?
Comparing Bitcoin, EUR & Gold
But getting out of, or into BTC will cost you
And what you see isn’t what you get
And nothing’s isolated; it impacts other Crypto, Home, Cross Pairs
So what does Bitstamp’s BTCUSD Orderbook look like?
Demo with CoinTrader CSV file in AWS
With all the turbulence - What about arbitrage opportunities?
And there’s Triangular Arbitrage -- Demo Example
Priceonomics.com -- Find best 2-currency plus Bitcoin arbitrage among 3 currencies in live price feed:
Find most profitable sequence of transactions from any Chosen Home Currency, through an Intermediate Currency, then through Bitcoin and finally back to the Home Currency.
Exchange Rates at a Point in Time
{USD_JPY: "95.7422091",USD_USD: "1.0000000",JPY_EUR: "0.0080872",BTC_USD: "105.5641218",...}
R Script
xchgTable <- xchgTable()foreignCurrs <- allCurrs[!allCurrs %in% c(input$homeCurr, "BTC")]foreignAmts <- btcAmts <- endHomeAmts <- rep(0, length(foreignCurrs))names(foreignAmts) <- names(btcAmts) <- names(endHomeAmts) <- foreignCurrsfor (foreignCurr in foreignCurrs) { foreignAmts[foreignCurr] <- xchgTable[input$homeCurr, foreignCurr] * as.numeric(input$initHomeAmt) btcAmts[foreignCurr] <- xchgTable[foreignCurr, "BTC"] * foreignAmts[foreignCurr] endHomeAmts[foreignCurr] <- xchgTable["BTC", input$homeCurr] * btcAmts[foreignCurr] } maxArbCurr <- foreignCurrs[which.max(endHomeAmts)] cat(c("Trade", input$initHomeAmt, input$homeCurr, "to", round(foreignAmts[maxArbCurr],2), maxArbCurr, "to", round(btcAmts[maxArbCurr],6), "BTC", "to", round(endHomeAmts[maxArbCurr], 2), input$homeCurr, "which =", round(((endHomeAmts[maxArbCurr]/as.numeric(input$initHomeAmt) - 1) * 100), 2), "% Gross Gain"), "\n\n\n")
Running in Amazon Cloud
AWS - Account, EC2, private key, static IPStack - AMI (Medium), Windows Server, Firefox, Google Drive, R, Shiny, RStudio, AppsSet up URL with AWS namespaces
Demo -- www.next1up.com
Demo
Run Shiny App in cloudAccess through browserBasic - Calculate & DisplayNext - Monitor, Control & Execution
Machine Learning can help
Prediction & Classification Lots of raw, currrent data (CoinTrader
CSV)Code up savvy features Forget the scholarly modelsUse many non-linear methodsDon’t overfit or let the future leak in!Cross-validate, analyze resdualsPerformance going forward is what
matters!
Steps to build robust Algos & Rules to Trade, Hedge, Place Limit Orders
Feature primitives -
Full feature variables - Differences, EMAs, etc.Data - Training, Testing, Reserved data testVariables - Bagging, Boosting, Selection Models - Trees, RF, GLM, GA, GP, EnsembleUse final code or live signal in CoinTrader
The Take-AwayBuy when under valued;
Sell when over valued.Price changes faster and,
for reasons other, than value.Good information & analysis can help.The bigger the mispricing,
the bigger the opportunityWhether trading, products, services or
coins.Making money helps us all and Bitcoin!
SourcesTom Johnson [email protected] Demo http://next1up.nethttps://www.linkedin.com/in/tom-johnson-62a16
Prices www.cryptocoincharts.infoAPIs www.quandl.com/markets/bitcoinCool www.bitlisten.comAnalyses www.priceonomics.comShiny www.rstudio.com/shiny