Registry / data / stockstats

stockstats

JSON →
library0.6.8pypypi✓ verified 84d ago

A Python library that provides a DataFrame subclass with inline stock statistics support, including common technical indicators (e.g., SMA, EMA, RSI, MACD, Bollinger Bands) and more advanced indicators like Supertrend, Ichimoku Cloud, KST, and PVO. The current version is 0.6.8, with active development on GitHub. Release cadence is irregular, roughly a few releases per year.

pip install stockstats
INSTALL
IMPORT
SIG · STOCKSTATS
S
stockstats
datapythonv0.6.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StockDataFrame
from stockstats import StockDataFrame
import stockstats stockstats.StockDataFrame
Direct import is preferred and clearer

Download stock data with yfinance, convert to StockDataFrame, and compute technical indicators.

import yfinance as yf from stockstats import StockDataFrame # Download historical data for AAPL df = yf.download('AAPL', start='2023-01-01', end='2023-12-31') # Convert to StockDataFrame stock = StockDataFrame.retype(df) # Access RSI (14-day) and MACD print(stock['rsi_14'].tail()) print(stock['macd'].tail())
Debug
Known issues
breakingIn version 0.6.x, the column naming convention for some indicators changed (e.g., 'rsi' became 'rsi_14'). Old code using 'rsi' without the period will break.
fix
Update column names to include the period (e.g., 'rsi_14', 'macd').
affects: <0.6.0
breakingThe method _tp() previously returned a scalar when the result was constant; in 0.6.7 it was fixed to always return a pandas Series. Code that relied on scalar output (e.g., item access) may break.
fix
Ensure code handles Series output instead of scalar.
affects: <0.6.7
gotchayfinance may change its API (e.g., 'period' parameter). StockDataFrame expects columns: 'open', 'high', 'low', 'close', 'volume'. If yfinance changes column names, the library may not recognize them.
fix
Use yfinance with keyword arguments for column mapping, or ensure column names match the expected format.
affects: all
gotchaMany indicators can produce NaN values due to division by zero or insufficient data length. These are silently ignored in some versions, leading to misleading results.
fix
Upgrade to 0.6.6+ which fixes division-by-zero issues (PR #201).
affects: <=0.6.5
Errors
Common errors & fixes
AttributeError: module 'stockstats' has no attribute 'StockDataFrame'
Incorrect import: trying to use stockstats.StockDataFrame instead of importing the class directly.
fix
Use: from stockstats import StockDataFrame
KeyError: 'rsi'
Column name changed: in older versions, 'rsi' was the column; in new versions, it's 'rsi_14' (or other period).
fix
Access 'rsi_14' instead of 'rsi' (adjust period as needed).
ValueError: cannot reindex from a duplicate axis
DataFrame index has duplicate timestamps (e.g., from intraday data with same day). The library does not handle duplicates gracefully.
fix
Ensure index is unique: df = df[~df.index.duplicated(keep='first')]
Upgrade
Version history
0.6.8latest on PyPI · released Feb 16, 2026
Audit
Dependencies
pandasrequiredCore dependency for DataFrame operations
numpyrequiredUsed for numerical computations
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
stockstats — pip install stockstats · libregistry