abaquant.marketdata.universe_portfolio

Import path: abaquant.marketdata.universe_portfolio

Domain: Provider-neutral market-data facades, normalized records, caching, and analytics.

Purpose

Applied static portfolio construction for ticker universes.

When to use it

Use this package to retrieve or inject quotes, price history, option chains, and financial statements while preserving a stable analytical interface.

Public objects

  • class: UniversePortfolioAnalytics — Static portfolio-analysis namespace for a :class:’MarketUniverse’. * UniversePortfolioAnalytics.equal_weight — Construct or evaluate an equally weighted fully invested portfolio. * UniversePortfolioAnalytics.minimum_variance — Construct a bounded global minimum-variance portfolio. * UniversePortfolioAnalytics.max_sharpe — Construct a bounded maximum-Sharpe-ratio portfolio. * UniversePortfolioAnalytics.evaluate — Evaluate a user-supplied portfolio allocation against historical inputs. * UniversePortfolioAnalytics.backtest — Backtest a deterministic rebalanced allocation for this universe. * UniversePortfolioAnalytics.scenario_analysis — Evaluate a one-period shock scenario for this universe.

Detailed reference

Applied static portfolio construction for ticker universes.

Purpose

The module converts a universe return panel into equal-weight, minimum-variance, maximum-Sharpe, and user-specified portfolio evaluations.

Conventions

Risk-free rates are annualized decimal arithmetic rates. Optimizers use the core pure portfolio functions and require at least two assets.

Scope and limitations

Results are static in-sample calculations; the lightweight backtest adds deterministic rebalancing and explicit transaction costs but still excludes execution, taxes, financing, and market impact.

References

[ 1 ] Markowitz, H. (1952), “Portfolio Selection”. [ 2 ] Sharpe, W. F. (1966), “Mutual Fund Performance”.

class abaquant.marketdata.universe_portfolio.UniversePortfolioAnalytics(universe)

Bases: object

Static portfolio-analysis namespace for a MarketUniverse.

The namespace requests aligned returns lazily through universe.history and delegates estimation and optimization to the pure financial-math layer. It does not retain raw provider objects or execute trades.

Parameters:

universe (MarketUniverse)

universe

Universe that supplies normalized ticker symbols, market-data provider, and historical return panels.

Type:

MarketUniverse

equal_weight(*, risk_free_rate, kind='simple', start=None, end=None, period='1y', interval='1d', auto_adjust=True, periods_per_year=252)

Construct or evaluate an equally weighted fully invested portfolio.

Parameters:
  • risk_free_rate (float) – Annual risk-free rate in decimal units.

  • kind (ReturnKind, default='simple') – Return convention: "simple" for arithmetic returns or "log" for logarithmic returns.

  • start (str | date | None, default=None) – Optional inclusive history start date.

  • end (str | date | None, default=None) – Optional exclusive or provider-defined history end date.

  • period (str | None, default='1y') – Provider history period label, such as "1y", when explicit dates are not supplied.

  • interval (str, default='1d') – Provider sampling interval label, such as "1d".

  • auto_adjust (bool, default=True) – Whether provider-adjusted price history is requested.

  • periods_per_year (int, default=252) – Number of periodic observations interpreted as one year for annualization.

Returns:

Immutable result containing equal 1/N weights indexed by universe symbol, together with annualized expected return, volatility, and Sharpe ratio.

Return type:

PortfolioResult

Notes

This is an analytical in-sample calculation. It does not by itself model transaction costs, execution effects, taxes, or future return uncertainty. The applied layer normalizes provider data but cannot guarantee provider completeness, timeliness, or accuracy.

minimum_variance(*, risk_free_rate, bounds=(0.0, 1.0), kind='simple', start=None, end=None, period='1y', interval='1d', auto_adjust=True, periods_per_year=252)

Construct a bounded global minimum-variance portfolio.

Parameters:
  • risk_free_rate (float) – Annual risk-free rate in decimal units.

  • bounds (tuple[float, float], default=(0.0, 1.0)) – Allocation bounds in the format accepted by the underlying optimizer.

  • kind (ReturnKind, default='simple') – Return convention: "simple" for arithmetic returns or "log" for logarithmic returns.

  • start (str | date | None, default=None) – Optional inclusive history start date.

  • end (str | date | None, default=None) – Optional exclusive or provider-defined history end date.

  • period (str | None, default='1y') – Provider history period label, such as "1y", when explicit dates are not supplied.

  • interval (str, default='1d') – Provider sampling interval label, such as "1d".

  • auto_adjust (bool, default=True) – Whether provider-adjusted price history is requested.

  • periods_per_year (int, default=252) – Number of periodic observations interpreted as one year for annualization.

Returns:

Immutable result containing indexed weights and annualized portfolio performance statistics.

Return type:

PortfolioResult

Notes

This is an analytical in-sample calculation. It does not by itself model transaction costs, execution effects, taxes, or future return uncertainty. The applied layer normalizes provider data but cannot guarantee provider completeness, timeliness, or accuracy.

max_sharpe(*, risk_free_rate, bounds=(0.0, 1.0), kind='simple', start=None, end=None, period='1y', interval='1d', auto_adjust=True, periods_per_year=252)

Construct a bounded maximum-Sharpe-ratio portfolio.

