PINE LIBRARY
Diupdate

CausalityLib - granger casuality and transfer entropy helpers

557
Library "CausalityLib"
Causality Analysis Library - Transfer Entropy, Granger Causality, and Causality Filtering

f_shannon_entropy(data, num_bins)
  Calculate Shannon entropy of data distribution
  Parameters:
    data (array<float>): Array of continuous values
    num_bins (int): Number of bins for discretization
  Returns: Entropy value (higher = more randomness)

f_calculate_te_score(primary_arr, ticker_arr, window, bins, lag)
  Calculate Transfer Entropy from source to target
  Parameters:
    primary_arr (array<float>): Target series (e.g., primary ticker returns)
    ticker_arr (array<float>): Source series (e.g., basket ticker returns)
    window (int): Window size for TE calculation
    bins (int): Number of bins for discretization
    lag (int): Lag for source series
  Returns: [te_score, direction] - TE score and direction (-1 or 1)

f_correlation_at_lag(primary_arr, ticker_arr, lag, window, correlation_method)
  Calculate Pearson correlation at specific lag
  Parameters:
    primary_arr (array<float>): Primary series
    ticker_arr (array<float>): Ticker series
    lag (int): Lag value (positive = ticker lags primary)
    window (int): Window size for correlation
    correlation_method (string): Correlation method to use ("Pearson", "Spearman", "Kendall")
  Returns: Correlation coefficient [-1, 1]

f_calculate_granger_score(primary_arr, ticker_arr, window, max_lag, correlation_method)
  Calculate Granger causality score with lag testing
  Parameters:
    primary_arr (array<float>): Primary series
    ticker_arr (array<float>): Ticker series
    window (int): Window size for correlation
    max_lag (int): Maximum lag to test
    correlation_method (string): Correlation method to use
  Returns: [granger_score, beta_sum] - Granger score and directional beta

f_partial_correlation(x_arr, y_arr, z_arr, window)
  Calculate partial correlation between X and Y controlling for Z
  Parameters:
    x_arr (array<float>): First series
    y_arr (array<float>): Second series
    z_arr (array<float>): Mediator series
    window (int): Window size for correlation
  Returns: Partial correlation coefficient [-1, 1]

f_pcmci_filter_score(raw_score, primary_arr, ticker_arr, mediator1, mediator2, mediator3, mediator4, window)
  PCMCI Filter: Adjust Granger score by checking for mediating tickers
  Parameters:
    raw_score (float): Original Granger score
    primary_arr (array<float>): Primary series
    ticker_arr (array<float>): Ticker series
    mediator1 (array<float>): First potential mediator series
    mediator2 (array<float>): Second potential mediator series
    mediator3 (array<float>): Third potential mediator series
    mediator4 (array<float>): Fourth potential mediator series
    window (int): Window size for correlation
  Returns: Filtered score (reduced if causality is indirect/spurious)
Catatan Rilis
v2

Updated:
f_calculate_granger_score(primary_arr, ticker_arr, window, max_lag, correlation_method)
  Calculate Granger causality score with lag testing
  Parameters:
    primary_arr (array<float>): Primary series
    ticker_arr (array<float>): Ticker series
    window (int): Window size for correlation
    max_lag (int): Maximum lag to test
    correlation_method (string): Correlation method to use
  Returns: [granger_score, beta_sum, best_lag] - Granger score, directional beta, and best lag (highest |correlation|)
Catatan Rilis
v3
Catatan Rilis
v4

Added:
f_discretize(data, bins)
  Discretize continuous data into bins (for entropy calculations)
  Parameters:
    data (array<float>): Array of continuous values
    bins (int): Number of bins
  Returns: Array of bin indices
Catatan Rilis
v5

Added:
f_shannon_entropy_v2(data, num_bins)
  Calculate Shannon entropy of data distribution using explicit discretize->probability pipeline
  Parameters:
    data (array<float>): Array of continuous values
    num_bins (int): Number of bins for discretization
  Returns: Entropy value (higher = more randomness)

f_calculate_te_score_v2(primary_arr, ticker_arr, window, bins, lag)
  Calculate Transfer Entropy from source to target using normalized TE formulation
  Parameters:
    primary_arr (array<float>): Target series (e.g., primary ticker returns)
    ticker_arr (array<float>): Source series (e.g., basket ticker returns)
    window (int): Window size for TE calculation
    bins (int): Number of bins for discretization
    lag (int): Lag for source series
  Returns: [te_score, direction] - normalized TE score and direction (-1 or 1)
Catatan Rilis
v6

Added:
f_calculate_te_multilag(primary_arr, ticker_arr, window, bins, max_lag)
  Parameters:
    primary_arr (array<float>)
    ticker_arr (array<float>)
    window (int)
    bins (int)
    max_lag (int)

f_calculate_te_gated(primary_arr, ticker_arr, window, bins, max_lag, coupling_damping, coupling_floor)
  Parameters:
    primary_arr (array<float>)
    ticker_arr (array<float>)
    window (int)
    bins (int)
    max_lag (int)
    coupling_damping (float)
    coupling_floor (float)

f_calculate_net_te(primary_arr, ticker_arr, window, bins, lag)
  Parameters:
    primary_arr (array<float>)
    ticker_arr (array<float>)
    window (int)
    bins (int)
    lag (int)

