Coder Social home page Coder Social logo

monty-se / pinstimation Goto Github PK

View Code? Open in Web Editor NEW
30.0 2.0 6.0 5.41 MB

A comprehensive bundle of utilities for the estimation of probability of informed trading models: original 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). Implementations of various estimation methods suggested in the literature are included. Additional compelling features comprise posterior probabilities, an implementation of an expectation-maximization (EM) algorithm, and PIN decomposition into layers, and into bad/good components. Versatile data simulation tools, and trade classification algorithms are among the supplementary utilities. The package provides fast, compact, and precise utilities to tackle the sophisticated, error-prone, and time-consuming estimation procedure of informed trading, and this solely using the raw trade-level data.

Home Page: https://pinstimation.com/

License: GNU General Public License v3.0

R 92.07% TeX 7.56% JavaScript 0.04% CSS 0.34%
clustering-analysis expectation-maximisation-algorithm hierarchical-clustering information-asymmetry market-microstructure maximum-likelihood-estimation mixture-distributions poisson-distribution

pinstimation's People

Contributors

monty-se avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pinstimation's Issues

`.lwbound` is assigned to the global environment [PATCH]

Hi,

I'm running reverse-dependency checks for the future package, where I'm looking for code that assigns variables to the global environment. Depending on how it's used, doing so in parallel processing might not give the result that is expected. While doing this scan, I've got:

* checking re-building of vignette outputs ... ERROR
  Error(s) in re-building vignettes:
    ...
  --- re-buildingPINstimation.rmdusing rmarkdown
  Quitting from lines 255-256 (PINstimation.rmd) 
  Error: processing vignette 'PINstimation.rmd' failed with diagnostics:
  Future (<none>) added variables to the global environment. A future expression should never assign variables to the global environment - neither 
 assign() nor by <<-: [n=1] '.lwbound'
  --- failed re-buildingPINstimation.rmd--- re-buildingparallel_processing.rmdusing rmarkdown
  Quitting from lines 81-84 (parallel_processing.rmd) 
  Error: processing vignette 'parallel_processing.rmd' failed with diagnostics:
  Future (<none>) added variables to the global environment. A future expression should never assign variables to the global environment - neither 
 assign() nor by <<-: [n=1] '.lwbound'
  --- failed re-buildingparallel_processing.rmdSUMMARY: processing the following files failed:PINstimation.rmd’ ‘parallel_processing.rmdError: Vignette re-building failed.
  Execution halted

This appears to come from:

.get_lagged_value <- function(cindex) {
if (!exists(".lwbound") || cindex == 1) .lwbound <- 1
pasttimes <- data$timestamp[.lwbound:cindex]
currenttime <- data$timestamp[cindex]
threshold <- currenttime - (timelag / 1000)
atorbelowthreshold <- .lwbound - 1 + findInterval(threshold, pasttimes)
atorbelowthreshold <- max(atorbelowthreshold, 0)
.lwbound <<- atorbelowthreshold
if (verbose) setTxtProgressBar(pblagged, cindex)
return(atorbelowthreshold)
}

FYI, a better way to achieve the same without assigning to the global environment is to do:

.get_lagged_value <- local({
  .lwbound <- 1
                           
  function(cindex) {
    if (cindex == 1) .lwbound <- 1
  
    pasttimes <- data$timestamp[.lwbound:cindex]
  
    currenttime <- data$timestamp[cindex]
  
    threshold <- currenttime - (timelag / 1000)
  
    atorbelowthreshold <- .lwbound - 1 + findInterval(threshold, pasttimes)
  
    atorbelowthreshold <- max(atorbelowthreshold, 0)
  
    .lwbound <<- atorbelowthreshold
  
    if (verbose) setTxtProgressBar(pblagged, cindex)
  
    return(atorbelowthreshold)
  }
})

Please do not change future options

Hello. Please do not set future options from within your package, as in:

options(future.globals.maxSize = +Inf)

This might have unintended side effects for other packages and risk producing incorrect results elsewhere. R options are meant for end-users, not developers. If you need to tweak the settings, please do so temporarily, as explained in https://future.futureverse.org/articles/future-7-for-package-developers.html#avoid-changing-the-future-options.

Undoing future plan()

Hi, congrats to your CRAN release.

Issue

I noticed that you use:

future::plan(
multisession, gc = TRUE, workers = .default$parallel_cores())
laggedindices <- furrr::future_map(xs, .get_lagged_value)
laggedindices <- unlist(laggedindices)
future::plan(sequential)

to "undo" the future plan. There are two problems with this approach:

  1. The user might have another plan than 'sequential' set before they call your function
  2. If there's an error before you get to undo the plan, the plan will never be reset

Solution

A better, straightforward approach is explained Section 'For package developers' of ?future::plan.

No rush, but please consider fixing this for your next release.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.