Portfolio¶
Portfolio is Fundcloud's shared post-simulation object. Every entry path — Simulator.run_strategy, run_weights, run_signals, run_orders, and the skfolio round-trip via from_skfolio / to_skfolio — produces one. Metrics (sharpe, max_drawdown, turnover, attribution), the full summary() bundle, and the tear-sheet renderers all read from the same object, which keeps notebook exploration and production reporting numerically identical. Population holds a set of portfolios for cross-strategy comparison; Position is the per-asset record.
fundcloud.portfolio
¶
Unified position + analytics container.
One :class:Portfolio class handles both live simulation state (via
:meth:Portfolio.apply / :meth:Portfolio.mark_to_market) and post-run
analytics (Sharpe, drawdowns, CVaR, attribution, …). :class:Population
compares several portfolios side-by-side.
Portfolio
¶
Portfolio(
*,
returns: DataFrame | Series | None = None,
weights: DataFrame | Series | None = None,
benchmark: Series | None = None,
cash: float = 0.0,
positions: dict[str, float] | None = None,
name: str | None = None,
)
Unified position + analytics container.
Source code in python/fundcloud/portfolio/portfolio.py
equity_curve
property
¶
Running equity. For analytics-mode portfolios, cumulates returns.
apply
¶
Apply a Trade (from :mod:fundcloud.sim) to live state.
The method only depends on the trade's duck-typed attributes
(asset, qty, price, fee) so this module doesn't have to
import the simulator package.
Source code in python/fundcloud/portfolio/portfolio.py
attribution
¶
Asset-level return contribution = weights × returns (shifted).
Requires a weights frame. Uses the current-bar weight × current-bar asset return, which is the standard backward-looking decomposition.
Source code in python/fundcloud/portfolio/portfolio.py
contribution
¶
Average per-asset contribution to total return.
drawdown_details
¶
One row per drawdown episode: start / valley / recovery + durations.
See :func:fundcloud.metrics.drawdown_details for the column
definitions.
Source code in python/fundcloud/portfolio/portfolio.py
from_nav
classmethod
¶
from_nav(
nav: Series | DataFrame,
*,
distributions: Series | None = None,
capital_flows: Series | None = None,
method: ReturnMethod = "total_return",
trades: DataFrame | None = None,
positions: DataFrame | None = None,
benchmark: Series | None = None,
name: str | None = None,
) -> Portfolio
Analytics-mode Portfolio built from a NAV series.
Return computation is delegated to
:func:fundcloud.metrics.returns_from_nav — see there for the
four-method menu. The default (total_return on per-share
NAV with distributions added back) matches how public funds
report performance: injections and withdrawals are
NAV-per-share-invariant, and only DISTRIBUTION flows need
a per-share add-back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nav
|
Series | DataFrame
|
NAV timeseries. A :class: |
required |
distributions
|
Series | None
|
Forwarded to :func: |
None
|
capital_flows
|
Series | None
|
Forwarded to :func: |
None
|
method
|
Series | None
|
Forwarded to :func: |
None
|
trades
|
DataFrame | None
|
Stashed on the returned Portfolio as |
None
|
positions
|
DataFrame | None
|
Stashed on the returned Portfolio as |
None
|
benchmark
|
Series | None
|
Forwarded to :meth: |
None
|
name
|
Series | None
|
Forwarded to :meth: |
None
|
Returns:
| Type | Description |
|---|---|
Portfolio
|
Analytics-mode portfolio with |
Source code in python/fundcloud/portfolio/portfolio.py
from_skfolio
classmethod
¶
Lift a skfolio Portfolio into a Fundcloud Portfolio.
Copies the returns series and the (per-period) weight vector if one is exposed. Compatible with skfolio >= 0.6.
Source code in python/fundcloud/portfolio/portfolio.py
mark_to_market
¶
Compute and record equity at timestamp ts.
prices is a Series of asset → price at that timestamp. When a
price is missing (NaN) — typical for a mixed-frequency panel
on a weekend / market holiday — the portfolio falls back to the
last known price for that asset so a held position keeps its
value across the closed bar. Cash-only positions (qty == 0)
are skipped.
Source code in python/fundcloud/portfolio/portfolio.py
metrics
¶
metrics(
*,
benchmark: Series | None = None,
risk_free: float | None = None,
periods_per_year: int | None = None,
cvar_alpha: float = 0.95,
) -> pd.Series
Full portfolio-metrics bundle.
Delegates to :func:fundcloud.metrics.metrics. When this Portfolio
was constructed with benchmark=, that benchmark is used by
default; pass an explicit benchmark= to override.
Source code in python/fundcloud/portfolio/portfolio.py
period_returns
¶
period_returns(
*,
benchmark: Series | None = None,
periods_per_year: int | None = None,
) -> pd.Series | pd.DataFrame
MTD / 3M / 6M / YTD / 1Y / 3Y / 5Y / 10Y / All-time bundle.
When a benchmark is not passed and :attr:benchmark was set on
construction, it's used as the default. See
:func:fundcloud.metrics.period_returns.
Source code in python/fundcloud/portfolio/portfolio.py
runup_details
¶
One row per runup (rally) episode between drawdowns.
See :func:fundcloud.metrics.runup_details for the column
definitions.
snapshot
¶
Freeze live state into an analytics-mode copy.
Builds returns from the equity curve (if there is one) and
weights from the recorded weights history, then detaches live
state so the returned instance behaves immutably for analytics.
Source code in python/fundcloud/portfolio/portfolio.py
summary
¶
summary(
*,
risk_free: float | None = None,
periods_per_year: int | None = None,
cvar_alpha: float = 0.95,
) -> pd.Series
Single-column summary of key metrics (rows = metric names).
Compact 11-metric view. For the full ~55-metric bundle use
:meth:metrics.
Source code in python/fundcloud/portfolio/portfolio.py
to_skfolio
¶
Build a skfolio Portfolio mirror of this object.
Requires the [pf] extra. The resulting object is an instance of
:class:skfolio.Portfolio.
Source code in python/fundcloud/portfolio/portfolio.py
turnover
¶
Average one-way turnover across rebalance boundaries.
Returns 0.0 when weights are constant or unknown.
Source code in python/fundcloud/portfolio/portfolio.py
worst_drawdowns
¶
Top-top drawdown episodes, display-formatted.
Columns: Started / Recovered / Drawdown / Days.
Episodes are sorted by depth (worst first).
Source code in python/fundcloud/portfolio/portfolio.py
worst_runups
¶
Top-top runup episodes, display-formatted.
Columns: Started / Peaked / Runup / Days.
Episodes are sorted by magnitude (biggest first).
Source code in python/fundcloud/portfolio/portfolio.py
yearly_returns
¶
End-of-year returns.
Returns a :class:pd.Series when no benchmark is available, or a
two-column :class:pd.DataFrame (benchmark, strategy)
when one is supplied (or set on construction).
Source code in python/fundcloud/portfolio/portfolio.py
Population
¶
A named bag of :class:Portfolio objects.
Source code in python/fundcloud/portfolio/population.py
composition
¶
Latest weights per portfolio, as rows-per-portfolio × asset columns.
Source code in python/fundcloud/portfolio/population.py
cumulative_returns
¶
Wide frame of cumulative (compounded) returns per portfolio.
Source code in python/fundcloud/portfolio/population.py
summary
¶
summary(
*,
risk_free: float | None = None,
periods_per_year: int | None = None,
cvar_alpha: float = 0.95,
) -> pd.DataFrame
Metric-by-portfolio comparison table (rows = metrics, cols = portfolios).
Source code in python/fundcloud/portfolio/population.py
Position
dataclass
¶
Live position for a single asset.