safepine_os.math.statistics

Members

Functions

compute_autocorrelation
double compute_autocorrelation(double[] array_IN, int tao)

Summary: Computes the autocorrelation of an input array at a specified lag (τ). The function measures how correlated a signal is with a delayed version of itself.

compute_correlation
double compute_correlation(double[] array_x_IN, double[] array_y_IN)

Summary: Computes the Pearson correlation coefficient between two input arrays. The correlation coefficient measures the linear relationship between two datasets, ranging from -1 (perfect negative correlation) to +1 (perfect positive correlation).

compute_correlogram
double[] compute_correlogram(double[] array_IN)

Summary: Computes the correlogram (autocorrelation function) of an input array over multiple lags. The function calculates autocorrelation values for lag values ranging from 0 to n/5, where n is the length of the input array.

compute_geometric_average
double compute_geometric_average(double[] array_IN)

Summary: Computes the geometric average (also known as the geometric mean) of an input array. The function applies a logarithmic transformation to the input values before computing the mean.

compute_histogram
auto compute_histogram(R numbers, ulong bins_length)

Summary: Computes a histogram by binning numerical values into a specified number of intervals (bins_length). The function normalizes input values and counts occurrences within each bin.

compute_mean
double compute_mean(double[] array_IN)

Summary: Computes the arithmetic mean (average) of an input array.

compute_mean_std
auto compute_mean_std(R numbers)

Summary: Computes both the arithmetic mean and standard deviation of a given range of numbers in a single pass. This function is optimized for performance by avoiding multiple iterations over the data.

compute_ordinary_least_squares
double[2] compute_ordinary_least_squares(double[] array_x_IN, double[] array_y_IN)

Summary: Computes the Ordinary Least Squares (OLS) regression coefficients for a simple linear regression model. The function finds the best-fitting line y = b1 + b2 * x that minimizes the sum of squared residuals.

compute_spread
double[] compute_spread(double[] array_a, double[] array_b, double k)

Summary: Computes the spread between two input arrays using a logarithmic transformation. The function calculates: log(array_ai) - k * log(array_bi) for each element.

compute_std
double compute_std(double[] array_IN)

Summary: Computes the standard deviation of an input array. The function calculates the square root of the variance, which measures the spread of the data relative to its mean.

compute_swings
Swings compute_swings(double[] prices_IN, string[] dates_IN, double swingPercentage_IN)

Summary: Identifies swing highs and swing lows in a time series of price data based on a given swing percentage threshold. The function detects turning points where price movement changes direction beyond the specified percentage.

compute_variance
double compute_variance(double[] array_IN)

Summary: Computes the variance of an input array. Variance measures the spread of data relative to the mean by calculating the squared deviation of each value.

compute_z_score
double[] compute_z_score(double[] array_IN)

Summary: Computes the Z-score normalization of an input array. Each element is transformed to represent how many standard deviations it is from the mean. This helps standardize data with different magnitudes or units.

generate_arma_process
double[] generate_arma_process(double alpha, double beta, int n)

Summary: Generates an AutoRegressive Moving Average (ARMA) process of order (1,1). The function simulates a time series where each value is influenced by both past values (autoregressive component) and white noise (moving average component).

generate_autoregressive_process
double[] generate_autoregressive_process(double alpha, double rho, int n)

Summary: Generates an AutoRegressive (AR) process of order 1 (AR(1)). The function models a time series where each value is influenced by the previous value, a deterministic term (alpha), and a random noise component.

generate_autoregressive_process_dice
double[] generate_autoregressive_process_dice(double alpha, double rho, double e_t, int n)

Summary: Generates an AutoRegressive (AR) process with stochastic perturbations determined by a dice-based mechanism. The function models a time series where each value is influenced by its previous value, a deterministic term (alpha), and a stochastic noise term (e_t) that randomly switches sign.

generate_gbm_process
double[] generate_gbm_process(double S0, double mu, double sigma, double dt, int n)

Summary: Generates a time series using Geometric Brownian Motion (GBM), commonly used to model asset prices. Ensures prices are always positive.

generate_moving_average_process
double[] generate_moving_average_process(double beta, int n)

Summary: Generates a Moving Average (MA) process of order 1 (MA(1)). The function simulates a time series where each value is derived from white noise and a weighted influence of the previous value.

generate_white_noise
double[] generate_white_noise(int n)

Summary: Generates an array of white noise values uniformly distributed in the range [-1.0, 1.0]. White noise consists of random values with a mean of approximately zero and no discernible pattern.

monte_carlo
double[][] monte_carlo(double[] return_distribution, int dice_rolls, int possible_futures, ulong offset)

Summary: Performs a Monte Carlo simulation to model possible future equity values based on a given return distribution. This function generates multiple possible futures by iteratively sampling returns and compounding the equity value.

print_histogram
void print_histogram(T hist)

Summary: Prints a text-based histogram representation of a given histogram dataset. The function scales the frequency of each bin into a visual bar made of asterisks (*).

sample_standard_normal
double sample_standard_normal()

Generates a single sample from the standard normal distribution (mean = 0, stddev = 1) using the Box-Muller transform.

Structs

Swings
struct Swings

Summary: Represents the results of a swing analysis, storing detected swing highs and lows along with their corresponding dates.