Weighting¶
The classes in Weighting
defines the algorithms as to how weights are computed.
- class fipie.EqualWeight¶
Equal nominal weighting across instruments. For instance, if there are 4 instruments in a portfolio, 25% of capital is allocated to each one.
- __init__()¶
- optimise(ret: pandas.core.frame.DataFrame, *args, **kwargs) pandas.core.series.Series ¶
Calculate weights for instruments
- Parameters
ret (pd.DataFrame) – return time-series
- Returns
weights for each instrument
- Return type
pd.Series
- class fipie.EqualRiskContribution(fully_invested: bool = True, bounds: Tuple[float, None] = (0, None))¶
Create a portfolio with equal risk contribution (ERC, aka risk parity) such that each instrument contributes the same amount of risk to the portfolio. More formally, let \(\sigma \left( w \right)\) be the volatility of portfolio and \(w\) be the weight for each instrument. The volatility of portfolio can be decomposed to the following:
\[\sigma \left( w \right) = \sum_i \sigma_i \left( x \right) = \sum_i w_i \frac{ {\partial} \sigma \left( x \right) }{ {\partial} w_i }\]where \(\sigma_i \left( x \right)\) is the total risk contribution of instrument \(i\), \(\frac{ {\partial} \sigma \left( x \right) }{ {\partial} w_i }\) is the marginal risk contribution.
The ERC portfolio is derived such that all instruments have the same amount of total risk contribution.
Reference
Maillard, S., Roncalli, T. and Teïletche, J., 2010. The properties of equally weighted risk contribution portfolios. The Journal of Portfolio Management, 36(4), pp.60-70.
- __init__(fully_invested: bool = True, bounds: Tuple[float, None] = (0, None))¶
- Parameters
fully_invested (bool, default True) – If True, weights are rescaled so that they add up to 100%. By default the optimal weights are rescaled to add up to 100% as the Sharpe ratio is scale-invariant with respect to the weight.
bounds (tuple, list-like) – Lower and upper bounds of weights. If None, weights are unbounded, i.e.,
(0, None)
means it only allows long positions.
Note
With default parameters, this class produces a long-only fully-invested portfolio.
- optimise(ret: pandas.core.frame.DataFrame, *args, **kwargs) pandas.core.series.Series ¶
Calculate weights for instruments
- Parameters
ret (pd.DataFrame) – return time-series
- Returns
weights for each instrument
- Return type
pd.Series
- class fipie.MaximumDiversification(fully_invested: bool = True, bounds: Tuple[float, None] = (0, None))¶
Create a portfolio which maximises the diversification factor
\[\frac{ w^T \cdot \sigma }{ \sqrt{w^T \cdot \Sigma \cdot w} }\]where \(w\) is the weight vector of each instrument, \(\sigma\) is the volatility vector of each instrument, \(\Sigma\) is the covariance matrix. The numerator of the diversification factor is a weighted average of instrument volatility whereas the denominator is the portfolio volatility after diversification.
- __init__(fully_invested: bool = True, bounds: Tuple[float, None] = (0, None))¶
- Parameters
fully_invested (bool, default True) – If True, weights are rescaled so that they add up to 100%. By default the optimal weights are rescaled to add up to 100% as the Sharpe ratio is scale-invariant with respect to the weight.
bounds (tuple, list-like) – Lower and upper bounds of weights. If None, weights are unbounded, i.e.,
(0, None)
means it only allows long positions.
Note
With default parameters, this class produces a long-only fully-invested portfolio.
- optimise(ret: pandas.core.frame.DataFrame, *args, **kwargs) pandas.core.series.Series ¶
Calculate weights for instruments
- Parameters
ret (pd.DataFrame) – return time-series
- Returns
weights for each instrument
- Return type
pd.Series
- class fipie.MeanVariance(fully_invested: bool = True, bounds: Tuple[float, None] = (0, None))¶
Weights are determined by the mean-variance approach and maximising the Sharpe ratio. Expected returns and risk are estimated by historical means and covariance matrix
- __init__(fully_invested: bool = True, bounds: Tuple[float, None] = (0, None))¶
- Parameters
fully_invested (bool, default True) – If True, weights are rescaled so that they add up to 100%. By default the optimal weights are rescaled to add up to 100% as the Sharpe ratio is scale-invariant with respect to the weight.
bounds (tuple, list-like) – Lower and upper bounds of weights. If None, weights are unbounded, i.e.,
(0, None)
means it only allows long positions.
Note
With default parameters, this class produces a long-only fully-invested portfolio.
- optimise(ret: pandas.core.frame.DataFrame, *args, **kwargs) pandas.core.series.Series ¶
Calculate weights for instruments
- Parameters
ret (pd.DataFrame) – return time-series
- Returns
weights for each instrument
- Return type
pd.Series
- class fipie.MinimumVariance(fully_invested: bool = True, bounds: Tuple[float, None] = (0, None))¶
Create a portfolio by minimising its variance.
- __init__(fully_invested: bool = True, bounds: Tuple[float, None] = (0, None))¶
- Parameters
fully_invested (bool, default True) – If True, weights are rescaled so that they add up to 100%. By default the optimal weights are rescaled to add up to 100% as the Sharpe ratio is scale-invariant with respect to the weight.
bounds (tuple, list-like) – Lower and upper bounds of weights. If None, weights are unbounded, i.e.,
(0, None)
means it only allows long positions.
Note
With default parameters, this class produces a long-only fully-invested portfolio.
- optimise(ret: pandas.core.frame.DataFrame, *args, **kwargs) pandas.core.series.Series ¶
Calculate weights for instruments
- Parameters
ret (pd.DataFrame) – return time-series
- Returns
weights for each instrument
- Return type
pd.Series
- class fipie.VolatilityParity(target_vol: float = 0.1, fully_invested: bool = False)¶
Volatility parity weighting across instruments. Allocate capital so that each instrument has a volatility equal to the target volatility. As a result instruments with lower volatility gets a relatively higher nominal weight. This method ignores the correlation between assets.
- __init__(target_vol: float = 0.1, fully_invested: bool = False)¶
- Parameters
target_vol – Annualised target volatility of each instrument
fully_invested – If True, weights are rescaled so that they add up to 100%.
- optimise(ret: pandas.core.frame.DataFrame, *args, **kwargs) pandas.core.series.Series ¶
Calculate weights for instruments
- Parameters
ret (pd.DataFrame) – return time-series
- Returns
weights for each instrument
- Return type
pd.Series