Index
The Index class provides access to market indices like TOPIX and Nikkei 225 with a yfinance-style API.
Basic Usage
import pyjquants as pjq
topix = pjq.Index.topix()
print(topix.name) # "TOPIX"
df = topix.history("1y") # Last year of data
API Reference
pyjquants.domain.index.Index
Bases: CodeBasedEntity
Market index with yfinance-style API.
Example
topix = Index.topix() df = topix.history(period="30d") df = topix.history(start="2024-01-01", end="2024-12-31")
name
property
Index name.
__init__(code, name=None, session=None)
Initialize Index.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
code
|
str
|
Index code (e.g., "0000" for TOPIX) |
必須 |
name
|
str | None
|
Index name (optional, auto-detected for known indices) |
None
|
session
|
Session | None
|
Optional session (uses global session if not provided) |
None
|
history(period='30d', start=None, end=None)
Get price history (yfinance-style).
Note: Non-TOPIX indices (e.g., Nikkei 225) require Standard tier or higher.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
period
|
str | None
|
Time period (e.g., "30d", "1y"). Ignored if start/end provided. |
'30d'
|
start
|
str | date | None
|
Start date (YYYY-MM-DD string or date object) |
None
|
end
|
str | date | None
|
End date (YYYY-MM-DD string or date object) |
None
|
戻り値:
| タイプ | デスクリプション |
|---|---|
DataFrame
|
DataFrame with columns: date, open, high, low, close |
topix(session=None)
classmethod
Get TOPIX index.
nikkei225(session=None)
classmethod
Get Nikkei 225 index.
all(session=None)
classmethod
Get all known indices.
Examples
Get TOPIX
topix = pjq.Index.topix()
print(topix.code) # "0000"
print(topix.name) # "TOPIX"
# Get price history
df = topix.history("30d")
print(df[['date', 'close']])
Get Nikkei 225
nikkei = pjq.Index.nikkei225()
print(nikkei.code) # "0001"
print(nikkei.name) # "Nikkei 225"
df = nikkei.history("1y")
All Available Indices
# Get list of all known indices
indices = pjq.Index.all()
for idx in indices:
print(f"{idx.code}: {idx.name}")
Price History
from datetime import date
topix = pjq.Index.topix()
# Recent prices (default 30 days)
df = topix.history()
# Specific period
df = topix.history("1y") # 1 year
df = topix.history("6mo") # 6 months
# Custom date range
df = topix.history(start="2024-01-01", end="2024-06-30")
# With date objects
df = topix.history(start=date(2024, 1, 1), end=date(2024, 6, 30))