f_kalman_hedge_ratio(measurement, observation, prev_beta, prev_P, Q, R)
  Parameters:
    measurement (float)
    observation (float)
    prev_beta (float)
    prev_P (float)
    Q (float)
    R (float)
Catatan Rilis
v7

Added:
f_compute_te_ensemble(pri_arr, b1, b2, b3, b4, b5, window, bins, smoothing, self1, self2, self3, self4, self5, use5)
  Parameters:
    pri_arr (array<float>)
    b1 (array<float>)
    b2 (array<float>)
    b3 (array<float>)
    b4 (array<float>)
    b5 (array<float>)
    window (int)
    bins (int)
    smoothing (simple int)
    self1 (bool)
    self2 (bool)
    self3 (bool)
    self4 (bool)
    self5 (bool)
    use5 (bool)
Catatan Rilis
v8

Updated:
f_compute_te_ensemble(pri_arr, b1, b2, b3, b4, b5, window, bins, smoothing, self1, self2, self3, self4, self5, use5)
  Parameters:
    pri_arr (array<float>)
    b1 (array<float>)
    b2 (array<float>)
    b3 (array<float>)
    b4 (array<float>)
    b5 (array<float>)
    window (int)
    bins (int)
    smoothing (int)
    self1 (bool)
    self2 (bool)
    self3 (bool)
    self4 (bool)
    self5 (bool)
    use5 (bool)
Catatan Rilis
v9

Added:
f_calculate_te_score_debug(primary_arr, ticker_arr, window, bins, lag)
  Calculate Transfer Entropy with diagnostics for debugging data sufficiency and bin occupancy
  Parameters:
    primary_arr (array<float>): Target series (e.g., primary ticker returns)
    ticker_arr (array<float>): Source series (e.g., basket ticker returns)
    window (int): Window size for TE calculation
    bins (int): Number of bins for discretization
    lag (int): Lag for source series
  Returns: [te_score, direction, win_size, valid_count, min_x, max_x, min_y, max_y, b0_share, b1_share, b2_share, b3_share, b4_share, b5_share, b6_share, b7_share]
Catatan Rilis
v10
Catatan Rilis
v11
Catatan Rilis
v12
Catatan Rilis
v13

Updated:
f_compute_te_ensemble(pri_arr, b1, b2, b3, b4, b5, window, bins, smoothing, self1, self2, self3, self4, self5, use5)
  Parameters:
    pri_arr (array<float>)
    b1 (array<float>)
    b2 (array<float>)
    b3 (array<float>)
    b4 (array<float>)
    b5 (array<float>)
    window (int)
    bins (int)
    smoothing (simple int)
    self1 (bool)
    self2 (bool)
    self3 (bool)
    self4 (bool)
    self5 (bool)
    use5 (bool)
Catatan Rilis
v14

Added:
f_compute_te_wrapper(te_primary, te_b1, te_b2, te_b3, te_b4, te_win, te_b, te_smooth, self1, self2, self3, self4, is_hard, bar_idx)
  Wrapper for Transfer Entropy calculation with ensemble and fallback logic
  Parameters:
    te_primary (array<float>): Primary asset return array
    te_b1 (array<float>): Basket asset 1 return array
    te_b2 (array<float>): Basket asset 2 return array
    te_b3 (array<float>): Basket asset 3 return array
    te_b4 (array<float>): Basket asset 4 return array
    te_win (int): TE window size
    te_b (int): TE bins count
    te_smooth (simple int): TE smoothing length
    self1 (bool): Whether basket 1 is self-reference
    self2 (bool): Whether basket 2 is self-reference
    self3 (bool): Whether basket 3 is self-reference
    self4 (bool): Whether basket 4 is self-reference
    is_hard (bool): Whether in hard zone (recent bars)
    bar_idx (int): Current bar index
  Returns: [te_osc, te_strength, te_direction] - TE oscillator, strength, and direction
Catatan Rilis
v15
Catatan Rilis
v16

Added:
fmobiusnew()

fmobiusupdate(st, cur, prev, alpha)
  Parameters:
    st (MobiusState)
    cur (float)
    prev (float)
    alpha (float)

fmobiuscompose(s1, s2)
  Parameters:
    s1 (MobiusState)
    s2 (MobiusState)

fmobiusapply(st, x)
  Parameters:
    st (MobiusState)
    x (float)

fcausalcovupdate(sigma_tri, state, mu, net_te, te_threshold, alpha)
  Parameters:
    sigma_tri (array<float>)
    state (array<float>)
    mu (array<float>)
    net_te (float)
    te_threshold (float)
    alpha (float)

fcausalweights(te0, te1, te2, alpha)
  Parameters:
    te0 (float)
    te1 (float)
    te2 (float)
    alpha (float)

MobiusState
  Fields:
    a (series float)
    b (series float)
    c (series float)
Catatan Rilis
v17

Added:
fharrvforecast(rv_buffer, beta_d, beta_w, beta_m)
  Parameters:
    rv_buffer (array<float>)
    beta_d (float)
    beta_w (float)
    beta_m (float)

fdurbinwatson(window)
  Parameters:
    window (array<float>)

fpcaexplained(cov_tri, shrinkage)
  Parameters:
    cov_tri (array<float>)
    shrinkage (float)

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.