Environment:AI4Finance Foundation FinGPT SciPy
| Knowledge Sources | |
|---|---|
| Domains | Scientific_Computing, Portfolio_Analytics |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
SciPy scientific computing library used by the vendored pyfolio package's `timeseries` module for statistical significance tests, distribution functions, and numerical computations in risk metric calculation.
Description
This environment covers the `scipy` dependency used by pyfolio's `timeseries` module. The module uses `scipy.stats` for calculating p-values, t-tests, and probability distributions when computing risk metrics like Sharpe ratio significance, Value at Risk (VaR), and conditional VaR (CVaR). These statistical functions complement the basic pandas-based metric computations.
Usage
Use this environment for statistical analysis within portfolio performance evaluation. Required by the pyfolio timeseries module for risk metric computation.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Any | Cross-platform |
| Python | >= 3.8 | 3.10+ recommended |
| Hardware | CPU sufficient | No GPU needed |
Dependencies
Python Packages
- `scipy` >= 1.10.0
- `numpy` < 2 (see Environment:AI4Finance_Foundation_FinGPT_Python)
- `pandas` >= 1.5.0 (see Environment:AI4Finance_Foundation_FinGPT_Pandas)
Credentials
No credentials required.
Quick Install
pip install "scipy>=1.10.0"
Code Evidence
Statistical tests from `pyfolio/timeseries.py`:
from scipy import stats
def sharpe_ratio(returns, risk_free=0, period='daily'):
...
p_val = stats.t.sf(Sharpe_ratio, n - 1) * 2
...
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `ImportError: scipy.stats` | SciPy not installed | `pip install scipy` |
| `RuntimeWarning: invalid value` | NaN in returns data | Drop NaN values before computing metrics |
Compatibility Notes
- NumPy pin: Must use `numpy<2` for SciPy compatibility.
- Stats module: All statistical functions are in `scipy.stats`.