permutation_test

Defined in fynance.research

permutation_test(strategy, data, *, metric='sharpe', n_permutations=200, seed=0)[source]

Permutation test for a spurious edge.

Runs the strategy on the real series, then on n_permutations shuffles of the asset’s returns (which destroys any temporal structure). If the strategy scores as well on shuffled data as on the real data, its edge is not real.

Parameters:
strategyfynance.strategy.Strategy

The strategy to evaluate.

dataPriceSeries or array-like

Price series.

metricstr

Metric key from the run summary (default "sharpe").

n_permutationsint

Number of shuffles forming the null distribution.

seedint

Seed for the shuffles and the runs.

Returns:
dict

observed, p_value, null_mean, null_std. The p-value is the (smoothed) fraction of shuffles scoring at least the observed metric.