Skip to main content

ef

Get Efficient Frontier

Source Code: [link]

openbb.portfolio.po.ef(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
value_shortfloatAmount to allocate to portfolio in short positions, by default 0.0NoneTrue
risk_measurestrThe risk measure used to optimize the portfolio, by default 'MV'
Possible values are:

- 'MV': Standard Deviation.
- 'MAD': Mean Absolute Deviation.
- 'MSV': Semi Standard Deviation.
- 'FLPM': First Lower Partial Moment (Omega Ratio).
- 'SLPM': Second Lower Partial Moment (Sortino Ratio).
- 'CVaR': Conditional Value at Risk.
- 'EVaR': Entropic Value at Risk.
- 'WR': Worst Realization.
- 'ADD': Average Drawdown of uncompounded cumulative returns.
- 'UCI': Ulcer Index of uncompounded cumulative returns.
- 'CDaR': Conditional Drawdown at Risk of uncompounded cumulative returns.
- 'EDaR': Entropic Drawdown at Risk of uncompounded cumulative returns.
- 'MDD': Maximum Drawdown of uncompounded cumulative returns.
NoneTrue
risk_free_ratefloatRisk free rate, annualized. Used for 'FLPM' and 'SLPM' and Sharpe objective function, by default 0.0NoneTrue
alphafloatSignificance level of VaR, CVaR, EDaR, DaR, CDaR, EDaR, Tail Gini of losses, by default 0.05NoneTrue
n_portfoliosintNumber of portfolios to simulate, by default 100NoneTrue
seedintSeed used to generate random portfolios, by default 123NoneTrue

Returns

TypeDescription
Tuple[pd.DataFrame,
pd.DataFrame,
pd.DataFrame,
pd.DataFrame,
Optional[pd.DataFrame],
NDArray[floating],
NDArray[floating],
rp.Portfolio,

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.ef(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")
frontier = openbb.portfolio.po.ef(portfolio_engine=p)