knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "tools/" )
The pinbasic
package ships utilities for fast and stable estimation of the probability of informed trading in the static PIN framework.
The function design is chosen to fit the extended EHO model setup but can also be applied to the simpler EKOP model
by equating the intensities of uninformed buys and sells.
State-of-the-art factorization of the model likelihood function as well as
most recent algorithms for generating initial values for optimization routines are implemented.
In total, two likelihood factorizations and three methodologies for starting values are included.
Likelihood functions are evaluated with pin_ll
and sets of starting values are returned by initial_vals
.
The probability of informed trading can be estimated for arbitrary length of daily buys and sells data with pin_est
which is a wrapper around the workhorse function pin_est_core
.
No information about the time span of the underlying data is required to perform optimizations with pin_est
.
However, the recommendation given in the literature is using at least data for 60 trading days to ensure convergence
of the likelihood maximization.
Quarterly estimates are returned by qpin
which can be visualized with ggplot
.
Datasets of daily aggregated numbers of buys and sells can be simulated with simulateBS
.
Calculation of confidence intervals for the probability of informed trading can be enabled by confint
argument in
optimization routines (pin_est_core
, pin_est
and qpin
) or by calling pin_confint
directly.
Additionally, posterior probabilities for conditions of trading days can be computed with posterior
and plotted with ggplot
.
The dataset BSfrequent
cover 60 trading days and represent a frequently traded equity.
Model parameters and the probability of informed trading can be estimated with pin_est
.
library(pinbasic) # Loading data data("BSfrequent") # Estimation pin_freq <- pin_est(numbuys = BSfrequent[,"Buys"], numsells = BSfrequent[,"Sells"]) pin_freq
BSfrequent2015
contains simulated daily buys and sells for a frequently traded equity for business days in 2015.
qpin
returns quarterly estimates which can be visualized with ggplot
.
# Quarterly PIN estimates # Confidence interval computation enabled: # * using only 1000 simulated datasets # * confidence level set to 0.95 # * seed set to 123 data('BSfrequent2015') qpin2015 <- qpin(numbuys = BSfrequent2015[,"Buys"], numsells = BSfrequent2015[,"Sells"], dates = as.Date(rownames(BSfrequent2015), format = "%Y-%m-%d"), confint = TRUE, ci_control = list(n = 1000, seed = 123)) # Print confidence intervals for all four quarters ci_quarters <- lapply(qpin2015[["res"]], function(x) x$confint) ci_quarters # Visualization of estimated parameters library(ggplot2) ggplot(qpin2015[["res"]])
Posterior probabilities of trading days' condition are returned by posterior
and can be displayed with ggplot
.
The following code chunk shows how posterior probabilities for BSfrequent2015
in the third quarter can be calculated and visualized.
# Corresponding parameter estimates freq_2015.3 <- qpin2015[["res"]]$'2015.3'$Results[,"Estimate"] # Subsetting data third_quarter <- subset(BSfrequent2015, subset = lubridate::quarter(rownames(BSfrequent2015)) == 3) # Calculating posterior probabilities post_third <- posterior(param = freq_2015.3, numbuys = third_quarter[,"Buys"], numsells = third_quarter[,"Sells"]) # Plotting ggplot(post_third)
You may install the stable version from CRAN, or the development version from GitHub using devtools:
# install from CRAN install.packages("pinbasic") # install from github using devtools devtools::install_github("anre005/pinbasic")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.