## Overview

PINstimation provides utilities for the estimation of probability of informed trading models: original PIN (PIN) in Easley and O’Hara (1992) and Easley et al. (1996); multilayer PIN (MPIN) in Ersan (2016); Adjusted PIN (AdjPIN) in Duarte and Young (2009); and volume- synchronized PIN (VPIN) in Easley et al. (2011, 2012). Various computation methods suggested in the literature are included. Data simulation tools and trade classification algorithms are among the supplementary utilities. The package enables fast and precise solutions for the sophisticated, error-prone and time-consuming estimation procedure of the probability of informed trading measures, and it is compact in the sense detailed estimation results can be achieved by solely the use of raw trade level data.

#### New Features in Version 0.1.2

We introduce a new function called`classify_trades()`

that
enables users to classify high-frequency (HF) trades individually,
without aggregating them. For each HF trade, the function assigns a
variable `isBuy`

that is set to `TRUE`

if the
trade is buyer-initiated, or `FALSE`

if it is
seller-initiated. –

The

`aggregate_trades()`

function enables users to aggregate high-frequency (HF) trades at
different frequencies. In the previous version, HF trades were
automatically aggregated into daily trade data. However, with the
updated version, users can now specify the desired frequency, such as
every 15 minutes.
## Installation

The easiest way to get PINstimation is the following:

`install.packages("PINstimation")`

To get a bugfix or to use a feature from the development version, you can install the development version of PINstimation from GitHub.

```
# install.packages("devtools")
# library(devtools)
devtools::install_github("monty-se/PINstimation")
```

Loading the package

#### Get Started!

For a smooth introduction to the main functionalities of the package, as well as useful tips how to get started with**PINstimation**, please refer to the section Get Started.

A detailed description of the package functions is available in online documentation

## Note to frequent users

If you are a frequent user of PINstimation, you might want to avoid
repetitively loading the package PINstimation whenever you open a new R
session. You can do that by adding PINstimation to
`.R profile`

either manually, or using the function
`load_pinstimation_for_good()`

.

To automatically load PINstimation, run
`load_pinstimation_for_good()`

, and the following code will
be added to your .R profile.

`if (interactive()) suppressMessages(require(PINstimation))`

After restart of the R session, PINstimation will be loaded
automatically, whenever a new R session is started. To remove the
automatic loading of PINstimation, just open the .R profile for editing
`usethis::edit_r_profile()`

, find the code above, and delete
it.

## Resources

For a smooth introduction to, and useful tips on the main functionalities of the package, please refer to:

- The sections Get Started, and Online documentation on the package site.
- The package documentation in PDF format is available for download here.
- An overview of the scientific research underlying the package is available here.

## Contributions

The package makes a series of original contributions to the literature:

An

**efficient, user-friendly, and comprehensive implementation**of the standard models of probability of informed trading.A

**first implementation of the estimation of the multilayer probability of informed trading (MPIN)**as developed by Ersan (2016).A comprehensive treatment of the

**estimation of the adjusted probability of informed trading**as introduced by Duarte and Young (2009). This includes the implementation of the factorization of the AdjPIN likelihood function, various algorithms to generate initial parameter sets, and MLE method.The introduction of

**the expectation-conditional maximization (ECM) algorithm**as an alternative method to estimate the models of probability of informed trading. The contribution is both theoretical and computational. The theoretical contribution is included in the paper by Ghachem and Ersan (2022b). The implementation of the ECM algorithm allows the estimation of PIN, MPIN, as well as the adjusted PIN model.Implementation of three

**layer-detection algorithms**, namely of preexistent algorithm of Ersan (2016), as well as two newly developed algorithms, described in Ersan and Ghachem (2022a), and Ghachem and Ersan (2022b), respectively.A

**first implementation of the estimation of the volume-synchronized probability of informed trading (VPIN)**as introduced by Easley et al (2011, 2012).**One do-it-all function for trade classification**in buyer-initiated or seller-initiated trades that implements the standard algorithms in the field, namely`Tick`

,`Quote`

,`LR`

, and`EMO`

.

## Alternative packages

To our knowledge, there are two preexisting R packages for the estimation of the probability of informed trading: pinbasic, and InfoTrad.

## Getting help

If you encounter a clear bug, please file an issue with a minimal reproducible example on GitHub.