R in Finance 1 / 113
Explorative Data
Analysis
NYSE data
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 2 / 113
Cluster Analysis
Explorative Data
Analysis
NYSE data
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
R in Finance 3 / 113
Cluster Analysis
Explorative Data
Analysis
NYSE data
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 4 / 113
R in Finance 5 / 113
25
2006
Index
2008
60
80
140
220 42
50 30
BAC
45
HP
80
MLINCH
140 50
DB
40 50 60
30
SONY
45 100
CITI
22
MOTO
35 16
NOKIA
45 55 20
EA
EXXON GSACHS
15
LG
40
18
DELL
30
AMD
19
30
40
SYMATEC PHILIPS
50 15
JPM
24 20 26 3210
INTEL
35
BORL
25
MSOFT
2006
2007
2008
Index
R in Finance 6 / 113
The are several ways to measure the distance between two time series
NYSE data
Estimation of Financial
Models
Likelihood approach
R in Finance 7 / 113
Let X and Y be two time series, then the usual Euclidean distance
v
uN
uX
dEU C (X, Y ) = t
(Xi Yi )2
i=1
is one of the most used in the applied literature. We use it only for
comparison purposes.
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 8 / 113
Let X and Y be two time series, then the usual Euclidean distance
v
uN
uX Xi Xi1 Yi Yi1 2
.
dST S (X, Y ) = t
i=1
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 9 / 113
.
dDT W (X, Y ) = t
i=1
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Essentially, all shiftings between two time series are attempted and each
time a cost function is applied (e.g. a weighted Euclidean distance
between the shifted series). The minimum of the cost function over all
possible shiftings is the dynamic time warping distance dDT W .
R in Finance 10 / 113
R in Finance 11 / 113
(1)
j,kJ
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
N
X
1
{j (Xi1 )k (Xi ) + k (Xi1 )j (Xi )}
(P )j,k (X) =
2N
(2)
i=1
Simulations
We simulate 10 paths Xi , i = 1, . . . , 10, according to the combinations of drift bi and
diffusion coefficients i , i = 1, . . . , 4 presented in the following table
b1 (x)
b2 (x)
b3 (x)
b4 (x)
1 (x)
X10, X1
2 (x)
X2,X3
X6, X7
3 (x)
X5
X4
4 (x)
X8
where
b1 (x) = 1 2x,
The process X9=1-X1, hence it has drift b1 (x) and the same quadratic variation of X1
and X10.
S.M. Iacus 2011
R in Finance 13 / 113
0.0
0.0
X5
Time
4
5
6
0.4
X10
0.4
0.8
0.8
0.0
0.0
X4
0.4
X9
0.4
0.8
0.8
0.0
0.0
X3
0.4
X8
0.4
0.8
0.8
0.0
0.0
X2
0.4
X7
0.4
0.8
0.8
0.0
0.0
X1
0.4
X6
0.4
0.8
0.8
Trajectories
Simulated diffusions
1
2
3
Time
4
5
6
R in Finance 14 / 113
Dendrograms
R in Finance 15 / 113
Multidimensional scaling
R in Finance 16 / 113
Software
Explorative Data
Analysis
NYSE data
Estimation of Financial
Models
Likelihood approach
data(quotes)
d <- MOdist(quotes)
cl <- hclust( d )
groups <- cutree(cl, k=4)
plot(quotes, col=groups)
cmd <- cmdscale(d)
plot( cmd, col=groups)
text( cmd, labels(d) , col=groups)
R in Finance 17 / 113
R in Finance 18 / 113
Explorative Data
Analysis
Estimation of Financial
Models
Examples
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 19 / 113
Statistical models
We focus on the general approach to statistical inference for the parameter of models in
the wide class of diffusion processes solutions to stochastic differential equations
dXt = b(, Xt )dt + (, Xt )dWt
with initial condition X0 and the p-dimensional parameter of interest.
R in Finance 20 / 113
Examples
Explorative Data
Analysis
Estimation of Financial
Models
Examples
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Cox-Ingersoll-Ross (CIR)
dXt = (1 + 2 Xt )dt + 3
Xt dWt
Chan-Karolyi-Longstaff-Sanders (CKLS)
dXt = (1 + 2 Xt )dt + 3 Xt4 dWt
R in Finance 21 / 113
Examples
Explorative Data
Analysis
Estimation of Financial
Models
Examples
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
Examples
Explorative Data
Analysis
Ornstein-Uhlenbeck (OU)
Estimation of Financial
Models
dXt = Xt dt + dWt
Examples
Likelihood approach
Two stage least squares
estimation
Model selection
radial Ornstein-Uhlenbeck
dXt = (Xt1 Xt )dt + dWt
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
...and so on.
R in Finance 23 / 113
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
MLE
QMLE
Two stage least squares
estimation
Likelihood approach
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 24 / 113
n
Y
p (, Xi |Xi1 ) p (X0 )
n
X
i=1
i=1
R in Finance 25 / 113
Likelihood approach
MLE
QMLE
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
R in Finance 26 / 113
MLE with R
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
MLE
QMLE
Two stage least squares
estimation
Model selection
Numerical Evidence
R in Finance 27 / 113
QUASI - MLE
Consider the multidimensional diffusion process
dXt = b(2 , Xt )dt + (1 , Xt )dWt
where Wt is an r-dimensional standard Wiener process independent of the initial value
X0 = x0 . Quasi-MLE assumes the following approximation of the true log-likelihood for
multidimensional diffusions
n
1
1X
log det(i1 (1 )) +
(Xi n bi1 (2 ))T 1
n (Xn , ) =
i1 (1 )(Xi n bi1 (2 ))
2 i=1
n
(3)
R in Finance 28 / 113
QUASI - MLE
Consider the matrix
(n) =
1
nn Ip
0
1
n Iq
where Ip and Iq are respectively the identity matrix of order p and q. Then, is possible to
show that
d
(n)1/2 (n ) N (0, I()1 ).
where I() is the Fisher information matrix.
The above result means that the estimator of the parameter of the drift converges slowly to
the true value because nn = T slower than n, as n .
R in Finance 29 / 113
R in Finance 30 / 113
not very good estimate of the drift so now we consider a longer time series.
R in Finance 31 / 113
n <- 1000
ysamp <- setSampling(Terminal = (n)^(1/3), n = n)
yuima <- setYuima(model = ymodel, sampling = ysamp)
set.seed(123)
yuima <- simulate(yuima, xinit = 1, true.parameter = list(theta1 = 0.3,
theta2 = 0.1))
mle1 <- qmle(yuima, start = list(theta1 = 0.8, theta2 = 0.7),
lower = list(theta1=0.05, theta2=0.05),
upper = list(theta1=0.5, theta2=0.5), method = "L-BFGS-B")
coef(mle1)
theta1
theta2
0.3015202 0.1029822
R> summary(mle1)
Maximum likelihood estimation
Coefficients:
Estimate Std. Error
theta1 0.3015202 0.006879348
theta2 0.1029822 0.114539931
-2 log L: -4192.279
R in Finance 32 / 113
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 33 / 113
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 34 / 113
R in Finance 34 / 113
R in Finance 34 / 113
R in Finance 34 / 113
R in Finance 35 / 113
R in Finance 36 / 113
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Model selection
Idea
AIC example
Lasso
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 37 / 113
Idea
The aim is to try to identify the underlying continuous model on the basis of discrete
observations using AIC (Akaike Information Criterion) statistics defined as (Akaike
1973,1974)
AIC = 2n n(M L) + 2 dim(),
(M L)
where n
is the true maximum likelihood estimator and n () is the log-likelihood
R in Finance 38 / 113
2n n(M L)
with the dimension of the parameter space
2 dim()
(M L)
Thus, as the number of parameter increases, the fit may be better, i.e. 2n n
decreases, at the cost of overspecification and dim() compensate for this effect.
When comparing several models for a given data set, the models such that the AIC is
lower is preferred.
R in Finance 39 / 113
n(M L)
+ 2 dim(),
(M L)
.
we need to evaluate the exact value of the log-likelihood n () at point n
Problem: for discretely observed diffusion processes the true likelihood function is not
known in most cases
Uchida and Yoshida (2005) develop the AIC statistics defined as
(QM
L)
AIC = 2n n
+ 2 dim(),
(QM L)
where n
is the quasi maximum likelihood estimator and n the local Gaussian
approximation of the true log-likelihood.
R in Finance 40 / 113
A trivial example
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Idea
AIC example
Lasso
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
(true model),
(competing model 1),
(competing model 2),
We test the performance of the AIC statistics for the three competing
models
R in Finance 41 / 113
p
dXt = (Xt 10)dt + 2 Xt dWt
p
dXt = 1 (Xt 2 )dt + 1 Xt dWt
p
dXt = 1 (Xt 2 )dt + 1 + 2 Xt dWt
(true model),
(Model 1)
(Model 2)
(Model 3)
Model selection
Idea
AIC example
Lasso
Numerical Evidence
LASSO estimation
The Least Absolute Shrinkage and Selection Operator (LASSO) is a useful and well
studied approach to the problem of model selection and its major advantage is the
simultaneous execution of both parameter estimation and variable selection (see
Tibshirani, 1996; Knight and Fu, 2000, Efron et al., 2004).
To simplify the idea: take a full specified regression model
Y = 0 + 1 X1 + 2 X2 + + k Xk
perform least squares estimation under L1 constraints, i.e.
(
)
k
X
T
|i |
= arg min (Y X) (Y X) +
i=1
R in Finance 43 / 113
p1
q1
b : p Rd Rd , : q Rd Rd Rm and Wt , t [0, T ], is a
standard Brownian motion in Rm .
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
R in Finance 44 / 113
Quasi-likelihood function
The classical adaptive LASSO objective function for the present model is then
q
p
X
X
n,j |j | +
n,k |k |
min Hn (, ) +
,
j=1
k=1
n,j and n,k are appropriate sequences representing an adaptive amount of shrinkage for
each element of and .
R in Finance 45 / 113
n (Xn , n )( n ) + op (1)
= Hn (Xn , n ) + ( n ) H
2
n and H
n the gradient and Hessian of Hn with respect to .
with H
R in Finance 46 / 113
Likelihood approach
Two stage least squares
estimation
Model selection
with
Idea
AIC example
Lasso
Numerical Evidence
Application to real data
n (Xn , n )( n ) +
F () = ( n )H
p
X
j=1
n,j |j | +
q
X
k=1
n,k |k |
R in Finance 47 / 113
where
n,j and n,k are the unpenalized QML estimator of j and k
respectively, 1 , 2 > 0 and usually taken unitary.
Lasso
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 48 / 113
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 49 / 113
A multidimensional example
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 50 / 113
Results
True
Qmle: n = 100
Lasso: 0 = 0 = 1, n = 100
% of times i = 0
Lasso: 0 = 0 = 5, n = 100
% of times i = 0
Qmle: n = 1000
Lasso: 0 = 0 = 1, n = 1000
% of times i = 0
Lasso: 0 = 0 = 5, n = 1000
% of times i = 0
S.M. Iacus 2011
11
0.9
0.96
(0.08)
12
0.0
0.05
(0.06)
21
0.0
0.25
(0.27)
22
0.7
0.81
(0.15)
11
0.3
0.30
(0.03)
12
0.0
0.04
(0.05)
21
0.0
0.01
(0.02)
22
0.2
0.20
(0.02)
0.86
(0.12)
0.0
0.00
(0.00)
99.9
0.05
(0.13)
80.2
0.71
(0.09)
0.0
0.30
(0.03)
0.3
0.02
(0.05)
67.2
0.01
(0.02)
66.7
0.20
(0.02)
0.1
0.82
(0.12)
0.0
0.95
(0.07)
0.00
(0.00)
100.0
0.03
(0.04)
0.00
(0.00)
99.9
0.21
(0.25)
0.66
(0.09)
0.0
0.79
(0.13)
0.29
(0.03)
0.4
0.30
(0.03)
0.01
(0.03)
86.9
0.04
(0.06)
0.00
(0.01)
89.7
0.01
(0.02)
0.20
(0.02)
0.2
0.20
(0.02)
0.88
(0.08)
0.0
0.00
(0.00)
99.7
0.08
(0.16)
72.1
0.73
(0.09)
0.0
0.30
(0.03)
0.1
0.02
(0.05)
67.5
0.01
(0.01)
66.6
0.20
(0.02)
0.1
0.86
(0.09)
0.0
0.00
(0.00)
100.0
0.00
(0.01)
99.4
0.68
(0.06)
0.0
0.29
(0.03)
0.2
0.01
(0.04)
87.8
0.00
(0.01)
89.9
0.20
(0.02)
0.2
R in Finance 51 / 113
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 52 / 113
15
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
10
Model selection
rates
Numerical Evidence
1950
S.M. Iacus 2011
1960
1970
1980
1990
R in Finance 53 / 113
Model
dXt = dt + dWt
dXt = ( + Xt )dt + dW
t
dXt = ( + Xt )dt + Xt dWt
dXt = Xt dWt
dXt = Xt dt + Xt dWt
dXt = ( + Xt )dt + Xt dWt
3/2
dXt = Xt dWt
dXt = Xt dt + Xt dWt
dXt = ( + Xt )dt + Xt dWt
0
0
0
0
0
0
1/2
1
1
1
3/2
R in Finance 54 / 113
Model
Vasicek
Estimation Method
MLE
4.1889
-0.6072
0.8096
CKLS
Nowman
2.4272
-0.3277
0.1741
1.3610
CKLS
Exact Gaussian
(Yu & Phillips)
2.0069
(0.5216)
-0.3330
(0.0677)
0.1741
1.3610
CKLS
QMLE
2.0822
(0.9635)
-0.2756
(0.1895)
0.1322
(0.0253)
1.4392
(0.1018)
CKLS
QMLE + LASSO
with mild penalization
1.5435
(0.6813)
-0.1687
(0.1340)
0.1306
(0.0179)
1.4452
(0.0720)
CKLS
QMLE + LASSO
with strong penalization
0.5412
(0.2076)
0.0001
(0.0054)
0.1178
(0.0179)
1.4944
(0.0720)
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
R in Finance 55 / 113
Lasso in practice
An example of Lasso estimation using yuima package. We make use of real data with
CKLS model
dXt = ( + Xt )dt + Xt dWt
library(Ecdat)
data(Irates)
rates <- Irates[,"r1"]
plot(rates)
require(yuima)
X <- window(rates, start=1964.471, end=1989.333)
mod <- setModel(drift="alpha+beta*x", diffusion=matrix("sigma*x^gamma",1,1))
yuima <- setYuima(data=setData(X), model=mod)
rates
10
15
R>
R>
R>
R>
R>
R>
R>
R>
1950
1960
1970
1980
1990
R in Finance 56 / 113
# LASSO
R in Finance 57 / 113
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Least Squares
QMLE
Overview of the yuima
package
Option Pricing with R
R in Finance 58 / 113
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Least Squares
QMLE
Overview of the yuima
package
Option Pricing with R
R in Finance 59 / 113
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Least Squares
QMLE
Overview of the yuima
package
Option Pricing with R
R in Finance 59 / 113
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
950 1050
Explorative Data
Analysis
750
Numerical Evidence
850
Model selection
1972
0.00 0.04
1974
Dow-Jones returns
Least Squares
QMLE
1973
-0.06
1972
1973
1974
WatergateR in
scandal
(right)
Finance 59 / 113
De Gregorio and I. (2008) considered the change point problem for the
ergodic model
R in Finance 60 / 113
Xi+1 Xi b(Xi )n
k0 = arg max
,
k
n Sn
Sk =
k
X
Zi2 .
i=1
R in Finance 61 / 113
Xi+1 Xi b(Xi )n
k0 = arg max
,
k
n Sn
Sk =
k
X
Zi2 .
i=1
QMLE
Overview of the yuima
package
we can still estimate b() non parametrically and obtain a good change
point estimator.
This approach has been used in Smaldone (2009) to re-analyze the recent
global financial crisis using data from different markets.
S.M. Iacus 2011
R in Finance 61 / 113
Time
June 30
July 4
Lehman
Brothers
July 7
July 11
July 14
July18
August 18
August 22
DJ Stoxx Global
1800 Banks
August 25
August 29
Sept. 1
Sept. 5
FTSE
DJ Stoxx 600
Lehman
Brothers
S&P MIB
Nikkei 225
Sept. 8
Sept. 12
Sept. 15
Sept. 19
DJ Stoxx Goldman
600 Banks Sachs
Sept. 22
Sept. 26
Sept. 29
Oct. 3
Deutsche Bank
HSBC
Nyse
Dow Jones
S&P 500
FTSE
DAX
S&P MIB
CAC
IBEX
SMI
Nikkei 225
DJ Stoxx 600 Banks
Oct. 6
Oct. 10
Oct. 20
Oct 24
[20040723/20050505]
log returns
0.04
Last 20.45
Bollinger Bands (20,2) [Upper/Lower]: 21.731/20.100
0.00
0.02
22
0.02
20
0.04
18
16
0
50
100
150
200
Index
Lug 23
2004
Ott 01
2004
Dic 01
2004
Feb 01
2005
Apr 01
2005
end = "2005-05-05")$Close
R in Finance 63 / 113
Numerical Evidence
Application to real data
The change point
problem
Least Squares
QMLE
R in Finance 64 / 113
Change-point analysis
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
R in Finance 65 / 113
dXt1
dXt2
1
3
Xt1
Xt2
dt +
X01 = 1.0,
1.1 Xt1
0 Xt2
Xt1
2.2 Xt2
dWt1
dWt2
X02 = 1.0,
1.5
1
x2
7 0.5
x1
R in Finance 66
10/ 113
the object yuima contains the model and the data from the previous slide
so we can call CPoint on this yuima object
> t.est <- CPoint(yuima,param1=t1,param2=t2, plot=TRUE)
>
> t.est$tau
[1] 3.99
Numerical Evidence
Application to real data
The change point
problem
Least Squares
QMLE
Overview of the yuima
package
Option Pricing with R
R in Finance 67 / 113
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
R in Finance 68 / 113
The main object is the yuima object which allows to describe the model
in a mathematically sound way.
Then the data and the sampling structure can be included as well or, just
the sampling scheme from which data can be generated according to the
model.
The package exposes very few generic functions like simulate, qmle,
plot, etc. and some other specific functions for special tasks.
Before looking at the details, let us see an overview of the main object.
yuima object
functionalities
how to use it
Option Pricing with R
R in Finance 69 / 113
univariate
multivariate
Data
multigrid
asynch.
diffusion
Lvy
fractional
BM
regular
irregular
Sampling
Yuima
Model
tick times
space disc.
...
random
deterministic
Markov
Switching
HMM
univariate
multivariate
Data
multigrid
asynch.
diffusion
Lvy
fractional
BM
regular
irregular
Sampling
Yuima
Model
tick times
space disc.
...
random
deterministic
Markov
Switching
HMM
univariate
multivariate
Data
multigrid
asynch.
diffusion
Lvy
fractional
BM
regular
irregular
Sampling
Yuima
Model
tick times
space disc.
...
random
deterministic
Markov
Switching
HMM
univariate
multivariate
Data
multigrid
asynch.
diffusion
Lvy
fractional
BM
regular
irregular
Sampling
Yuima
Model
tick times
space disc.
...
random
deterministic
Markov
Switching
HMM
yuima
yuima-class
yuima-class
model
data
sampling
characteristic
functional
model
yuima.model
sampling
yuima.sampling
data
yuima.data
functional
yuima.functional
yuima.model
yuima.sampling
yuima.data
yuima.functional
drift
diffusion
hurst
measure
measure.type
state.variable
parameter
state.variable
jump.variable
time.variable
noise.number
equation.number
dimension
solve.variable
xinit
J.flag
Initial
Terminal
n
delta
grid
random
regular
sdelta
sgrid
oindex
interpolation
original.data
zoo.data
F
f
xinit
e
characteristic
yuima.characteristic
yuima.characteristic
equation.number
time.scale
EulerMaruyama
Covariation
Nonparametrics
Space
discr.
Exact
p-variation
High freq.
Low freq.
Simulation
Parametric
Inference
Yuima
Asymptotic
expansion
Option
pricing
Monte
Carlo
Adaptive
Bayes
MCMC
Akaikes
LASSOtype
Model
selection
Quasi
MLE
Diff,
Jumps,
fBM
Hypotheses
Testing
Change
point
EulerMaruyama
Covariation
Nonparametrics
Space
discr.
Exact
p-variation
High freq.
Low freq.
Simulation
Parametric
Inference
Yuima
Asymptotic
expansion
Option
pricing
Monte
Carlo
Adaptive
Bayes
MCMC
Akaikes
LASSOtype
Model
selection
Quasi
MLE
Diff,
Jumps,
fBM
Hypotheses
Testing
Change
point
EulerMaruyama
Covariation
Nonparametrics
Space
discr.
Exact
p-variation
High freq.
Low freq.
Simulation
Parametric
Inference
Yuima
Asymptotic
expansion
Option
pricing
Monte
Carlo
Adaptive
Bayes
MCMC
Akaikes
LASSOtype
Model
selection
Quasi
MLE
Diff,
Jumps,
fBM
Hypotheses
Testing
Change
point
EulerMaruyama
Covariation
Nonparametrics
Space
discr.
Exact
p-variation
High freq.
Low freq.
Simulation
Parametric
Inference
Yuima
Asymptotic
expansion
Option
pricing
Monte
Carlo
Adaptive
Bayes
MCMC
Akaikes
LASSOtype
Model
selection
Quasi
MLE
Diff,
Jumps,
fBM
Hypotheses
Testing
Change
point
EulerMaruyama
Covariation
Nonparametrics
Space
discr.
Exact
p-variation
High freq.
Low freq.
Simulation
Parametric
Inference
Yuima
Asymptotic
expansion
Option
pricing
Monte
Carlo
Adaptive
Bayes
MCMC
Akaikes
LASSOtype
Model
selection
Quasi
MLE
Diff,
Jumps,
fBM
Hypotheses
Testing
Change
point
EulerMaruyama
Covariation
Nonparametrics
Space
discr.
Exact
p-variation
High freq.
Low freq.
Simulation
Parametric
Inference
Yuima
Asymptotic
expansion
Option
pricing
Monte
Carlo
Adaptive
Bayes
MCMC
Akaikes
LASSOtype
Model
selection
Quasi
MLE
Diff,
Jumps,
fBM
Hypotheses
Testing
Change
point
We consider here the three main classes of SDEs which can be easily
specified. All multidimensional and eventually parametric models.
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
R in Finance 81 / 113
We consider here the three main classes of SDEs which can be easily
specified. All multidimensional and eventually parametric models.
R in Finance 81 / 113
We consider here the three main classes of SDEs which can be easily
specified. All multidimensional and eventually parametric models.
Model selection
Numerical Evidence
R in Finance 81 / 113
We consider here the three main classes of SDEs which can be easily
specified. All multidimensional and eventually parametric models.
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
|z|>1
Option Pricing with R
0<|z|1
S.M. Iacus 2011
R in Finance 81 / 113
dXt = 3Xt dt +
Explorative Data
Analysis
1
dWt
1+Xt2
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
R in Finance 82 / 113
dXt = 3Xt dt +
Explorative Data
Analysis
1
dWt
1+Xt2
Estimation of Financial
Models
yuima
yuima-class
Likelihood approach
yuima-class
model
data
sampling
characteristic
functional
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
model
yuima.model
yuima.model
drift
diffusion
hurst
measure
measure.type
state.variable
parameter
state.variable
jump.variable
time.variable
noise.number
equation.number
dimension
solve.variable
xinit
J.flag
sampling
yuima.sampling
data
yuima.data
functional
yuima.functional
yuima.sampling
yuima.data
yuima.functional
Initial
Terminal
n
delta
grid
random
regular
sdelta
sgrid
oindex
interpolation
original.data
zoo.data
F
f
xinit
e
characteristic
yuima.characteristic
yuima.characteristic
equation.number
time.scale
R in Finance 82 / 113
dXt = 3Xt dt +
Explorative Data
Analysis
1
dWt
1+Xt2
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
> str(mod1)
Formal class yuima.model [package "yuima"] with 16 slots
..@ drift
: expression((-3 * x))
..@ diffusion
:List of 1
.. ..$ : expression(1/(1 + x^2))
..@ hurst
: num 0.5
..@ jump.coeff
: expression()
..@ measure
: list()
..@ measure.type
: chr(0)
..@ parameter
:Formal class model.parameter [package "yuima"] with 6 slots
.. .. ..@ all
: chr(0)
.. .. ..@ common
: chr(0)
.. .. ..@ diffusion: chr(0)
.. .. ..@ drift
: chr(0)
.. .. ..@ jump
: chr(0)
.. .. ..@ measure : chr(0)
..@ state.variable : chr "x"
..@ jump.variable : chr(0)
..@ time.variable : chr "t"
..@ noise.number
: num 1
..@ equation.number: int 1
..@ dimension
: int [1:6] 0 0 0 0 0 0
..@ solve.variable : chr "x"
..@ xinit
: num 0
..@ J.flag
: logi FALSE
R in Finance 83 / 113
dXt = 3Xt dt +
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
1
dWt
1+Xt2
Model selection
0.2
Numerical Evidence
functionalities
how to use it
Option Pricing with R
0.4
0.6
yuima object
0.8
0.2
0.0
0.0
0.2
0.4
0.6
0.8
1.0
R in Finance 84 / 113
dXt = 3Xt dt +
Explorative Data
Analysis
Estimation of Financial
Models
1
dWt
1+Xt2
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
R in Finance 85 / 113
dXt = 3Xt dt +
Explorative Data
Analysis
Estimation of Financial
Models
1
dWt
1+Xt2
Likelihood approach
yuima-class
yuima-class
model
data
sampling
characteristic
functional
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
model
yuima.model
sampling
yuima.sampling
data
yuima.data
functional
yuima.functional
yuima.model
yuima.sampling
yuima.data
yuima.functional
drift
diffusion
hurst
measure
measure.type
state.variable
parameter
state.variable
jump.variable
time.variable
noise.number
equation.number
dimension
solve.variable
xinit
J.flag
Initial
Terminal
n
delta
grid
random
regular
sdelta
sgrid
oindex
interpolation
original.data
zoo.data
F
f
xinit
e
characteristic
yuima.characteristic
yuima.characteristic
equation.number
time.scale
R in Finance 85 / 113
dXt = 3Xt dt +
Explorative Data
Analysis
Estimation of Financial
Models
1
dWt
1+Xt2
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
..@
..
..
..
..
..
..
..
..
..
..
..
sampling
:Formal
.. ..@ Initial
:
.. ..@ Terminal
:
.. ..@ n
:
.. ..@ delta
:
.. ..@ grid
:
.. ..@ random
:
.. ..@ regular
:
.. ..@ sdelta
:
.. ..@ sgrid
:
.. ..@ oindex
:
.. ..@ interpolation:
R in Finance 86 / 113
1
dWt
1+Xt
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
> str(mod2)
Formal class yuima.model [package "yuima"] with 16 slots
..@ drift
: expression((-theta * x))
..@ diffusion
:List of 1
.. ..$ : expression(1/(1 + x^gamma))
..@ hurst
: num 0.5
..@ jump.coeff
: expression()
..@ measure
: list()
..@ measure.type
: chr(0)
..@ parameter
:Formal class model.parameter [package "yuima"] with 6 slots
.. .. ..@ all
: chr [1:2] "theta" "gamma"
.. .. ..@ common
: chr(0)
.. .. ..@ diffusion: chr "gamma"
.. .. ..@ drift
: chr "theta"
.. .. ..@ jump
: chr(0)
.. .. ..@ measure : chr(0)
..@ state.variable : chr "x"
..@ jump.variable : chr(0)
..@ time.variable : chr "t"
..@ noise.number
: num 1
..@ equation.number: int 1
..@ dimension
: int [1:6] 2 0 1 1 0 0
..@ solve.variable : chr "x"
..@ xinit
: num 0
..@ J.flag
: logi FALSE
R in Finance 87 / 113
1
dWt
1+Xt
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
R in Finance 88 / 113
Estimation of Financial
Models
Likelihood approach
Model selection
Numerical Evidence
Application to real data
dXt1
dXt2
3Xt1
Xt1 2Xt2
dt +
1 0 Xt2
Xt1 3 0
dWt1
dWt2
dWt3
>
>
>
>
functionalities
how to use it
Option Pricing with R
R in Finance 89 / 113
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
> str(mod3)
Formal class yuima.model [package "yuima"] with 16 slots
..@ drift
: expression((-3 * x1), (-x1 - 2 * x2))
..@ diffusion
:List of 2
.. ..$ : expression(1, 0, x2)
.. ..$ : expression(x1, 3, 0)
..@ hurst
: num 0.5
..@ jump.coeff
: expression()
..@ measure
: list()
..@ measure.type
: chr(0)
..@ parameter
:Formal class model.parameter [package "yuima"] with 6 slots
.. .. ..@ all
: chr(0)
.. .. ..@ common
: chr(0)
.. .. ..@ diffusion: chr(0)
.. .. ..@ drift
: chr(0)
.. .. ..@ jump
: chr(0)
.. .. ..@ measure : chr(0)
..@ state.variable : chr "x"
..@ jump.variable : chr(0)
..@ time.variable : chr "t"
..@ noise.number
: int 3
..@ equation.number: int 2
..@ dimension
: int [1:6] 0 0 0 0 0 0
..@ solve.variable : chr [1:2] "x1" "x2"
..@ xinit
: num [1:2] 0 0
..@ J.flag
: logi FALSE
R in Finance
90 / 113
> set.seed(123)
> X <- simulate(mod3)
> plot(X,plot.type="single",col=c("red","blue"))
Likelihood approach
Numerical Evidence
1
2
x1
functionalities
yuima object
how to use it
Option Pricing with R
0.0
0.2
0.4
0.6
0.8
1.0
R in Finance 91 / 113
Multidimensional SDE
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
1 2/3
2
1
X dW 1 ,
=
X
dX
t
t
t
t
,
dXt2 = g(t)dXt3 ,
1
3
3
dXt = Xt (dt + (dWt + 1 2 dWt2 ))
R in Finance 92 / 113
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
R in Finance 93 / 113
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
Option Pricing with R
> str(mod4)
Formal class yuima.model [package "yuima"] with 16 slots
..@ drift
: expression((3 * y))
..@ diffusion
:List of 1
.. ..$ : expression(1)
..@ hurst
: num 0.3
..@ jump.coeff
: expression()
..@ measure
: list()
..@ measure.type
: chr(0)
..@ parameter
:Formal class model.parameter [package "yuima"] with 6 slots
.. .. ..@ all
: chr(0)
.. .. ..@ common
: chr(0)
.. .. ..@ diffusion: chr(0)
.. .. ..@ drift
: chr(0)
.. .. ..@ jump
: chr(0)
.. .. ..@ measure : chr(0)
..@ state.variable : chr "x"
..@ jump.variable : chr(0)
..@ time.variable : chr "t"
..@ noise.number
: num 1
..@ equation.number: int 1
..@ dimension
: int [1:6] 0 0 0 0 0 0
..@ solve.variable : chr "y"
..@ xinit
: num 0
..@ J.flag
: logi FALSE
R in Finance 93 / 113
> set.seed(123)
> X <- simulate(mod4, n=1000)
> plot(X, main="Im fractional!")
Likelihood approach
Im fractional!
4
Numerical Evidence
yuima object
functionalities
how to use it
Option Pricing with R
0.0
0.2
0.4
0.6
0.8
1.0
R in Finance 94 / 113
Jump processes
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
yuima object
functionalities
how to use it
R in Finance 95 / 113
Model selection
Im jumping!
Numerical Evidence
0
functionalities
yuima object
how to use it
0.0
0.2
0.4
0.6
t
0.8
1.0
R in Finance 96 / 113
Jump processes
Explorative Data
Analysis
Estimation of Financial
Models
Another way is to specify the Lvy measure. Without going into too much
details, here is an example of a simple OU process with IG Lvy measure
dXt = Xt dt + dZt
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
Im also jumping!
20
15
yuima object
how to use it
10
functionalities
in
yuima object
functionalities
how to use it
Option Pricing with R
R in Finance 98 / 113
in
yuima object
functionalities
how to use it
Option Pricing with R
R in Finance 99 / 113
in
yuima object
functionalities
how to use it
Option Pricing with R
in
yuima object
functionalities
how to use it
Option Pricing with R
in
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
Advertizing
There are several good packages on CRAN which implement the basic
option pricing formulas. Just to mention a couple (with apologizes to the
authors pf the other packages)
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
But if you need to go outside the standard Black & Scholes geometric
Brownian Motion model, the only way reamins Monte Carlo analysis.
And for jump processes, maybe, yuima package is one of the current
frameworks you an think to use.
Advertizing
Asymptotic expansion
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
Numerical Evidence
(0, 1]
F (Xt ) =
r Z
X
=0 0
Wt0 = t
Likelihood approach
Two stage least squares
estimation
Model selection
1
T
T
0
Xt dt K, 0
. Thus
Numerical Evidence
Application to real data
The change point
problem
F (Xt ) =
T
T
0
Xt dt,
r=1
Estimation of Financial
Models
dXt = Xt dt + Xt dWt
Likelihood approach
Two stage least squares
estimation
Model selection
1
T
T
0
Xt dt K, 0
. Thus
Numerical Evidence
F (Xt ) =
T
with
f0 (x, ) =
in
F (Xt ) =
x
,
T
r Z
X
=0 0
T
0
Xt dt,
f1 (x, ) = 0,
T
r=1
F (x, ) = 0
So, the call option price requires the composition of a smooth functional
F
(Xt )
1
=
T
T
0
Xt dt,
r=1
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
Advertizing
max(x K, 0)
Monte Carlo methods require a HUGE number of simulations to get the
desired accuracy of the calculation of the price, while asymptotic
expansion of F provides unexpectedly accurate approximations.
The yuima package provides functions to construct the functional F ,
and automatic asymptotic expansion based on Malliavin calculus starting
from a yuima object.
setFunctional method
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
>
>
>
>
>
>
>
>
>
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
Advertizing
setFunctional method
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
>
>
>
>
>
>
>
>
>
Numerical Evidence
yuima
yuima-class
yuima-class
model
data
sampling
characteristic
functional
model
yuima.model
yuima.model
drift
diffusion
hurst
measure
measure.type
state.variable
parameter
state.variable
sampling
yuima.sampling
data
yuima.data
functional
yuima.functional
yuima.sampling
yuima.data
yuima.functional
Initial
Terminal
n
delta
grid
random
regular
sdelta
original.data
zoo.data
F
f
xinit
e
characteristic
yuima.characteristic
setFunctional method
Explorative Data
Analysis
Estimation of Financial
Models
Likelihood approach
Two stage least squares
estimation
Model selection
>
>
>
>
>
>
>
>
>
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
Advertizing
Then, it is as easy as
> F0 <- F0(yuima)
> F0
[1] 1.716424
> max(F0-K,0) # asian call option price
[1] 0.7164237
Model selection
Numerical Evidence
Application to real data
The change point
problem
Overview of the yuima
package
Option Pricing with R
Advertizing
Then, it is as easy as
> F0 <- F0(yuima)
> F0
[1] 1.716424
> max(F0-K,0) # asian call option price
[1] 0.7164237
> LevyAsianApproxOption("c", S = 1, SA = 1, X = 1,
+
Time = 1, time = 1, r = 0, b = 1, sigma = e)
Option Price:
[1] 0.7184944
> X <- sde.sim(drift=expression(x), sigma=expression(e*x), N=1000,M=1000)
> mean(colMeans((X-K)*(X-K>0))) # MC asian call price based on M=1000 repl.
[1] 0.707046
Advertizing
Iacus (2008) Simulation and Inference for Stochastic Differential Equations with R
Examples, Springer, New York.
Iacus (2011) Option Pricing and Estimation of Financial Models with R, Wiley &
Sons, Chichester.