Model generic
Generic model class.
SDE
Bases: ABC
Generic Model.
Attributes:
| Name | Type | Description |
|---|---|---|
param |
parameter instance
|
True parameters used for simulation of the data |
Methods:
| Name | Description |
|---|---|
simulate |
Simulate observations from the model |
sim_realized |
Simulate realized returns and variance |
sim_realized_pq |
Simulate realized returns and variance under both P and Q |
gmmest |
Estimate model parameters using GMM |
integrated_gmm |
Estimate model parameters using Integrated GMM |
nvars
property
Number of state variables.
__init__(param=None)
Initialize the class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
parameter instance
|
True parameters used for simulation of the data |
None
|
depvar_unc_mean(*, param, aggh)
Unconditional means of realized data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
parameter instance
|
Model parameters |
required |
aggh
|
float
|
Interval length |
required |
Returns:
| Type | Description |
|---|---|
array
|
|
euler_loc(*, state, theta)
Euler location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
(nsim, nvars) array
|
Current value of the process |
required |
theta
|
parameter instance
|
Model parameters |
required |
Returns:
| Type | Description |
|---|---|
(nsim, nvars) array
|
Location term in Euler discretization |
euler_scale(*, state, theta)
Euler scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
(nsim, nvars) array
|
Current value of the process |
required |
theta
|
parameter instance
|
Model parameters |
required |
Returns:
| Type | Description |
|---|---|
(nsim, nvars, nvars) array
|
Scale term in Euler discretization |
exact_loc(*, state, theta)
Exact location.
exact_scale(*, state, theta)
Exact scale.
get_start()
abstractmethod
Return starting values for simulation.
gmmest(*, theta_start, data=None, instrlag=1, iter=2, method='BFGS', kernel='Bartlett', band=None)
Estimate model parameters using GMM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta_start
|
parameter instance
|
Initial parameter values for estimation |
required |
data
|
array_like
|
Data passed to the moment condition function |
None
|
instrlag
|
int
|
Number of lags for the instruments |
1
|
iter
|
int
|
Number of GMM iterations |
2
|
method
|
str
|
Optimization method passed to scipy.optimize.minimize |
'BFGS'
|
kernel
|
str
|
HAC kernel for weighting matrix ('Bartlett', 'Parzen', etc.) |
'Bartlett'
|
band
|
int
|
HAC bandwidth. If None, chosen automatically. |
None
|
Notes
For moment condition arguments see momcond.
integrated_gmm(*, param_start, data=None, instr_data=None, instr_choice='const', aggh=1, instrlag=1, subset=Subset.all, measure=Measure.P, names=None, bounds=None, constraints=(), iter=2, method='BFGS', kernel='Bartlett', band=None)
Estimate model parameters using Integrated GMM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_start
|
parameter class
|
Initial parameter values for estimation |
required |
data
|
array_like
|
Returns and realized variance used in moment conditions |
None
|
instr_data
|
array_like
|
Instruments (no lags) |
None
|
instr_choice
|
str {'const', 'var'}
|
Choice of instruments |
'const'
|
aggh
|
int or list of int
|
Number of intervals (days) to aggregate over using rolling mean |
1
|
instrlag
|
int
|
Number of lags for the instruments |
1
|
subset
|
Subset
|
Which parameters to estimate. Belongs to - 'all' : all parameters, including those related to returns - 'vol' : only those related to volatility |
all
|
measure
|
Measure
|
Under which measure to estimate: - 'P' : physical measure - 'Q' : risk-neutral - 'PQ' : both |
P
|
names
|
list of str
|
Parameter names |
None
|
bounds
|
list of tuples
|
Parameter bounds |
None
|
constraints
|
dict or sequence of dict
|
Equality and inequality constraints. See scipy.optimize.minimize |
()
|
iter
|
int
|
Number of GMM iterations |
2
|
method
|
str
|
Optimization method passed to scipy.optimize.minimize |
'BFGS'
|
kernel
|
str
|
HAC kernel for weighting matrix ('Bartlett', 'Parzen', etc.) |
'Bartlett'
|
band
|
int
|
HAC bandwidth. If None, chosen automatically. |
None
|
integrated_mom(*, theta, data=None, instr_data=None, instr_choice='const', aggh=1, subset=Subset.all, instrlag=1, measure=Measure.P)
Integrated moment function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
array
|
Model parameters |
required |
data
|
(2, nobs) array
|
Returns and realized variance |
None
|
instr_data
|
(ninstr, nobs) array
|
Instruments (no lags) |
None
|
instrlag
|
int
|
Number of lags for the instruments |
1
|
instr_choice
|
str {'const', 'var'}
|
Choice of instruments. - 'const' : just a constant (unconditional moments) - 'var' : lags of instrument data |
'const'
|
aggh
|
int
|
Number of intervals (days) to aggregate over using rolling mean |
1
|
subset
|
Subset
|
Which parameters to estimate. Belongs to - 'all' : all parameters, including those related to returns - 'vol' : only those related to volatility |
all
|
measure
|
Measure
|
Under which measure to estimate: - 'P' : physical measure - 'Q' : risk-neutral - 'PQ' : both |
P
|
Returns:
| Name | Type | Description |
|---|---|---|
moments |
(nobs - instrlag - 2, 3 * ninstr = nmoms) array
|
Moment restrictions |
dmoments |
(nmoms, nparams) array
|
Average derivative of the moment restrictions |
loc(*, state, theta)
Location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
(nsim, nvars) array
|
Current value of the process |
required |
theta
|
parameter instance
|
Model parameters |
required |
Returns:
| Type | Description |
|---|---|
(nsim, nvars) array
|
Location term in Euler discretization |
mat_a(*, param, subset=None)
Matrix A in integrated moments.
mean_cross(*, param, aggh)
staticmethod
Unconditional mean of returns times volatility.
mean_ret(*, param, aggh)
staticmethod
Unconditional mean of returns.
mean_vol(*, param, aggh)
staticmethod
Unconditional mean of volatility.
mean_vol2(*, param, aggh)
staticmethod
Unconditional mean of squared volatility.
momcond(*, theta, data=None, instrlag=1)
Moment conditions.
realized_const(*, param=None, aggh=1, subset=None)
Realized constant in integrated moments.
realized_depvar(*, data, subset=None)
staticmethod
Realized dependent variables.
scale(*, state, theta)
Scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
(nsim, nvars) array
|
Current value of the process |
required |
theta
|
parameter instance
|
Model parameters |
required |
Returns:
| Type | Description |
|---|---|
(nsim, nvars, nvars) array
|
Scale term in Euler discretization |
sim_realized(*, start=None, nsub=80, ndiscr=10, aggh=1, nperiods=500, nsim=1, diff=None, new_innov=True, cython=False, seed=None)
Simulate realized returns and variance from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
array_like
|
Starting value for simulation |
None
|
nsub
|
int
|
Number of subintervals for latent simulation (fractions of the day) |
80
|
ndiscr
|
int
|
Number of Euler discretization points inside unit interval |
10
|
aggh
|
int
|
Number of intervals (days) to aggregate over using rolling mean |
1
|
nperiods
|
int
|
Number of points to simulate in one series (days) |
500
|
nsim
|
int
|
Number of time series to simulate |
1
|
diff
|
int
|
Dimensions which should be differentiated, i.e. return = price[1:] - price[:-1] |
None
|
new_innov
|
bool
|
Whether to generate new innovations (True), or use already stored (False) |
True
|
cython
|
bool
|
Whether to use cython-optimized simulation (True) or not (False) |
False
|
seed
|
int
|
Random seed for reproducibility |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
returns |
(nperiods, ) array
|
Simulated returns |
rvar |
(nperiods, ) array
|
Simulated realized variance |
sim_realized_pq(*, start_p=None, start_q=None, aggh=None, nsub=80, ndiscr=10, nperiods=500, nsim=1, diff=None, new_innov=True, cython=False)
Simulate realized data from the model under both P and Q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_p
|
array_like
|
Starting value for simulation under P |
None
|
start_q
|
array_like
|
Starting value for simulation under Q |
None
|
aggh
|
list
|
Aggregation windows for P and Q respectively |
None
|
nsub
|
int
|
Number of subintervals for latent simulation (fractions of the day) |
80
|
ndiscr
|
int
|
Number of Euler discretization points inside unit interval |
10
|
nperiods
|
int
|
Number of points to simulate in one series (days) |
500
|
nsim
|
int
|
Number of time series to simulate |
1
|
diff
|
int
|
Dimensions which should be differentiated |
None
|
new_innov
|
bool
|
Whether to generate new innovations (True), or use already stored (False) |
True
|
cython
|
bool
|
Whether to use cython-optimized simulation (True) or not (False) |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
data_p |
tuple
|
Returns and realized variance under P |
data_q |
tuple
|
Returns and realized variance under Q |
simulate(*, start=None, nsub=80, ndiscr=1, nobs=500, nsim=1, diff=None, new_innov=True, cython=False, seed=None)
Simulate observations from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
array_like
|
Starting value for simulation |
None
|
nsub
|
int
|
Interval length |
80
|
ndiscr
|
int
|
Number of Euler discretization points inside a subinterval |
1
|
nobs
|
int
|
Number of points to simulate in one series |
500
|
nsim
|
int
|
Number of time series to simulate |
1
|
diff
|
int
|
Dimensions which should be differentiated, i.e. return = price[1:] - price[:-1] |
None
|
new_innov
|
bool
|
Whether to generate new innovations (True), or use already stored (False) |
True
|
cython
|
bool
|
Whether to use cython-optimized simulation (True) or not (False) |
False
|
seed
|
int
|
Random seed for reproducibility. If None (default), simulations are non-reproducible. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
paths |
(nobs, 2*nsim, nvars) array
|
Simulated data |
update(*, state, error)
Euler update function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
(nsim, nvars) array_like
|
Current value of the process |
required |
error
|
(nsim, nvars) array_like
|
Random shocks |
required |
Returns:
| Type | Description |
|---|---|
(nsim, nvars) array
|
Update of the process value. Same shape as the input. |
update_theta(param)
Update model parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
parameter instance
|
True parameters used for simulation of the data |
required |