View source: R/data_simulation.R
| generatedata_adjpin | R Documentation |
Generates a dataset object or a data.series object (a list
of dataset objects) storing simulation parameters as well as aggregate
daily buys and sells simulated following the assumption of the AdjPIN model
of \insertCiteDuarte09;textualPINstimation.
generatedata_adjpin(series=1, days = 60, parameters = NULL, ranges = list(),
restricted = list(), verbose = TRUE)
series |
The number of datasets to generate. |
days |
The number of trading days, for which aggregated
buys and sells are generated. The default value is |
parameters |
A vector of model parameters of size |
ranges |
A list of ranges for the different simulation
parameters having named elements |
restricted |
A binary list that allows estimating restricted
AdjPIN models by specifying which model parameters are assumed to be equal.
It contains one or multiple of the following four elements
|
verbose |
A binary variable that determines whether detailed
information about the progress of the data generation is displayed.
No output is produced when |
If the argument parameters is missing, then the parameters are
generated using the ranges specified in the argument ranges.
If the argument ranges is set to list(), default ranges are used. Using
the default ranges, the simulation parameters are obtained using the
following procedure:
\alpha, \delta: (alpha, delta) uniformly
distributed on (0, 1).
\theta, \theta': (theta,thetap) uniformly
distributed on (0, 1).
: (eps.b) an integer uniformly drawn from the interval
(100, 10000) with step 50.
: (eps.s) an integer uniformly drawn from ((4/5)\eb,
(6/5)\eb) with step 50.
: (d.b) an integer uniformly drawn from ((1/2)\eb,
2\eb).
: (d.s) an integer uniformly drawn from ((4/5)\Db,
(6/5)\Db).
: (mu.b) uniformly distributed on the interval
((1/2) max(\eb, \es), 5 max(\eb, \es)).
: (mu.s) uniformly distributed on the interval
((4/5)\mub, (6/5)\mub)..
Based on the simulation parameters parameters, daily buys and sells are
generated by the assumption that buys and sells follow Poisson
distributions with mean parameters:
(\eb, \es) in a day with no information and no liquidity shock;
(\eb+\Db, \es+\Ds) in a day with no information and with liquidity shock;
(\eb+\mub, \es) in a day with good information and no liquidity shock;
(\eb+\mub+\Db, \es+\Ds) in a day with good information and liquidity shock;
(\eb, \es+\mus) in a day with bad information and no liquidity shock;
(\eb+\Ds, \es+\mus+\Ds) in a day with bad information and liquidity shock;
Returns an object of class dataset if series=1, and an
object of class data.series if series>1.
# ------------------------------------------------------------------------ #
# Generate data following the AdjPIN model using generatedata_adjpin() #
# ------------------------------------------------------------------------ #
# With no arguments, the function generates one dataset object spanning
# 60 days, and where the parameters are chosen as described in the section
# 'Details'.
sdata <- generatedata_adjpin()
# Alternatively, simulation parameters can be provided. Recall the order of
# parameters (alpha, delta, theta, theta', eps.b, eps.s, mub, mus, db, ds).
givenpoint <- c(0.4, 0.1, 0.5, 0.6, 800, 1000, 2300, 4000, 500, 500)
sdata <- generatedata_adjpin(parameters = givenpoint)
# Data can be generated following restricted AdjPIN models, for example, with
# restrictions 'eps.b = eps.s', and 'mu.b = mu.s'.
sdata <- generatedata_adjpin(restricted = list(eps = TRUE, mu = TRUE))
# Data can be generated using provided ranges of simulation parameters as fed
# to the function using the argument 'ranges', where thetap corresponds to
# theta'.
sdata <- generatedata_adjpin(ranges = list(
alpha = c(0.1, 0.15), delta = c(0.2, 0.2),
theta = c(0.2, 0.6), thetap = c(0.2, 0.4)
))
# The value of a given simulation parameter can be set to a specific value by
# setting the range of the desired parameter takes a unique value, instead of
# a pair of values.
sdata <- generatedata_adjpin(ranges = list(
alpha = 0.4, delta = c(0.2, 0.7),
eps.b = c(100, 7000), mu.b = 8000
))
# Display the details of the generated simulation data
show(sdata)
# ------------------------------------------------------------------------ #
# Use generatedata_adjpin() to check the accuracy of adjpin() #
# ------------------------------------------------------------------------ #
model <- adjpin(sdata@data, verbose = FALSE)
summary <- cbind(
c(sdata@emp.pin['adjpin'], model@adjpin, abs(model@adjpin -
sdata@emp.pin['adjpin'])),
c(sdata@emp.pin['psos'], model@psos, abs(model@psos -
sdata@emp.pin['psos']))
)
colnames(summary) <- c('adjpin', 'psos')
rownames(summary) <- c('Data', 'Model', 'Difference')
show(knitr::kable(summary, 'simple'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.