shallow focus photography of computer codes

Using SciPy’s Wilcoxon Signed-Rank Test for Cryptocurrency Strategy Evaluation

When evaluating trading strategies in cryptocurrency markets, robust statistical methods are essential. SciPy’s implementation of the Wilcoxon Signed-Rank Test provides an ideal tool for this purpose. This article explains why this library is particularly well-suited for cryptocurrency analysis and highlights the key parameters that analysts can modify to tailor the test to their specific needs.

Why SciPy for Wilcoxon Testing?

The SciPy library offers several compelling advantages for cryptocurrency strategy evaluation:

  1. Non-parametric approach: Unlike tests that assume normal distribution, SciPy’s Wilcoxon implementation makes no assumptions about the underlying data distribution, making it ideal for cryptocurrency returns which often exhibit non-normal characteristics.
  2. Robust to outliers: Cryptocurrency markets frequently experience extreme price movements. The Wilcoxon test uses ranks rather than actual values, making it less sensitive to these outliers than parametric tests.
  3. Well-documented and maintained: As part of the SciPy ecosystem, the implementation receives regular updates, has extensive documentation, and is widely used in scientific and financial research.
  4. Integration with pandas: SciPy works seamlessly with pandas DataFrames, allowing for straightforward analysis of time series data common in cryptocurrency trading.
  5. Computational efficiency: The implementation is optimized for performance, enabling quick analysis of large datasets spanning multiple years of trading data.

Key Parameters for Customization

SciPy’s Wilcoxon implementation (scipy.stats.wilcoxon) offers several parameters that analysts can modify:

    
      wilcoxon(
          x, 
          y=None, 
          zero_method='wilcox', 
          correction=False, 
          alternative='two-sided', 
          mode='auto'
      )
    
  

1. Treatment of Zero Differences (zero_method)

  • ‘wilcox’ (default): Discards pairs with zero difference
  • ‘pratt’: Includes zero differences in the ranking
  • ‘zsplit’: Splits zeros evenly between positive and negative ranks

For cryptocurrency strategy comparison, the choice depends on how you want to treat trading days where both strategies perform identically. ‘wilcox’ is typically preferred as it focuses only on days with performance differences.

2. Continuity Correction (correction)

  • False (default): No continuity correction applied
  • True: Applies continuity correction for better approximation

When analyzing larger datasets (>20 pairs), continuity correction makes little difference. For smaller samples of trading days, setting this to True can improve accuracy.

3. Alternative Hypothesis (alternative)

  • ‘two-sided’ (default): Tests if strategies differ in either direction
  • ‘greater’: Tests if the first strategy outperforms the second
  • ‘less’: Tests if the first strategy underperforms the second

The choice depends on your research question. When comparing a new algorithm against a benchmark, ‘greater’ tests specifically whether the new strategy is superior, while ‘two-sided’ merely tests for any difference.

4. Testing Mode (mode)

  • ‘auto’ (default): Automatically selects exact or approximate test
  • ‘exact’: Uses exact distribution of the test statistic
  • ‘approx’: Uses normal approximation

For most cryptocurrency strategy evaluations, ‘auto’ works well, as it uses the exact calculation for smaller samples and switches to approximation for larger datasets.

Practical Considerations

When applying the Wilcoxon test to cryptocurrency strategies, consider these adjustments:

  1. For highly volatile markets like Bitcoin, use zero_method='pratt' if frequent days with identical returns occur.
  2. When evaluating strategies across different market conditions, consider using alternative='greater' during bull markets and alternative='less' during bear markets to test specific directional advantages.
  3. For new coins with limited historical data, use correction=True to improve the accuracy of the test with smaller sample sizes.

By understanding and appropriately configuring these parameters, cryptocurrency analysts can extract more meaningful insights from their strategy comparisons, leading to more informed trading decisions backed by robust statistical evidence.