Library "GaussianDistribution" This library defines a custom type `distr` representing a Gaussian (or other statistical) distribution. It provides methods to calculate key statistical moments and scores, including mean, median, mode, standard deviation, variance, skewness, kurtosis, and Z-scores. This library is useful for analyzing probability distributions in financial data.
Disclaimer: I am not a mathematician, but I have implemented this library to the best of my understanding and capacity. Please be indulgent as I tried to translate statistical concepts into code as accurately as possible. Feedback, suggestions, and corrections are welcome to improve the reliability and robustness of this library.
mean(source, length) Calculate the mean (average) of the distribution Parameters: source (float): Distribution source (typically a price or indicator series) length (int): Window length for the distribution (must be >= 30 for meaningful statistics) Returns: Mean (μ)
stdev(source, length) Calculate the standard deviation (σ) of the distribution Parameters: source (float): Distribution source (typically a price or indicator series) length (int): Window length for the distribution (must be >= 30 for meaningful statistics) Returns: Standard deviation (σ)
skewness(source, length, mean, stdev) Calculate the skewness (γ₁) of the distribution Parameters: source (float): Distribution source (typically a price or indicator series) length (int): Window length for the distribution (must be >= 30 for meaningful statistics) mean (float): the mean (average) of the distribution stdev (float): the standard deviation (σ) of the distribution return Skewness (γ₁)
skewness(source, length) Overloaded skewness to calculate from source and length Parameters: source (float): Distribution source (typically a price or indicator series) length (int): Window length for the distribution (must be >= 30 for meaningful statistics) return Skewness (γ₁)
mode(mean, stdev, skewness) Estimate mode - Most frequent value in the distribution (approximation based on skewness) Parameters: mean (float): the mean (average) of the distribution stdev (float): the standard deviation (σ) of the distribution skewness (float): the skewness (γ₁) of the distribution return Mode
mode(source, length) Overloaded mode to calculate from source and length Parameters: source (float): Distribution source (typically a price or indicator series) length (int): Window length for the distribution (must be >= 30 for meaningful statistics) return Mode
median(mean, stdev, skewness) Estimate median - Middle value of the distribution (approximation) Parameters: mean (float): the mean (average) of the distribution stdev (float): the standard deviation (σ) of the distribution skewness (float): the skewness (γ₁) of the distribution return Median
median(source, length) Overloaded median to calculate from source and length Parameters: source (float): Distribution source (typically a price or indicator series) length (int): Window length for the distribution (must be >= 30 for meaningful statistics) return Median
variance(stdev) Calculate variance (σ²) - Square of the standard deviation Parameters: stdev (float): the standard deviation (σ) of the distribution return Variance (σ²)
variance(source, length) Overloaded variance to calculate from source and length Parameters: source (float): Distribution source (typically a price or indicator series) length (int): Window length for the distribution (must be >= 30 for meaningful statistics) return Variance (σ²)
kurtosis(source, length, mean, stdev) Calculate kurtosis (γ₂) - Degree of "tailedness" in the distribution Parameters: source (float): Distribution source (typically a price or indicator series) length (int): Window length for the distribution (must be >= 30 for meaningful statistics) mean (float): the mean (average) of the distribution stdev (float): the standard deviation (σ) of the distribution return Kurtosis (γ₂)
kurtosis(source, length) Overloaded kurtosis to calculate from source and length Parameters: source (float): Distribution source (typically a price or indicator series) length (int): Window length for the distribution (must be >= 30 for meaningful statistics) return Kurtosis (γ₂)
normal_score(source, mean, stdev) Calculate Z-score (standard score) assuming a normal distribution Parameters: source (float): Distribution source (typically a price or indicator series) mean (float): the mean (average) of the distribution stdev (float): the standard deviation (σ) of the distribution return Z-Score
normal_score(source, length) Overloaded normal_score to calculate from source and length Parameters: source (float): Distribution source (typically a price or indicator series) length (int): Window length for the distribution (must be >= 30 for meaningful statistics) return Z-Score
non_normal_score(source, mean, stdev, skewness, kurtosis) Calculate adjusted Z-score considering skewness and kurtosis Parameters: source (float): Distribution source (typically a price or indicator series) mean (float): the mean (average) of the distribution stdev (float): the standard deviation (σ) of the distribution skewness (float): the skewness (γ₁) of the distribution kurtosis (float): the "tailedness" in the distribution return Z-Score
non_normal_score(source, length) Overloaded non_normal_score to calculate from source and length Parameters: source (float): Distribution source (typically a price or indicator series) length (int): Window length for the distribution (must be >= 30 for meaningful statistics) return Z-Score
method init(this) Initialize all statistical fields of the `distr` type Namespace types: distr Parameters: this (distr)
method init(this, source, length) Overloaded initializer to set source and length Namespace types: distr Parameters: this (distr) source (float) length (int)
distr Custom type to represent a Gaussian distribution Fields: source (series float): Distribution source (typically a price or indicator series) length (series int): Window length for the distribution (must be >= 30 for meaningful statistics) mode (series float): Most frequent value in the distribution median (series float): Middle value separating the greater and lesser halves of the distribution mean (series float): μ (1st central moment) - Average of the distribution stdev (series float): σ or standard deviation (square root of the variance) - Measure of dispersion variance (series float): σ² (2nd central moment) - Squared standard deviation skewness (series float): γ₁ (3rd central moment) - Asymmetry of the distribution kurtosis (series float): γ₂ (4th central moment) - Degree of "tailedness" relative to a normal distribution normal_score (series float): Z-score assuming normal distribution non_normal_score (series float): Adjusted Z-score considering skewness and kurtosis
진정한 TradingView 정신에 따라, 저자는 이 파인 코드를 다른 파인 프로그래머들이 재사용할 수 있도록 오픈 소스 라이브러리로 공개했습니다. 저자에게 박수를 보냅니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈 소스 출판물에서 사용할 수 있지만, 이 코드를 출판물에서 재사용하는 것은 하우스 룰에 의해 관리됩니다.