
Description
The tedious part after a backtest is computing the performance: Sharpe, Sortino, max drawdown, CAGR, Calmar — each a few dozen lines of pandas. Portfolio optimisation means deriving the mean-variance formula again. These functions come up on almost every quant task, yet get rewritten from scratch each time, slowly and with room for error.
ffn packages all of that into one Python library. You feed in equity or portfolio prices, and it computes returns, risk and drawdown paths, and will rebase and plot them for you. The financial functions a quant reaches for most were written and tested here a decade ago, standing on the shoulders of Pandas, NumPy and SciPy.
The two core calls: calc_stats() returns a full performance sheet in one shot — total and annualised return, Sharpe, Sortino, max drawdown, Calmar, win rate and dozens more; calc_mean_var_weights() computes Markowitz optimal weights in one line, handing you the portfolio allocation directly. It also has data download built in: `ffn.get('aapl,msft,c,gs,ge')` pulls several tickers at once and `to_returns()` converts to a return series. Drawdown series, underwater plots, correlation matrices and equity curves all plot straight from it.
As for ecosystem, the mature backtesting framework bt is built on top of ffn by the same author. MIT licensed, 2.6k stars, `pip install ffn`. Stop hand-writing performance functions.
Full stats in one call: calc_stats() returns total and annualised return, Sharpe, Sortino, max drawdown, Calmar, win rate and dozens more, so nothing is computed by hand after a backtest.
Portfolio optimisation: calc_mean_var_weights() computes Markowitz mean-variance optimal weights in one line, no formula derivation required.
Built-in data download: ffn.get() pulls historical prices for several tickers at once, with to_returns() and to_log_returns() converting them into return series.
Drawdown and risk analysis: compute drawdown series and draw underwater plots to see each loss from onset to recovery.
Plotting out of the box: equity curves, rebased comparisons and correlation heatmaps come as single method calls.
Common transforms: price to returns, resampling, period returns and rolling statistics are all provided rather than rewritten each time.
Foundation for bt: the mature bt backtesting framework is built on ffn by the same author, connecting metric computation and strategy backtesting in one chain.
ffn packages all of that into one Python library. You feed in equity or portfolio prices, and it computes returns, risk and drawdown paths, and will rebase and plot them for you. The financial functions a quant reaches for most were written and tested here a decade ago, standing on the shoulders of Pandas, NumPy and SciPy.
The two core calls: calc_stats() returns a full performance sheet in one shot — total and annualised return, Sharpe, Sortino, max drawdown, Calmar, win rate and dozens more; calc_mean_var_weights() computes Markowitz optimal weights in one line, handing you the portfolio allocation directly. It also has data download built in: `ffn.get('aapl,msft,c,gs,ge')` pulls several tickers at once and `to_returns()` converts to a return series. Drawdown series, underwater plots, correlation matrices and equity curves all plot straight from it.
As for ecosystem, the mature backtesting framework bt is built on top of ffn by the same author. MIT licensed, 2.6k stars, `pip install ffn`. Stop hand-writing performance functions.
Features
Full stats in one call: calc_stats() returns total and annualised return, Sharpe, Sortino, max drawdown, Calmar, win rate and dozens more, so nothing is computed by hand after a backtest.
Portfolio optimisation: calc_mean_var_weights() computes Markowitz mean-variance optimal weights in one line, no formula derivation required.
Built-in data download: ffn.get() pulls historical prices for several tickers at once, with to_returns() and to_log_returns() converting them into return series.
Drawdown and risk analysis: compute drawdown series and draw underwater plots to see each loss from onset to recovery.
Plotting out of the box: equity curves, rebased comparisons and correlation heatmaps come as single method calls.
Common transforms: price to returns, resampling, period returns and rolling statistics are all provided rather than rewritten each time.
Foundation for bt: the mature bt backtesting framework is built on ffn by the same author, connecting metric computation and strategy backtesting in one chain.

