Developing Automated Trading Systems

Eric Novik and Steve Barber
30 January 2014

Presentation Outline

  • Welcome and Introductions
  • Technology Survey Results
  • Quick Overview of the Pairs Trading Strategy
  • Develeloping and Deploying Real Time Systems in Streambase
  • Q&A

Trading Technology Survey

plot of chunk unnamed-chunk-1

Nice Reference on Quant Trading

alt text

Overview of Pairs Trading

  • We are working with cointegrated time series
  • Cointegration != Correlation
set.seed(1)
e1 <- rnorm(500)
e2 <- rnorm(500)
trd <- 1:500
y1 <- 0.8 * trd + cumsum(e1)
y2 <- 0.6 * trd + cumsum(e2)
reg <- lm(y1 ~ y2)
display(reg)
lm(formula = y1 ~ y2)
            coef.est coef.se
(Intercept) 14.71     0.85  
y2           1.47     0.01  
---
n = 500, k = 2
residual sd = 9.85, R-Squared = 0.99

Overview of Pairs Trading

plot of chunk unnamed-chunk-3

plot of chunk unnamed-chunk-4

The Quest For Stationarity, Mean Reversion

  • Strong stationarity: joint distribution of \( (x_{t_{1}},...,x_{t_{k}}) \) is identical to \( (x_{t_{1}+t},...,x_{t_{k}+t}) \) for all \( t \).
  • Weak stationarity is sufficient: \[ \begin{aligned} E(x_{t}) = \mu \\ Cov(x_{t}, x_{t-l}) = \gamma_{l} \end{aligned} \]
  • For two non-stationary assets, we would like to find a stationary linear combination.

\[ \begin{aligned} Spread_{t} = log(Y_{t}) - (\alpha + \beta log(X_{t})) \end{aligned} \]

Parameter Estimation

EstimateParameters <- function (price.pair, method = lm) 
{
    x <- log(price.pair)
    reg <- method(x[, 2] ~ x[, 1])
    hedge.ratio <- as.numeric(reg$coef[2])
    premium <- as.numeric(reg$coef[1])
    spread <- x[, 2] - (hedge.ratio * x[, 1] + premium)
    list(spread = spread, 
         hedge.ratio = hedge.ratio, 
         premium = premium)
}

Parameter Estimation

price.pair <- stock.price[, 1:2]["2008-03-31::"]
params <- EstimateParametersHistorically(price.pair, period = 180)
plot(params$spread)

plot of chunk unnamed-chunk-6

References

  • Carn Package: PairTrading
  • Updated: 2012-03-24
  • By: Shinichi Takayanagi, Kohta Ishikawa
  • Maintainer: Shinichi Takayanagi shinichi.takayanagi@gmail.com