Skip to main content

herc

Optimize with Hierarchical Equal Risk Contribution (HERC) method.

Source Code: [link]

openbb.portfolio.po.herc(portfolio_engine: Optional[portfolio_optimization.po_engine.PoEngine] = None, kwargs: Any)

Parameters

NameTypeDescriptionDefaultOptional
portfolio_enginePoEnginePortfolio optimization engine, by default None
Use portfolio.po.load to load a portfolio engine
NoneTrue
intervalstrInterval to get data, by default '3y'NoneTrue
start_datestrIf not using interval, start date string (YYYY-MM-DD), by default ""NoneTrue
end_datestrIf not using interval, end date string (YYYY-MM-DD). If empty use last weekday, by default ""NoneTrue
log_returnsboolIf True use log returns, else arithmetic returns, by default FalseNoneTrue
freqstrFrequency of returns, by default 'D'. Options: 'D' for daily, 'W' for weekly, 'M' for monthlyNoneTrue
maxnanfloatMaximum percentage of NaNs allowed in the data, by default 0.05NoneTrue
thresholdfloatValue used to replace outliers that are higher than threshold, by default 0.0NoneTrue
methodstrMethod used to fill nan values, by default 'time'
For more information see interpolate <https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.interpolate.html>__.
NoneTrue
valuefloatAmount to allocate to portfolio in long positions, by default 1.0NoneTrue
objectivestrObjective function of the optimization model, by default 'MinRisk'
Possible values are:

- 'MinRisk': Minimize the selected risk measure.
- 'Utility': Maximize the risk averse utility function.
- 'Sharpe': Maximize the risk adjusted return ratio based on the selected risk measure.
- 'MaxRet': Maximize the expected return of the portfolio.
NoneTrue
risk_measurestrThe risk measure used to optimize the portfolio, by default 'MV'
If model is 'NCO', the risk measures available depends on the objective function.
Possible values are:

- 'MV': Variance.
- 'MAD': Mean Absolute Deviation.
- 'MSV': Semi Standard Deviation.
- 'FLPM': First Lower Partial Moment (Omega Ratio).
- 'SLPM': Second Lower Partial Moment (Sortino Ratio).
- 'VaR': Value at Risk.
- 'CVaR': Conditional Value at Risk.
- 'TG': Tail Gini.
- 'EVaR': Entropic Value at Risk.
- 'WR': Worst Realization (Minimax).
- 'RG': Range of returns.
- 'CVRG': CVaR range of returns.
- 'TGRG': Tail Gini range of returns.
- 'MDD': Maximum Drawdown of uncompounded cumulative returns (Calmar Ratio).
- 'ADD': Average Drawdown of uncompounded cumulative returns.
- 'DaR': Drawdown at Risk of uncompounded cumulative returns.
- 'CDaR': Conditional Drawdown at Risk of uncompounded cumulative returns.
- 'EDaR': Entropic Drawdown at Risk of uncompounded cumulative returns.
- 'UCI': Ulcer Index of uncompounded cumulative returns.
- 'MDD_Rel': Maximum Drawdown of compounded cumulative returns (Calmar Ratio).
- 'ADD_Rel': Average Drawdown of compounded cumulative returns.
- 'DaR_Rel': Drawdown at Risk of compounded cumulative returns.
- 'CDaR_Rel': Conditional Drawdown at Risk of compounded cumulative returns.
- 'EDaR_Rel': Entropic Drawdown at Risk of compounded cumulative returns.
- 'UCI_Rel': Ulcer Index of compounded cumulative returns.
NoneTrue
risk_free_ratefloatRisk free rate, annualized. Used for 'FLPM' and 'SLPM' and Sharpe objective function, by default 0.0NoneTrue
risk_aversionfloatRisk aversion factor of the 'Utility' objective function, by default 1.0NoneTrue
alphafloatSignificance level of VaR, CVaR, EDaR, DaR, CDaR, EDaR, Tail Gini of losses, by default 0.05NoneTrue
a_simfloatNumber of CVaRs used to approximate Tail Gini of losses, by default 100NoneTrue
betafloatSignificance level of CVaR and Tail Gini of gains. If None it duplicates alpha value, by default NoneNoneTrue
b_simfloatNumber of CVaRs used to approximate Tail Gini of gains. If None it duplicates a_sim value, by default NoneNoneTrue
covariancestrThe method used to estimate the covariance matrix, by default 'hist'
Possible values are:

