> ## Documentation Index
> Fetch the complete documentation index at: https://systematica.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Base

> systematica.portfolio.frontier.base

## `BaseFrontier`

```python theme={null}
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[str, str]] = 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.frontier.models.FrontierAssetStats`
* `systematica.portfolio.frontier.models.FrontierBLFactorsStats`
* `systematica.portfolio.frontier.models.FrontierBLStats`
* `systematica.portfolio.frontier.models.FrontierFactorsStats`
* `systematica.portfolio.frontier.models.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`

```python theme={null}
init(
    self,
    market_returns: pandas.core.frame.DataFrame,
)
```

Initialize the portfolio object with market returns.

**Parameters**:

| Name             | Type           | Default | Description                               |
| ---------------- | -------------- | ------- | ----------------------------------------- |
| `market_returns` | `pd.DataFrame` | `--`    | DataFrame containing market returns data. |

**Raises**:

| Type         | Description                                               |
| ------------ | --------------------------------------------------------- |
| `ValueError` | If the cleaned market returns still contain `NaN` values. |

#### `fit`

```python theme={null}
fit(
    self,
    market_returns: pandas.core.frame.DataFrame,
) ‑> systematica.portfolio.frontier.base.BaseFrontier
```

Abstract method to fit the portfolio model.

**Parameters**:

| Name             | Type           | Default | Description          |
| ---------------- | -------------- | ------- | -------------------- |
| `market_returns` | `pd.DataFrame` | `--`    | Market returns data. |

**Returns**:

| Type           | Description              |
| -------------- | ------------------------ |
| `BaseFrontier` | Fitted portfolio object. |

#### `add_constraints`

```python theme={null}
add_constraints(
    self,
) ‑> systematica.portfolio.frontier.base.BaseFrontier
```

Add inequality constraints to the portfolio.

**Returns**:

| Type           | Description                              |
| -------------- | ---------------------------------------- |
| `BaseFrontier` | Portfolio object with added constraints. |

#### `predict`

```python theme={null}
predict(
    self,
    points: int = 20,
) ‑> pandas.core.frame.DataFrame
```

Predict the efficient frontier.

**Parameters**:

| Name     | Type  | Default | Description                                                   |
| -------- | ----- | ------- | ------------------------------------------------------------- |
| `points` | `int` | `20`    | Number of points to calculate on the frontier, by default 20. |

**Returns**:

| Type           | Description                                  |
| -------------- | -------------------------------------------- |
| `pd.DataFrame` | DataFrame containing the efficient frontier. |

#### `get_portfolio`

```python theme={null}
get_portfolio(
    self,
    weights: pandas.core.series.Series,
) ‑> pandas.core.frame.DataFrame
```

Calculate the portfolio performance based on the given weights.

**Parameters**:

| Name      | Type        | Default | Description        |
| --------- | ----------- | ------- | ------------------ |
| `weights` | `pd.Series` | `--`    | Portfolio weights. |

**Returns**:

| Type           | Description       |
| -------------- | ----------------- |
| `pd.DataFrame` | Target portfolio. |

#### `get_efficient_frontier`

```python theme={null}
get_efficient_frontier(
    self,
    points: int = 20,
) ‑> pandas.core.frame.DataFrame
```

Calculate the efficient frontier.

**Parameters**:

| Name     | Type  | Default | Description                                                   |
| -------- | ----- | ------- | ------------------------------------------------------------- |
| `points` | `int` | `20`    | Number of points to calculate on the frontier, by default 20. |

**Returns**:

| Type           | Description         |
| -------------- | ------------------- |
| `pd.DataFrame` | Efficient frontier. |

#### `plot_frontier`

```python theme={null}
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**:

| Name                 | Type            | Default     | Description                                                   |
| -------------------- | --------------- | ----------- | ------------------------------------------------------------- |
| `weights`            | `pd.Series`     | `--`        | Portfolio weights.                                            |
| `display_frontier`   | `bool`          | `True`      | Display frontier. Defaults to True.                           |
| `portfolio_name`     | `str`           | `Target...` | Portfolio name. Defaults to "Target Portfolio".               |
| `marker_color`       | `str`           | `red`       | Color of the portfolio star shaped marker. Defaults to "red". |
| `marker_size`        | `int`           | `20`        | Size of the portfolio star shaped marker. Default to 20.      |
| `make_figure_kwargs` | `tp.KwargsLike` | `None`      | Additional figure arguments, by default None.                 |
| `fig`                | `tp.BaseFigure` | `None`      | Existing figure to update, by default None.                   |
| `showscale`          | `bool`          | `True`      | Whether to show the scale, by default True.                   |
| `layout_kwargs`      | `tp.Kwargs`     | `--`        | Additional layout arguments for the figure.                   |

**Returns**:

| Type               | Description                                         |
| ------------------ | --------------------------------------------------- |
| `vbt.FigureWidget` | A Plotly FigureWidget containing the frontier plot. |