Parameters:
  • risk_free_rate (float) – Annual risk-free rate in decimal units.

  • bounds (tuple[float, float], default=(0.0, 1.0)) – Allocation bounds in the format accepted by the underlying optimizer.

  • kind (ReturnKind, default='simple') – Return convention: "simple" for arithmetic returns or "log" for logarithmic returns.

  • start (str | date | None, default=None) – Optional inclusive history start date.

  • end (str | date | None, default=None) – Optional exclusive or provider-defined history end date.

  • period (str | None, default='1y') – Provider history period label, such as "1y", when explicit dates are not supplied.

  • interval (str, default='1d') – Provider sampling interval label, such as "1d".

  • auto_adjust (bool, default=True) – Whether provider-adjusted price history is requested.

  • periods_per_year (int, default=252) – Number of periodic observations interpreted as one year for annualization.

Returns:

Immutable result containing indexed weights and annualized portfolio performance statistics.

Return type:

PortfolioResult

Notes

This is an analytical in-sample calculation. It does not by itself model transaction costs, execution effects, taxes, or future return uncertainty. The applied layer normalizes provider data but cannot guarantee provider completeness, timeliness, or accuracy.

evaluate(weights, *, risk_free_rate, kind='simple', start=None, end=None, period='1y', interval='1d', auto_adjust=True, periods_per_year=252)

Evaluate a user-supplied portfolio allocation against historical inputs.

Parameters:
  • weights (Mapping[str, float] | Sequence[float]) – Portfolio weights, either a mapping keyed by asset or an ordered numeric vector as documented by the callable.

  • risk_free_rate (float) – Annual risk-free rate in decimal units.

  • kind (ReturnKind, default='simple') – Return convention: "simple" for arithmetic returns or "log" for logarithmic returns.

  • start (str | date | None, default=None) – Optional inclusive history start date.

  • end (str | date | None, default=None) – Optional exclusive or provider-defined history end date.

  • period (str | None, default='1y') – Provider history period label, such as "1y", when explicit dates are not supplied.

  • interval (str, default='1d') – Provider sampling interval label, such as "1d".

  • auto_adjust (bool, default=True) – Whether provider-adjusted price history is requested.

  • periods_per_year (int, default=252) – Number of periodic observations interpreted as one year for annualization.

Returns:

Immutable result containing indexed weights and annualized portfolio performance statistics.

Return type:

PortfolioResult

Notes

The applied layer normalizes provider data but cannot guarantee provider completeness, timeliness, or accuracy.

backtest(*, weights='equal_weight', rebalance='monthly', transaction_cost_bps=0.0, slippage_bps=0.0, fixed_transaction_cost=0.0, initial_capital=1.0, benchmark='equal_weight', lookback=63, min_history=2, kind='simple', start=None, end=None, period='1y', interval='1d', auto_adjust=True, periods_per_year=252, risk_free_rate=0.0)

Backtest a deterministic rebalanced allocation for this universe.

Parameters:
  • weights (str or Mapping[str, float] or Sequence[float], default="equal_weight") – Target allocation policy. Supported string policies include "equal_weight", "buy_and_hold", and "inverse_volatility". Mappings are normalized to universe ticker symbols; sequences follow universe symbol order.

  • rebalance ({"none", "daily", "weekly", "monthly", "quarterly", "annual"}, default="monthly") – Calendar rebalance schedule.

  • transaction_cost_bps (float, default=0.0) – One-way transaction cost in basis points of turnover.

  • slippage_bps (float, default=0.0) – Additional one-way slippage in basis points of turnover.

  • fixed_transaction_cost (float, default=0.0) – Fixed cost charged whenever a non-zero rebalance occurs.

  • initial_capital (float, default=1.0) – Starting portfolio value.

  • benchmark (str or Mapping[str, float] or Sequence[float] or pandas.Series or None, default="equal_weight") – Benchmark specification used for active-return diagnostics.

  • lookback (int, default=63) – Historical window used by dynamic policies such as "inverse_volatility".

  • min_history (int, default=2) – Minimum observations required before dynamic policies are estimated.

  • kind ({"simple", "log"}, default="simple") – Return convention requested from the universe history namespace.

  • start (optional) – Historical-data request controls forwarded to universe.history.returns.

  • end (optional) – Historical-data request controls forwarded to universe.history.returns.

  • period (optional) – Historical-data request controls forwarded to universe.history.returns.

  • interval (optional) – Historical-data request controls forwarded to universe.history.returns.

  • auto_adjust (optional) – Historical-data request controls forwarded to universe.history.returns.

  • periods_per_year (int, default=252) – Number of return observations interpreted as one year.

  • risk_free_rate (float, default=0.0) – Annualized risk-free rate in decimal units for summary metrics.

Returns:

Simulated equity curve, drawdowns, returns, weights, trades, turnover, transaction costs, benchmark diagnostics, and summaries.

Return type:

PortfolioBacktestResult

scenario_analysis(shocks, *, weights=None, base_value=1.0)

Evaluate a one-period shock scenario for this universe.

Parameters:
  • shocks (Mapping[str, float]) – Asset-level shock returns in decimal units. Missing universe symbols receive a zero shock; unknown symbols are rejected.

  • weights (Mapping[str, float] or Sequence[float], optional) – Portfolio weights to evaluate. Equal universe weights are used when omitted.

  • base_value (float, default=1.0) – Starting portfolio value used to compute the ending scenario value.

Returns:

Shock, weight, contribution, portfolio return, and ending-value diagnostics.

Return type:

PortfolioScenarioAnalysis

abaquant.marketdata.universe_portfolio.MarketUniversePortfolio

alias of UniversePortfolioAnalytics