Class LiquidityMeasures

java.lang.Object
com.quantfinlib.microstructure.LiquidityMeasures

public final class LiquidityMeasures extends Object
Liquidity estimated from BARS ALONE — the estimators for every market where you have prices but no quotes: history before your tick capture started, less-developed markets, bonds marked once a day, or a 20-year backtest that would otherwise pretend spreads were zero.
  • Roll (1984) — the effective spread implied by bid-ask BOUNCE: trade prices ping-ponging between bid and ask create negative autocovariance in price changes, and s = 2√(−cov(Δp_t, Δp_{t−1})). When the autocovariance is POSITIVE (trending sample, no bounce signature) the estimator is undefined and returns NaN — not zero, because "zero spread" is a claim and NaN is an honest shrug;
  • Corwin-Schultz (2012) — the spread from two days' HIGH-LOW ranges: variance grows with time but the spread does not, so comparing one 2-day range against two 1-day ranges isolates the spread. Negative estimates clamp to 0 (standard practice, stated);
  • Amihud (2002) — price impact per currency unit traded: mean(|return| / dollarVolume). The cross-sectional illiquidity ranker — multiply by 1e6 for the conventional "per million" quotation.

Static, deterministic, research lane. These are ESTIMATORS with real sampling error on short windows — rank with them, do not mark books with them.

  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    amihudIlliquidity(double[] returns, double[] dollarVolumes)
    Amihud illiquidity: mean(|return| / dollarVolume) — return per currency unit traded.
    static double
    corwinSchultzSpread(double high1, double low1, double high2, double low2)
    Corwin-Schultz high-low spread estimate as a FRACTION of price, from two consecutive periods' highs and lows.
    static double
    rollSpread(double[] prices)
    Roll's implied effective spread from trade/close prices (same units as the prices).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • rollSpread

      public static double rollSpread(double[] prices)
      Roll's implied effective spread from trade/close prices (same units as the prices). NaN when the bounce signature is absent — see class doc.
      Parameters:
      prices - ≥ 3 finite positive prices
    • corwinSchultzSpread

      public static double corwinSchultzSpread(double high1, double low1, double high2, double low2)
      Corwin-Schultz high-low spread estimate as a FRACTION of price, from two consecutive periods' highs and lows. Negative estimates clamp to 0 (stated standard practice).
    • amihudIlliquidity

      public static double amihudIlliquidity(double[] returns, double[] dollarVolumes)
      Amihud illiquidity: mean(|return| / dollarVolume) — return per currency unit traded. Zero-volume periods are a data problem, not an infinity: they throw.
      Parameters:
      returns - per-period returns (fractions), finite
      dollarVolumes - per-period traded value, > 0, aligned