qis.to_portfolio_returns

qis.to_portfolio_returns(weights, returns, portfolio_name='portfolios')[source]

Compute portfolio returns from asset weights and returns.

Uses lagged weights (rebalanced at prior period close). On a shared, unique DatetimeIndex without NaT, the lag follows date order, not the physical row order of either input. The result retains the return frame’s original index order; neither input is modified.

NaN handling — IMPORTANT:

This function aggregates returns * lagged_weights via nansum across the asset axis. A NaN return contributes 0 to that day’s portfolio PnL — equivalent to “asset held its notional but earned 0%”. It does NOT renormalize remaining asset weights.

Example: weights = [0.5, 0.5], returns = [+0.02, NaN]. Output = nansum([0.5*0.02, 0.5*NaN]) = 0.01, not 0.02.

This is the right convention if NaN means “asset wasn’t tradable that day, position held in cash earning 0%”. It is wrong if NaN means “data missing, treat the position as fully invested in the remaining assets”. For the latter, drop NaN rows or renormalize weights yourself before calling.

A date where ALL asset returns are NaN produces NaN portfolio return (rather than 0), so fully-NaN periods propagate correctly.

Parameters:
  • weights (DataFrame) – Portfolio weight DataFrame (columns = assets), on the return dates. Sparse rebalancing schedules must be reindexed and forward-filled by the caller first

  • returns (DataFrame) – Asset return DataFrame (columns = assets), sharing the weight frame’s date grid

  • portfolio_name (str) – Name for output series

Returns:

Portfolio return time series

Return type:

Series