markowitz.data.loaders¶
markowitz.data.loaders
¶
High-level loaders and return / statistics utilities.
These functions form the public entry-point used by the rest of the
markowitz package. They orchestrate the provider stack, enforce
integrity invariants, and convert raw prices into the return-and-stat
representations consumed by optimizers.
align_universe(returns: pd.DataFrame, *, min_obs_per_ticker: int = 252, common_window: bool = True) -> pd.DataFrame
¶
Drop tickers with sparse history; optionally restrict to common window.
Source code in src/markowitz/data/loaders.py
compute_returns(prices: pd.DataFrame, *, method: str = 'simple', dropna: bool = True) -> pd.DataFrame
¶
Convert a price panel into period-over-period returns.
method="simple" is the Markowitz default. method="log" is
provided for portfolio diagnostics and for users who prefer
continuously compounded returns.
Source code in src/markowitz/data/loaders.py
load_prices(tickers: str | Iterable[str], start: DateLike, end: DateLike, *, provider: PriceProvider | None = None, frequency: str = '1d', min_history_sessions: int = 252) -> pd.DataFrame
¶
Fetch adjusted close prices for tickers as a wide DataFrame.
Each column is a ticker; the index is a tz-naive, monotonic,
unique :class:~pandas.DatetimeIndex aligned across tickers via an
outer join. Tickers without at least min_history_sessions
non-NaN observations raise :class:InsufficientDataError.
Source code in src/markowitz/data/loaders.py
summary_stats(returns: pd.DataFrame, *, frequency: str = 'daily', annualize: bool = True) -> pd.DataFrame
¶
Per-asset summary statistics used as covariance / mean targets.
Returned columns: mu_hat, sigma_hat, sharpe, skew,
kurtosis, n_obs, min, max.
When annualize=True (default), mu_hat is scaled by the
periods-per-year factor and sigma_hat by its square root.