HOME




Simulating and Optimizing an arbitrage algorithm

How much can we hope to do with arbitrage? What are the best parameters?





Data


Previous parts of this analysis harvested data on crypto prices for 5 exchanges and 5 currencies. It showed that price differences exist, offering arbitrage opportunities. It also described the behaviour of a bot realizing arbitrage.

Here we gonna apply this bot to the harvested dataset. The bot is gonna perform arbitrage on Bitcoin cash between Bitstamp and Cex. Here is description of Bitcoin cash price for these 2 platforms on the period:

# Library
library(tidyverse)
library(DT)
library(plotly)
library(viridis)
library(lubridate)
library(hrbrthemes)
library(lubridate)

# Load result
load(url("https://raw.githubusercontent.com/holtzy/Crypto-Arbitrage/master/DATA/public_ticker_harvest.Rdata"))
Ticker$last <- as.numeric(Ticker$last)
Ticker= head(Ticker, 100000)

# Choose 2 exchanges
plat1 <- "Bitstamp"
plat2 <- "Cex"

# Keep the 2 plateform only
data <- Ticker %>% 
    filter(symbol=="BCHEUR") %>%
    filter(platform %in% c(plat1, plat2)) %>%
    select(time, platform, symbol, ask, bid) %>%
    mutate(ask=as.numeric(ask), bid=as.numeric(bid)) %>%
    gather(temp, value, -time, -platform, -symbol) %>%
    mutate(platform=gsub(plat1,"plat1", platform)) %>%
    mutate(platform=gsub(plat2,"plat2", platform)) %>%
    unite(temp1, platform, temp, sep="_") %>%
    spread( key=temp1, value=value) %>%
    mutate( 
      diff1=(plat1_bid-plat2_ask)/plat1_bid*100, 
      diff2=(plat2_bid-plat1_ask)/plat2_bid*100
    ) %>%
    na.omit()

# Plot
p <- Ticker %>%
  filter(symbol=="ETHEUR") %>%
  filter(platform=="Bitstamp" | platform=="Cex") %>%
  ggplot( aes(x=time, y=last, color=platform, group=platform)) +
    geom_line() +
    scale_color_viridis(discrete=TRUE, name="") +
    ylab("Etherum price on the exchange") +
    theme_ipsum()
ggplotly(p)