Skip to main content

BaseComposer

BaseComposer(
    model_name: str,
    signal_params=_Nothing.NOTHING,
    portfolio_params: Dict[str, Any] = _Nothing.NOTHING,
    model_params: Dict[str, Any] = _Nothing.NOTHING,
)
Compose portfolio(s). This abstract base class provides a framework for creating portfolio composers that can run models with varying parameters. Method generated by attrs for class BaseComposer.

Descendants

  • systematica.portfolio.composers.ColumnStackComposer
  • systematica.portfolio.composers.Composer
  • systematica.portfolio.composers.SignalComposer

Class variables

  • model_name: str: Name of the model to use. Should match to a model in systematica.api.models.
  • portfolio_params: Dict[str, Any]: Additional keyword arguments for portfolio simulation.
  • model_params: Dict[str, Any]: A dictionary of optional keyword arguments needed to compute the model.

Methods

run

run(
    self,
    data: vectorbtpro.data.base.Data,
    s1: str,
    s2: str,
    portfolio_kwargs: Dict[str, Any],
    **kwargs,
) ‑> systematica.portfolio.analyzer.PortfolioAnalyzer
Run the portfolio composer with the specified data. Parameters:
NameTypeDefaultDescription
datavbt.Data--Vector BT data object containing the input data.
s1str--First symbol or identifier for the data.
s2str--Second symbol or identifier for the data.
portfolio_kwargstp.Kwargs--Keyword arguments for portfolio configuration.
kwargstp.Kwargs--Additional keyword arguments passed to the model.
Returns:
TypeDescription
PortfolioAnalyzerPortfolio analyzer instance containing the results of the composition.

BaseFrontier

BaseFrontier(
    alpha: float = 0.05,
    a_sim: int = 100,
    beta: float = None,
    b_sim: int = None,
    kappa: float = 0.3,
    model: str = 'Classic',
    rm: str = 'MV',
    kelly: str = None,
    rf: float = 0.0,
    hist: bool = True,
    solver: str = 'CLARABEL',
    constraints: List[Dict[strstr]] = None,
    asset_classes: dict = _Nothing.NOTHING,
    config: Dict[str, Any] = _Nothing.NOTHING,
)
Base class for portfolio objects with all properties needed to calculate optimal portfolios. Risk Measures:
  • MV: Standard Deviation.
  • KT: Square Root of Kurtosis.
  • MAD: Mean Absolute Deviation.
  • GMD: Gini Mean Difference.
  • MSV: Semi Standard Deviation.
  • SKT: Square Root of Semi Kurtosis.
  • FLPM: First Lower Partial Moment (Omega Ratio).
  • SLPM: Second Lower Partial Moment (Sortino Ratio).
  • CVaR: Conditional Value at Risk.
  • TG: Tail Gini.
  • EVaR: Entropic Value at Risk.
  • RLVaR: Relativistic Value at Risk.
  • WR: Worst Realization (Minimax).
  • RG: Range of returns.
  • CVRG: CVaR range of returns.
  • TGRG: Tail Gini range of returns.
  • EVRG: EVaR range of returns.
  • RVRG: RLVaR range of returns. I recommend only use this function with MOSEK solver.
  • MDD: Maximum Drawdown of uncompounded cumulative returns (Calmar Ratio).
  • ADD: Average Drawdown of uncompounded cumulative returns.
  • CDaR: Conditional Drawdown at Risk of uncompounded cumulative returns.
  • EDaR: Entropic Drawdown at Risk of uncompounded cumulative returns.
  • RLDaR: Relativistic Drawdown at Risk of uncompounded cumulative returns.
  • UCI: Ulcer Index of uncompounded cumulative returns.
Method generated by attrs for class BaseFrontier.

Ancestors

  • abc.ABC
  • riskfolio.src.Portfolio.Portfolio

Descendants

  • systematica.portfolio.frontiers.FrontierAssetStats
  • systematica.portfolio.frontiers.FrontierBLFactorsStats
  • systematica.portfolio.frontiers.FrontierBLStats
  • systematica.portfolio.frontiers.FrontierFactorsStats
  • systematica.portfolio.frontiers.FrontierWCStats

