$ show fja05680/pinkfish
Pinkfish is a Python library for backtesting equity trading strategies, primarily used via Jupyter notebooks. It provides a modular framework with components for data fetching (Yahoo Finance via yfinance), trade logging, portfolio management, performance statistics, and signal generation. The core architecture revolves around a Strategy class pattern, a Portfolio class for multi-symbol backtesting, and a TradeLog class for simulating trade entries/exits with realistic open/close fills. The library includes a wide range of technical indicators (both custom and TA-Lib wrappers), comprehensive performance metrics (Sharpe, Sortino, drawdown, etc.), and support for signal notifications via Pushover/email. The codebase is well-structured with clear separation of concerns, but uses some global state in TradeLog and relies on a static stock market calendar, introducing minor maintenance risks. The examples cover diverse strategies such as momentum, moving average crossovers, and sector rotation, serving as both documentation and reusable templates.
The LLM identified 4 files worth highlighting for reuse:
Provides custom implementations of common technical indicators (SMA, EMA, CROSSOVER, MOMENTUM, VOLATILITY, annualized returns, Sharpe ratio, etc.) that operate directly on pandas DataFrames. These are drop-in replacements for TA-Lib functions, requiring no external C library. The functions are vectorized and can be easily used in any backtesting or data analysis pipeline, making them a self-contained, reusable asset.
Implements the Portfolio class for multi-symbol backtesting, including a `@technical_indicator` decorator that applies a given indicator function to each symbol's timeseries and adds the result as a column. This pattern cleanly separates indicator computation from portfolio logic. The class also provides methods for weight adjustment, rebalancing, correlation maps, and performance per symbol, making it a reusable foundation for any asset allocation strategy.
Contains the TradeLog class, which tracks individual trades, daily balances, and position sizing with support for long/short, margin, and leverage. It logs entry/exit prices, shares, and P&L, and provides methods to compute daily balance and equity curves. Despite some global state for convenience, the core logic is modular and can be extracted for use in other backtesting frameworks or standalone trade simulation.
Provides a comprehensive set of performance statistics for backtested strategies, including CAGR, Sharpe/Sortino ratios, maximum drawdown, profit factor, monthly/weekly returns, and rolling metrics. The `stats()` function takes a timeseries, trade log, and daily balance as input and returns a structured Series of metrics. This module is self-contained and can be reused to evaluate any trading strategy, regardless of the backtesting framework used.