diff --git a/toolbox/helpfiles/FSDA/FM_int_cov.html b/toolbox/helpfiles/FSDA/FM_int_cov.html new file mode 100644 index 000000000..2ca105576 --- /dev/null +++ b/toolbox/helpfiles/FSDA/FM_int_cov.html @@ -0,0 +1,57 @@ + FM_int_cov

FM_int_cov

FM_int_cov computes the integrated covariance of a bivariate diffusion process via the Fourier-Malliavin estimator

Syntax

  • C_int=FM_int_cov(x1,x2,t1,t2,T)example
  • C_int=FM_int_cov(x1,x2,t1,t2,T,Name,Value)example

Description

example

C_int =FM_int_cov(x1, x2, t1, t2, T) Example of call of FM_int_cov with default value of N.

example

C_int =FM_int_cov(x1, x2, t1, t2, T, Name, Value) Example of call of FM_int_cov with custom choice of N.

Examples

expand all

  • Example of call of FM_int_cov with default value of N.
  • + The following example estimates the daily integrated covariance of a bivariate + Heston model from a discrete sample. The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1; 
    +n=23400; 
    +parameters=[0,0;0.4,0.4;2,2;1,1];
    +Rho=[0.5,-0.5,0,0,-0.5,0.5];
    +x0=[log(100); log(100)]; 
    +V0=[0.4; 0.4];
    +[x,V,t]=Heston2D(T,n,parameters,Rho,x0,V0); 
    +% Integrated covariance estimation 
    +t1=t; 
    +t2=t;
    +C_int=FM_int_cov(x(:,1),x(:,2),t1,t2,T);

  • Example of call of FM_int_cov with custom choice of N.
  • + The following example estimates the integrated covariance of a bivariate + Heston model from a discrete sample. The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1; % horizon of the trajectory (in days)
    +n=23400; % number of observations simulated in one trajectory 
    +parameters=[0 , 0; 0.4 , 0.4; 2 , 2; 1 , 1 ];
    +Rho=[0.5 ; -0.5 ; 0 ; 0 ; -0.5 ; 0.5];
    +x0=[log(100); log(100)]; V0=[0.4; 0.4];
    +[x,V,t] = Heston2D(T,n,parameters,Rho,x0,V0); 
    +% Integrated covariance estimation 
    +t1=t; 
    +t2=t;
    +C_int=FM_int_cov(x(:,1),x(:,2),t1,t2,T,'N',5000);

    Input Arguments

    expand all

    x1 — Observation values of process 1. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    x2 — Observation values of process 2. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    t1 — Observation times of process 1. Vector.

    Row or column vector containing + the observation times.

    Data Types: single| double

    t2 — Observation times of process 2. Vector.

    Row or column vector containing + the observation times.

    Data Types: single| double

    T — Estimation horizon. Scalar.

    Data Types: single| double

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'N',400 +

    N —Cutting frequency.scalar.

    If N is not specified, it is set + equal to floor((min(length(x1),length(x2))-1)/2).

    +

    Example: 'N',400 +

    Data Types: single | double

    Output Arguments

    expand all

    C_int —Integrated covariance of processes 1 and 2 on [0,T]. Scalar

    Value of the integrated + covariance of processes 1 and 2.

    More About

    expand all

    Additional Details

    + We assume that vectors x1 and x2 contain discrete observations from a bivariate diffusion + process $(x_1,x_2)$ following the Ito stochastic differential equation + $$dx_i(t)= \sigma_i(t) \ dW_i(t) + b_i(t) \ dt, \quad i=1,2,$$ + where $W_1$ and $W_2$ are two Brownian motions defined on the filtered probability space + $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, + while $\sigma_1, \sigma_2, b_1$ and $b_2$ are random processes, adapted to $\mathcal{F}_t$.

    + See the References for further mathematical details.

    + The integrated covariance of the process $(x_1,x_2)$ on $[0,T]$ is defined as + $$IC_{[0,T]}:=\rho \, \int_0^T \sigma_1(t) \sigma_2(t) \, dt$$ + + Let $i=1,2$. For any positive integer $n_i$, let $\mathcal{S}^i_{n_i}:=\{ 0=t^i_{0}\leq \cdots + \leq t^i_{n_i}=T \}$ be the observation times for the $i$-th asset. Moreover, let $\delta_l(x^i):= + x^i(t^i_{l+1})-x^i(t^i_l)$ be the increments of $x^i$.

    + The Fourier estimator of the integrated covariance on $[0,T]$ is + given by + $$T c_0(c_{n_1,n_2,N})={T\over {2N+1}} \sum_{|k|\leq N} c_{k}(dx^1_{n_1})c_{-k}(dx^2_{n_2}),$$ + + $$c_k(dx^i_{n_i})= {1\over {T}} \sum_{l=0}^{n_i-1} e^{-{\rm i}\frac{2\pi}{T}kt^i_l}\delta_{l}(x_i).$$ + +

    References

    Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer.

    Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv.

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/FM_int_lev.html b/toolbox/helpfiles/FSDA/FM_int_lev.html new file mode 100644 index 000000000..5811546ec --- /dev/null +++ b/toolbox/helpfiles/FSDA/FM_int_lev.html @@ -0,0 +1,63 @@ + FM_int_lev

    FM_int_lev

    FM_int_lev computes the integrated leverage of a diffusion process via the Fourier-Malliavin estimator

    Syntax

    • L_int=FM_int_lev(x,t,T)example
    • L_int=FM_int_lev(x,t,T,Name,Value)example

    Description

    example

    L_int =FM_int_lev(x, t, T) Example of call of FM_int_lev with default values of N and M.

    example

    L_int =FM_int_lev(x, t, T, Name, Value) Example of call of FM_int_lev with custom choices of N and M.

    Examples

    expand all

  • Example of call of FM_int_lev with default values of N and M.
  • + The following example estimates the integrated leverage + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0; 0.5; 7; 2];
    +rho=-0.9;
    +x0=log(100); 
    +V0=0.5;
    +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0);
    +% Integrated leverage estimation
    +L_int = FM_int_lev(x,t,T);

  • Example of call of FM_int_lev with custom choices of N and M.
  • + The following example estimates the integrated leverage + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0; 0.5; 7; 2];
    +rho=-0.9;
    +x0=log(100); 
    +V0=0.5;
    +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0);
    +% Integrated leverage estimation
    +L_int= FM_int_lev(x,t,T,'N',10000,'M',70);

    Input Arguments

    expand all

    x — Observed process values. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    t — Observation times. Vector.

    Row or column vector with the same + length of x containing the observation times.

    Data Types: single| double

    T — Estimation horizon. Scalar.

    Data Types: single| double

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'N',400 +, 'M',20 +

    N —Cutting frequency.scalar.

    If N is not specified, it is set + equal to floor((length(x)-1)/2).

    +

    Example: 'N',400 +

    Data Types: single | double

    M —Cutting frequency.scalar.

    If M is not specified, it is set + equal to floor(floor((length(x)-1)/2)^0.5).

    +

    Example: 'M',20 +

    Data Types: single | double + Data Types - single | double

    Output Arguments

    expand all

    L_int —Integrated leverage. Scalar

    Value of the integrated + leverage.

    More About

    expand all

    Additional Details

    + We assume that the vectors x contains discrete observations from a diffusion + process $x$ following the Ito stochastic differential equation + $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ + $$d\sigma^2(t)= \gamma(t) \ dZ(t) + a(t) \ dt,$$ + where $W$ and $Z$ are two Brownian motions defined on the filtered probability space + $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, while + $\sigma, \gamma, b$ and $a$ are random processes, adapted to $\mathcal{F}_t$.

    + See the References for further mathematical details.

    + The integrated leverage on $[0,T]$ is defined as + $$IL_{[0,T]}:= \langle x,\sigma^2 \rangle_T =\rho\int_0^T\sigma(s)\gamma(s)ds.$$ + + +For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots + \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= + x(t_{l+1})-x(t_l)$ be the increments of $x$.

    + The Fourier estimator of the integrated leverage on $[0,T]$ is + given by + $$T c_0(B_{{n},N})={T^2\over {2M+1}} \sum_{|k|\leq M} c_{k}(d\sigma_{n,N})c_{-k}(dx_{n}),$$ + + where: + $$c_k(d\sigma_{n,N})= i k \frac{2\pi}{T} c_k(\sigma_{n,N}), \quad c_k(\sigma_{{n},N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ + $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ + +

    References

    Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer.

    Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv.

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/FM_int_quart.html b/toolbox/helpfiles/FSDA/FM_int_quart.html new file mode 100644 index 000000000..50c125712 --- /dev/null +++ b/toolbox/helpfiles/FSDA/FM_int_quart.html @@ -0,0 +1,61 @@ + FM_int_quart

    FM_int_quart

    FM_int_quart computes the integrated quarticity of a diffusion process via the Fourier-Malliavin estimator

    Syntax

    • Q_int=FM_int_quart(x,t,T)example
    • Q_int=FM_int_quart(x,t,T,Name,Value)example

    Description

    example

    Q_int =FM_int_quart(x, t, T) Example of call of FM_int_quart default values of N and M.

    example

    Q_int =FM_int_quart(x, t, T, Name, Value) Example of call of FM_int_quart with custom choices of N and M.

    Examples

    expand all

  • Example of call of FM_int_quart default values of N and M.
  • + The following example estimates the integrated quarticity + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0,0.4,5,1];
    +rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0);
    +% Integrated quarticity estimation 
    +Q_int = FM_int_quart(x,t,T);

  • Example of call of FM_int_quart with custom choices of N and M.
  • + The following example estimates the integrated quarticity + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0,0.4,5,1];
    +rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0);
    +% Integrated quarticity estimation 
    +Q_int= FM_int_quart(x,t,T,'N',10000,'M',120);

    Input Arguments

    expand all

    x — Observed process values. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    t — Observation times. Vector.

    Row or column vector with the same + length of x containing the observation times.

    Data Types: single| double

    T — Estimation horizon. Scalar.

    Data Types: single| double

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'N',400 +, 'M',20 +

    N —Cutting frequency.scalar.

    If N is not specified, it is set + equal to floor((length(x)-1)/2).

    +

    Example: 'N',400 +

    Data Types: single | double

    M —Cutting frequency.scalar.

    If M is not specified, it is set + equal to floor(floor((length(x)-1)/2)^0.5).

    +

    Example: 'M',20 +

    Data Types: single | double + Data Types - single | double

    Output Arguments

    expand all

    Q_int —Integrated quarticity. Scalar

    Value of the integrated + quarticity.

    More About

    expand all

    Additional Details

    + We assume that the vectors x contains discrete observations from a diffusion + process $x$ following the Ito stochastic differential equation + $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ + where $W$ is a Brownian motions defined on the filtered probability space + $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, while $\sigma$ and $b$ are random processes, adapted to $\mathcal{F}_t$.

    + See the References for further mathematical details.

    + The integrated quarticity on $[0,T]$ is defined as + $$IQ_{[0,T]}:=\int_0^T\sigma^4(s)ds.$$ + + +For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots + \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= + x(t_{l+1})-x(t_l)$ be the increments of $x$.

    + The Fourier estimator of the integrated quarticity on $[0,T]$ is + given by + $$T c_0(Q_{{n},N.M})={T^2\over {2M+1}} \sum_{|k|\leq M} c_{k}(\sigma_{n,N})c_{-k}(\sigma_{n,N}),$$ + + where: + $$c_k(\sigma_{{n},N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ + $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ + +

    References

    Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer.

    Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv.

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/FM_int_vol.html b/toolbox/helpfiles/FSDA/FM_int_vol.html new file mode 100644 index 000000000..6d6a547c4 --- /dev/null +++ b/toolbox/helpfiles/FSDA/FM_int_vol.html @@ -0,0 +1,53 @@ + FM_int_vol

    FM_int_vol

    FM_int_vol computes the integrated variance of a diffusion process via the Fourier-Malliavin estimator

    Syntax

    • V_int=FM_int_vol(x,t,T)example
    • V_int=FM_int_vol(x,t,T,Name,Value)example

    Description

    example

    V_int =FM_int_vol(x, t, T) Example of call of FM_int_vol with default value of N.

    example

    V_int =FM_int_vol(x, t, T, Name, Value) Example of call of FM_int_vol with custom choice of N.

    Examples

    expand all

  • Example of call of FM_int_vol with default value of N.
  • + The following example estimates the integrated volatility of a + Heston model from a discrete sample. The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0,0.4,2,1];
    +Rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V,t]=Heston1D(T,n,parameters,Rho,x0,V0); 
    +% Integrated volatility estimation
    +V_int=FM_int_vol(x,t,T);

  • Example of call of FM_int_vol with custom choice of N.
  • + The following example estimates the integrated volatility of a + Heston model from a discrete sample. The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1; 
    +n=23400;  
    +parameters=[0,0.4,2,1];
    +Rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V,t]=Heston1D(T,n,parameters,Rho,x0,V0); 
    +% Integrated volatility estimation
    +V_int= FM_int_vol(x,t,T,'N',5000);

    Input Arguments

    expand all

    x — Observed process values. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    t — Observation times. Vector.

    Row or column vector with the same + length of x containing the observation times.

    Data Types: single| double

    T — Estimation horizon. Scalar.

    Data Types: single| double

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'N',400 +

    N —Cutting frequency.scalar.

    If N is not specified, it is set + equal to floor(length(x)-/2).

    +

    Example: 'N',400 +

    Data Types: single | double

    Output Arguments

    expand all

    V_int —Integrated variance. Scalar

    Values of the integrated + variance.

    More About

    expand all

    Additional Details

    + We assume that the vector x contains discrete observations from a diffusion + process following the Ito stochastic differential equation + $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ + where $W$ is a Brownian motions defined on the filtered probability space + $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, while $\sigma$ and $b$ are random processes, adapted to $\mathcal{F}_t$.

    + See the References for further mathematical details.

    + The integrated variance of the process $x$ on $[0,T]$ is defined as + $$IV_{[0,T]}:=\int_0^T \sigma^2(t)\, dt.$$ + + For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots + \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= + x(t_{l+1})-x(t_l)$ be the increments of $x$.

    + The Fourier estimator of the integrated volatility on $[0,T]$ is + given by + + $$T c_0(\sigma_{{n},N})={T^2\over {2N+1}} \sum_{|k|\leq N} c_{k}(dx_{n})c_{-k}(dx_{n}),$$ + + where + $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ + +

    References

    Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer.

    Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv.

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/FM_int_volvol.html b/toolbox/helpfiles/FSDA/FM_int_volvol.html new file mode 100644 index 000000000..ee565fe4a --- /dev/null +++ b/toolbox/helpfiles/FSDA/FM_int_volvol.html @@ -0,0 +1,62 @@ + FM_int_volvol

    FM_int_volvol

    FM_int_volvol computes the integrated volatility of volatility of a diffusion process via the Fourier-Malliavin estimator

    Syntax

    • VV_int=FM_int_volvol(x,t,T)example
    • VV_int=FM_int_volvol(x,t,T,Name,Value)example

    Description

    example

    VV_int =FM_int_volvol(x, t, T) Example of call of FM_int_volvol with default values of N and M.

    example

    VV_int =FM_int_volvol(x, t, T, Name, Value) Example of call of FM_int_volvol with custom choices of N and M.

    Examples

    expand all

  • Example of call of FM_int_volvol with default values of N and M.
  • + The following example estimates the integrated volatility of volatility + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0,0.8,10,3.25];
    +rho=-0.3;
    +x0=log(100); 
    +V0=0.8;
    +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0);
    +% Integrated volatility of volatility estimation
    +VV_int = FM_int_volvol(x,t,T);

  • Example of call of FM_int_volvol with custom choices of N and M.
  • + The following example estimates the integrated volatility of volatility + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1; 
    +n=23400; % number of observations simulated in one trajectory 
    +parameters=[0,0.8,10,3.25];
    +rho=-0.3;
    +x0=log(100); 
    +V0=0.8;
    +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0);
    +% Integrated volatility of volatility estimation 
    +VV_int = FM_int_volvol(x,t,T,'N',11200, 'M', 50);

    Input Arguments

    expand all

    x — Observed process values. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    t — Observation times. Vector.

    Row or column vector with the same + length of x containing the observation times.

    Data Types: single| double

    T — Estimation horizon. Scalar.

    Data Types: single| double

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'N',400 +, 'M',20 +

    N —Cutting frequency.scalar.

    If N is not specified, it is set + equal to floor((length(x)-1)/2).

    +

    Example: 'N',400 +

    Data Types: single | double

    M —Cutting frequency.scalar.

    If M is not specified, it is set + equal to floor(floor((length(x)-1)/2)^0.4).

    +

    Example: 'M',20 +

    Data Types: single | double + Data Types - single | double

    Output Arguments

    expand all

    VV_int —Integrated volatility of volatility. Scalar

    Value of the integrated volatility of volatility.

    More About

    expand all

    Additional Details

    + We assume that the vectors x contains discrete observations from a diffusion + process $x$ following the Ito stochastic differential equation + $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ + $$d\sigma^2(t)= \gamma(t) \ dZ(t) + a(t) \ dt,$$ + where $W$ and $Z$ are two Brownian motions defined on the filtered probability space + $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, while + $\sigma, \gamma, b$ and $a$ are random processes, adapted to $\mathcal{F}_t$.

    + See the References for further mathematical details.

    + The integrated volatility of volatility on $[0,T]$ is defined as + $$ IVV_{[0,T]}:= \langle \sigma^2 ,\sigma^2 \rangle_T =\int_0^T\gamma^2(s)ds.$$ + + +For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots + \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= + x(t_{l+1})-x(t_l)$ be the increments of $x$.

    + The Fourier estimator of the integrated volatility of volatility on $[0,T]$ is + given by + $$T c_0(V_{{n},N,M})={T^2\over {2M+1}} \sum_{|k|\leq M} c_{k}(d\sigma_{n,N})c_{-k}(d\sigma_{n,N}),$$ + + where: + $$c_k(d\sigma_{n,N})= i k \frac{2\pi}{T} c_k(\sigma_{n,N}), \quad c_k(\sigma_{{n},N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ + $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ + +

    References

    Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer.

    Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv.

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/FM_spot_cov.html b/toolbox/helpfiles/FSDA/FM_spot_cov.html new file mode 100644 index 000000000..2e0698131 --- /dev/null +++ b/toolbox/helpfiles/FSDA/FM_spot_cov.html @@ -0,0 +1,112 @@ + FM_spot_cov

    FM_spot_cov

    FM_spot_cov computes the spot covariance of a bivariate diffusion process via the Fourier-Malliavin estimator

    Syntax

    • C_spot=FM_spot_cov(x1,x2,t1,t2,T)example
    • C_spot=FM_spot_cov(x1,x2,t1,t2,T,Name,Value)example
    • [C_spot, tau_out]=FM_spot_cov(___)example

    Description

    example

    C_spot =FM_spot_cov(x1, x2, t1, t2, T) Example of call of FM_spot_cov with default values of N, M and tau.

    example

    C_spot =FM_spot_cov(x1, x2, t1, t2, T, Name, Value) Example of call of FM_spot_cov with custom choices of N, M and tau.

    example

    [C_spot, tau_out] =FM_spot_cov(___) Example of call of FM_spot_cov when tau has length larger than 2M + 1.

    Examples

    expand all

  • Example of call of FM_spot_cov with default values of N, M and tau.
  • + The following example estimates the path of the spot covariance of a bivariate + Heston model from a discrete sample. The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1; 
    +n=23400; 
    +parameters=[0,0;0.4,0.4;2,2;1,1];
    +Rho=[0.5,-0.5,0,0,-0.5,0.5];
    +x0=[log(100); log(100)]; 
    +V0=[0.4; 0.4];
    +[x,V,t]=Heston2D(T,n,parameters,Rho,x0,V0); 
    +% Spot covariance estimation
    +t1=t; 
    +t2=t;
    +[C_spot, tau_out]=FM_spot_cov(x(:,1),x(:,2),t1,t2,T);
    +M=(length(C_spot)-1)/2;   
    +figure
    +Cov=Rho(6)*sqrt(V(:,1)).*sqrt(V(:,2));
    +plot(tau_out,Cov(1:round(n/(2*M)):end));
    +hold on
    +plot(tau_out,C_spot); 
    +xlabel('tau'); 
    +title('Spot co-volatility estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of FM_spot_cov with custom choices of N, M and tau.
  • + The following example estimates the path of the spot covariance of a bivariate + Heston model from a discrete sample. The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0 , 0; 0.4 , 0.4; 2 , 2; 1 , 1 ];
    +Rho=[0.5 ; -0.5 ; 0 ; 0 ; -0.5 ; 0.5];
    +x0=[log(100); log(100)]; V0=[0.4; 0.4];
    +[x,V,t] = Heston2D(T,n,parameters,Rho,x0,V0); 
    +% Estimation of the spot covariance 
    +t1=t; 
    +t2=t;
    +tau=0:T/50:T;
    +[C_spot,tau_out]=FM_spot_cov(x(:,1),x(:,2),t1,t2,T,'N',5000,'M',100,'tau',tau);
    +figure
    +Cov=Rho(6)*sqrt(V(:,1)).*sqrt(V(:,2));
    +plot(tau_out,Cov(1:round(n/50):end));
    +hold on
    +plot(tau_out,C_spot); 
    +xlabel('tau'); 
    +title('Spot co-volatility estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of FM_spot_cov when tau has length larger than 2M + 1.
  • + The following example estimates the path of the spot covariance of a bivariate + Heston model from a discrete sample. The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0 , 0; 0.4 , 0.4; 2 , 2; 1 , 1 ];
    +Rho=[0.5 ; -0.5 ; 0 ; 0 ; -0.5 ; 0.5];
    +x0=[log(100); log(100)]; V0=[0.4; 0.4];
    +[x,V,t] = Heston2D(T,n,parameters,Rho,x0,V0); 
    +% Estimation of the spot covariance 
    +t1=t; 
    +t2=t;
    +tau=0:T/1000:T;
    +[C_spot,tau_out]=FM_spot_cov(x(:,1),x(:,2),t1,t2,T,'N',5000,'M',100,'tau',tau);
    +figure
    +Cov=Rho(6)*sqrt(V(:,1)).*sqrt(V(:,2));
    +M=100;
    +plot(tau_out,Cov(1:round(n/(2*M)):end));
    +hold on
    +plot(tau_out,C_spot); 
    +xlabel('tau'); 
    +title('Spot co-volatility estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    WARNING: estimation will be performed on the equally-spaced grid with mesh size equal to T/(2*M), provided as an output variable.
    +
    Click here for the graphical output of this example (link to Ro.S.A. website).

    Input Arguments

    expand all

    x1 — Observation values of process 1. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    x2 — Observation values of process 2. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    t1 — Observation times of process 1. Vector.

    Row or column vector with the same + length of x1 containing the observation times.

    Data Types: single| double

    t2 — Observation times of process 2. Vector.

    Row or column vector with the same + length of x2 containing the observation times.

    Data Types: single| double

    T — Estimation horizon. Scalar.

    Data Types: single| double

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'N',400 +, 'M',20 +, 'tau', 0:T/100:T +

    N —Cutting frequency.scalar.

    If N is not specified, it is set + equal to floor(min(length(x1),length(x2))-1)/2).

    +

    Example: 'N',400 +

    Data Types: single | double

    M —Cutting frequency.scalar.

    If M is not specified, it is set + equal to floor(floor(min(length(x1),length(x2))-1)/2)^0.5).

    +

    Example: 'M',20 +

    Data Types: single | double

    tau —Estimation times.vector.

    If tau is not specified, it is set + equal to 0:T/(2*M):T.

    +

    Example: 'tau', 0:T/100:T +

    Data Types: single | double

    Output Arguments

    expand all

    C_spot —Spot covariance of processes 1 and 2. Vector

    Values of the + spot covariance of processes 1 and 2.

    tau_out —Estimation times. Vector

    Coincides with the input vector tau unless the length + of the latter is larger than 2M+1.

    More About

    expand all

    Additional Details

    + We assume that vectors x1 and x2 contain discrete observations from a bivariate diffusion + process $(x_1,x_2)$ following the Ito stochastic differential equation + $$dx^i(t)= \sigma^i(t) \ dW^i(t) + b^i(t) \ dt, \quad i=1,2,$$ + where $W^1$ and $W^2$ are two Brownian motions defined on the filtered probability space + $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, while + $\sigma^1, \sigma^2, b^1$ and $b^2$ are random processes, adapted to $\mathcal{F}_t$.

    + See the References for further mathematical details.

    + The spot covariance $c$ between the processes $x^1$ and $x^2$ at time $t + \in [0,T]$ is defined as + $$c(t):= \frac{d \langle x^1, x^2 \rangle_t}{dt} = \rho \sigma^1(t) \sigma^2(t).$$ + + Let $i=1,2$. For any positive integer $n_i$, let $\mathcal{S}^i_{n_i}:=\{ 0=t^i_{0}\leq \cdots + \leq t^i_{n_i}=T \}$ be the observation times for the $i$-th asset. Moreover, let $\delta_l(x^i):= + x^i(t^i_{l+1})-x^i(t^i_l)$ be the increments of $x^i$.

    + The Fourier estimator of the spot covariance at time $t \in [0,T]$ is + given by + $$\widehat c_{n_1,n_2,N,M}(\tau)= \sum_{|k|\leq M} \left(1-{|k|\over + M}\right)c_k(c_{n_1,n_2,N}) \, e^{{\rm i}\frac{2\pi}{T}k\tau},$$ + where: + $$c_k(c_{n_1,n_2,N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx^1_{n_1})c_{k-s}(dx^2_{n_2}),$$ + + $$c_k(dx^i_{n_i})= {1\over {T}} \sum_{l=0}^{n_i-1} e^{-{\rm i}\frac{2\pi}{T}kt^i_l}\delta_{l}(x_i).$$ + +

    References

    Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer.

    Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv.

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/FM_spot_lev.html b/toolbox/helpfiles/FSDA/FM_spot_lev.html new file mode 100644 index 000000000..b42abe9c5 --- /dev/null +++ b/toolbox/helpfiles/FSDA/FM_spot_lev.html @@ -0,0 +1,117 @@ + FM_spot_lev

    FM_spot_lev

    FM_spot_lev computes the spot leverage of a diffusion process via the Fourier-Malliavin estimator

    Syntax

    • L_spot=FM_spot_lev(x,t,T)example
    • L_spot=FM_spot_lev(x,t,T,Name,Value)example
    • [L_spot, tau_out]=FM_spot_lev(___)example

    Description

    example

    L_spot =FM_spot_lev(x, t, T) Example of call of FM_spot_lev with default values of N,M,L and tau.

    example

    L_spot =FM_spot_lev(x, t, T, Name, Value) Example of call of FM_spot_lev with custom choices of N,M,L and tau.

    example

    [L_spot, tau_out] =FM_spot_lev(___) Example of call of FM_spot_lev when tau has length larger than 2L + 1.

    Examples

    expand all

  • Example of call of FM_spot_lev with default values of N,M,L and tau.
  • + The following example estimates the path of the spot leverage + of a random process following the Heston model from a discrete sample.

    % The Heston model assumes that the spot variance follows 
    +% a Cox-Ingersoll-Ross model.
    +% Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0; 0.5; 7; 2];
    +rho=-0.9;
    +x0=log(100); 
    +V0=0.5;
    +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0);
    +% Spot leverage estimation  
    +[L_spot, tau_out] = FM_spot_lev(x,t,T);
    +L=(length(L_spot)-1)/2;  
    +figure
    +Lev=rho*parameters(end)*V;
    +plot(tau_out,Lev(1:round(n/(2*L)):end));
    +hold on
    +plot(tau_out,L_spot); 
    +xlabel('tau'); 
    +title('Spot leverage estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of FM_spot_lev with custom choices of N,M,L and tau.
  • + The following example estimates the path of the spot leverage + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0; 0.5; 7; 2];
    +rho=-0.9;
    +x0=log(100); 
    +V0=0.5;
    +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0);
    +% Spot leverage estimation
    +tau=0:T/10:T;
    +[L_spot, tau_out]= FM_spot_lev(x,t,T,'N',10000,'M',120,'L',8,'tau',tau);
    +figure
    +Lev=rho*parameters(end)*V;
    +plot(tau_out,L_spot); 
    +hold on
    +plot(tau_out,Lev(1:round(n/10):end));
    +xlabel('tau'); 
    +title('Spot leverage estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of FM_spot_lev when tau has length larger than 2L + 1.
  • + The following example estimates the path of the spot leverage + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0; 0.5; 7; 2];
    +rho=-0.9;
    +x0=log(100); 
    +V0=0.5;
    +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0);
    +% Spot leverage estimation
    +tau=0:T/200:T;
    +[L_spot, tau_out]= FM_spot_lev(x,t,T,'N',10000,'M',120,'L',10,'tau',tau);
    +figure
    +Lev=rho*parameters(end)*V;
    +plot(tau_out,L_spot); 
    +hold on
    +L=10;
    +plot(tau_out,Lev(1:round(n/(2*L)):end));
    +xlabel('tau'); 
    +title('Spot leverage estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    WARNING: estimation will be performed on the equally-spaced grid with mesh size equal to T/(2*L), provided as an output variable.
    +
    Click here for the graphical output of this example (link to Ro.S.A. website).

    Input Arguments

    expand all

    x — Observed process values. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    t — Observation times. Vector.

    Row or column vector with the same + length of x containing the observation times.

    Data Types: single| double

    T — Estimation horizon. Scalar.

    Data Types: single| double

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'N',400 +, 'M',20 +, 'L',5 +, 'tau', 0:T/100:T +

    N —Cutting frequency.scalar.

    If N is not specified, it is set + equal to floor((length(x)-1)/2).

    +

    Example: 'N',400 +

    Data Types: single | double

    M —Cutting frequency.scalar.

    If M is not specified, it is set + equal to floor(floor((length(x)-1)/2)^0.5).

    +

    Example: 'M',20 +

    Data Types: single | double

    L —Cutting frequency.scalar.

    If L is not specified, it is set + equal to floor(floor(floor((length(x)-1)/2)^0.5)^0.5).

    +

    Example: 'L',5 +

    Data Types: single | double

    tau —Estimation times.vector.

    If tau is not specified, it is set + equal to 0:T/(2*L):T.

    +

    Example: 'tau', 0:T/100:T +

    Data Types: single | double

    Output Arguments

    expand all

    L_spot —Spot leverage. Vector

    Values of the spot + leverage of the process.

    tau_out —Estimation times. Vector

    Coincides with the input vector tau unless the length + of the latter is larger than 2L+1.

    More About

    expand all

    Additional Details

    + We assume that the vectors x contains discrete observations from a diffusion + process $x$ following the Ito stochastic differential equation + $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ + $$d\sigma^2(t)= \gamma(t) \ dZ(t) + a(t) \ dt,$$ + where $W$ and $Z$ are two Brownian motions defined on the filtered probability space + $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, while + $\sigma, \gamma, b$ and $a$ are random processes, adapted to $\mathcal{F}_t$.

    + See the References for further mathematical details.

    + The spot leverage at time $t \in [0,T]$ is defined as + $$B(t):=\frac{d\langle x,\sigma^2 \rangle_t}{dt}=\rho\sigma(t)\gamma(t).$$ + + + For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots + \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= + x(t_{l+1})-x(t_l)$ be the increments of $x$.

    + The Fourier estimator of the spot leverage at time $t \in [0,T]$ is + given by + $$\widehat B_{n,N,M,L}(\tau)= \sum_{|k|\leq L} \left(1-{|k|\over + L}\right)c_k(B_{n,N,M}) \, e^{{\rm i}\frac{2\pi}{T}k\tau},$$ + where: + $$c_k(B_{n,N,M})= {T \over {2M+1}} \sum_{|s|\leq M} c_s(d\sigma_{{n},N})c_{k-s}(dx_{n}),$$ + + $$c_k(d\sigma_{{n},N})={\rm i} \, k\, \frac{2\pi}{T} + c_k(\sigma_{{n},N}), \quad c_k(\sigma_{n,N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ + + $$c_k(dx_{n}):= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ + +

    References

    Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer.

    Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv.

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/FM_spot_quart.html b/toolbox/helpfiles/FSDA/FM_spot_quart.html new file mode 100644 index 000000000..163f8bab6 --- /dev/null +++ b/toolbox/helpfiles/FSDA/FM_spot_quart.html @@ -0,0 +1,113 @@ + FM_spot_quart

    FM_spot_quart

    FM_spot_quart computes the spot quarticity of a diffusion process via the Fourier-Malliavin estimator

    Syntax

    • Q_spot=FM_spot_quart(x,t,T)example
    • Q_spot=FM_spot_quart(x,t,T,Name,Value)example
    • [Q_spot, tau_out]=FM_spot_quart(___)example

    Description

    example

    Q_spot =FM_spot_quart(x, t, T) Example of call of FM_spot_quart with default values of N,M,L and tau.

    example

    Q_spot =FM_spot_quart(x, t, T, Name, Value) Example of call of FM_spot_quart with custom choices of N,M,L and tau.

    example

    [Q_spot, tau_out] =FM_spot_quart(___) Example of call of FM_spot_quart when tau has length larger than 2L + 1.

    Examples

    expand all

  • Example of call of FM_spot_quart with default values of N,M,L and tau.
  • + The following example estimates the path of the spot quarticity + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0,0.4,5,1];
    +rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0);
    +% Spot qaurticity estimation 
    +[Q_spot, tau_out] = FM_spot_quart(x,t,T);
    +L=(length(Q_spot)-1)/2;
    +figure
    +Q=V.^2;
    +plot(tau_out,Q(1:round(n/(2*L)):end));
    +hold on
    +plot(tau_out,Q_spot);  
    +title('Spot quarticity estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of FM_spot_quart with custom choices of N,M,L and tau.
  • + The following example estimates the path of the spot quarticity + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0,0.4,5,1];
    +rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0);
    +% Spot quarticity estimation  
    +tau=0:T/10:T;
    +[Q_spot,tau_out]= FM_spot_quart(x,t,T,'N',11000,'M',120,'L',15,'tau',tau);
    +figure
    +Q=V.^2;
    +plot(tau_out,Q(1:round(n/10):end));
    +hold on
    +plot(tau_out,Q_spot); 
    +xlabel('tau'); 
    +title('Spot quarticity estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of FM_spot_quart when tau has length larger than 2L + 1.
  • + The following example estimates the path of the spot quarticity + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0,0.4,5,1];
    +rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0);
    +% Spot quarticity estimation  
    +tau=0:T/500:T;
    +[Q_spot,tau_out]= FM_spot_quart(x,t,T,'N',11000,'M',120,'L',10,'tau',tau);
    +figure
    +Q=V.^2;
    +L=10;
    +plot(tau_out,Q(1:round(n/(2*L)):end));
    +hold on
    +plot(tau_out,Q_spot); 
    +xlabel('tau'); 
    +title('Spot quarticity estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    WARNING: estimation will be performed on the equally-spaced grid with mesh size equal to T/(2*L), provided as an output variable.
    +
    Click here for the graphical output of this example (link to Ro.S.A. website).

    Input Arguments

    expand all

    x — Observed process values. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    t — Observation times. Vector.

    Row or column vector with the same + length of x containing the observation times.

    Data Types: single| double

    T — Estimation horizon. Scalar.

    Data Types: single| double

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'N',400 +, 'M',20 +, 'L',5 +, 'tau', 0:T/100:T +

    N —Cutting frequency.scalar.

    If N is not specified, it is set + equal to floor((length(x)-1)/2).

    +

    Example: 'N',400 +

    Data Types: single | double

    M —Cutting frequency.scalar.

    If M is not specified, it is set + equal to floor(floor((length(x)-1)/2)^0.5).

    +

    Example: 'M',20 +

    Data Types: single | double

    L —Cutting frequency.scalar.

    If L is not specified, it is set + equal to floor(floor(floor((length(x)-1)/2)^0.5)^0.5).

    +

    Example: 'L',5 +

    Data Types: single | double

    tau —Estimation times.vector.

    If tau is not specified, it is set + equal to 0:T/(2*L):T.

    +

    Example: 'tau', 0:T/100:T +

    Data Types: single | double

    Output Arguments

    expand all

    Q_spot —Spot quarticity estimates. Vector

    Estimated values of the spot + quarticity of the process.

    tau_out —Estimation times. Vector

    Coincides with the input vector tau unless the length + of the latter is larger than 2L+1.

    More About

    expand all

    Additional Details

    + We assume that the vectors x contains discrete observations from a diffusion + process $x$ following the Ito stochastic differential equation + $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ + where $W$ is a Brownian motions defined on the filtered probability space + $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, while + $\sigma$ and $b$ are random processes, adapted to $\mathcal{F}_t$.

    + See the References for further mathematical details.

    + The spot quarticity at time $t \in [0,T]$ is defined as $Q(t):=\sigma^4(t).$ + + + For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots + \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= + x(t_{l+1})-x(t_l)$ be the increments of $x$.

    + The Fourier estimator of the spot quarticity at time $t \in [0,T]$ is + given by + $$\widehat Q_{n,N,M,L}(\tau)= \sum_{|k|\leq L} \left(1-{|k|\over + L}\right)c_k(Q_{n,N,M}) \, e^{{\rm i}\frac{2\pi}{T}k\tau},$$ + where: + $$c_k(Q_{n,N,M})= {T \over {2M+1}} \sum_{|s|\leq M} c_s( \sigma_{{n},N})c_{k-s}(\sigma_{{n},N}),$$ + + $$c_k(\sigma_{n,N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ + + $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ + +

    References

    Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer.

    Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv.

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/FM_spot_vol.html b/toolbox/helpfiles/FSDA/FM_spot_vol.html new file mode 100644 index 000000000..7237ceb47 --- /dev/null +++ b/toolbox/helpfiles/FSDA/FM_spot_vol.html @@ -0,0 +1,100 @@ + FM_spot_vol

    FM_spot_vol

    FM_spot_vol computes the spot volatility of a diffusion process via the Fourier-Malliavin estimator

    Syntax

    • V_spot=FM_spot_vol(x,t,T)example
    • V_spot=FM_spot_vol(x,t,T,Name,Value)example
    • [V_spot,tau_out]=FM_spot_vol(___)example

    Description

    example

    V_spot =FM_spot_vol(x, t, T) Example of call of FM_spot_vol with default values of M,N and tau.

    example

    V_spot =FM_spot_vol(x, t, T, Name, Value) Example of call of FM_spot_vol with custom choices of M,N and tau.

    example

    [V_spot, tau_out] =FM_spot_vol(___) Example of call of FM_spot_vol when tau has length larger than 2M + 1.

    Examples

    expand all

  • Example of call of FM_spot_vol with default values of M,N and tau.
  • + The following example estimates the path of the spot volatility of a + Heston model from a discrete sample. The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0,0.4,2,1];
    +Rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V,t]=Heston1D(T,n,parameters,Rho,x0,V0); 
    +% Spot volatility estimation 
    +[V_spot, tau_out]=FM_spot_vol(x,t,T);
    +M=(length(V_spot)-1)/2;   
    +figure
    +plot(tau_out,V(1:round(n/(2*M)):end));
    +hold on
    +plot(tau_out,V_spot); 
    +xlabel('tau'); 
    +title('Spot volatility estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of FM_spot_vol with custom choices of M,N and tau.
  • + The following example estimates the path of the spot volatility of a + Heston model from a discrete sample. The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1; 
    +n=23400;  
    +parameters=[0,0.4,2,1];
    +Rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V,t]=Heston1D(T,n,parameters,Rho,x0,V0); 
    +% Spot volatility estimation
    +tau=0:T/50:T;
    +[V_spot, tau_out]= FM_spot_vol(x,t,T,'N',5000,'M',100,'tau',tau);
    +figure
    +plot(tau_out,V(1:round(n/50):end));
    +hold on
    +plot(tau_out,V_spot); 
    +xlabel('tau'); 
    +title('Spot volatility estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of FM_spot_vol when tau has length larger than 2M + 1.
  • + The following example estimates the path of the spot volatility of a + Heston model from a discrete sample. The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1; 
    +n=23400;  
    +parameters=[0,0.4,2,1];
    +Rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V,t]=Heston1D(T,n,parameters,Rho,x0,V0); 
    +% Spot volatility estimation
    +tau=0:T/1000:T;
    +[V_spot, tau_out]= FM_spot_vol(x,t,T,'N',5000,'M',100,'tau',tau);
    +figure
    +M=100;
    +plot(tau_out,V(1:round(n/(2*M)):end));
    +hold on
    +plot(tau_out,V_spot); 
    +xlabel('tau'); 
    +title('Spot volatility estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    WARNING: estimation will be performed on the equally-spaced grid with mesh size equal to T/(2*M), provided as an output variable.
    +
    Click here for the graphical output of this example (link to Ro.S.A. website).

    Input Arguments

    expand all

    x — Observed process values. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    t — Observation times. Vector.

    Row or column vector with the same + length of x containing the observation times.

    Data Types: single| double

    T — Estimation horizon. Scalar.

    Data Types: single| double

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'N',400 +, 'M',20 +, 'tau', 0:T/100:T +

    N —Cutting frequency.scalar.

    If N is not specified, it is set + equal to floor((length(x)-1)/2).

    +

    Example: 'N',400 +

    Data Types: single | double

    M —Cutting frequency.scalar.

    If M is not specified, it is set + equal to floor(floor((length(x)-1)/2)^0.5).

    +

    Example: 'M',20 +

    Data Types: single | double

    tau —Estimation times.vector.

    If tau is not specified, it is set + equal to 0:T/(2*M):T.

    +

    Example: 'tau', 0:T/100:T +

    Data Types: single | double

    Output Arguments

    expand all

    V_spot —Spot variance estimates. Vector

    Estimated values of the spot + variance of the process.

    tau_out —Estimation times. Vector

    Coincides with the input vector tau unless the length + of the latter is larger than 2M+1.

    More About

    expand all

    Additional Details

    + We assume that the vector x contains discrete observations from a diffusion + process $x$ following the Ito stochastic differential equation + $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ + where $W$ is a Brownian motion defined on the filtered probability space $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, + while $\sigma$ and $b$ are random processes, adapted to $\mathcal{F}_t$.

    + See the Reference for further mathematical details.

    + The spot volatility of the process $x$ at time $t \in [0,T]$ is defined as $V(t):=\sigma^2(t)$.

    + + For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots + \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= + x(t_{l+1})-x(t_l)$ be the increments of $x$.

    + The Fourier estimator of the spot volatility at time $t \in [0,T]$ is + given by + $$\widehat V_{n,N,M}(\tau)= \sum_{|k|\leq M} \left(1-{|k|\over + M}\right)c_k(\sigma_{n,N}) \, e^{{\rm i}\frac{2\pi}{T}k\tau},$$ + where: + $$c_k(\sigma_{n,N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ + + $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ + +

    References

    Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer.

    Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv.

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/FM_spot_volvol.html b/toolbox/helpfiles/FSDA/FM_spot_volvol.html new file mode 100644 index 000000000..2c4b1817c --- /dev/null +++ b/toolbox/helpfiles/FSDA/FM_spot_volvol.html @@ -0,0 +1,117 @@ + FM_spot_volvol

    FM_spot_volvol

    FM_spot_volvol computes the spot volatiity of volatility of a diffusion process via the Fourier-Malliavin estimator

    Syntax

    • VV_spot=FM_spot_volvol(x,t,T)example
    • VV_spot=FM_spot_volvol(x,t,T,Name,Value)example
    • [VV_spot, tau_out]=FM_spot_volvol(___)example

    Description

    example

    VV_spot =FM_spot_volvol(x, t, T) Example of call of FM_spot_volvol with default values of N,M,L and tau.

    example

    VV_spot =FM_spot_volvol(x, t, T, Name, Value) Example of call of FM_spot_volvol with custom choices of N,M,L and tau.

    example

    [VV_spot, tau_out] =FM_spot_volvol(___) Example of call of FM_spot_volvol when tau has length larger than 2L + 1.

    Examples

    expand all

  • Example of call of FM_spot_volvol with default values of N,M,L and tau.
  • + The following example estimates the path of the spot volatility of volatility + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1;  
    +n=23400;  
    +parameters=[0,0.8,10,3.25];
    +rho=-0.3;
    +x0=log(100); 
    +V0=0.8;
    +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0);
    +% Spot volatility of volatility estimation  
    +[VV_spot, tau_out] = FM_spot_volvol(x,t,T);
    +L=(length(VV_spot)-1)/2;
    +figure
    +VV=parameters(end)^2*V;
    +plot(tau_out,VV(1:round(n/(2*L)):end));
    +hold on
    +plot(tau_out,VV_spot); 
    +xlabel('tau');
    +title('Spot volatility of volatility estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of FM_spot_volvol with custom choices of N,M,L and tau.
  • + The following example estimates the daily path of the spot volatility of volatility + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1; % horizon of the trajectory 
    +n=23400; % number of observations simulated in one trajectory 
    +parameters=[0,0.8,10,3.25];
    +rho=-0.3;
    +x0=log(100); 
    +V0=0.8;
    +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0);
    +% Spot volatility of volatility estimation
    +tau=0:T/10:T;
    +[VV_spot, tau_out] = FM_spot_volvol(x,t,T,'N',10000,'M',50,'L',10,'tau',tau);
    +figure
    +VV=parameters(end)^2*V;
    +plot(tau_out,VV(1:round(n/10):end));
    +hold on
    +plot(tau_out,VV_spot); 
    +xlabel('tau'); 
    +title('Spot volatility of volatility estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of FM_spot_volvol when tau has length larger than 2L + 1.
  • + The following example estimates the daily path of the spot volatility of volatility + of a random process following the Heston model from a discrete sample. + The Heston model assumes that the spot variance follows + a Cox-Ingersoll-Ross model.

    % Heston model simulation
    +T=1; % horizon of the trajectory 
    +n=23400; % number of observations simulated in one trajectory 
    +parameters=[0,0.8,10,3.25];
    +rho=-0.3;
    +x0=log(100); 
    +V0=0.8;
    +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0);
    +% Spot volatility of volatility estimation
    +tau=0:T/100:T;
    +[VV_spot, tau_out] = FM_spot_volvol(x,t,T,'N',10000,'M',50,'L',10,'tau',tau);
    +figure
    +VV=parameters(end)^2*V;
    +L=10;
    +plot(tau_out,VV(1:round(n/(2*L)):end));
    +hold on
    +plot(tau_out,VV_spot); 
    +xlabel('tau'); 
    +title('Spot volatility of volatility estimates Vs Actual values')
    +legend('Actual values','Estimated values')
    WARNING: estimation will be performed on the equally-spaced grid with mesh size equal to T/(2*L), provided as an output variable.
    +
    Click here for the graphical output of this example (link to Ro.S.A. website).

    Input Arguments

    expand all

    x — Observed process values. Vector.

    Row or column vector containing + the observed values.

    Data Types: single| double

    t — Observation times. Vector.

    Row or column vector with the same + length of x containing the observation times.

    Data Types: single| double

    T — Estimation horizon. Scalar.

    Data Types: single| double

    Name-Value Pair Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: 'N',400 +, 'M',20 +, 'L',5 +, 'tau', 0:T/100:T +

    N —Cutting frequency.scalar.

    If N is not specified, it is set + equal to floor((length(x)-1)/2).

    +

    Example: 'N',400 +

    Data Types: single | double

    M —Cutting frequency.scalar.

    If M is not specified, it is set + equal to floor(floor((length(x)-1)/2)^0.4).

    +

    Example: 'M',20 +

    Data Types: single | double

    L —Cutting frequency.scalar.

    If L is not specified, it is set + equal to floor(floor(floor((length(x)-1)/2)^0.4)^0.5).

    +

    Example: 'L',5 +

    Data Types: single | double

    tau —Estimation times.vector.

    If tau is not specified, it is set + equal to 0:T/(2*L):T.

    +

    Example: 'tau', 0:T/100:T +

    Data Types: single | double

    Output Arguments

    expand all

    VV_spot —Spot volatility of volatility estimates. Vector

    Estimated values of the spot + volatility of volatility of the process.

    tau_out —Estimation times. Vector

    Coincides with the input vector tau unless the length + of the latter is larger than 2L+1.

    More About

    expand all

    Additional Details

    + We assume that the vectors x contains discrete observations from a diffusion + process $x$ following the Ito stochastic differential equation + $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ + $$d\sigma^2(t)= \gamma(t) \ dZ(t) + a(t) \ dt,$$ + where $W$ and $Z$ are two Brownian motions defined on the filtered probability space + $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, while + $\sigma, \gamma, b$ and $a$ are random processes, adapted to $\mathcal{F}_t$.

    + See the References for further mathematical details.

    + The spot volatility of volatility at time $t \in [0,T]$ is defined as + $$C(t):=\frac{d\langle \sigma^2,\sigma^2 \rangle_t}{dt}=\gamma^2(t).$$ + + +For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots + \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= + x(t_{l+1})-x(t_l)$ be the increments of $x$.

    + The Fourier estimator of the spot volatility of volatility at time $t \in [0,T]$ is + given by + $$\widehat C_{n,N,M,L}(\tau)= \sum_{|k|\leq L} \left(1-{|k|\over + L}\right)c_k(C_{n,N,M}) \, e^{{\rm i}\frac{2\pi}{T}k\tau},$$ + where: + $$c_k(C_{n,N,M})= {T \over {2M+1}} \sum_{|s|\leq M} c_s(d\sigma_{{n},N})c_{k-s}(d\sigma_{{n},N}),$$ + + $$c_k(d\sigma_{{n},N})={\rm i} \, k\, \frac{2\pi}{T} + c_k(\sigma_{{n},N}), \quad c_k(\sigma_{n,N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ + + $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ + +

    References

    Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer.

    Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv.

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/Heston1D.html b/toolbox/helpfiles/FSDA/Heston1D.html new file mode 100644 index 000000000..1e4226581 --- /dev/null +++ b/toolbox/helpfiles/FSDA/Heston1D.html @@ -0,0 +1,59 @@ + Heston1D

    Heston1D

    Heston1D simulates observations and instantaneous variances from the Heston model

    Syntax

    Description

    Heston1D simulates, using the Euler–Maruyama method, observations and instantaneous variances from the + model by [S. Heston, The Review of Financial Studies, Vol. 6, No. 2, 1993].

    example

    x =Heston1D(T, n, parameters, rho, x0, V0) Example of call of Heston1D for obtaining process observations only.

    example

    [x, V] =Heston1D(___) Example of call of Heston1D for obtaning process observations and volatility values.

    example

    [x, V, t] =Heston1D(___) Example of call of Heston1D for obtaning process observations, volatility values and sampling times.

    Examples

    expand all

  • Example of call of Heston1D for obtaining process observations only.
  • + Generates observations from the Heston model.

    T=1;  
    +n=23400;   
    +parameters=[0,0.4,2,1];
    +rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +x = Heston1D(T,n,parameters,rho,x0,V0);  
    +figure
    +plot(x)
    +ylabel('Observations')
    +title('Heston model')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of Heston1D for obtaning process observations and volatility values.
  • + Generates observations and volatilities from the Heston model.

    T=1; 
    +n=23400; 
    +parameters=[0,0.4,2,1];
    +rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V] = Heston1D(T,n,parameters,rho,x0,V0);  
    +figure
    +subplot(2,1,1)
    +plot(x)
    +ylabel('Observations')
    +title('Heston model')
    +subplot(2,1,2)
    +plot(V)
    +ylabel('Spot Variances')
    +title('Heston model')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of Heston1D for obtaning process observations, volatility values and sampling times.
  • + Generates observations, volatilities and sampling times from the Heston model.

    T=1; 
    +n=23400; 
    +parameters=[0,0.4,2,1];
    +rho=-0.5;
    +x0=log(100); 
    +V0=0.4;
    +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0);  
    +figure
    +subplot(2,1,1)
    +plot(t,x)
    +xlabel('Time')
    +ylabel('Observations')
    +title('Heston model')
    +subplot(2,1,2)
    +plot(t,V)
    +xlabel('Time')
    +ylabel('Spot Variances')
    +title('Heston model')
    Click here for the graphical output of this example (link to Ro.S.A. website).

    Input Arguments

    expand all

    T — Time horizon. Scalar.

    Data Types: single| double

    n — Number of simulated observation. Scalar.

    Data Types: single| double

    parameters — Model parameters. Vector.

    Vector of dimension 4.

    Data Types: single| double

    rho — Leverage parameter. Scalar.

    Data Types: single| double

    x0 — Initial observation value. Scalar.

    Data Types: single| double

    V0 — Initial variance value. Scalar.

    Data Types: single| double

    Output Arguments

    expand all

    x —Process observations. Vector

    Vector of dimension n+1.

    V —Spot variance values. Vector

    Vector of dimension n+1.

    t —Observation times. Vector

    Vector of dimension n+1.

    More About

    expand all

    Additional Details

    + The Heston model [S. Heston, The Review of Financial Studies, Vol. 6, No. 2, 1993] is given by the following stochastic + differential equations: + $$\left\{\begin{array}{l} + dx_t=\left( \mu-\frac{1}{2} \sigma^2_t \right) \, dt + \sigma_t \, dW_t \\ + d\sigma^2_t=\theta \, \left( \alpha-\sigma^2_t \right) \, dt + \gamma \, \sigma_t \, dZ_t + \end{array}\right. ,$$ + where $\mu$ is a real-valued constant, $\theta, \, \alpha$ and $\gamma$ are + positive constants, and $W$ and $Z$ are + Brownian motions with correlation $\rho$.

    + +

    References

    Heston, S. (1993), A closed-form solution for options with stochastic volatility + with applications to bond and currency options, The Review of Financial Studies, Vol. 6, No. 2.

    See Also

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/Heston2D.html b/toolbox/helpfiles/FSDA/Heston2D.html new file mode 100644 index 000000000..eac213e0b --- /dev/null +++ b/toolbox/helpfiles/FSDA/Heston2D.html @@ -0,0 +1,82 @@ + Heston2D

    Heston2D

    Heston2D simulates observations and instantaneous variances from the bivariate Heston model

    Syntax

    Description

    Heston2D simulates, using the Euler–Maruyama method, observations and instantaneous variances from + a 2-dimensional version of the model by [S. Heston, The Review of Financial Studies, Vol. 6, No. 2, 1993].

    example

    x =Heston2D(T, n, parameters, Rho, x0, V0) Example of call of Heston2D for obtaining process observations only.

    example

    [x, V] =Heston2D(___) Example of call of Heston2D for obtaining process observations and volatility values.

    example

    [x, V, t] =Heston2D(___) Example of call of Heston2D for obtaining process observations, volatility values and sampling times.

    Examples

    expand all

  • Example of call of Heston2D for obtaining process observations only.
  • + Generates observations from the bivariate Heston model.

    T=1;  
    +n=23400;   
    +parameters=[0,0;0.4,0.4;2,2;1,1];
    +Rho=[0.5;-0.5;0;0;-0.5;0.5];
    +x0=[log(100),log(100)]; 
    +V0=[0.4,0.4];
    +x = Heston2D(T,n,parameters,Rho,x0,V0);  
    +figure
    +subplot(2,1,1)
    +plot(x(:,1))
    +ylabel('Observed values of process 1')
    +title('Heston model')
    +subplot(2,1,2)
    +plot(x(:,2))
    +ylabel('Observed values of process 2')
    +title('Heston model')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of Heston2D for obtaining process observations and volatility values.
  • + Generates observations and volatilities from the bivariate Heston model.

    T=1; 
    +n=23400; 
    +parameters=[0,0;0.4,0.4;2,2;1,1];
    +Rho=[0.5,-0.5,0,0,-0.5,0.5];
    +x0=[log(100),log(100)]; V0=[0.4,0.4];
    +[x,V] = Heston2D(T,n,parameters,Rho,x0,V0); 
    +figure
    +subplot(2,1,1)
    +plot(x(:,1))
    +ylabel('Observed values of process 1')
    +title('Heston model')
    +subplot(2,1,2)
    +plot(x(:,2))
    +ylabel('Observed values of process 2')
    +title('Heston model')
    +figure
    +subplot(2,1,1)
    +plot(V(:,1))
    +ylabel('Spot variance of process 1')
    +title('Heston model')
    +subplot(2,1,2)
    +plot(V(:,2))
    +ylabel('Spot variance of process 2')
    +title('Heston model')
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • Example of call of Heston2D for obtaining process observations, volatility values and sampling times.
  • + Generates observations, volatilities and sampling times from the bivariate Heston model.

    T=1; 
    +n=23400; 
    +parameters=[0,0;0.4,0.4;2,2;1,1];
    +Rho=[0.5,-0.5,0,0,-0.5,0.5];
    +x0=[log(100),log(100)]; V0=[0.4,0.4];
    +[x,V,t] = Heston2D(T,n,parameters,Rho,x0,V0); 
    +figure
    +subplot(2,1,1)
    +plot(t,x(:,1))
    +xlabel('Time')
    +ylabel('Observed values of process 1')
    +title('Heston model')
    +subplot(2,1,2)
    +plot(t,x(:,2))
    +xlabel('Time')
    +ylabel('Observed values of process 2')
    +title('Heston model')
    +figure
    +subplot(2,1,1)
    +plot(t,V(:,1))
    +xlabel('Time')
    +ylabel('Spot variance of process 1')
    +title('Heston model')
    +subplot(2,1,2)
    +plot(t,V(:,2))
    +xlabel('Time')
    +ylabel('Spot variance of process 2')
    +title('Heston model')
    Click here for the graphical output of this example (link to Ro.S.A. website).

    Input Arguments

    expand all

    T — Time horizon. Scalar.

    Data Types: single| double

    n — Number of simulated observation. Scalar.

    Data Types: single| double

    parameters — Model parameters. Matrix.

    Matrix with 4 rows and 2 columns.

    Data Types: single| double

    Rho — Correlation vector. Vector.

    Vector of dimension 6.

    Data Types: single| double

    x0 — Initial process observation values. Vector.

    Vector of dimension 2.

    Data Types: single| double

    V0 — Initial variance values. Vector.

    Vector of dimension 2.

    Data Types: single| double

    Output Arguments

    expand all

    x —Process observations. Matrix

    Matrix with n+1 rows and 2 columns.

    V —Spot variance values. Matrix

    Matrix with n+1 rows and 2 columns.

    t —Observation times. Vector

    Vector of dimension n+1.

    More About

    expand all

    Additional Details

    + A bivariate version of the Heston model [S. Heston, The Review of Financial Studies, Vol. 6, No. 2, 1993] is given by the following stochastic + differential equations: + $$\left\{\begin{array}{l} + dx^i(t)=\left( \mu_{i}-\frac{1}{2} v^i(t) \right) \, dt + \sqrt{v^i(t)} \, dW^i_t \\ + dv^i(t)=\theta_{i} \, \left( \alpha_{i}- v^i(t) \right) \, dt + \gamma_{i} \, \sqrt{v^i(t)}\, dZ^i_t + \end{array}\right. ,\quad i=1,2,$$ + where, for each i, $v^i:=(\sigma^i)^2$, $\mu_i$ is a real-valued constant, $\theta_i, \, \alpha_i$ and $\gamma_i$ are + positive constants, and $W_i$ and $Z_i$ are Brownian motions that are + correlated with each other and with $W_j$ and $Z_j$, $j \neq i$.

    + +

    References

    Heston, S. (1993), A closed-form solution for options with stochastic volatility + with applications to bond and currency options, The Review of Financial Studies, Vol. 6, No. 2.

    See Also

    This page has been automatically generated by our routine publishFS
    \ No newline at end of file diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_cov_01.png b/toolbox/helpfiles/FSDA/images/FM_spot_cov_01.png new file mode 100644 index 000000000..aa4a2bb87 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_cov_01.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_cov_02.png b/toolbox/helpfiles/FSDA/images/FM_spot_cov_02.png new file mode 100644 index 000000000..2ea086027 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_cov_02.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_cov_03.png b/toolbox/helpfiles/FSDA/images/FM_spot_cov_03.png new file mode 100644 index 000000000..14428fc5e Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_cov_03.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_cov_04.png b/toolbox/helpfiles/FSDA/images/FM_spot_cov_04.png new file mode 100644 index 000000000..20eed8b63 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_cov_04.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_cov_05.png b/toolbox/helpfiles/FSDA/images/FM_spot_cov_05.png new file mode 100644 index 000000000..beec21f62 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_cov_05.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_cov_06.png b/toolbox/helpfiles/FSDA/images/FM_spot_cov_06.png new file mode 100644 index 000000000..2c1dd4abb Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_cov_06.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_lev_01.png b/toolbox/helpfiles/FSDA/images/FM_spot_lev_01.png new file mode 100644 index 000000000..a6e37a931 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_lev_01.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_lev_02.png b/toolbox/helpfiles/FSDA/images/FM_spot_lev_02.png new file mode 100644 index 000000000..21bfd2843 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_lev_02.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_lev_03.png b/toolbox/helpfiles/FSDA/images/FM_spot_lev_03.png new file mode 100644 index 000000000..1c49d66cc Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_lev_03.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_quart_01.png b/toolbox/helpfiles/FSDA/images/FM_spot_quart_01.png new file mode 100644 index 000000000..d85710021 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_quart_01.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_quart_02.png b/toolbox/helpfiles/FSDA/images/FM_spot_quart_02.png new file mode 100644 index 000000000..e91b86739 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_quart_02.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_quart_03.png b/toolbox/helpfiles/FSDA/images/FM_spot_quart_03.png new file mode 100644 index 000000000..b22c10319 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_quart_03.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_vol_01.png b/toolbox/helpfiles/FSDA/images/FM_spot_vol_01.png new file mode 100644 index 000000000..c50c67e18 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_vol_01.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_vol_02.png b/toolbox/helpfiles/FSDA/images/FM_spot_vol_02.png new file mode 100644 index 000000000..da88ac523 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_vol_02.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_vol_03.png b/toolbox/helpfiles/FSDA/images/FM_spot_vol_03.png new file mode 100644 index 000000000..091bab322 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_vol_03.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_volvol_01.png b/toolbox/helpfiles/FSDA/images/FM_spot_volvol_01.png new file mode 100644 index 000000000..16ad24ca0 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_volvol_01.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_volvol_02.png b/toolbox/helpfiles/FSDA/images/FM_spot_volvol_02.png new file mode 100644 index 000000000..c42db6445 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_volvol_02.png differ diff --git a/toolbox/helpfiles/FSDA/images/FM_spot_volvol_03.png b/toolbox/helpfiles/FSDA/images/FM_spot_volvol_03.png new file mode 100644 index 000000000..371934b78 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/FM_spot_volvol_03.png differ diff --git a/toolbox/helpfiles/FSDA/images/Heston1D_01.png b/toolbox/helpfiles/FSDA/images/Heston1D_01.png new file mode 100644 index 000000000..25f5f0c82 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/Heston1D_01.png differ diff --git a/toolbox/helpfiles/FSDA/images/Heston1D_02.png b/toolbox/helpfiles/FSDA/images/Heston1D_02.png new file mode 100644 index 000000000..6c3c6d3e1 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/Heston1D_02.png differ diff --git a/toolbox/helpfiles/FSDA/images/Heston1D_03.png b/toolbox/helpfiles/FSDA/images/Heston1D_03.png new file mode 100644 index 000000000..1dcb86f26 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/Heston1D_03.png differ diff --git a/toolbox/helpfiles/FSDA/images/Heston2D_01.png b/toolbox/helpfiles/FSDA/images/Heston2D_01.png new file mode 100644 index 000000000..528242430 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/Heston2D_01.png differ diff --git a/toolbox/helpfiles/FSDA/images/Heston2D_02.png b/toolbox/helpfiles/FSDA/images/Heston2D_02.png new file mode 100644 index 000000000..049e12c88 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/Heston2D_02.png differ diff --git a/toolbox/helpfiles/FSDA/images/Heston2D_03.png b/toolbox/helpfiles/FSDA/images/Heston2D_03.png new file mode 100644 index 000000000..47cf38dbf Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/Heston2D_03.png differ diff --git a/toolbox/helpfiles/FSDA/images/Heston2D_04.png b/toolbox/helpfiles/FSDA/images/Heston2D_04.png new file mode 100644 index 000000000..3493ef376 Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/Heston2D_04.png differ diff --git a/toolbox/helpfiles/FSDA/images/Heston2D_05.png b/toolbox/helpfiles/FSDA/images/Heston2D_05.png new file mode 100644 index 000000000..6492166fc Binary files /dev/null and b/toolbox/helpfiles/FSDA/images/Heston2D_05.png differ diff --git a/toolbox/utilities_stat/FM_int_cov.m b/toolbox/utilities_stat/FM_int_cov.m new file mode 100644 index 000000000..bf2611ed2 --- /dev/null +++ b/toolbox/utilities_stat/FM_int_cov.m @@ -0,0 +1,202 @@ +function C_int = FM_int_cov(x1,x2,t1,t2,T,varargin) +%FM_int_cov computes the integrated covariance of a bivariate diffusion process via the Fourier-Malliavin estimator +% +%Link to the help function +% +% Required input arguments: +% +% x1 : Observation values of process 1. Vector. Row or column vector containing +% the observed values. +% x2 : Observation values of process 2. Vector. Row or column vector containing +% the observed values. +% t1 : Observation times of process 1. Vector. Row or column vector containing +% the observation times. +% t2 : Observation times of process 2. Vector. Row or column vector containing +% the observation times. +% T : Estimation horizon. Scalar. +% +% Optional input arguments: +% +% N : Cutting frequency. Scalar. If N is not specified, it is set +% equal to floor((min(length(x1),length(x2))-1)/2). +% Example - 'N',400 +% Data Types - single | double +% +% Output: +% +% C_int : Integrated covariance of processes 1 and 2 on [0,T]. Scalar. Value of the integrated +% covariance of processes 1 and 2. +% +% +% More About: +% +% We assume that vectors x1 and x2 contain discrete observations from a bivariate diffusion +% process $(x_1,x_2)$ following the Ito stochastic differential equation +% $$dx_i(t)= \sigma_i(t) \ dW_i(t) + b_i(t) \ dt, \quad i=1,2,$$ +% where $W_1$ and $W_2$ are two Brownian motions defined on the filtered probability space +% $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, +% while $\sigma_1, \sigma_2, b_1$ and $b_2$ are random processes, adapted to $\mathcal{F}_t$. +% See the References for further mathematical details. +% The integrated covariance of the process $(x_1,x_2)$ on $[0,T]$ is defined as +% $$IC_{[0,T]}:=\rho \, \int_0^T \sigma_1(t) \sigma_2(t) \, dt$$ +% +% Let $i=1,2$. For any positive integer $n_i$, let $\mathcal{S}^i_{n_i}:=\{ 0=t^i_{0}\leq \cdots +% \leq t^i_{n_i}=T \}$ be the observation times for the $i$-th asset. Moreover, let $\delta_l(x^i):= +% x^i(t^i_{l+1})-x^i(t^i_l)$ be the increments of $x^i$. +% The Fourier estimator of the integrated covariance on $[0,T]$ is +% given by +% $$T c_0(c_{n_1,n_2,N})={T\over {2N+1}} \sum_{|k|\leq N} c_{k}(dx^1_{n_1})c_{-k}(dx^2_{n_2}),$$ +% +% $$c_k(dx^i_{n_i})= {1\over {T}} \sum_{l=0}^{n_i-1} e^{-{\rm i}\frac{2\pi}{T}kt^i_l}\delta_{l}(x_i).$$ +% +% See also: FE_int_vol.m, FE_int_vol_Fejer.m, FM_int_vol, FM_int_quart.m, FM_int_volvol.m, FM_int_lev.m, Heston2D.m +% +% References: +% +% Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer. +% +% Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv. +% +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Examples: + +%{ + %% Example of call of FM_int_cov with default value of N. + % The following example estimates the daily integrated covariance of a bivariate + % Heston model from a discrete sample. The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0;0.4,0.4;2,2;1,1]; +Rho=[0.5,-0.5,0,0,-0.5,0.5]; +x0=[log(100); log(100)]; +V0=[0.4; 0.4]; +[x,V,t]=Heston2D(T,n,parameters,Rho,x0,V0); + + +% Integrated covariance estimation +t1=t; +t2=t; +C_int=FM_int_cov(x(:,1),x(:,2),t1,t2,T); + +%} + +%{ + %% Example of call of FM_int_cov with custom choice of N. + % The following example estimates the integrated covariance of a bivariate + % Heston model from a discrete sample. The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; % horizon of the trajectory (in days) +n=23400; % number of observations simulated in one trajectory +parameters=[0 , 0; 0.4 , 0.4; 2 , 2; 1 , 1 ]; +Rho=[0.5 ; -0.5 ; 0 ; 0 ; -0.5 ; 0.5]; +x0=[log(100); log(100)]; V0=[0.4; 0.4]; +[x,V,t] = Heston2D(T,n,parameters,Rho,x0,V0); + + +% Integrated covariance estimation +t1=t; +t2=t; +C_int=FM_int_cov(x(:,1),x(:,2),t1,t2,T,'N',5000); + + +%} + +%% Beginning of code + +% Make sure that x1, x2, t1 and t2 are column vectors. + +x1=x1(:); +x2=x2(:); +t1=t1(:); +t2=t2(:); + +if length(x1) ~= length(t1) + error('FSDA:FM_int_cov:WrongInputOpt','Input arguments x1 and t1 must have the same length.'); +end + +if length(x2) ~= length(t2) + error('FSDA:FM_int_cov:WrongInputOpt','Input arguments x2 and t2 must have the same length.'); +end + +const=2*pi/T; + +r1=diff(x1); +r2=diff(x2); + +n1=length(r1); n2=length(r2); +N=floor((min(n1,n2)-1)/2); + +if nargin>2 + options=struct('N',N); + + UserOptions=varargin(1:2:length(varargin)); + if ~isempty(UserOptions) + + % Check if number of supplied options is valid + if length(varargin) ~= 2*length(UserOptions) + error('FSDA:FM_int_cov:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.'); + end + + % Check if all the specified optional arguments were present + % in structure options + inpchk=isfield(options,UserOptions); + WrongOptions=UserOptions(inpchk==0); + if ~isempty(WrongOptions) + disp(strcat('Non existent user option found->', char(WrongOptions{:}))) + error('FSDA:FM_int_cov:NonExistInputOpt','In total %d non-existent user options found.', length(WrongOptions)); + end + end + + % Write in structure 'options' the options chosen by the user + for i=1:2:length(varargin) + options.(varargin{i})=varargin{i+1}; + end + + N=options.N; +end + +if N >= min(n1,n2) + error('FSDA:FM_int_cov:WrongInputOpt','N must be strictly smaller than min(n1,n2).'); +end + +K=1:1:N; +tt1=-1i*const*t1(1:end-1)'; tt2=-1i*const*t2(1:end-1)'; + +c_r1a=zeros(N,1); +c_r2a=zeros(N,1); + +for j = 1:N + c_r1a(j)= exp(K(j)*tt1)*r1; + c_r2a(j)= exp(K(j)*tt2)*r2; +end + +c_r1=1/T* [ flip(conj(c_r1a)) ; sum(r1) ; c_r1a]; +c_r2=1/T* [ flip(conj(c_r2a)) ; sum(r2) ; c_r2a]; + +c_r1b=zeros(2*N+1,1); +c_r2b=zeros(2*N+1,1); + +for j = 1 : 2*N+1 +c_r1b(j)= (1 - abs(j-N-1 )/(N+1)) *c_r1 (j) ; +c_r2b(j)= (1 - abs(j-N-1 )/(N+1))*c_r2 (j) ; +end + +C_int = T^2/(N+1) * real(c_r2b.' * flip(c_r1)) ; + + +end + +%FScategory:FMvol \ No newline at end of file diff --git a/toolbox/utilities_stat/FM_int_lev.m b/toolbox/utilities_stat/FM_int_lev.m new file mode 100644 index 000000000..f94640b20 --- /dev/null +++ b/toolbox/utilities_stat/FM_int_lev.m @@ -0,0 +1,214 @@ +function L_int = FM_int_lev(x,t,T,varargin) +%FM_int_lev computes the integrated leverage of a diffusion process via the Fourier-Malliavin estimator +% +%Link to the help function +% +% Required input arguments: +% +% x : Observed process values. Vector. Row or column vector containing +% the observed values. +% t : Observation times. Vector. Row or column vector with the same +% length of x containing the observation times. +% T : Estimation horizon. Scalar. +% +% Optional input arguments: +% +% N : Cutting frequency. Scalar. If N is not specified, it is set +% equal to floor((length(x)-1)/2). +% Example - 'N',400 +% Data Types - single | double +% M : Cutting frequency. Scalar. If M is not specified, it is set +% equal to floor(floor((length(x)-1)/2)^0.5). +% Example - 'M',20 +% Data Types - single | double +% Data Types - single | double +% +% Output: +% +% L_int : Integrated leverage. Scalar. Value of the integrated +% leverage. +% +% +% More About: +% +% We assume that the vectors x contains discrete observations from a diffusion +% process $x$ following the Ito stochastic differential equation +% $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ +% $$d\sigma^2(t)= \gamma(t) \ dZ(t) + a(t) \ dt,$$ +% where $W$ and $Z$ are two Brownian motions defined on the filtered probability space +% $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, while +% $\sigma, \gamma, b$ and $a$ are random processes, adapted to $\mathcal{F}_t$. +% See the References for further mathematical details. +% The integrated leverage on $[0,T]$ is defined as +% $$IL_{[0,T]}:= \langle x,\sigma^2 \rangle_T =\rho\int_0^T\sigma(s)\gamma(s)ds.$$ +% +% +%For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots +% \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= +% x(t_{l+1})-x(t_l)$ be the increments of $x$. +% The Fourier estimator of the integrated leverage on $[0,T]$ is +% given by +% $$T c_0(B_{{n},N})={T^2\over {2M+1}} \sum_{|k|\leq M} c_{k}(d\sigma_{n,N})c_{-k}(dx_{n}),$$ +% +% where: +% $$c_k(d\sigma_{n,N})= i k \frac{2\pi}{T} c_k(\sigma_{n,N}), \quad c_k(\sigma_{{n},N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ +% $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ +% +% See also: FM_int_vol.m, FM_int_cov.m, FM_int_quart.m, FM_int_volvol.m, Heston1D.m +% +% References: +% +% Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer. +% +% Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv. +% +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Example: + +%{ + %% Example of call of FM_int_lev with default values of N and M. + % The following example estimates the integrated leverage + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0; 0.5; 7; 2]; +rho=-0.9; +x0=log(100); +V0=0.5; +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0); + + +% Integrated leverage estimation +L_int = FM_int_lev(x,t,T); + +%} + +%{ + %% Example of call of FM_int_lev with custom choices of N and M. + % The following example estimates the integrated leverage + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0; 0.5; 7; 2]; +rho=-0.9; +x0=log(100); +V0=0.5; +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0); + + +% Integrated leverage estimation +L_int= FM_int_lev(x,t,T,'N',10000,'M',70); + +%} + +%% Beginning of code + +% Make sure that x and t are column vectors. + +x=x(:); +t=t(:); + +if length(x) ~= length(t) + error('FSDA:FM_int_lev:WrongInputOpt','Input arguments x and t must have the same length.'); +end + + +const=2*pi/T; + +r=diff(x); + + +n=length(r); +N=floor(n/2); +M=floor(N^0.5); + +if nargin>2 + options=struct('N',N,'M',M); + + UserOptions=varargin(1:2:length(varargin)); + if ~isempty(UserOptions) + + % Check if number of supplied options is valid + if length(varargin) ~= 2*length(UserOptions) + error('FSDA:FM_int_lev:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.'); + end + + % Check if all the specified optional arguments were present + % in structure options + inpchk=isfield(options,UserOptions); + WrongOptions=UserOptions(inpchk==0); + if ~isempty(WrongOptions) + disp(strcat('Non existent user option found->', char(WrongOptions{:}))) + error('FSDA:FM_int_lev:NonExistInputOpt','In total %d non-existent user options found.', length(WrongOptions)); + end + end + + + % Write in structure 'options' the options chosen by the user + for i=1:2:length(varargin) + options.(varargin{i})=varargin{i+1}; + end + + N=options.N; + M=options.M; +end + +if N >= n + error('FSDA:FM_int_lev:WrongInputOpt','N must be strictly smaller than min(n1,n2).'); +end + +if M >= N + error('FSDA:FM_int_lev:WrongInputOpt','M must be strictly smaller than N.'); +end + + + +k=1:1:N+M; +tt=-1i*const*t(1:end-1)'; + + +c_ra=zeros(length(k),1); + +for j = 1:length(k) + c_ra(j)= exp(k(j)*tt)*r; + end + +c_r1=1/T* [ flip(conj(c_ra)) ; sum(r) ; c_ra]; % Fourier coefficients of dx1 + + +c_v=zeros(2*M+1,1); +c_r_aux1=zeros(2*M+1,2*N+1); +c_dv=zeros(2*M+1,1); + +center=N+M+1; + +for j = 1 : 2*M+1 + c_r_aux1(j,1:2*N+1)= c_r1 ( center -N +( j-M-1 ) : center +N +( j-M-1 ) ) ; + c_v(j)= T/(2*N+1) * c_r1 ( center -N : center +N ).' * flip(c_r_aux1(j, : )).'; + c_dv(j)=const*1i*(j-M-1 ) *(1-abs(j-M-1)/(M+1))*c_v(j); +end + + + + +L_int= T^2/(M+1)* real( c_dv.'*flip(c_r1(center-M: center+M))); + +end + +%FScategory:FMvol \ No newline at end of file diff --git a/toolbox/utilities_stat/FM_int_quart.m b/toolbox/utilities_stat/FM_int_quart.m new file mode 100644 index 000000000..abc0be051 --- /dev/null +++ b/toolbox/utilities_stat/FM_int_quart.m @@ -0,0 +1,208 @@ +function Q_int = FM_int_quart(x,t,T,varargin) +%FM_int_quart computes the integrated quarticity of a diffusion process via the Fourier-Malliavin estimator +% +%Link to the help function +% +% Required input arguments: +% +% x : Observed process values. Vector. Row or column vector containing +% the observed values. +% t : Observation times. Vector. Row or column vector with the same +% length of x containing the observation times. +% T : Estimation horizon. Scalar. +% +% Optional input arguments: +% +% N : Cutting frequency. Scalar. If N is not specified, it is set +% equal to floor((length(x)-1)/2). +% Example - 'N',400 +% Data Types - single | double +% M : Cutting frequency. Scalar. If M is not specified, it is set +% equal to floor(floor((length(x)-1)/2)^0.5). +% Example - 'M',20 +% Data Types - single | double +% Data Types - single | double +% +% Output: +% +% Q_int : Integrated quarticity. Scalar. Value of the integrated +% quarticity. +% +% +% +% More About: +% +% We assume that the vectors x contains discrete observations from a diffusion +% process $x$ following the Ito stochastic differential equation +% $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ +% where $W$ is a Brownian motions defined on the filtered probability space +% $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, while $\sigma$ and $b$ are random processes, adapted to $\mathcal{F}_t$. +% See the References for further mathematical details. +% The integrated quarticity on $[0,T]$ is defined as +% $$IQ_{[0,T]}:=\int_0^T\sigma^4(s)ds.$$ +% +% +%For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots +% \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= +% x(t_{l+1})-x(t_l)$ be the increments of $x$. +% The Fourier estimator of the integrated quarticity on $[0,T]$ is +% given by +% $$T c_0(Q_{{n},N.M})={T^2\over {2M+1}} \sum_{|k|\leq M} c_{k}(\sigma_{n,N})c_{-k}(\sigma_{n,N}),$$ +% +% where: +% $$c_k(\sigma_{{n},N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ +% $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ +% +% See also: FM_int_vol.m, FM_int_cov.m, FM_int_volvol.m, FM_int_lev.m, Heston1D.m +% +% References: +% +% Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer. +% +% Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv. +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Example: + +%{ + %% Example of call of FM_int_quart default values of N and M. + % The following example estimates the integrated quarticity + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.4,5,1]; +rho=-0.5; +x0=log(100); +V0=0.4; +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0); + + +% Integrated quarticity estimation +Q_int = FM_int_quart(x,t,T); + + + +%} +%{ + %% Example of call of FM_int_quart with custom choices of N and M. + % The following example estimates the integrated quarticity + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.4,5,1]; +rho=-0.5; +x0=log(100); +V0=0.4; +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0); + +% Integrated quarticity estimation +Q_int= FM_int_quart(x,t,T,'N',10000,'M',120); + +%} + +%% Beginning of code + +% Make sure that x and t are column vectors. + +x=x(:); +t=t(:); + +if length(x) ~= length(t) + error('FSDA:FM_int_quart:WrongInputOpt','Input arguments x and t must have the same length.'); +end + + +const=2*pi/T; + +r=diff(x); + + +n=length(r); +N=floor(n/2); +M=floor(N^0.5); + +if nargin>2 + options=struct('N',N,'M',M); + + UserOptions=varargin(1:2:length(varargin)); + if ~isempty(UserOptions) + + % Check if number of supplied options is valid + if length(varargin) ~= 2*length(UserOptions) + error('FSDA:FM_int_quart:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.'); + end + + % Check if all the specified optional arguments were present + % in structure options + inpchk=isfield(options,UserOptions); + WrongOptions=UserOptions(inpchk==0); + if ~isempty(WrongOptions) + disp(strcat('Non existent user option found->', char(WrongOptions{:}))) + error('FSDA:FM_int_quart:NonExistInputOpt','In total %d non-existent user options found.', length(WrongOptions)); + end + end + + + % Write in structure 'options' the options chosen by the user + for i=1:2:length(varargin) + options.(varargin{i})=varargin{i+1}; + end + + N=options.N; + M=options.M; +end + +if N >= n + error('FSDA:FM_int_quart:WrongInputOpt','N must be strictly smaller than min(n1,n2).'); +end + +if M >= N + error('FSDA:FM_int_quart:WrongInputOpt','M must be strictly smaller than N.'); +end + + + +k=1:1:N+M; +tt=-1i*const*t(1:end-1)'; + + +c_ra=zeros(length(k),1); + +for j = 1:length(k) + c_ra(j)= exp(k(j)*tt)*r; + end + +c_r1=1/T* [ flip(conj(c_ra)) ; sum(r) ; c_ra]; % Fourier coefficients of dx1 + + +c_v=zeros(2*M+1,1); +c_r_aux1=zeros(2*M+1,2*N+1); + +center=N+M+1; +for j = 1 : 2*M+1 + c_r_aux1(j,1:2*N+1)= c_r1 ( center -N +( j-M-1 ) : center +N +( j-M-1 ) ) ; + c_v(j)= T/(2*N+1) * c_r1 ( center -N : center +N ).' * flip(c_r_aux1(j, : )).'; +end + + + +Q_int= T * real( c_v.'*flip(c_v)); + +end + +%FScategory:FMvol \ No newline at end of file diff --git a/toolbox/utilities_stat/FM_int_vol.m b/toolbox/utilities_stat/FM_int_vol.m new file mode 100644 index 000000000..2094e2ae7 --- /dev/null +++ b/toolbox/utilities_stat/FM_int_vol.m @@ -0,0 +1,186 @@ +function V_int = FM_int_vol(x,t,T,varargin) +%FM_int_vol computes the integrated variance of a diffusion process via the Fourier-Malliavin estimator +% +%Link to the help function +% +% Required input arguments: +% +% x : Observed process values. Vector. Row or column vector containing +% the observed values. +% t : Observation times. Vector. Row or column vector with the same +% length of x containing the observation times. +% T : Estimation horizon. Scalar. +% +% Optional input arguments: +% +% N : Cutting frequency. Scalar. If N is not specified, it is set +% equal to floor(length(x)-/2). +% Example - 'N',400 +% Data Types - single | double +% +% Output: +% +% V_int : Integrated variance. Scalar. Values of the integrated +% variance. +% +% +% More About: +% +% We assume that the vector x contains discrete observations from a diffusion +% process following the Ito stochastic differential equation +% $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ +% where $W$ is a Brownian motions defined on the filtered probability space +% $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, while $\sigma$ and $b$ are random processes, adapted to $\mathcal{F}_t$. +% See the References for further mathematical details. +% The integrated variance of the process $x$ on $[0,T]$ is defined as +% $$IV_{[0,T]}:=\int_0^T \sigma^2(t)\, dt.$$ +% +% For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots +% \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= +% x(t_{l+1})-x(t_l)$ be the increments of $x$. +% The Fourier estimator of the integrated volatility on $[0,T]$ is +% given by +% +% $$T c_0(\sigma_{{n},N})={T^2\over {2N+1}} \sum_{|k|\leq N} c_{k}(dx_{n})c_{-k}(dx_{n}),$$ +% +% where +% $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ +% +% See also: FE_int_vol.m, FE_int_vol_Fejer.m, OptimalCuttingFrequency.m, FM_int_cov.m, FM_int_quart.m, FM_int_volvol.m, FM_int_lev.m, Heston1D.m +% +% References: +% +% Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer. +% +% Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv. +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Examples: + +%{ +%% Example of call of FM_int_vol with default value of N. +% The following example estimates the integrated volatility of a +% Heston model from a discrete sample. The Heston model assumes that the spot variance follows +% a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.4,2,1]; +Rho=-0.5; +x0=log(100); +V0=0.4; +[x,V,t]=Heston1D(T,n,parameters,Rho,x0,V0); + + +% Integrated volatility estimation +V_int=FM_int_vol(x,t,T); + +%} + +%{ +%% Example of call of FM_int_vol with custom choice of N. +% The following example estimates the integrated volatility of a +% Heston model from a discrete sample. The Heston model assumes that the spot variance follows +% a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.4,2,1]; +Rho=-0.5; +x0=log(100); +V0=0.4; +[x,V,t]=Heston1D(T,n,parameters,Rho,x0,V0); + + +% Integrated volatility estimation +V_int= FM_int_vol(x,t,T,'N',5000); + + +%} + + + + + +%% Beginning of code + +% Make sure that x1, x2, t1 and t2 are column vectors. + +x=x(:); +t=t(:); + +if length(x) ~= length(t) + error('FSDA:FM_int_vol:WrongInputOpt','Input arguments x and t must have the same length.'); +end + + +const=2*pi/T; + +r=diff(x); + + +n=length(r); +N=floor(n/2); + + +if nargin>2 + options=struct('N',N); + + UserOptions=varargin(1:2:length(varargin)); + if ~isempty(UserOptions) + + % Check if number of supplied options is valid + if length(varargin) ~= 2*length(UserOptions) + error('FSDA:FM_int_vol:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.'); + end + + % Check if all the specified optional arguments were present + % in structure options + inpchk=isfield(options,UserOptions); + WrongOptions=UserOptions(inpchk==0); + if ~isempty(WrongOptions) + disp(strcat('Non existent user option found->', char(WrongOptions{:}))) + error('FSDA:FM_int_vol:NonExistInputOpt','In total %d non-existent user options found.', length(WrongOptions)); + end + end + + + % Write in structure 'options' the options chosen by the user + for i=1:2:length(varargin) + options.(varargin{i})=varargin{i+1}; + end + + N=options.N; +end + +if N >= n + error('FSDA:FM_int_vol:WrongInputOpt','N must be strictly smaller than n.'); +end + +K=1:1:N; +tt=-1i*const*t(1:end-1)'; + +c_ra=zeros(N,1); + + +for j = 1:N + c_ra(j)= exp(K(j)*tt)*r; + +end + +c_r=1/T* [ flip(conj(c_ra)) ; sum(r) ; c_ra]; % Fourier coefficients of dx + +V_int = T^2/(2*N+1) * real(c_r.' * flip(c_r)) ; + +end + +%FScategory:FMvol \ No newline at end of file diff --git a/toolbox/utilities_stat/FM_int_volvol.m b/toolbox/utilities_stat/FM_int_volvol.m new file mode 100644 index 000000000..5c85797ff --- /dev/null +++ b/toolbox/utilities_stat/FM_int_volvol.m @@ -0,0 +1,215 @@ +function VV_int = FM_int_volvol(x,t,T,varargin) +%FM_int_volvol computes the integrated volatility of volatility of a diffusion process via the Fourier-Malliavin estimator +% +%Link to the help function +% +% Required input arguments: +% +% x : Observed process values. Vector. Row or column vector containing +% the observed values. +% t : Observation times. Vector. Row or column vector with the same +% length of x containing the observation times. +% T : Estimation horizon. Scalar. +% +% Optional input arguments: +% +% N : Cutting frequency. Scalar. If N is not specified, it is set +% equal to floor((length(x)-1)/2). +% Example - 'N',400 +% Data Types - single | double +% M : Cutting frequency. Scalar. If M is not specified, it is set +% equal to floor(floor((length(x)-1)/2)^0.4). +% Example - 'M',20 +% Data Types - single | double +% Data Types - single | double +% +% Output: +% +% VV_int : Integrated volatility of volatility. Scalar. Value of the integrated volatility of volatility. +% +% +% More About: +% +% We assume that the vectors x contains discrete observations from a diffusion +% process $x$ following the Ito stochastic differential equation +% $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ +% $$d\sigma^2(t)= \gamma(t) \ dZ(t) + a(t) \ dt,$$ +% where $W$ and $Z$ are two Brownian motions defined on the filtered probability space +% $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, while +% $\sigma, \gamma, b$ and $a$ are random processes, adapted to $\mathcal{F}_t$. +% See the References for further mathematical details. +% The integrated volatility of volatility on $[0,T]$ is defined as +% $$ IVV_{[0,T]}:= \langle \sigma^2 ,\sigma^2 \rangle_T =\int_0^T\gamma^2(s)ds.$$ +% +% +%For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots +% \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= +% x(t_{l+1})-x(t_l)$ be the increments of $x$. +% The Fourier estimator of the integrated volatility of volatility on $[0,T]$ is +% given by +% $$T c_0(V_{{n},N,M})={T^2\over {2M+1}} \sum_{|k|\leq M} c_{k}(d\sigma_{n,N})c_{-k}(d\sigma_{n,N}),$$ +% +% where: +% $$c_k(d\sigma_{n,N})= i k \frac{2\pi}{T} c_k(\sigma_{n,N}), \quad c_k(\sigma_{{n},N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ +% $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ +% +% See also: FM_int_vol.m, FM_int_cov.m, FM_int_quart.m, FM_int_lev.m, Heston1D.m +% +% References: +% +% Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer. +% +% Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv. +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Example: + +%{ + %% Example of call of FM_int_volvol with default values of N and M. + % The following example estimates the integrated volatility of volatility + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.8,10,3.25]; +rho=-0.3; +x0=log(100); +V0=0.8; +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0); + + +% Integrated volatility of volatility estimation +VV_int = FM_int_volvol(x,t,T); + +%} + +%{ + %% Example of call of FM_int_volvol with custom choices of N and M. + % The following example estimates the integrated volatility of volatility + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; % number of observations simulated in one trajectory +parameters=[0,0.8,10,3.25]; +rho=-0.3; +x0=log(100); +V0=0.8; +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0); + + +% Integrated volatility of volatility estimation +VV_int = FM_int_volvol(x,t,T,'N',11200, 'M', 50); + + + + +%} + + +%% Beginning of code + +% Make sure that x and t are column vectors. + +x=x(:); +t=t(:); + +if length(x) ~= length(t) + error('FSDA:FM_int_volvol:WrongInputOpt','Input arguments x and t must have the same length.'); +end + + +const=2*pi/T; + +r=diff(x); + + +n=length(r); +N=floor(n/2); +M=floor(N^0.4); + +if nargin>2 + options=struct('N',N,'M',M); + + UserOptions=varargin(1:2:length(varargin)); + if ~isempty(UserOptions) + + % Check if number of supplied options is valid + if length(varargin) ~= 2*length(UserOptions) + error('FSDA:FM_int_volvol:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.'); + end + + % Check if all the specified optional arguments were present + % in structure options + inpchk=isfield(options,UserOptions); + WrongOptions=UserOptions(inpchk==0); + if ~isempty(WrongOptions) + disp(strcat('Non existent user option found->', char(WrongOptions{:}))) + error('FSDA:FM_int_volvol:NonExistInputOpt','In total %d non-existent user options found.', length(WrongOptions)); + end + end + + + % Write in structure 'options' the options chosen by the user + for i=1:2:length(varargin) + options.(varargin{i})=varargin{i+1}; + end + + N=options.N; + M=options.M; +end + +if N >= n + error('FSDA:FM_int_volvol:WrongInputOpt','N must be strictly smaller than min(n1,n2).'); +end + +if M >= N + error('FSDA:FM_int_volvol:WrongInputOpt','M must be strictly smaller than N.'); +end + + + +k=1:1:N+M; +tt=-1i*const*t(1:end-1)'; + + +c_ra=zeros(length(k),1); + +for j = 1:length(k) + c_ra(j)= exp(k(j)*tt)*r; + end + +c_r1=1/T* [ flip(conj(c_ra)) ; sum(r) ; c_ra]; % Fourier coefficients of dx1 + + +c_v=zeros(2*M+1,1); +c_r_aux1=zeros(2*M+1,2*N+1); +c_dv=zeros(2*M+1,1); +c_dv2=zeros(2*M+1,1); + +center=N+M+1; + +for j = 1 : 2*M+1 + c_r_aux1(j,1:2*N+1)= c_r1 ( center -N +( j-M-1 ) : center +N +( j-M-1 ) ) ; + c_v(j)= T/(2*N+1) * c_r1 ( center -N : center +N ).' * flip(c_r_aux1(j, : )).'; + c_dv(j)=const*1i*(j-M-1) *(1-abs(j-M-1)/(M+1))*c_v(j); + c_dv2(j)=const*1i*(j-M-1) *c_v(j); +end + +VV_int= T^2/(M+1)* real( c_dv.'*flip(c_dv2)) ; + +end + +%FScategory:FMvol \ No newline at end of file diff --git a/toolbox/utilities_stat/FM_spot_cov.m b/toolbox/utilities_stat/FM_spot_cov.m new file mode 100644 index 000000000..ed905d6e5 --- /dev/null +++ b/toolbox/utilities_stat/FM_spot_cov.m @@ -0,0 +1,300 @@ +function [C_spot, tau_out] = FM_spot_cov(x1,x2,t1,t2,T,varargin) +%FM_spot_cov computes the spot covariance of a bivariate diffusion process via the Fourier-Malliavin estimator +% +%Link to the help function +% +% Required input arguments: +% +% x1 : Observation values of process 1. Vector. Row or column vector containing +% the observed values. +% x2 : Observation values of process 2. Vector. Row or column vector containing +% the observed values. +% t1 : Observation times of process 1. Vector. Row or column vector with the same +% length of x1 containing the observation times. +% t2 : Observation times of process 2. Vector. Row or column vector with the same +% length of x2 containing the observation times. +% T : Estimation horizon. Scalar. +% +% Optional input arguments: +% +% N : Cutting frequency. Scalar. If N is not specified, it is set +% equal to floor(min(length(x1),length(x2))-1)/2). +% Example - 'N',400 +% Data Types - single | double +% M : Cutting frequency. Scalar. If M is not specified, it is set +% equal to floor(floor(min(length(x1),length(x2))-1)/2)^0.5). +% Example - 'M',20 +% Data Types - single | double +% tau : Estimation times. Vector. If tau is not specified, it is set +% equal to 0:T/(2*M):T. +% Example - 'tau', 0:T/100:T +% Data Types - single | double +% +% Output: +% +% C_spot : Spot covariance of processes 1 and 2. Vector. Values of the +% spot covariance of processes 1 and 2. +% +% tau_out : Estimation times. Vector. Coincides with the input vector tau unless the length +% of the latter is larger than 2M+1. +% +% +% More About: +% +% We assume that vectors x1 and x2 contain discrete observations from a bivariate diffusion +% process $(x_1,x_2)$ following the Ito stochastic differential equation +% $$dx^i(t)= \sigma^i(t) \ dW^i(t) + b^i(t) \ dt, \quad i=1,2,$$ +% where $W^1$ and $W^2$ are two Brownian motions defined on the filtered probability space +% $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, while +% $\sigma^1, \sigma^2, b^1$ and $b^2$ are random processes, adapted to $\mathcal{F}_t$. +% See the References for further mathematical details. +% The spot covariance $c$ between the processes $x^1$ and $x^2$ at time $t +% \in [0,T]$ is defined as +% $$c(t):= \frac{d \langle x^1, x^2 \rangle_t}{dt} = \rho \sigma^1(t) \sigma^2(t).$$ +% +% Let $i=1,2$. For any positive integer $n_i$, let $\mathcal{S}^i_{n_i}:=\{ 0=t^i_{0}\leq \cdots +% \leq t^i_{n_i}=T \}$ be the observation times for the $i$-th asset. Moreover, let $\delta_l(x^i):= +% x^i(t^i_{l+1})-x^i(t^i_l)$ be the increments of $x^i$. +% The Fourier estimator of the spot covariance at time $t \in [0,T]$ is +% given by +% $$\widehat c_{n_1,n_2,N,M}(\tau)= \sum_{|k|\leq M} \left(1-{|k|\over +% M}\right)c_k(c_{n_1,n_2,N}) \, e^{{\rm i}\frac{2\pi}{T}k\tau},$$ +% where: +% $$c_k(c_{n_1,n_2,N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx^1_{n_1})c_{k-s}(dx^2_{n_2}),$$ +% +% $$c_k(dx^i_{n_i})= {1\over {T}} \sum_{l=0}^{n_i-1} e^{-{\rm i}\frac{2\pi}{T}kt^i_l}\delta_{l}(x_i).$$ +% +% See also: FE_spot_vol.m, FE_spot_vol_FFT.m, FM_spot_vol.m, FM_spot_quart.m, FM_spot_volvol.m, FM_spot_lev.m, Heston2D.m +% +% References: +% +% Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer. +% +% Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv. +% +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Examples: + +%{ + %% Example of call of FM_spot_cov with default values of N, M and tau. + % The following example estimates the path of the spot covariance of a bivariate + % Heston model from a discrete sample. The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0;0.4,0.4;2,2;1,1]; +Rho=[0.5,-0.5,0,0,-0.5,0.5]; +x0=[log(100); log(100)]; +V0=[0.4; 0.4]; +[x,V,t]=Heston2D(T,n,parameters,Rho,x0,V0); + + +% Spot covariance estimation +t1=t; +t2=t; +[C_spot, tau_out]=FM_spot_cov(x(:,1),x(:,2),t1,t2,T); +M=(length(C_spot)-1)/2; + +figure +Cov=Rho(6)*sqrt(V(:,1)).*sqrt(V(:,2)); +plot(tau_out,Cov(1:round(n/(2*M)):end)); +hold on +plot(tau_out,C_spot); +xlabel('tau'); +title('Spot co-volatility estimates Vs Actual values') +legend('Actual values','Estimated values') + + +%} + +%{ + %% Example of call of FM_spot_cov with custom choices of N, M and tau. + % The following example estimates the path of the spot covariance of a bivariate + % Heston model from a discrete sample. The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0 , 0; 0.4 , 0.4; 2 , 2; 1 , 1 ]; +Rho=[0.5 ; -0.5 ; 0 ; 0 ; -0.5 ; 0.5]; +x0=[log(100); log(100)]; V0=[0.4; 0.4]; +[x,V,t] = Heston2D(T,n,parameters,Rho,x0,V0); + + + +% Estimation of the spot covariance +t1=t; +t2=t; +tau=0:T/50:T; +[C_spot,tau_out]=FM_spot_cov(x(:,1),x(:,2),t1,t2,T,'N',5000,'M',100,'tau',tau); + +figure +Cov=Rho(6)*sqrt(V(:,1)).*sqrt(V(:,2)); +plot(tau_out,Cov(1:round(n/50):end)); +hold on +plot(tau_out,C_spot); +xlabel('tau'); +title('Spot co-volatility estimates Vs Actual values') +legend('Actual values','Estimated values') + + + +%} + +%{ + %% Example of call of FM_spot_cov when tau has length larger than 2M + 1. + % The following example estimates the path of the spot covariance of a bivariate + % Heston model from a discrete sample. The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0 , 0; 0.4 , 0.4; 2 , 2; 1 , 1 ]; +Rho=[0.5 ; -0.5 ; 0 ; 0 ; -0.5 ; 0.5]; +x0=[log(100); log(100)]; V0=[0.4; 0.4]; +[x,V,t] = Heston2D(T,n,parameters,Rho,x0,V0); + + + +% Estimation of the spot covariance +t1=t; +t2=t; +tau=0:T/1000:T; +[C_spot,tau_out]=FM_spot_cov(x(:,1),x(:,2),t1,t2,T,'N',5000,'M',100,'tau',tau); + +figure +Cov=Rho(6)*sqrt(V(:,1)).*sqrt(V(:,2)); +M=100; +plot(tau_out,Cov(1:round(n/(2*M)):end)); +hold on +plot(tau_out,C_spot); +xlabel('tau'); +title('Spot co-volatility estimates Vs Actual values') +legend('Actual values','Estimated values') + + + +%} + +%% Beginning of code + +% Make sure that x1, x2, t1 and t2 are column vectors. + +x1=x1(:); +x2=x2(:); +t1=t1(:); +t2=t2(:); + +if length(x1) ~= length(t1) + error('FSDA:FM_spot_cov:WrongInputOpt','Input arguments x1 and t1 must have the same length.'); +end + +if length(x2) ~= length(t2) + error('FSDA:FM_spot_cov:WrongInputOpt','Input arguments x2 and t2 must have the same length.'); +end + +const=2*pi/T; + +r1=diff(x1); +r2=diff(x2); + +n1=length(r1); n2=length(r2); +N=floor(min(n1,n2)/2); +M=floor(N^0.5); +tau=0:T/(2*M):T; + +if nargin>2 + options=struct('N',N,'M',M,'tau',tau); + + UserOptions=varargin(1:2:length(varargin)); + if ~isempty(UserOptions) + + % Check if number of supplied options is valid + if length(varargin) ~= 2*length(UserOptions) + error('FSDA:FM_spot_cov:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.'); + end + + % Check if all the specified optional arguments were present + % in structure options + inpchk=isfield(options,UserOptions); + WrongOptions=UserOptions(inpchk==0); + if ~isempty(WrongOptions) + disp(strcat('Non existent user option found->', char(WrongOptions{:}))) + error('FSDA:FM_spot_cov:NonExistInputOpt','In total %d non-existent user options found.', length(WrongOptions)); + end + end + + + % Write in structure 'options' the options chosen by the user + for i=1:2:length(varargin) + options.(varargin{i})=varargin{i+1}; + end + + N=options.N; + M=options.M; + tau=options.tau; +end + +if N >= min(n1,n2) + error('FSDA:FM_spot_cov:WrongInputOpt','N must be strictly smaller than min(n1,n2).'); +end + +if M >= N + error('FSDA:FM_spot_cov:WrongInputOpt','M must be strictly smaller than N.'); +end + + +if length(tau) > 2*M+1 + disp('WARNING: estimation will be performed on the equally-spaced grid with mesh size equal to T/(2*M), provided as an output variable.') + tau_out=0:T/(2*M):T; +else + tau_out=tau; +end + +k=1:1:N+M; +tt1=-1i*const*t1(1:end-1)'; tt2=-1i*const*t2(1:end-1)'; + +c_r1a=zeros(length(k),1); +c_r2a=zeros(length(k),1); + +for j = 1:length(k) + c_r1a(j)= exp(k(j)*tt1)*r1; + c_r2a(j)= exp(k(j)*tt2)*r2; +end + +c_r1=1/T* [ flip(conj(c_r1a)) ; sum(r1) ; c_r1a]; +c_r2=1/T* [ flip(conj(c_r2a)) ; sum(r2) ; c_r2a]; + + +c_c=zeros(2*M+1,1); +c_r_aux1=zeros(2*M+1,2*N+1); +c_c_spot=zeros(2*M+1,length(tau_out)); + + +center=N+M+1; + +for j = 1 : 2*M+1 + c_r_aux1(j,1:2*N+1)= c_r1 ( center -N +( j-M-1 ) : center +N +( j-M-1 ) ) ; + c_c(j)= T/(2*N+1) * c_r2 ( center -N : center +N ).' * flip(c_r_aux1(j, : )).'; + for ii=1 : length(tau_out) + c_c_spot(j,ii)=c_c(j)*(1-abs(j-M-1)/(M+1))*exp(const*tau_out(ii)*(j-M-1)*1i); + end +end + +C_spot=real(sum(c_c_spot)); + +end + +%FScategory:FMvol \ No newline at end of file diff --git a/toolbox/utilities_stat/FM_spot_lev.m b/toolbox/utilities_stat/FM_spot_lev.m new file mode 100644 index 000000000..69500f4ec --- /dev/null +++ b/toolbox/utilities_stat/FM_spot_lev.m @@ -0,0 +1,307 @@ +function [L_spot, tau_out] = FM_spot_lev(x,t,T,varargin) +%FM_spot_lev computes the spot leverage of a diffusion process via the Fourier-Malliavin estimator +% +%Link to the help function +% +% Required input arguments: +% +% x : Observed process values. Vector. Row or column vector containing +% the observed values. +% t : Observation times. Vector. Row or column vector with the same +% length of x containing the observation times. +% T : Estimation horizon. Scalar. +% +% Optional input arguments: +% +% N : Cutting frequency. Scalar. If N is not specified, it is set +% equal to floor((length(x)-1)/2). +% Example - 'N',400 +% Data Types - single | double +% M : Cutting frequency. Scalar. If M is not specified, it is set +% equal to floor(floor((length(x)-1)/2)^0.5). +% Example - 'M',20 +% Data Types - single | double +% L : Cutting frequency. Scalar. If L is not specified, it is set +% equal to floor(floor(floor((length(x)-1)/2)^0.5)^0.5). +% Example - 'L',5 +% Data Types - single | double +% tau : Estimation times. Vector. If tau is not specified, it is set +% equal to 0:T/(2*L):T. +% Example - 'tau', 0:T/100:T +% Data Types - single | double +% +% Output: +% +% L_spot : Spot leverage. Vector. Values of the spot +% leverage of the process. +% +% tau_out : Estimation times. Vector. Coincides with the input vector tau unless the length +% of the latter is larger than 2L+1. +% +% More About: +% +% We assume that the vectors x contains discrete observations from a diffusion +% process $x$ following the Ito stochastic differential equation +% $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ +% $$d\sigma^2(t)= \gamma(t) \ dZ(t) + a(t) \ dt,$$ +% where $W$ and $Z$ are two Brownian motions defined on the filtered probability space +% $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, while +% $\sigma, \gamma, b$ and $a$ are random processes, adapted to $\mathcal{F}_t$. +% See the References for further mathematical details. +% The spot leverage at time $t \in [0,T]$ is defined as +% $$B(t):=\frac{d\langle x,\sigma^2 \rangle_t}{dt}=\rho\sigma(t)\gamma(t).$$ +% +% +% For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots +% \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= +% x(t_{l+1})-x(t_l)$ be the increments of $x$. +% The Fourier estimator of the spot leverage at time $t \in [0,T]$ is +% given by +% $$\widehat B_{n,N,M,L}(\tau)= \sum_{|k|\leq L} \left(1-{|k|\over +% L}\right)c_k(B_{n,N,M}) \, e^{{\rm i}\frac{2\pi}{T}k\tau},$$ +% where: +% $$c_k(B_{n,N,M})= {T \over {2M+1}} \sum_{|s|\leq M} c_s(d\sigma_{{n},N})c_{k-s}(dx_{n}),$$ +% +% $$c_k(d\sigma_{{n},N})={\rm i} \, k\, \frac{2\pi}{T} +% c_k(\sigma_{{n},N}), \quad c_k(\sigma_{n,N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ +% +% $$c_k(dx_{n}):= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ +% +% See also: FM_spot_vol.m, FM_spot_quart.m, FM_spot_volvol.m, Heston1D.m +% +% References: +% +% Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer. +% +% Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv. +% +% +% +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Examples: + +%{ + %% Example of call of FM_spot_lev with default values of N,M,L and tau. + % The following example estimates the path of the spot leverage + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0; 0.5; 7; 2]; +rho=-0.9; +x0=log(100); +V0=0.5; +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0); + +% Spot leverage estimation +[L_spot, tau_out] = FM_spot_lev(x,t,T); +L=(length(L_spot)-1)/2; + +figure +Lev=rho*parameters(end)*V; +plot(tau_out,Lev(1:round(n/(2*L)):end)); +hold on +plot(tau_out,L_spot); +xlabel('tau'); +title('Spot leverage estimates Vs Actual values') +legend('Actual values','Estimated values') + + +%} + +%{ + %% Example of call of FM_spot_lev with custom choices of N,M,L and tau. + % The following example estimates the path of the spot leverage + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0; 0.5; 7; 2]; +rho=-0.9; +x0=log(100); +V0=0.5; +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0); + +% Spot leverage estimation +tau=0:T/10:T; +[L_spot, tau_out]= FM_spot_lev(x,t,T,'N',10000,'M',120,'L',8,'tau',tau); + +figure +Lev=rho*parameters(end)*V; +plot(tau_out,L_spot); +hold on +plot(tau_out,Lev(1:round(n/10):end)); +xlabel('tau'); +title('Spot leverage estimates Vs Actual values') +legend('Actual values','Estimated values') + + +%} + +%{ + %% Example of call of FM_spot_lev when tau has length larger than 2L + 1. + % The following example estimates the path of the spot leverage + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0; 0.5; 7; 2]; +rho=-0.9; +x0=log(100); +V0=0.5; +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0); + +% Spot leverage estimation +tau=0:T/200:T; +[L_spot, tau_out]= FM_spot_lev(x,t,T,'N',10000,'M',120,'L',10,'tau',tau); + +figure +Lev=rho*parameters(end)*V; +plot(tau_out,L_spot); +hold on +L=10; +plot(tau_out,Lev(1:round(n/(2*L)):end)); +xlabel('tau'); +title('Spot leverage estimates Vs Actual values') +legend('Actual values','Estimated values') + + +%} + +%% Beginning of code + +% Make sure that x and t are column vectors. + +x=x(:); +t=t(:); + +if length(x) ~= length(t) + error('FSDA:FM_spot_lev:WrongInputOpt','Input arguments x and t must have the same length.'); +end + + +const=2*pi/T; + +r=diff(x); + + +n=length(r); +N=floor(n/2); +M=floor(N^0.5); +L=floor(M^0.5); + +tau=0:T/(2*L):T; + +if nargin>2 + options=struct('N',N,'M',M,'L',L,'tau',tau); + + UserOptions=varargin(1:2:length(varargin)); + if ~isempty(UserOptions) + + % Check if number of supplied options is valid + if length(varargin) ~= 2*length(UserOptions) + error('FSDA:FM_spot_lev:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.'); + end + + % Check if all the specified optional arguments were present + % in structure options + inpchk=isfield(options,UserOptions); + WrongOptions=UserOptions(inpchk==0); + if ~isempty(WrongOptions) + disp(strcat('Non existent user option found->', char(WrongOptions{:}))) + error('FSDA:FM_spot_lev:NonExistInputOpt','In total %d non-existent user options found.', length(WrongOptions)); + end + end + + + % Write in structure 'options' the options chosen by the user + for i=1:2:length(varargin) + options.(varargin{i})=varargin{i+1}; + end + + N=options.N; + M=options.M; + L=options.L; + tau=options.tau; +end + +if N >= n + error('FSDA:FM_spot_lev:WrongInputOpt','N must be strictly smaller than min(n1,n2).'); +end + +if M >= N + error('FSDA:FM_spot_lev:WrongInputOpt','M must be strictly smaller than N.'); +end + +if L >= M + error('FSDA:FM_spot_lev:WrongInputOpt','L must be strictly smaller than M.'); +end + +if length(tau) > 2*L+1 + disp('WARNING: estimation will be performed on the equally-spaced grid with mesh size equal to T/(2*L), provided as an output variable.') + tau_out=0:T/(2*L):T; +else + tau_out=tau; +end + +k=1:1:N+M+L; +tt=-1i*const*t(1:end-1)'; + + +c_ra=zeros(length(k),1); + +for j = 1:length(k) + c_ra(j)= exp(k(j)*tt)*r; + end + +c_r1=1/T* [ flip(conj(c_ra)) ; sum(r) ; c_ra]; % Fourier coefficients of dx1 + + +c_v=zeros(2*M+1,1); +c_r_aux1=zeros(2*M+1,2*N+1); +c_dv=zeros(2*M+1,1); + +center=N+M+L+1; + +for j = 1 : 2*M+1 + c_r_aux1(j,1:2*N+1)= c_r1 ( center -N +( j-M-1 ) : center +N +( j-M-1 ) ) ; + c_v(j)= T/(2*N+1) * c_r1 ( center -N : center +N ).' * flip(c_r_aux1(j, : )).'; + c_dv(j)=const*1i*(j-M-1 )*c_v(j); +end + +c_lev=zeros(2*L+1,1); c_lev_spot=zeros(2*L+1,length(tau_out)); c_r_aux2=zeros(2*L+1,2*M+1); + + +for j = 1 : 2*L+1 +c_r_aux2(j,1:2*M+1)= c_r1(center-M+(j-L-1):center+M+(j-L-1)); +c_lev(j)=T/(2*M+1)*c_dv.'*flip(c_r_aux2(j,:)).'; + + for ii=1 : length(tau_out) + c_lev_spot(j,ii)=c_lev(j)*(1-abs(j-L-1)/(L+1))*exp(const*tau_out(ii)*(j-L-1)*1i); + end + +end + +L_spot=real(sum(c_lev_spot)); + +end + +%FScategory:FMvol + diff --git a/toolbox/utilities_stat/FM_spot_quart.m b/toolbox/utilities_stat/FM_spot_quart.m new file mode 100644 index 000000000..cf0cedd87 --- /dev/null +++ b/toolbox/utilities_stat/FM_spot_quart.m @@ -0,0 +1,303 @@ +function [Q_spot, tau_out] = FM_spot_quart(x,t,T,varargin) +%FM_spot_quart computes the spot quarticity of a diffusion process via the Fourier-Malliavin estimator +% +%Link to the help function +% +% Required input arguments: +% +% x : Observed process values. Vector. Row or column vector containing +% the observed values. +% t : Observation times. Vector. Row or column vector with the same +% length of x containing the observation times. +% T : Estimation horizon. Scalar. +% +% Optional input arguments: +% +% N : Cutting frequency. Scalar. If N is not specified, it is set +% equal to floor((length(x)-1)/2). +% Example - 'N',400 +% Data Types - single | double +% M : Cutting frequency. Scalar. If M is not specified, it is set +% equal to floor(floor((length(x)-1)/2)^0.5). +% Example - 'M',20 +% Data Types - single | double +% L : Cutting frequency. Scalar. If L is not specified, it is set +% equal to floor(floor(floor((length(x)-1)/2)^0.5)^0.5). +% Example - 'L',5 +% Data Types - single | double +% tau : Estimation times. Vector. If tau is not specified, it is set +% equal to 0:T/(2*L):T. +% Example - 'tau', 0:T/100:T +% Data Types - single | double +% +% Output: +% +% Q_spot : Spot quarticity estimates. Vector. Estimated values of the spot +% quarticity of the process. +% tau_out : Estimation times. Vector. Coincides with the input vector tau unless the length +% of the latter is larger than 2L+1. +% More About: +% +% We assume that the vectors x contains discrete observations from a diffusion +% process $x$ following the Ito stochastic differential equation +% $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ +% where $W$ is a Brownian motions defined on the filtered probability space +% $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, while +% $\sigma$ and $b$ are random processes, adapted to $\mathcal{F}_t$. +% See the References for further mathematical details. +% The spot quarticity at time $t \in [0,T]$ is defined as $Q(t):=\sigma^4(t).$ +% +% +% For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots +% \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= +% x(t_{l+1})-x(t_l)$ be the increments of $x$. +% The Fourier estimator of the spot quarticity at time $t \in [0,T]$ is +% given by +% $$\widehat Q_{n,N,M,L}(\tau)= \sum_{|k|\leq L} \left(1-{|k|\over +% L}\right)c_k(Q_{n,N,M}) \, e^{{\rm i}\frac{2\pi}{T}k\tau},$$ +% where: +% $$c_k(Q_{n,N,M})= {T \over {2M+1}} \sum_{|s|\leq M} c_s( \sigma_{{n},N})c_{k-s}(\sigma_{{n},N}),$$ +% +% $$c_k(\sigma_{n,N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ +% +% $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ +% +% See also: FM_spot_vol.m, FM_spot_volvol.m, FM_spot_lev.m, Heston1D.m +% +% References: +% +% Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer. +% +% Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv. +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Examples: + +%{ + %% Example of call of FM_spot_quart with default values of N,M,L and tau. + % The following example estimates the path of the spot quarticity + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.4,5,1]; +rho=-0.5; +x0=log(100); +V0=0.4; +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0); + + +% Spot qaurticity estimation +[Q_spot, tau_out] = FM_spot_quart(x,t,T); +L=(length(Q_spot)-1)/2; + +figure +Q=V.^2; +plot(tau_out,Q(1:round(n/(2*L)):end)); +hold on +plot(tau_out,Q_spot); +title('Spot quarticity estimates Vs Actual values') +legend('Actual values','Estimated values') + +%} +%{ + %% Example of call of FM_spot_quart with custom choices of N,M,L and tau. + % The following example estimates the path of the spot quarticity + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.4,5,1]; +rho=-0.5; +x0=log(100); +V0=0.4; +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0); + +% Spot quarticity estimation +tau=0:T/10:T; +[Q_spot,tau_out]= FM_spot_quart(x,t,T,'N',11000,'M',120,'L',15,'tau',tau); + +figure +Q=V.^2; +plot(tau_out,Q(1:round(n/10):end)); +hold on +plot(tau_out,Q_spot); +xlabel('tau'); +title('Spot quarticity estimates Vs Actual values') +legend('Actual values','Estimated values') + + +%} + +%{ + %% Example of call of FM_spot_quart when tau has length larger than 2L + 1. + % The following example estimates the path of the spot quarticity + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.4,5,1]; +rho=-0.5; +x0=log(100); +V0=0.4; +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0); + +% Spot quarticity estimation +tau=0:T/500:T; +[Q_spot,tau_out]= FM_spot_quart(x,t,T,'N',11000,'M',120,'L',10,'tau',tau); + +figure +Q=V.^2; +L=10; +plot(tau_out,Q(1:round(n/(2*L)):end)); +hold on +plot(tau_out,Q_spot); +xlabel('tau'); +title('Spot quarticity estimates Vs Actual values') +legend('Actual values','Estimated values') +%} + +%% Beginning of code + +% Make sure that x and t are column vectors. + +x=x(:); +t=t(:); + +if length(x) ~= length(t) + error('FSDA:FM_spot_quart:WrongInputOpt','Input arguments x and t must have the same length.'); +end + + +const=2*pi/T; + +r=diff(x); + + +n=length(r); +N=floor(n/2); +M=floor(N^0.5); +L=floor(M^0.5); + +tau=0:T/(2*L):T; + +if nargin>2 + options=struct('N',N,'M',M,'L',L,'tau',tau); + + UserOptions=varargin(1:2:length(varargin)); + if ~isempty(UserOptions) + + % Check if number of supplied options is valid + if length(varargin) ~= 2*length(UserOptions) + error('FSDA:FM_spot_quart:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.'); + end + + % Check if all the specified optional arguments were present + % in structure options + inpchk=isfield(options,UserOptions); + WrongOptions=UserOptions(inpchk==0); + if ~isempty(WrongOptions) + disp(strcat('Non existent user option found->', char(WrongOptions{:}))) + error('FSDA:FM_spot_quart:NonExistInputOpt','In total %d non-existent user options found.', length(WrongOptions)); + end + end + + + % Write in structure 'options' the options chosen by the user + for i=1:2:length(varargin) + options.(varargin{i})=varargin{i+1}; + end + + N=options.N; + M=options.M; + L=options.L; + tau=options.tau; +end + +if N >= n + error('FSDA:FM_spot_quart:WrongInputOpt','N must be strictly smaller than min(n1,n2).'); +end + +if M >= N + error('FSDA:FM_spot_quart:WrongInputOpt','M must be strictly smaller than N.'); +end + +if L >= M + error('FSDA:FM_spot_quart:WrongInputOpt','L must be strictly smaller than M.'); +end + +if length(tau) > 2*L+1 + disp('WARNING: estimation will be performed on the equally-spaced grid with mesh size equal to T/(2*L), provided as an output variable.') + tau_out=0:T/(2*L):T; +else + tau_out=tau; +end + +k=1:1:N+M+L; +tt=-1i*const*t(1:end-1)'; + + +c_ra=zeros(length(k),1); + +for j = 1:length(k) + c_ra(j)= exp(k(j)*tt)*r; + end + +c_r1=1/T* [ flip(conj(c_ra)) ; sum(r) ; c_ra]; + + +c_v=zeros(2*M+1,1); +c_r_aux1=zeros(2*M+1,2*N+1); + +center=N+M+L+1; +for j = 1 : 2*M+1 + c_r_aux1(j,1:2*N+1)= c_r1 ( center -N +( j-M-1 ) : center +N +( j-M-1 ) ) ; + c_v(j)= T/(2*N+1) * c_r1 ( center -N : center +N ).' * flip(c_r_aux1(j, : )).'; +end + +MM=M+L; + +c_v2=zeros(2*MM+1,1); +c_r_aux2=zeros(2*MM+1,2*N+1); + + + +for j = 1 : 2*MM+1 +c_r_aux2(j,1:2*N+1)= c_r1(center-N+(j-MM-1) : center+N+(j-MM-1)); +c_v2(j)= T/(2*N+1)*c_r1(center-N : center+N).'*flip(c_r_aux2(j, : )).'; +end + +c_q=zeros(2*L+1,1); c_q_spot=zeros(2*L+1,length(tau_out)); c_v3=zeros(2*L+1, 2*M +1); + +center2=MM+1; + +for j = 1 : 2*L+1 +c_v3(j,1:2*M +1)= c_v2 ( center2 -M +(j-L-1 ) : center2 +M +(j-L-1 ) ); +c_q(j)= T * c_v.'*flip(c_v3(j,:)).'; + + for ii=1 : length(tau_out) + c_q_spot(j,ii)=c_q(j)*(1-abs(j-L-1)/L)*exp(const*tau_out(ii)*(j-L-1)*1i); + end +end + +Q_spot=real(sum(c_q_spot)); + +end + +%FScategory:FMvol diff --git a/toolbox/utilities_stat/FM_spot_vol.m b/toolbox/utilities_stat/FM_spot_vol.m new file mode 100644 index 000000000..826f9c214 --- /dev/null +++ b/toolbox/utilities_stat/FM_spot_vol.m @@ -0,0 +1,275 @@ +function [V_spot,tau_out] = FM_spot_vol(x,t,T,varargin) +%FM_spot_vol computes the spot volatility of a diffusion process via the Fourier-Malliavin estimator +% +%Link to the help function +% +% Required input arguments: +% +% x : Observed process values. Vector. Row or column vector containing +% the observed values. +% t : Observation times. Vector. Row or column vector with the same +% length of x containing the observation times. +% T : Estimation horizon. Scalar. +% +% Optional input arguments: +% +% N : Cutting frequency. Scalar. If N is not specified, it is set +% equal to floor((length(x)-1)/2). +% Example - 'N',400 +% Data Types - single | double +% M : Cutting frequency. Scalar. If M is not specified, it is set +% equal to floor(floor((length(x)-1)/2)^0.5). +% Example - 'M',20 +% Data Types - single | double +% tau : Estimation times. Vector. If tau is not specified, it is set +% equal to 0:T/(2*M):T. +% Example - 'tau', 0:T/100:T +% Data Types - single | double +% +% Output: +% +% V_spot : Spot variance estimates. Vector. Estimated values of the spot +% variance of the process. +% tau_out : Estimation times. Vector. Coincides with the input vector tau unless the length +% of the latter is larger than 2M+1. +% More About: +% +% We assume that the vector x contains discrete observations from a diffusion +% process $x$ following the Ito stochastic differential equation +% $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ +% where $W$ is a Brownian motion defined on the filtered probability space $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, +% while $\sigma$ and $b$ are random processes, adapted to $\mathcal{F}_t$. +% See the Reference for further mathematical details. +% The spot volatility of the process $x$ at time $t \in [0,T]$ is defined as $V(t):=\sigma^2(t)$. +% +% For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots +% \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= +% x(t_{l+1})-x(t_l)$ be the increments of $x$. +% The Fourier estimator of the spot volatility at time $t \in [0,T]$ is +% given by +% $$\widehat V_{n,N,M}(\tau)= \sum_{|k|\leq M} \left(1-{|k|\over +% M}\right)c_k(\sigma_{n,N}) \, e^{{\rm i}\frac{2\pi}{T}k\tau},$$ +% where: +% $$c_k(\sigma_{n,N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ +% +% $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ +% +% See also: FE_spot_vol.m, FE_spot_vol_FFT.m, FM_spot_quart.m, FM_spot_volvol.m, FM_spot_lev.m, Heston1D.m +% +% References: +% +% Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer. +% +% Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv. +% +% +% +% +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Examples: + + +%{ +%% Example of call of FM_spot_vol with default values of M,N and tau. +% The following example estimates the path of the spot volatility of a +% Heston model from a discrete sample. The Heston model assumes that the spot variance follows +% a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.4,2,1]; +Rho=-0.5; +x0=log(100); +V0=0.4; +[x,V,t]=Heston1D(T,n,parameters,Rho,x0,V0); + + +% Spot volatility estimation +[V_spot, tau_out]=FM_spot_vol(x,t,T); +M=(length(V_spot)-1)/2; + +figure +plot(tau_out,V(1:round(n/(2*M)):end)); +hold on +plot(tau_out,V_spot); +xlabel('tau'); +title('Spot volatility estimates Vs Actual values') +legend('Actual values','Estimated values') + +%} + +%{ +%% Example of call of FM_spot_vol with custom choices of M,N and tau. +% The following example estimates the path of the spot volatility of a +% Heston model from a discrete sample. The Heston model assumes that the spot variance follows +% a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.4,2,1]; +Rho=-0.5; +x0=log(100); +V0=0.4; +[x,V,t]=Heston1D(T,n,parameters,Rho,x0,V0); + + +% Spot volatility estimation +tau=0:T/50:T; +[V_spot, tau_out]= FM_spot_vol(x,t,T,'N',5000,'M',100,'tau',tau); + +figure +plot(tau_out,V(1:round(n/50):end)); +hold on +plot(tau_out,V_spot); +xlabel('tau'); +title('Spot volatility estimates Vs Actual values') +legend('Actual values','Estimated values') +%} + +%{ +%% Example of call of FM_spot_vol when tau has length larger than 2M + 1. +% The following example estimates the path of the spot volatility of a +% Heston model from a discrete sample. The Heston model assumes that the spot variance follows +% a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.4,2,1]; +Rho=-0.5; +x0=log(100); +V0=0.4; +[x,V,t]=Heston1D(T,n,parameters,Rho,x0,V0); + + +% Spot volatility estimation +tau=0:T/1000:T; +[V_spot, tau_out]= FM_spot_vol(x,t,T,'N',5000,'M',100,'tau',tau); + +figure +M=100; +plot(tau_out,V(1:round(n/(2*M)):end)); +hold on +plot(tau_out,V_spot); +xlabel('tau'); +title('Spot volatility estimates Vs Actual values') +legend('Actual values','Estimated values') +%} + + +%% Beginning of code + +% Make sure that x and t are column vectors. + +x=x(:); +t=t(:); + + +if length(x) ~= length(t) + error('FSDA:FM_spot_vol:WrongInputOpt','Input arguments x and t must have the same length.'); +end + + + +const=2*pi/T; + +r=diff(x); + + +n=length(r); +N=floor(n/2); +M=floor(N^0.5); +tau=0:T/(2*M):T; + + +if nargin>2 + options=struct('N',N,'M',M,'tau',tau); + + UserOptions=varargin(1:2:length(varargin)); + if ~isempty(UserOptions) + + % Check if number of supplied options is valid + if length(varargin) ~= 2*length(UserOptions) + error('FSDA:FM_spot_vol:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.'); + end + + % Check if all the specified optional arguments were present + % in structure options + inpchk=isfield(options,UserOptions); + WrongOptions=UserOptions(inpchk==0); + if ~isempty(WrongOptions) + disp(strcat('Non existent user option found->', char(WrongOptions{:}))) + error('FSDA:FM_spot_vol:NonExistInputOpt','In total %d non-existent user options found.', length(WrongOptions)); + end + end + + + % Write in structure 'options' the options chosen by the user + for i=1:2:length(varargin) + options.(varargin{i})=varargin{i+1}; + end + + N=options.N; + M=options.M; + tau=options.tau; +end + +if N >= n + error('FSDA:FM_spot_vol:WrongInputOpt','N must be strictly smaller than n.'); +end + +if M >= N + error('FSDA:FM_spot_vol:WrongInputOpt','M must be strictly smaller than N.'); +end + +if length(tau) > 2*M+1 + disp('WARNING: estimation will be performed on the equally-spaced grid with mesh size equal to T/(2*M), provided as an output variable.') + tau_out=0:T/(2*M):T; +else + tau_out=tau; +end + + +k=1:1:N+M; +tt=-1i*const*t(1:end-1)'; + +c_ra=zeros(length(k),1); + + +for j = 1:length(k) + c_ra(j)= exp(k(j)*tt)*r; +end + +c_r=1/T* [ flip(conj(c_ra)) ; sum(r) ; c_ra]; % Fourier coefficients of dx + + + +c_v=zeros(2*M+1,1); +c_r_aux=zeros(2*M+1,2*N+1); +c_v_spot=zeros(2*M+1,length(tau_out)); + + +center=N+M+1; + +for j = 1 : 2*M+1 + c_r_aux(j,1:2*N+1)= c_r ( center -N +( j-M-1 ) : center +N +( j-M-1 ) ) ; + c_v(j)= T/(2*N+1) * c_r ( center -N : center +N ).' * flip(c_r_aux(j, : )).'; + for ii=1 : length(tau_out) + c_v_spot(j,ii)=c_v(j)*(1-abs(j-M-1)/(M+1))*exp(const*tau_out(ii)*(j-M-1)*1i); % spot variance of process x + end +end + +V_spot = real(sum(c_v_spot)); +end + +%FScategory:FMvol \ No newline at end of file diff --git a/toolbox/utilities_stat/FM_spot_volvol.m b/toolbox/utilities_stat/FM_spot_volvol.m new file mode 100644 index 000000000..ec545315e --- /dev/null +++ b/toolbox/utilities_stat/FM_spot_volvol.m @@ -0,0 +1,317 @@ +function [VV_spot, tau_out] = FM_spot_volvol(x,t,T,varargin) +%FM_spot_volvol computes the spot volatiity of volatility of a diffusion process via the Fourier-Malliavin estimator +% +%Link to the help function +% +% Required input arguments: +% +% x : Observed process values. Vector. Row or column vector containing +% the observed values. +% t : Observation times. Vector. Row or column vector with the same +% length of x containing the observation times. +% T : Estimation horizon. Scalar. +% +% Optional input arguments: +% +% N : Cutting frequency. Scalar. If N is not specified, it is set +% equal to floor((length(x)-1)/2). +% Example - 'N',400 +% Data Types - single | double +% M : Cutting frequency. Scalar. If M is not specified, it is set +% equal to floor(floor((length(x)-1)/2)^0.4). +% Example - 'M',20 +% Data Types - single | double +% L : Cutting frequency. Scalar. If L is not specified, it is set +% equal to floor(floor(floor((length(x)-1)/2)^0.4)^0.5). +% Example - 'L',5 +% Data Types - single | double +% tau : Estimation times. Vector. If tau is not specified, it is set +% equal to 0:T/(2*L):T. +% Example - 'tau', 0:T/100:T +% Data Types - single | double +% +% Output: +% +% VV_spot : Spot volatility of volatility estimates. Vector. Estimated values of the spot +% volatility of volatility of the process. +% +% tau_out : Estimation times. Vector. Coincides with the input vector tau unless the length +% of the latter is larger than 2L+1. +% +% More About: +% +% We assume that the vectors x contains discrete observations from a diffusion +% process $x$ following the Ito stochastic differential equation +% $$dx(t)= \sigma(t) \ dW(t) + b(t) \ dt,$$ +% $$d\sigma^2(t)= \gamma(t) \ dZ(t) + a(t) \ dt,$$ +% where $W$ and $Z$ are two Brownian motions defined on the filtered probability space +% $(\Omega, (\mathcal{F}_t)_{t \in [0,T]}, P)$, with correlation $\rho$, while +% $\sigma, \gamma, b$ and $a$ are random processes, adapted to $\mathcal{F}_t$. +% See the References for further mathematical details. +% The spot volatility of volatility at time $t \in [0,T]$ is defined as +% $$C(t):=\frac{d\langle \sigma^2,\sigma^2 \rangle_t}{dt}=\gamma^2(t).$$ +% +% +%For any positive integer $n$, let $\mathcal{S}_{n}:=\{ 0=t_{0}\leq \cdots +% \leq t_{n}=T \}$ be the observation times. Moreover, let $\delta_l(x):= +% x(t_{l+1})-x(t_l)$ be the increments of $x$. +% The Fourier estimator of the spot volatility of volatility at time $t \in [0,T]$ is +% given by +% $$\widehat C_{n,N,M,L}(\tau)= \sum_{|k|\leq L} \left(1-{|k|\over +% L}\right)c_k(C_{n,N,M}) \, e^{{\rm i}\frac{2\pi}{T}k\tau},$$ +% where: +% $$c_k(C_{n,N,M})= {T \over {2M+1}} \sum_{|s|\leq M} c_s(d\sigma_{{n},N})c_{k-s}(d\sigma_{{n},N}),$$ +% +% $$c_k(d\sigma_{{n},N})={\rm i} \, k\, \frac{2\pi}{T} +% c_k(\sigma_{{n},N}), \quad c_k(\sigma_{n,N})={T\over {2N+1}} \sum_{|s|\leq N} c_{s}(dx_{n})c_{k-s}(dx_{n}),$$ +% +% $$c_k(dx_{n})= {1\over {T}} \sum_{l=0}^{n-1} e^{-{\rm i}\frac{2\pi}{T}kt_l}\delta_{l}(x).$$ +% +% See also: FM_spot_vol.m, FM_spot_quart.m, FM_spot_lev.m, Heston1D.m +% +% References: +% +% Mancino, M.E., Recchioni, M.C., Sanfelici, S. (2017), Fourier-Malliavin Volatility Estimation. Theory and Practice, "Springer Briefs in Quantitative Finance", Springer. +% +% Sanfelici, S., Toscano, G. (2024), The Fourier-Malliavin Volatility (FMVol) MATLAB toolbox, available on ArXiv. +% +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Examples: + +%{ + %% Example of call of FM_spot_volvol with default values of N,M,L and tau. + % The following example estimates the path of the spot volatility of volatility + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; +n=23400; +parameters=[0,0.8,10,3.25]; +rho=-0.3; +x0=log(100); +V0=0.8; +[x,V,t] = Heston1D(T,n,parameters,rho,x0,V0); + +% Spot volatility of volatility estimation +[VV_spot, tau_out] = FM_spot_volvol(x,t,T); +L=(length(VV_spot)-1)/2; + +figure +VV=parameters(end)^2*V; +plot(tau_out,VV(1:round(n/(2*L)):end)); +hold on +plot(tau_out,VV_spot); +xlabel('tau'); +title('Spot volatility of volatility estimates Vs Actual values') +legend('Actual values','Estimated values') + + +%} +%{ + %% Example of call of FM_spot_volvol with custom choices of N,M,L and tau. + % The following example estimates the daily path of the spot volatility of volatility + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; % horizon of the trajectory +n=23400; % number of observations simulated in one trajectory +parameters=[0,0.8,10,3.25]; +rho=-0.3; +x0=log(100); +V0=0.8; +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0); + +% Spot volatility of volatility estimation +tau=0:T/10:T; +[VV_spot, tau_out] = FM_spot_volvol(x,t,T,'N',10000,'M',50,'L',10,'tau',tau); + +figure +VV=parameters(end)^2*V; +plot(tau_out,VV(1:round(n/10):end)); +hold on +plot(tau_out,VV_spot); +xlabel('tau'); +title('Spot volatility of volatility estimates Vs Actual values') +legend('Actual values','Estimated values') + + + +%} + +%{ + %% Example of call of FM_spot_volvol when tau has length larger than 2L + 1. + % The following example estimates the daily path of the spot volatility of volatility + % of a random process following the Heston model from a discrete sample. + % The Heston model assumes that the spot variance follows + % a Cox-Ingersoll-Ross model. + +% Heston model simulation +T=1; % horizon of the trajectory +n=23400; % number of observations simulated in one trajectory +parameters=[0,0.8,10,3.25]; +rho=-0.3; +x0=log(100); +V0=0.8; +[x,V,t]=Heston1D(T,n,parameters,rho,x0,V0); + +% Spot volatility of volatility estimation +tau=0:T/100:T; +[VV_spot, tau_out] = FM_spot_volvol(x,t,T,'N',10000,'M',50,'L',10,'tau',tau); + +figure +VV=parameters(end)^2*V; +L=10; +plot(tau_out,VV(1:round(n/(2*L)):end)); +hold on +plot(tau_out,VV_spot); +xlabel('tau'); +title('Spot volatility of volatility estimates Vs Actual values') +legend('Actual values','Estimated values') + + + +%} + +%% Beginning of code + +% Make sure that x and t are column vectors. + +x=x(:); +t=t(:); + +if length(x) ~= length(t) + error('FSDA:FM_spot_volvol:WrongInputOpt','Input arguments x and t must have the same length.'); +end + + +const=2*pi/T; + +r=diff(x); + + +n=length(r); +N=floor(n/2); +M=floor(N^0.4); +L=floor(M^0.5); +tau=0:T/(2*L):T; + +if nargin>2 + options=struct('N',N,'M',M,'L',L,'tau',tau); + + UserOptions=varargin(1:2:length(varargin)); + if ~isempty(UserOptions) + + % Check if number of supplied options is valid + if length(varargin) ~= 2*length(UserOptions) + error('FSDA:FM_spot_volvol:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.'); + end + + % Check if all the specified optional arguments were present + % in structure options + inpchk=isfield(options,UserOptions); + WrongOptions=UserOptions(inpchk==0); + if ~isempty(WrongOptions) + disp(strcat('Non existent user option found->', char(WrongOptions{:}))) + error('FSDA:FM_spot_volvol:NonExistInputOpt','In total %d non-existent user options found.', length(WrongOptions)); + end + end + + + % Write in structure 'options' the options chosen by the user + for i=1:2:length(varargin) + options.(varargin{i})=varargin{i+1}; + end + + N=options.N; + M=options.M; + L=options.L; + tau=options.tau; +end + +if N >= n + error('FSDA:FM_spot_volvol:WrongInputOpt','N must be strictly smaller than min(n1,n2).'); +end + +if M >= N + error('FSDA:FM_spot_volvol:WrongInputOpt','M must be strictly smaller than N.'); +end + +if L >= M + error('FSDA:FM_spot_volvol:WrongInputOpt','L must be strictly smaller than M.'); +end + +if length(tau) > 2*L+1 + disp('WARNING: estimation will be performed on the equally-spaced grid with mesh size equal to T/(2*L), provided as an output variable.') + tau_out=0:T/(2*L):T; +else + tau_out=tau; +end + +k=1:1:N+M+L; +tt=-1i*const*t(1:end-1)'; + + +c_ra=zeros(length(k),1); + +for j = 1:length(k) + c_ra(j)= exp(k(j)*tt)*r; + end + +c_r1=1/T* [ flip(conj(c_ra)) ; sum(r) ; c_ra]; % Fourier coefficients of dx1 + + +c_v=zeros(2*M+1,1); +c_r_aux1=zeros(2*M+1,2*N+1); +c_dv=zeros(2*M+1,1); + +center=N+M+L+1; +for j = 1 : 2*M+1 + c_r_aux1(j,1:2*N+1)= c_r1 ( center -N +( j-M-1 ) : center +N +( j-M-1 ) ) ; + c_v(j)= T/(2*N+1) * c_r1 ( center -N : center +N ).' * flip(c_r_aux1(j, : )).'; + c_dv(j)=const*1i*(j-M-1)*c_v(j); +end + +MM=M+L; + +c_v2=zeros(2*MM+1,1); +c_r_aux2=zeros(2*MM+1,2*N+1); +c_dv2=zeros(2*MM+1,1); + + +for j = 1 : 2*MM+1 +c_r_aux2(j,1:2*N+1)= c_r1(center-N+(j-MM-1) : center+N+(j-MM-1)); +c_v2(j)= T/(2*N+1)*c_r1(center-N : center+N).'*flip(c_r_aux2(j, : )).'; +c_dv2(j)=const*1i*(j-MM-1)*c_v2(j); +end + +c_w=zeros(2*L+1,1); +c_w_spot=zeros(2*L+1,length(tau_out)); +c_dv3=zeros(2*L+1, 2*M +1); + +center2=MM+1; + +for j = 1 : 2*L+1 +c_dv3(j,1:2*M +1)= c_dv2 ( center2 -M +(j-L-1 ) : center2 +M +(j-L-1 ) ); +c_w(j)= T /(2*M+1)* c_dv.'*flip(c_dv3(j,:)).'; + for ii=1 : length(tau_out) + c_w_spot(j,ii)=c_w(j)*(1-abs(j-L-1)/(L+1))*exp(const*tau_out(ii)*(j-L-1)*1i); + end +end + +VV_spot=real(sum(c_w_spot)); + +end + +%FScategory:FMvol diff --git a/toolbox/utilities_stat/Heston1D.m b/toolbox/utilities_stat/Heston1D.m new file mode 100644 index 000000000..b026d6a9e --- /dev/null +++ b/toolbox/utilities_stat/Heston1D.m @@ -0,0 +1,164 @@ +function [x,V,t] = Heston1D(T,n,parameters,rho,x0,V0) +% Heston1D simulates observations and instantaneous variances from the Heston model +% +% +%Link to the help function +% +% Heston1D simulates, using the Euler–Maruyama method, observations and instantaneous variances from the +% model by [S. Heston, The Review of Financial Studies, Vol. 6, No. 2, 1993]. +% +% Required input arguments: +% +% T : Time horizon. Scalar. +% +% n : Number of simulated observation. Scalar. +% +% parameters : Model parameters. Vector. Vector of dimension 4. +% +% rho : Leverage parameter. Scalar. +% +% x0 : Initial observation value. Scalar. +% +% V0 : Initial variance value. Scalar. +% +% +% Optional input arguments: +% +% +% Output: +% +% x : Process observations. Vector. Vector of dimension n+1. +% +% V : Spot variance values. Vector. Vector of dimension n+1. +% +% t : Observation times. Vector. Vector of dimension n+1. +% +% More About: +% +% The Heston model [S. Heston, The Review of Financial Studies, Vol. 6, No. 2, 1993] is given by the following stochastic +% differential equations: +% $$\left\{\begin{array}{l} +% dx_t=\left( \mu-\frac{1}{2} \sigma^2_t \right) \, dt + \sigma_t \, dW_t \\ +% d\sigma^2_t=\theta \, \left( \alpha-\sigma^2_t \right) \, dt + \gamma \, \sigma_t \, dZ_t +% \end{array}\right. ,$$ +% where $\mu$ is a real-valued constant, $\theta, \, \alpha$ and $\gamma$ are +% positive constants, and $W$ and $Z$ are +% Brownian motions with correlation $\rho$. +% +% See also: Heston2D.m +% + +% +% References: +% +% Heston, S. (1993), A closed-form solution for options with stochastic volatility +% with applications to bond and currency options, The Review of Financial Studies, Vol. 6, No. 2. +% +% +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Examples: + +%{ + %% Example of call of Heston1D for obtaining process observations only. + % Generates observations from the Heston model. + T=1; + n=23400; + parameters=[0,0.4,2,1]; + rho=-0.5; + x0=log(100); + V0=0.4; + x = Heston1D(T,n,parameters,rho,x0,V0); + figure + plot(x) + ylabel('Observations') + title('Heston model') + +%} + +%{ + %% Example of call of Heston1D for obtaning process observations and volatility values. + % Generates observations and volatilities from the Heston model. + T=1; + n=23400; + parameters=[0,0.4,2,1]; + rho=-0.5; + x0=log(100); + V0=0.4; + [x,V] = Heston1D(T,n,parameters,rho,x0,V0); + figure + subplot(2,1,1) + plot(x) + ylabel('Observations') + title('Heston model') + subplot(2,1,2) + plot(V) + ylabel('Spot Variances') + title('Heston model') +%} + +%{ + %% Example of call of Heston1D for obtaning process observations, volatility values and sampling times. + % Generates observations, volatilities and sampling times from the Heston model. + T=1; + n=23400; + parameters=[0,0.4,2,1]; + rho=-0.5; + x0=log(100); + V0=0.4; + [x,V,t] = Heston1D(T,n,parameters,rho,x0,V0); + figure + subplot(2,1,1) + plot(t,x) + xlabel('Time') + ylabel('Observations') + title('Heston model') + subplot(2,1,2) + plot(t,V) + xlabel('Time') + ylabel('Spot Variances') + title('Heston model') +%} + +%% Beginning of code + +dt=T/n; + +t=0:dt:T; + +m=parameters(1); a=parameters(2); k=parameters(3); g=parameters(4); + +if 2*a*k-g^2 < 0 + error('FSDA:Heston1D:WrongInputOpt','The process does not satisfy the Feller condition.'); +end + +mu=zeros(2,1); +S=[1 rho; rho 1]; + +dW=sqrt(dt)*mvnrnd(mu,S,n+1); + +x=zeros(1,n+1); +V=zeros(1,n+1); + +if V0 <= 0 + error('FSDA:Heston1D:WrongInputOpt','The initial variance must be positive.'); +end + +x(1)=x0; +V(1)=V0; + +for nn = 2 : n+1 + V(nn) = V(nn-1) + k*(a-V(nn-1))*dt + g*sqrt(V(nn-1))*dW(nn-1,1); + x(nn) = x(nn-1) + (m-0.5*V(nn-1))*dt + sqrt(V(nn-1))*dW(nn-1,2); +end + +end + +%FScategory:FMvol \ No newline at end of file diff --git a/toolbox/utilities_stat/Heston2D.m b/toolbox/utilities_stat/Heston2D.m new file mode 100644 index 000000000..f5c7a9a45 --- /dev/null +++ b/toolbox/utilities_stat/Heston2D.m @@ -0,0 +1,201 @@ +function [x,V,t] = Heston2D(T,n,parameters,Rho,x0,V0) +% Heston2D simulates observations and instantaneous variances from the bivariate Heston model +% +% +%Link to the help function +% +% Heston2D simulates, using the Euler–Maruyama method, observations and instantaneous variances from +% a 2-dimensional version of the model by [S. Heston, The Review of Financial Studies, Vol. 6, No. 2, 1993]. +% +% Required input arguments: +% +% T : Time horizon. Scalar. +% +% n : Number of simulated observation. Scalar. +% +% parameters : Model parameters. Matrix. Matrix with 4 rows and 2 columns. +% +% Rho : Correlation vector. Vector. Vector of dimension 6. +% +% x0 : Initial process observation values. Vector. Vector of dimension 2. +% +% V0 : Initial variance values. Vector. Vector of dimension 2. +% +% +% Optional input arguments: +% +% +% Output: +% +% x : Process observations. Matrix. Matrix with n+1 rows and 2 columns. +% +% V : Spot variance values. Matrix. Matrix with n+1 rows and 2 columns. +% +% t : Observation times. Vector. Vector of dimension n+1. +% +% More About: +% +% A bivariate version of the Heston model [S. Heston, The Review of Financial Studies, Vol. 6, No. 2, 1993] is given by the following stochastic +% differential equations: +% $$\left\{\begin{array}{l} +% dx^i(t)=\left( \mu_{i}-\frac{1}{2} v^i(t) \right) \, dt + \sqrt{v^i(t)} \, dW^i_t \\ +% dv^i(t)=\theta_{i} \, \left( \alpha_{i}- v^i(t) \right) \, dt + \gamma_{i} \, \sqrt{v^i(t)}\, dZ^i_t +% \end{array}\right. ,\quad i=1,2,$$ +% where, for each i, $v^i:=(\sigma^i)^2$, $\mu_i$ is a real-valued constant, $\theta_i, \, \alpha_i$ and $\gamma_i$ are +% positive constants, and $W_i$ and $Z_i$ are Brownian motions that are +% correlated with each other and with $W_j$ and $Z_j$, $j \neq i$. +% +% See also: Heston1D.m +% +% References: +% +% Heston, S. (1993), A closed-form solution for options with stochastic volatility +% with applications to bond and currency options, The Review of Financial Studies, Vol. 6, No. 2. +% +% +% +% +% Copyright 2008-2023. +% Written by FSDA team +% +%Link to the help function +% +%$LastChangedDate:: $: Date of the last commit + +% Examples: + +%{ + %% Example of call of Heston2D for obtaining process observations only. + % Generates observations from the bivariate Heston model. + T=1; + n=23400; + parameters=[0,0;0.4,0.4;2,2;1,1]; + Rho=[0.5;-0.5;0;0;-0.5;0.5]; + x0=[log(100),log(100)]; + V0=[0.4,0.4]; + x = Heston2D(T,n,parameters,Rho,x0,V0); + figure + subplot(2,1,1) + plot(x(:,1)) + ylabel('Observed values of process 1') + title('Heston model') + subplot(2,1,2) + plot(x(:,2)) + ylabel('Observed values of process 2') + title('Heston model') +%} + +%{ + %% Example of call of Heston2D for obtaining process observations and volatility values. + % Generates observations and volatilities from the bivariate Heston model. + T=1; + n=23400; + parameters=[0,0;0.4,0.4;2,2;1,1]; + Rho=[0.5,-0.5,0,0,-0.5,0.5]; + x0=[log(100),log(100)]; V0=[0.4,0.4]; + [x,V] = Heston2D(T,n,parameters,Rho,x0,V0); + figure + subplot(2,1,1) + plot(x(:,1)) + ylabel('Observed values of process 1') + title('Heston model') + subplot(2,1,2) + plot(x(:,2)) + ylabel('Observed values of process 2') + title('Heston model') + figure + subplot(2,1,1) + plot(V(:,1)) + ylabel('Spot variance of process 1') + title('Heston model') + subplot(2,1,2) + plot(V(:,2)) + ylabel('Spot variance of process 2') + title('Heston model') +%} + +%{ + %% Example of call of Heston2D for obtaining process observations, volatility values and sampling times. + % Generates observations, volatilities and sampling times from the bivariate Heston model. + T=1; + n=23400; + parameters=[0,0;0.4,0.4;2,2;1,1]; + Rho=[0.5,-0.5,0,0,-0.5,0.5]; + x0=[log(100),log(100)]; V0=[0.4,0.4]; + [x,V,t] = Heston2D(T,n,parameters,Rho,x0,V0); + figure + subplot(2,1,1) + plot(t,x(:,1)) + xlabel('Time') + ylabel('Observed values of process 1') + title('Heston model') + subplot(2,1,2) + plot(t,x(:,2)) + xlabel('Time') + ylabel('Observed values of process 2') + title('Heston model') + figure + subplot(2,1,1) + plot(t,V(:,1)) + xlabel('Time') + ylabel('Spot variance of process 1') + title('Heston model') + subplot(2,1,2) + plot(t,V(:,2)) + xlabel('Time') + ylabel('Spot variance of process 2') + title('Heston model') +%} + +%% Beginning of code + +dt=T/n; + +t=0:dt:T; + +m=parameters(1,1); a=parameters(2,1); k=parameters(3,1); g=parameters(4,1); % parameters of process 1 +m2=parameters(1,2); a2=parameters(2,2); k2=parameters(3,2) ; g2=parameters(4,2); % parameters of process 2 + +if 2*a*k-g^2 < 0 + error('FSDA:Heston2D:WrongInputOpt','Process 1 does not satisfy the Feller condition.'); +end + +if 2*a2*k2-g2^2 < 0 + error('FSDA:Heston2D:WrongInputOpt','Process 2 does not satisfy the Feller condition.'); +end + +mu=zeros(4,1); +S=[1 Rho(1) Rho(2) Rho(3); ... + Rho(1) 1 Rho(4) Rho(5); ... + Rho(2) Rho(4) 1 Rho(6); ... + Rho(3) Rho(5) Rho(6) 1]; + +dW=sqrt(dt)*mvnrnd(mu,S,n+1); + +x=zeros(n+1,2); +V=zeros(n+1,2); + +if V0(1) <= 0 + error('FSDA:Heston2D:WrongInputOpt','The initial variance of process 1 must be positive.'); +end + +if V0(2) <= 0 + error('FSDA:Heston2D:WrongInputOpt','The initial variance of process 2 must be positive.'); +end + +x(1,1)=x0(1); V(1,1)=V0(1); +x(1,2)=x0(2); V(1,2)=V0(2); + +for nn = 2 : n+1 + V(nn,1) = V(nn-1,1) + k*(a-V(nn-1,1))*dt + g*sqrt(V(nn-1,1))*dW(nn-1,1); + + V(nn,2) = V(nn-1,2) + k2*(a2-V(nn-1,2))*dt + g2*sqrt(V(nn-1,2))*dW(nn-1,2); + + x(nn,1) = x(nn-1,1) + (m-0.5*V(nn-1,1))*dt + sqrt(V(nn-1,1))*dW(nn-1,3); + + x(nn,2) = x(nn-1,2) + (m2-0.5*V(nn-1,2))*dt + sqrt(V(nn-1,2))*dW(nn-1,4); +end + +end + +%FScategory:FMvol \ No newline at end of file