Skip to main content

mktcap

Optimize weighted according to market capitalization

Source Code: [link]

openbb.portfolio.po.mktcap(symbols: List[str] = None, portfolio_engine: 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
symbolsList[str]List of symbols, by default NoneNoneTrue
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

Returns

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

Examples

from openbb_terminal.sdk import openbb
openbb.portfolio.po.mktcap(symbols=["AAPL", "MSFT", "AMZN"])
(         value
AAPL 0.465338
MSFT 0.345488
AMZN 0.189175,
{'Return': 0.25830567048487474,
'Volatility': 0.33058479906988086,
'Sharpe ratio': 0.7813597939519071})
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.mktcap(portfolio_engine=p)