Skip to content

markowizard.data

data

Convenience functions for fetching market data and computing returns.

Use these to quickly download prices from Yahoo Finance. The core analytical modules also accept a pre-computed returns DataFrame directly, so these helpers are optional in practice.

fetch_prices

fetch_prices(
    tickers: list[str],
    period: str = "5y",
    auto_adjust: bool = True,
) -> pd.DataFrame

Download historical adjusted close prices for a list of tickers.

Parameters:

Name Type Description Default
tickers list of str

Yahoo Finance ticker symbols (e.g., ['AAPL', 'MSFT', 'SPY']). Each ticker must match ^[A-Z0-9.-]+$.

required
period str

Data period (default '5y'). See yfinance for valid periods.

'5y'
auto_adjust bool

Whether to use auto-adjusted close prices (default True).

True

Returns:

Type Description
DataFrame

DataFrame of closing prices with DatetimeIndex and tickers as columns.

compute_monthly_returns

compute_monthly_returns(prices: DataFrame) -> pd.DataFrame

Convert daily close prices to monthly percentage returns.

Parameters:

Name Type Description Default
prices DataFrame

Daily closing prices with DatetimeIndex and tickers as columns.

required

Returns:

Type Description
DataFrame

DataFrame of monthly percentage returns.