<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi<br>
<br>
I am still trying to sort this one out. Any comments from anyone
would be most welcome.<br>
<br>
<div class="moz-signature">Stephen Choularton Ph.D., FIoD<br>
<br>
<br>
</div>
<br>
On 14/10/2010 7:29 AM, Stephen Choularton wrote:
<blockquote cite="mid:4CB61698.6070601@organicfoodmarkets.com.au"
type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
Thanks for this help.<br>
<br>
Trying to make sense of it so I have added some notes to the
code. I have marked them #?#<br>
<br>
Delighted if you can tell me if I am write or wrong, add any
comments, answers.<br>
<br>
<pre>#?# This appears to be the function that is doing the 'Ornstein-Uhlenbeck
#?# process work' particularly via dcOU
#?# I have noted in several places that I am after:
#?# 'the half-life of the decay equals ln(2)/θ'
#?# 'The half-life is given as log(2)/mean-reversion speed.'
#?# and I see theta appearing at a number of points in the code.
#?# Can you tell me why 3 thetas viz theta1, theta2, theta3 and what they do?
#?# eg is one of these the theta I am after?
# ex3.01.R
OU.lik <- function(theta1, theta2, theta3){
n <- length(X)
dt <- deltat(X)
-sum(dcOU(X[2:n], dt, X[1:(n-1)], c(theta1,theta2,theta3), log=TRUE))
}
require(stats4)
require(sde)
#?# random numer generation seed
set.seed(123)
#?# creation of a data set
X <- sde.sim(model="OU", theta=c(3,1,2), N=1000, delta=1)
#?# If I Look at X its like this:
#?# Time Series:
#?# Start = 0
#?# End = 1000
#?# Frequency = 1
#?# [1] 1.00000000 etc
#?# What sort of data object is it and how would I coerce an object with one
#?# column from a read.csv into it?
mle(OU.lik, start=list(theta1=1, theta2=0.5, theta3=1),
method="L-BFGS-B", lower=c(-Inf,0,0)) -> fit
summary(fit)
#?# This gives:
#?# Maximum likelihood estimation
#?# Call:
#?# mle(minuslogl = OU.lik, start = list(theta1 = 1, theta2 = 0.5,
#?# theta3 = 1), method = "L-BFGS-B", lower = c(-Inf, 0, 0))
#?# Coefficients:
#?# Estimate Std. Error
#?# theta1 3.355322 0.28159504
#?# theta2 1.106107 0.09010627
#?# theta3 2.052815 0.07624441
#?# -2 log L: 3366.389
#?# What's this telling me?
# ex3.01.R (cont.)
prof <- profile(fit)
par(mfrow=c(1,3))
plot(prof)
par(mfrow=c(1,1))
vcov(fit)
confint(fit)
#?# This provides me with this output using 'fit' from before:
#?# > vcov(fit)
#?# theta1 theta2 theta3
#?# theta1 0.07929576 0.024620718 0.016634557
#?# theta2 0.02462072 0.008119141 0.005485549
#?# theta3 0.01663456 0.005485549 0.005813209
#?# > confint(fit)
#?# Profiling...
#?# 2.5 % 97.5 %
#?# theta1 2.8448980 3.960982
#?# theta2 0.9433338 1.300629
#?# theta3 1.9147136 2.216113
#?# and 'fit' is:
#?# Call:
#?# mle(minuslogl = OU.lik, start = list(theta1 = 1, theta2 = 0.5,
#?# theta3 = 1), method = "L-BFGS-B", lower = c(-Inf, 0, 0))
#?# Coefficients:
#?# theta1 theta2 theta3
#?# 3.355322 1.106107 2.052815
#?# plus some graphic output
#?# Again, what's this telling me.
#?# This looks like a further example?
# ex3.01.R (cont.)
set.seed(123)
X <- sde.sim(model="OU", theta=c(3,1,2), N=1000, delta=1e-3)
mle(OU.lik, start=list(theta1=1, theta2=0.5, theta3=1),
method="L-BFGS-B", lower=c(-Inf,0,0)) -> fit2
summary(fit2)
Please excuse the length of this email (and my lack of understanding)
Hope you can help and thanks.
</pre>
<br>
<br>
<br>
<div class="moz-signature">Stephen Choularton Ph.D., FIoD<br>
<br>
</div>
<br>
On 13/10/2010 2:41 AM, stefano iacus wrote:
<blockquote
cite="mid:0C7BE64B-F2CB-40E4-BEAA-5ED53AA1C27D@unimi.it"
type="cite">
<pre wrap="">just for completeness: OU process is gaussian and transitiion density is known in exact form. So maximum likelihood estimation works fine and I suggest to avoid GMM.
sde package contains exact transition density for this process (e.g. ?dcOU) which you can use to build the likelihood to pass to mle() function.
This example taken from the "inst" directory of the package sde. For the parametrization of the model see ?dcOU
# ex3.01.R
OU.lik <- function(theta1, theta2, theta3){
n <- length(X)
dt <- deltat(X)
-sum(dcOU(X[2:n], dt, X[1:(n-1)], c(theta1,theta2,theta3), log=TRUE))
}
require(stats4)
require(sde)
set.seed(123)
X <- sde.sim(model="OU", theta=c(3,1,2), N=1000, delta=1)
mle(OU.lik, start=list(theta1=1, theta2=0.5, theta3=1),
method="L-BFGS-B", lower=c(-Inf,0,0)) -> fit
summary(fit)
# ex3.01.R (cont.)
prof <- profile(fit)
par(mfrow=c(1,3))
plot(prof)
par(mfrow=c(1,1))
vcov(fit)
confint(fit)
# ex3.01.R (cont.)
set.seed(123)
X <- sde.sim(model="OU", theta=c(3,1,2), N=1000, delta=1e-3)
mle(OU.lik, start=list(theta1=1, theta2=0.5, theta3=1),
method="L-BFGS-B", lower=c(-Inf,0,0)) -> fit2
summary(fit2)
I hope this helps out
stefano
On 12 Oct 2010, at 12:33, Bjorn Skogtro wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi Stephen,
You could take a look at
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://sitmo.com/doc/Calibrating_the_Ornstein-Uhlenbeck_model">http://sitmo.com/doc/Calibrating_the_Ornstein-Uhlenbeck_model</a>
for the linear regression method, or take a look at the package "sde" which
contains some examples using GMM (not for the Ornstein-Uhlenbeck process,
though, only the CIR).
The half-life is given as log(2)/mean-reversion speed.
Do keep an eye on the partition of the time-axis, e.g. what frequency you
are using (daily, yearly) for interpreting the half-life.
BR,
Bjørn
</pre>
<blockquote type="cite">
<pre wrap="">------------------------------
Message: 2
Date: Tue, 12 Oct 2010 05:43:32 -0400
From: Sarbo <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:cmdr_rogue@hotmail.com"><cmdr_rogue@hotmail.com></a>
To: <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:r-sig-finance@stat.math.ethz.ch">r-sig-finance@stat.math.ethz.ch</a>
Subject: Re: [R-SIG-Finance] Ornstein-Uhlenbeck
Message-ID: <a moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:BLU0-SMTP21220AA5FD288F890EED317E2540@phx.gbl"><BLU0-SMTP21220AA5FD288F890EED317E2540@phx.gbl></a>
Content-Type: text/plain; charset="utf-8"
By half-life, do you mean the speed of mean-reversion?
If so, there's a bit of algebraic tomfoolery that's required to
discretise the equation and then fit the data to it. I don't have the
time right now to go into all the details but it's not hard- you can
parameterise the process using simple linear regression. If you need
help with that I'll try and get back to you tonight about it.
On Tue, 2010-10-12 at 13:47 +1100, Stephen Choularton wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi
Wonder if anyone could point me how I use this method to discover the
half life of a mean reverting process.
I am looking into pair trading and the time it takes for a
cointegrated pair to revert to the norm.
--
Stephen Choularton Ph.D., FIoD
9999 2226
0413 545 182
for insurance go to <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="http://www.netinsure.com.au">www.netinsure.com.au</a>
for markets go to <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="http://www.organicfoodmarkets.com.au">www.organicfoodmarkets.com.au</a>
_______________________________________________
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:R-SIG-Finance@stat.math.ethz.ch">R-SIG-Finance@stat.math.ethz.ch</a> mailing list
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance">https://stat.ethz.ch/mailman/listinfo/r-sig-finance</a>
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions
</pre>
</blockquote>
<pre wrap="">should go.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20101012/26e32fc7/attachment-0001.html">https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20101012/26e32fc7/attachment-0001.html</a>
</pre>
<blockquote type="cite"> </blockquote>
<pre wrap="">-------------- next part --------------
A non-text attachment was scrubbed...
Name: CoS2010Winner.JPG
Type: image/jpeg
Size: 16091 bytes
Desc: not available
URL: <
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20101012/26e32fc7/attachment-0001.jpe">https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20101012/26e32fc7/attachment-0001.jpe</a>
</pre>
<blockquote type="cite"> </blockquote>
<pre wrap="">------------------------------
_______________________________________________
R-SIG-Finance mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:R-SIG-Finance@stat.math.ethz.ch">R-SIG-Finance@stat.math.ethz.ch</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance">https://stat.ethz.ch/mailman/listinfo/r-sig-finance</a>
End of R-SIG-Finance Digest, Vol 77, Issue 8
********************************************
</pre>
</blockquote>
<pre wrap=""> [[alternative HTML version deleted]]
_______________________________________________
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:R-SIG-Finance@stat.math.ethz.ch">R-SIG-Finance@stat.math.ethz.ch</a> mailing list
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance">https://stat.ethz.ch/mailman/listinfo/r-sig-finance</a>
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
</pre>
</blockquote>
<pre wrap="">
-----------------------------------
Stefano M. Iacus
Department of Economics,
Business and Statistics
University of Milan
Via Conservatorio, 7
I-20123 Milan - Italy
Ph.: +39 02 50321 461
Fax: +39 02 50321 505
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.economia.unimi.it/iacus">http://www.economia.unimi.it/iacus</a>
------------------------------------------------------------------------------------
Please don't send me Word or PowerPoint attachments if not
absolutely necessary. See:
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.gnu.org/philosophy/no-word-attachments.html">http://www.gnu.org/philosophy/no-word-attachments.html</a>
_______________________________________________
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:R-SIG-Finance@stat.math.ethz.ch">R-SIG-Finance@stat.math.ethz.ch</a> mailing list
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance">https://stat.ethz.ch/mailman/listinfo/r-sig-finance</a>
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
</pre>
<pre wrap=""><fieldset class="mimeAttachmentHeader"></fieldset>
No virus found in this incoming message.
Checked by AVG - <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="http://www.avg.com">www.avg.com</a>
</pre>
</blockquote>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
<a class="moz-txt-link-abbreviated" href="mailto:R-SIG-Finance@stat.math.ethz.ch">R-SIG-Finance@stat.math.ethz.ch</a> mailing list
<a class="moz-txt-link-freetext" href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance">https://stat.ethz.ch/mailman/listinfo/r-sig-finance</a>
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.</pre>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
No virus found in this incoming message.
Checked by AVG - <a class="moz-txt-link-abbreviated" href="http://www.avg.com">www.avg.com</a>
</pre>
</blockquote>
</body>
</html>