PINE LIBRARY

LibBrSt

70
Library "LibBrSt"
This is a library for quantitative analysis, designed to estimate
the statistical properties of price movements *within* a single
OHLC bar, without requiring access to tick data. It provides a
suite of estimators based on various statistical and econometric
models, allowing for analysis of intra-bar volatility and
price distribution.

Key Capabilities:

1. **Price Distribution Models (`PriceEst`):** Provides a selection
of estimators that model intra-bar price action as a probability
distribution over the [High, Low] range. This allows for the
calculation of the intra-bar mean (`priceMean`) and standard
deviation (`priceStdDev`) in absolute price units. Models include:
- **Symmetric Models:** `uniform`, `triangular`, `arcsine`,
`betaSym`, and `t4Sym` (Student-t with fat tails).
- **Skewed Models:** `betaSkew` and `t4Skew`, which adjust
their shape based on the Open/Close position.
- **Model Assumptions:** The skewed models rely on specific
internal constants. `betaSkew` uses a fixed concentration
parameter (`BETA_SKEW_CONCENTRATION = 4.0`), and `t4Sym`/`t4Skew`
use a heuristic scaling factor (`T4_SHAPE_FACTOR`)
to map the distribution.

2. **Econometric Log-Return Estimators (`LogEst`):** Includes a set of
econometric estimators for calculating the volatility (`logStdDev`)
and drift (`logMean`) of logarithmic returns within a single bar.
These are unit-less measures. Models include:
- **Parkinson (1980):** A High-Low range estimator.
- **Garman-Klass (1980):** An OHLC-based estimator.
- **Rogers-Satchell (1991):** An OHLC estimator that accounts
for non-zero drift.

3. **Distribution Analysis (PDF/CDF):** Provides functions to work
with the Probability Density Function (`pricePdf`) and
Cumulative Distribution Function (`priceCdf`) of the
chosen price model.
- **Note on `priceCdf`:** This function uses analytical (exact)
calculations for the `uniform`, `triangular`, and `arcsine`
models. For all other models (e.g., `betaSkew`, `t4Skew`),
it uses **numerical integration (Simpson's rule)** as
an approximation of the cumulative probability.

4. **Mathematical Functions:** The library's Beta distribution
models (`betaSym`, `betaSkew`) are supported by an internal
implementation of the natural log-gamma function, which is
based on the Lanczos approximation.

---

**DISCLAIMER**

This library is provided "AS IS" and for informational and
educational purposes only. It does not constitute financial,
investment, or trading advice.

The author assumes no liability for any errors, inaccuracies,
or omissions in the code. Using this library to build
trading indicators or strategies is entirely at your own risk.

As a developer using this library, you are solely responsible
for the rigorous testing, validation, and performance of any
scripts you create based on these functions. The author shall
not be held liable for any financial losses incurred directly
or indirectly from the use of this library or any scripts
derived from it.

priceStdDev(estimator, offset)
  Estimates **σ̂** (standard deviation) *in price units* for the current
bar, according to the chosen `PriceEst` distribution assumption.
  Parameters:
    estimator (series PriceEst): series PriceEst Distribution assumption (see enum).
    offset (int): series int To offset the calculated bar
  Returns: series float σ̂ ≥ 0 ; `na` if undefined (e.g. zero range).

priceMean(estimator, offset)
  Estimates **μ̂** (mean price) for the chosen `PriceEst` within the
current bar.
  Parameters:
    estimator (series PriceEst): series PriceEst Distribution assumption (see enum).
    offset (int): series int To offset the calculated bar
  Returns: series float μ̂ in price units.

pricePdf(estimator, price, offset)
  Probability-density under the chosen `PriceEst` model.
**Returns 0** when `p` is outside the current bar’s [High, Low].
  Parameters:
    estimator (series PriceEst): series PriceEst Distribution assumption (see enum).
    price (float): series float Price level to evaluate.
    offset (int): series int To offset the calculated bar
  Returns: series float Density value.

priceCdf(estimator, upper, lower, steps, offset)
  Cumulative probability **between** `upper` and `lower` under
the chosen `PriceEst` model. Outside-bar regions contribute zero.
Uses a fast, analytical calculation for Uniform, Triangular, and
Arcsine distributions, and defaults to numerical integration
(Simpson's rule) for more complex models.
  Parameters:
    estimator (series PriceEst): series PriceEst Distribution assumption (see enum).
    upper (float): series float Upper Integration Boundary.
    lower (float): series float Lower Integration Boundary.
    steps (int): series int # of sub-intervals for numerical integration (if used).
    offset (int): series int To offset the calculated bar.
  Returns: series float Probability mass ∈ [0,1].

logStdDev(estimator, offset)
  Estimates **σ̂** (standard deviation) of *log-returns* for the current bar.
  Parameters:
    estimator (series LogEst): series LogEst Distribution assumption (see enum).
    offset (int): series int To offset the calculated bar
  Returns: series float σ̂ (unit-less); `na` if undefined.

logMean(estimator, offset)
  Estimates μ̂ (mean log-return / drift) for the chosen `LogEst`.
The returned value is consistent with the assumptions of the
selected volatility estimator.
  Parameters:
    estimator (series LogEst): series LogEst Distribution assumption (see enum).
    offset (int): series int To offset the calculated bar
  Returns: series float μ̂ (unit-less log-return).

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。