Code for market making profitability simulations


#1

Accompanying code for this blog post.

Thanks to Hal 147 for finding a bug in this code!

library(ggplot2)

fund   <- 10000 # dollars
price  <- 8 # price in dollars for the asset you're interested in
spreads <- seq(0.01, 0.26, by = 0.05)

profits <- data.frame(trades = 0:100) # play with the number of trades

for (spread in spreads) {
  profit_per_deal     <- (fund / 2) * (spread / price) # thanks to Hal 147 for finding this bug
  profit_per_deal_pct <- profit_per_deal / fund
  profits[[paste0('$', spread)]] <- fund * (1 + profit_per_deal_pct)^profits$trades
}

df <- reshape2::melt(profits, id.vars = "trades")
names(df) <- c("trades", "spread", "value")

p <- ggplot(df, aes(x=trades, y=value, color=spread)) + geom_line() + xlab("Number of trades") + ylab("Fund size in $") + ggtitle("Made by Rados")
print(p)

How profitable is market making on different exchanges
#2

Hi,

Could you please explain me the equation for “Profit Per Deal”? Why should do we divide the fund by 2?

My equation was as following:
(Fund/Price)*Spread
(10000/8)*0.26= $325

Looking forward to your answer Thanks!


#3

The rationale for dividing by two is that in market making you have to take both sides of the market. So if you have $1000 to invest, you end up buying $500 worth at some price, and sell $500 worth at another price. Hence (fund / 2) * (spread / price)