- 'hist': use historical estimates.
- 'ewma1': use ewma with adjust=True. For more information see EWM <https://pandas.pydata.org/pandas-docs/stable/user_guide/window.html#exponentially-weighted-window>.
- 'ewma2': use ewma with adjust=False. For more information see EWM <https://pandas.pydata.org/pandas-docs/stable/user_guide/window.html#exponentially-weighted-window>
.
- 'ledoit': use the Ledoit and Wolf Shrinkage method.
- 'oas': use the Oracle Approximation Shrinkage method.
- 'shrunk': use the basic Shrunk Covariance method.
- 'gl': use the basic Graphical Lasso Covariance method.
- 'jlogo': use the j-LoGo Covariance method. For more information see: a-jLogo.
- 'fixed': denoise using fixed method. For more information see chapter 2 of a-MLforAM.
- 'spectral': denoise using spectral method. For more information see chapter 2 of a-MLforAM.
- 'shrink': denoise using shrink method. For more information see chapter 2 of a-MLforAM.
NoneTrue
d_ewmafloatThe smoothing factor of ewma methods, by default 0.94NoneTrue
codependencestrThe codependence or similarity matrix used to build the distance
metric and clusters. The default is 'pearson'. Possible values are:

- 'pearson': pearson correlation matrix. Distance formula:
.. math:: D{i,j} = \sqrt{0.5(1-\rho^{pearson}{i,j})}
- 'spearman': spearman correlation matrix. Distance formula:
.. math:: D{i,j} = \sqrt{0.5(1-\rho^{spearman}{i,j})}
- 'abspearson': absolute value pearson correlation matrix. Distance formula:
.. math:: D
{i,j} = \sqrt{(1-
\rho^{pearson}_{i,j})}
- 'absspearman': absolute value spearman correlation matrix. Distance formula:
.. math:: D
{i,j} = \sqrt{(1-
linkagestrLinkage method of hierarchical clustering. For more information see linkage <https://docs.scipy.org/doc/scipy/reference/generated/scipy.<br/>cluster.hierarchy.linkage.html?highlight=linkage#scipy.cluster.hierarchy.linkage>__.
The default is 'single'. Possible values are:

- 'single'.
- 'complete'.
- 'average'.
- 'weighted'.
- 'centroid'.
- 'median'.
- 'ward'.
- 'dbht': Direct Bubble Hierarchical Tree.
NoneTrue
kintNumber of clusters. This value is took instead of the optimal number
of clusters calculated with the two difference gap statistic, by default None
NoneTrue
max_kintMax number of clusters used by the two difference gap statistic
to find the optimal number of clusters, by default 10
NoneTrue
bins_infostrNumber of bins used to calculate variation of information, by default 'KN'.
Possible values are:

- 'KN': Knuth's choice method. For more information see knuth_bin_width <https://docs.astropy.org/en/stable/api/astropy.stats.knuth_bin_width.html>.
- 'FD': Freedman–Diaconis' choice method. For more information see freedman_bin_width <https://docs.astropy.org/en/stable/api/astropy.stats.freedman_bin_width.html>
.
- 'SC': Scotts' choice method. For more information see scott_bin_width <https://docs.astropy.org/en/stable/api/astropy.stats.scott_bin_width.html>__.
- 'HGR': Hacine-Gharbi and Ravier' choice method.
NoneTrue
alpha_tailfloatSignificance level for lower tail dependence index, by default 0.05NoneTrue
leaf_orderboolIndicates if the cluster are ordered so that the distance between
successive leaves is minimal, by default True
NoneTrue

Returns

TypeDescription
Tuple[pd.DataFrame, Dict]Tuple with weights and performance dictionary

Examples

from openbb_terminal.sdk import openbb
d = {
"SECTOR": {
"AAPL": "INFORMATION TECHNOLOGY",
"MSFT": "INFORMATION TECHNOLOGY",
"AMZN": "CONSUMER DISCRETIONARY",
},
"CURRENCY": {
"AAPL": "USD",
"MSFT": "USD",
"AMZN": "USD",
},
"CURRENT_INVESTED_AMOUNT": {
"AAPL": "100000.0",
"MSFT": "200000.0",
"AMZN": "300000.0",
},
}
p = openbb.portfolio.po.load(symbols_categories=d)
weights, performance = openbb.portfolio.po.herc(portfolio_engine=p)
from openbb_terminal.sdk import openbb
p = openbb.portfolio.po.load(symbols_file_path="~/openbb_terminal/miscellaneous/portfolio_examples/allocation/60_40_Portfolio.xlsx")
weights, performance = openbb.portfolio.po.herc(portfolio_engine=p)