I am looking for an example of the r code for using Ornstein-Uhlenbeck to estimate time for mean reversion when considering cointegrated securities
Ref: Package ‘ouch’ (link)
Title: Ornstein-Uhlenbeck models for phylogenetic comparative hypotheses
prev_sprd <- c(sprd[2:length(sprd)], 0)
d_sprd <- sprd - prev_sprd
prev_sprd_mean <- prev_sprd - mean(prev_sprd)
sprd.zoo <- merge(d_sprd, prev_sprd_mean)
sprd_t <- as.data.frame(sprd.zoo)
result <- lm(d_sprd ~ prev_sprd_mean, data = sprd_t)
half_life <- -log(2)/coef(result)[2]
half_life
result = lm(d_sprd ~ prev_sprd_mean + 0, data = sprd_t)
half_life1 = -log(2)/coef(result)[1]
half_life1
also try:
Statistical Methods for Financial Engineering, B. Remillard
On the Simulation and Estimation of the Mean-Reverting Ornstein-Uhlenbeck Process
If we enter into a mean-reverting position, and 3 or 4 half-life’s later the spread still has not reverted to zero, we have reason to believe that maybe the regime has changed, and our mean-reverting model may not be valid anymore
ref:
http://epchan.blogspot.co.uk/2007/01/what-is-your-stop-loss-strategy.html
http://cran.r-project.org/web/packages/peacots/peacots.pdf
There are several packages on CRAN that have the Ornstein-Uhlenbeck procedure. I would suggest using rseek to find them, then see which package best suits your needs.
I suggestion reading through this thread on the r-sig-finance list which directly addresses your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With