Portfolio

Portfolio class provides an entry point for all the analysis. It needs to be instantiated with instrument returns which the weighting and clustering method will depend on.


class fipie.Portfolio(ret: pandas.core.frame.DataFrame)

A portfolio of instrument returns

__init__(ret: pandas.core.frame.DataFrame)

Create a Portfolio instance

Parameters

ret (pd.DataFrame) – time-series of instrument returns

Note

ret is frequency agnostic – i.e., it can be daily, weekly or any other frequency as long as fipie.date.infer_ts_frequency can infer its frequency.

create_tree(cluster: fipie.cluster.ClusterAlgo, ret: Optional[pandas.core.frame.DataFrame] = None) fipie.tree.Tree

Create a tree out of the return data frame

Parameters
  • cluster (ClusterAlgo) – clustering algorithm instance

  • ret (pd.DataFrame, optional) – portfolio returns to use to create a tree. If not provided, use the returns provided upon instantiation. If provided, this parameter will be used to create a tree instead.

Returns

Tree instance which groups instruments into clusters

weight_historical(weighting: fipie.weighting.Weighting, cluster: fipie.cluster.ClusterAlgo = NoCluster(max_clusters=None), instrument_only: bool = True, final_weight: bool = True, freq: str = 'm', lookback: int = 104) pandas.core.frame.DataFrame

Compute the historical portfolio weights by applying the calculation on a rolling basis

Parameters
  • weighting (Weighting) – weighting scheme instance

  • cluster (ClusterAlgo) – clustering algorithm instance

  • instrument_only (bool, default True) – If True only weights for instruments are shown and ones for intermediate are omitted

  • final_weight (bool, default True) – If True return the final weights for each instruments are returned.

  • freq (str, default 'm') – frequency to update the portfolio weights.

  • lookback (int, default 52 * 2 (2 years with weekly observations)) – the number of return samples (lookback horizon) to compute the portfolio weights

Returns

historical weights for each node

Return type

pd.DataFrame

weight_latest(weighting: fipie.weighting.Weighting, cluster: fipie.cluster.ClusterAlgo = NoCluster(max_clusters=None), instrument_only: bool = True, final_weight: bool = True) pandas.core.series.Series

Compute the latest portfolio weights using the full return time-series.

Parameters
  • weighting (Weighting) – weighting scheme instance

  • cluster (ClusterAlgo) – clustering algorithm instance

  • instrument_only (bool, default True) – If True only weights for instruments are shown and ones for intermediate are omitted

  • final_weight (bool, default True) –

    If True return the final weights for each instruments are returned. The portfolio return \(r\) can then be calculated as follows:

    \[r = \sum_i w_i \cdot r_i\]

    where \(i\) is the index for each instrument, \(w_i\) is the final weight for instrument \(i\), and \(r_i\) is the return for instrument \(i\).

Returns

weights for each node

Return type

pd.Series