Class variables

  • alpha: float: Significance level of VaR, CVaR, EVaR, RLVaR, DaR, CDaR, EDaR, RLDaR and Tail Gini of losses. The default is 0.05.
  • a_sim: int: Number of CVaRs used to approximate Tail Gini of losses. The default is 100.
  • beta: float: Significance level of CVaR and Tail Gini of gains. If None it duplicates alpha value. The default is None.
  • b_sim: int: Number of CVaRs used to approximate Tail Gini of gains. If None it duplicates a_sim value. The default is None.
  • model: str: Methodology used to estimate input parameters. The default is Classic.
  • rm: str: The risk measure used to optimize the portfolio. The default is MV. Possible values are displayed above.
  • kelly: str: Method used to calculate mean return. Possible values are: None for arithmetic mean return, “approx” for approximate mean logarithmic return using first and second moment and “exact” for mean logarithmic return. The default is None.
  • rf: float: Risk free rate. The default is 0.0.
  • hist: bool: Indicate what kind of returns are used to calculate risk measures that depends on scenarios (All except MV risk measure). The default is True. If model = BL, True means historical covariance and returns and False Black Litterman covariance and historical returns. If model = FM, True means historical covariance and returns and False Risk Factor model for covariance and returns. If model = BL_FM, True means historical covariance and returns, False Black Litterman with Risk Factor model for covariance and Risk Factor model for returns, and 2 Risk Factor model for covariance and returns.
  • solver: str: Solver available for CVXPY that supports power cone programming. Used to calculate RLVaR and RLDaR. The default value is CLARABEL.
  • constraints: List[Dict[str, str]]: Risk contribution constraints. Defaults to None.
  • asset_classes: dict: Asset classes.
  • config: Dict[str, Any]: Riskfolio-lib configuration. Overwrite other required parameters if referenced.

Instance variables

  • kappa: float: Deformation parameter of RLVaR and RLDaR for losses, must be between 0 and 1. The default is 0.30.
  • freq: Infer the frequency of the returns index.
  • ann_factor: Calculate the annualization factor based on the frequency.
  • x_axis: str: Generate the label for the x-axis based on the risk measure.
  • y_axis: str: Generate the label for the y-axis based on the Kelly criterion.
  • z_axis: str: Generate the label for the z-axis.

Methods

init

init(
    self,
    market_returns: pandas.core.frame.DataFrame,
)
Initialize the portfolio object with market returns. Parameters:
NameTypeDefaultDescription
market_returnspd.DataFrame--DataFrame containing market returns data.
Raises:
TypeDescription
ValueErrorIf the cleaned market returns still contain NaN values.

fit

fit(
    self,
    market_returns: pandas.core.frame.DataFrame,
) ‑> systematica.portfolio.base.BaseFrontier
Abstract method to fit the portfolio model. Parameters:
NameTypeDefaultDescription
market_returnspd.DataFrame--Market returns data.
Returns:
TypeDescription
BaseFrontierFitted portfolio object.

add_constraints

add_constraints(
    self,
) ‑> systematica.portfolio.base.BaseFrontier
Add inequality constraints to the portfolio. Returns:
TypeDescription
BaseFrontierPortfolio object with added constraints.

predict

predict(
    self,
    points: int = 20,
) ‑> pandas.core.frame.DataFrame
Predict the efficient frontier. Parameters:
NameTypeDefaultDescription
pointsint20Number of points to calculate on the frontier, by default 20.
Returns:
TypeDescription
pd.DataFrameDataFrame containing the efficient frontier.

get_portfolio

get_portfolio(
    self,
    weights: pandas.core.series.Series,
) ‑> pandas.core.frame.DataFrame
Calculate the portfolio performance based on the given weights. Parameters:
NameTypeDefaultDescription
weightspd.Series--Portfolio weights.
Returns:
TypeDescription
pd.DataFrameTarget portfolio.

get_efficient_frontier

get_efficient_frontier(
    self,
    points: int = 20,
) ‑> pandas.core.frame.DataFrame
Calculate the efficient frontier. Parameters:
NameTypeDefaultDescription
pointsint20Number of points to calculate on the frontier, by default 20.
Returns:
TypeDescription
pd.DataFrameEfficient frontier.

plot_frontier

plot_frontier(
    self,
    weights,
    display_frontier: bool = True,
    points: int = 20,
    portfolio_name: str = 'Target Portfolio',
    marker_color: str = 'red',
    marker_size: int = 20,
    make_figure_kwargs: Dict[str, Any] | None = None,
    fig: plotly.basedatatypes.BaseFigure = None,
    showscale: bool = True,
    **layout_kwargs,
) ‑> vectorbtpro.utils.figure.FigureWidget
Plot the efficient frontier. Parameters:
NameTypeDefaultDescription
weightspd.Series--Portfolio weights.
display_frontierboolTrueDisplay frontier. Defaults to True.
portfolio_namestrTarget...Portfolio name. Defaults to “Target Portfolio”.
marker_colorstrredColor of the portfolio star shaped marker. Defaults to “red”.
marker_sizeint20Size of the portfolio star shaped marker. Default to 20.
make_figure_kwargstp.KwargsLikeNoneAdditional figure arguments, by default None.
figtp.BaseFigureNoneExisting figure to update, by default None.
showscaleboolTrueWhether to show the scale, by default True.
layout_kwargstp.Kwargs--Additional layout arguments for the figure.
Returns:
TypeDescription
vbt.FigureWidgetA Plotly FigureWidget containing the frontier plot.