From d82e3d2d54e979d40e032725e63f106e2074651f Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 18:39:19 +0000 Subject: [PATCH 01/30] create functions to interact with portfolio --- CONTRIBUTING.md | 2 +- .../portfolio/portfolio_controller.py | 8 +- openbb_terminal/portfolio/portfolio_model.py | 175 +++++++++++----- openbb_terminal/portfolio/portfolio_view.py | 191 +++++++++++------- openbb_terminal/sdk.py | 2 +- .../content/SDK/portfolio/calmar/_index.rst | 2 +- .../SDK/portfolio/commonsense/_index.rst | 2 +- .../content/SDK/portfolio/distr/_index.rst | 5 +- website/content/SDK/portfolio/dret/_index.rst | 5 +- website/content/SDK/portfolio/es/_index.rst | 2 +- .../SDK/portfolio/gaintopain/_index.rst | 2 +- .../content/SDK/portfolio/holdp/_index.rst | 5 +- .../content/SDK/portfolio/holdv/_index.rst | 5 +- .../SDK/portfolio/information/_index.rst | 2 +- .../content/SDK/portfolio/jensens/_index.rst | 2 +- .../content/SDK/portfolio/kelly/_index.rst | 2 +- .../content/SDK/portfolio/kurtosis/_index.rst | 2 +- .../portfolio/max_drawdown_ratio/_index.rst | 5 +- .../content/SDK/portfolio/maxdd/_index.rst | 7 +- .../SDK/portfolio/maxdrawdown/_index.rst | 2 +- website/content/SDK/portfolio/mret/_index.rst | 5 +- website/content/SDK/portfolio/om/_index.rst | 5 +- .../content/SDK/portfolio/payoff/_index.rst | 2 +- website/content/SDK/portfolio/perf/_index.rst | 2 +- .../SDK/portfolio/profitfactor/_index.rst | 2 +- .../content/SDK/portfolio/rbeta/_index.rst | 9 +- .../content/SDK/portfolio/rsharpe/_index.rst | 5 +- .../content/SDK/portfolio/rsortino/_index.rst | 9 +- .../content/SDK/portfolio/rsquare/_index.rst | 2 +- website/content/SDK/portfolio/rvol/_index.rst | 7 +- .../content/SDK/portfolio/sharpe/_index.rst | 2 +- website/content/SDK/portfolio/skew/_index.rst | 2 +- .../content/SDK/portfolio/sortino/_index.rst | 2 +- .../content/SDK/portfolio/summary/_index.rst | 2 +- website/content/SDK/portfolio/tail/_index.rst | 2 +- .../content/SDK/portfolio/trackerr/_index.rst | 2 +- website/content/SDK/portfolio/var/_index.rst | 2 +- .../SDK/portfolio/volatility/_index.rst | 2 +- website/content/SDK/portfolio/yret/_index.rst | 5 +- 39 files changed, 302 insertions(+), 195 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1569c7a0f8ed..5d31907d323f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -695,7 +695,7 @@ With: ```python - def get_gaintopain_ratio(portfolio: PortfolioModel) -> pd.DataFrame: + def get_gaintopain_ratio(portfolio: PortfolioEngine) -> pd.DataFrame: """...""" diff --git a/openbb_terminal/portfolio/portfolio_controller.py b/openbb_terminal/portfolio/portfolio_controller.py index d409b5453a9b..0ec16a16e130 100644 --- a/openbb_terminal/portfolio/portfolio_controller.py +++ b/openbb_terminal/portfolio/portfolio_controller.py @@ -139,8 +139,8 @@ def __init__(self, queue: List[str] = None): self.original_benchmark_name = "" self.risk_free_rate = 0 self.portlist: List[str] = os.listdir(self.DEFAULT_HOLDINGS_PATH) - self.portfolio: portfolio_model.PortfolioModel = ( - portfolio_model.PortfolioModel() + self.portfolio: portfolio_model.PortfolioEngine = ( + portfolio_model.PortfolioEngine() ) if session and obbff.USE_PROMPT_TOOLKIT: @@ -442,10 +442,10 @@ def call_load(self, other_args: List[str]): else: file_location = ns_parser.file # type: ignore - transactions = portfolio_model.PortfolioModel.read_transactions( + transactions = portfolio_model.PortfolioEngine.read_transactions( str(file_location) ) - self.portfolio = portfolio_model.PortfolioModel(transactions) + self.portfolio = portfolio_model.PortfolioEngine(transactions) self.benchmark_name = "" if ns_parser.name: diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 9b7a2afe9684..be47e36abf5b 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -30,7 +30,7 @@ pd.options.mode.chained_assignment = None -class PortfolioModel: +class PortfolioEngine: """ Class for portfolio analysis in OpenBB Implements a Portfolio and related methods. @@ -61,7 +61,7 @@ class PortfolioModel: """ def __init__(self, transactions: pd.DataFrame = pd.DataFrame()): - """Initialize PortfolioModel class""" + """Initialize PortfolioEngine class""" # Portfolio self.tickers_list = None @@ -106,7 +106,8 @@ def __set_transactions(self, transactions): def get_transactions(self): """Get formatted transactions - Returns: + Returns + ------- pd.DataFrame: formatted transactions """ df = self.__transactions[ @@ -133,12 +134,17 @@ def get_transactions(self): @staticmethod def read_transactions(path: str) -> pd.DataFrame: - """Static method to read transactions from file + """Static method to read transactions from file. Parameters ---------- path: str path to transactions file + + Returns + ------- + pd.DataFrame + DataFrame with transactions """ # Load transactions from file if path.endswith(".xlsx"): @@ -428,24 +434,24 @@ def load_company_data(self): ] = info_list @log_start_end(log=logger) - def load_benchmark(self, ticker: str = "SPY", full_shares: bool = False): - """Adds benchmark dataframe + def load_benchmark(self, symbol: str = "SPY", full_shares: bool = False): + """Load benchmark into portfolio. Parameters ---------- - ticker: str - benchmark ticker to download data + symbol: str + Benchmark symbol to download data full_shares: bool - whether to mimic the portfolio trades exactly (partial shares) or round down the - quantity to the nearest number. + Whether to mimic the portfolio trades exactly (partial shares) or round down the + quantity to the nearest number """ p_bar = tqdm(range(3), desc=" Loading benchmark") - self.benchmark_ticker = ticker + self.benchmark_ticker = symbol self.benchmark_historical_prices = yf.download( - ticker, + symbol, start=self.inception_date - datetime.timedelta(days=1), threads=False, progress=False, @@ -470,7 +476,7 @@ def load_benchmark(self, ticker: str = "SPY", full_shares: bool = False): p_bar.refresh() self.benchmark_returns = self.benchmark_historical_prices.pct_change().dropna() - self.benchmark_info = yf.Ticker(ticker).info + self.benchmark_info = yf.Ticker(symbol).info p_bar.n += 1 p_bar.refresh() @@ -785,14 +791,15 @@ def set_risk_free_rate(self, risk_free_rate: float): Parameters ---------- - risk_free (float): risk free rate in float format + risk_free_rate : float + Risk free rate in float format """ self.risk_free_rate = risk_free_rate # Metrics @log_start_end(log=logger) -def get_r2_score(portfolio: PortfolioModel) -> pd.DataFrame: +def get_r2_score(portfolio: PortfolioEngine) -> pd.DataFrame: """Class method that retrieves R2 Score for portfolio and benchmark selected Parameters @@ -822,7 +829,7 @@ def get_r2_score(portfolio: PortfolioModel) -> pd.DataFrame: @log_start_end(log=logger) -def get_skewness(portfolio: PortfolioModel) -> pd.DataFrame: +def get_skewness(portfolio: PortfolioEngine) -> pd.DataFrame: """Class method that retrieves skewness for portfolio and benchmark selected portfolio: Portfolio @@ -859,7 +866,7 @@ def get_skewness(portfolio: PortfolioModel) -> pd.DataFrame: @log_start_end(log=logger) -def get_kurtosis(portfolio: PortfolioModel) -> pd.DataFrame: +def get_kurtosis(portfolio: PortfolioEngine) -> pd.DataFrame: """Class method that retrieves kurtosis for portfolio and benchmark selected Parameters @@ -898,7 +905,7 @@ def get_kurtosis(portfolio: PortfolioModel) -> pd.DataFrame: @log_start_end(log=logger) -def get_stats(portfolio: PortfolioModel, window: str = "all") -> pd.DataFrame: +def get_stats(portfolio: PortfolioEngine, window: str = "all") -> pd.DataFrame: """Class method that retrieves stats for portfolio and benchmark selected based on a certain interval Parameters @@ -928,7 +935,7 @@ def get_stats(portfolio: PortfolioModel, window: str = "all") -> pd.DataFrame: @log_start_end(log=logger) -def get_volatility(portfolio: PortfolioModel) -> pd.DataFrame: +def get_volatility(portfolio: PortfolioEngine) -> pd.DataFrame: """Class method that retrieves volatility for portfolio and benchmark selected Parameters @@ -968,7 +975,7 @@ def get_volatility(portfolio: PortfolioModel) -> pd.DataFrame: @log_start_end(log=logger) def get_sharpe_ratio( - portfolio: PortfolioModel, risk_free_rate: float = 0 + portfolio: PortfolioEngine, risk_free_rate: float = 0 ) -> pd.DataFrame: """Class method that retrieves sharpe ratio for portfolio and benchmark selected @@ -1013,7 +1020,7 @@ def get_sharpe_ratio( @log_start_end(log=logger) def get_sortino_ratio( - portfolio: PortfolioModel, risk_free_rate: float = 0 + portfolio: PortfolioEngine, risk_free_rate: float = 0 ) -> pd.DataFrame: """Class method that retrieves sortino ratio for portfolio and benchmark selected @@ -1057,7 +1064,7 @@ def get_sortino_ratio( @log_start_end(log=logger) -def get_maximum_drawdown_ratio(portfolio: PortfolioModel) -> pd.DataFrame: +def get_maximum_drawdown_ratio(portfolio: PortfolioEngine) -> pd.DataFrame: """Class method that retrieves maximum drawdown ratio for portfolio and benchmark selected Parameters @@ -1096,7 +1103,7 @@ def get_maximum_drawdown_ratio(portfolio: PortfolioModel) -> pd.DataFrame: @log_start_end(log=logger) -def get_gaintopain_ratio(portfolio: PortfolioModel): +def get_gaintopain_ratio(portfolio: PortfolioEngine): """Get Pain-to-Gain ratio based on historical data Parameters @@ -1119,7 +1126,7 @@ def get_gaintopain_ratio(portfolio: PortfolioModel): @log_start_end(log=logger) -def get_tracking_error(portfolio: PortfolioModel, window: int = 252): +def get_tracking_error(portfolio: PortfolioEngine, window: int = 252): """Get tracking error Parameters @@ -1144,7 +1151,7 @@ def get_tracking_error(portfolio: PortfolioModel, window: int = 252): @log_start_end(log=logger) -def get_information_ratio(portfolio: PortfolioModel): +def get_information_ratio(portfolio: PortfolioEngine): """Get information ratio Parameters @@ -1168,7 +1175,7 @@ def get_information_ratio(portfolio: PortfolioModel): @log_start_end(log=logger) -def get_tail_ratio(portfolio: PortfolioModel, window: int = 252): +def get_tail_ratio(portfolio: PortfolioEngine, window: int = 252): """Get tail ratio Parameters @@ -1196,7 +1203,7 @@ def get_tail_ratio(portfolio: PortfolioModel, window: int = 252): @log_start_end(log=logger) -def get_common_sense_ratio(portfolio: PortfolioModel): +def get_common_sense_ratio(portfolio: PortfolioEngine): """Get common sense ratio Parameters @@ -1221,7 +1228,7 @@ def get_common_sense_ratio(portfolio: PortfolioModel): @log_start_end(log=logger) def get_jensens_alpha( - portfolio: PortfolioModel, risk_free_rate: float = 0, window: str = "1y" + portfolio: PortfolioEngine, risk_free_rate: float = 0, window: str = "1y" ): """Get jensen's alpha @@ -1254,7 +1261,7 @@ def get_jensens_alpha( @log_start_end(log=logger) -def get_calmar_ratio(portfolio: PortfolioModel, window: int = 756): +def get_calmar_ratio(portfolio: PortfolioEngine, window: int = 756): """Get calmar ratio Parameters @@ -1283,7 +1290,7 @@ def get_calmar_ratio(portfolio: PortfolioModel, window: int = 756): @log_start_end(log=logger) -def get_kelly_criterion(portfolio: PortfolioModel): +def get_kelly_criterion(portfolio: PortfolioEngine): """Gets kelly criterion Parameters @@ -1304,7 +1311,7 @@ def get_kelly_criterion(portfolio: PortfolioModel): @log_start_end(log=logger) -def get_payoff_ratio(portfolio: PortfolioModel): +def get_payoff_ratio(portfolio: PortfolioEngine): """Gets payoff ratio Returns @@ -1318,7 +1325,7 @@ def get_payoff_ratio(portfolio: PortfolioModel): @log_start_end(log=logger) -def get_profit_factor(portfolio: PortfolioModel): +def get_profit_factor(portfolio: PortfolioEngine): """Gets profit factor Parameters @@ -1336,7 +1343,7 @@ def get_profit_factor(portfolio: PortfolioModel): return pf_period_df -def get_holdings_value(portfolio: PortfolioModel) -> pd.DataFrame: +def get_holdings_value(portfolio: PortfolioEngine) -> pd.DataFrame: """Get holdings of assets (absolute value) Parameters @@ -1359,7 +1366,7 @@ def get_holdings_value(portfolio: PortfolioModel) -> pd.DataFrame: def get_holdings_percentage( - portfolio: PortfolioModel, + portfolio: PortfolioEngine, ): """Get holdings of assets (in percentage) @@ -1381,7 +1388,7 @@ def get_holdings_percentage( @log_start_end(log=logger) def get_maximum_drawdown( - portfolio: PortfolioModel, is_returns: bool = False + portfolio: PortfolioEngine, is_returns: bool = False ) -> pd.Series: """Calculate the drawdown (MDD) of historical series. Note that the calculation is done on cumulative returns (or prices). The definition of drawdown is @@ -1413,7 +1420,7 @@ def get_maximum_drawdown( def get_distribution_returns( - portfolio: PortfolioModel, + portfolio: PortfolioEngine, window: str = "all", ): """Display daily returns @@ -1438,7 +1445,7 @@ def get_distribution_returns( def get_rolling_volatility( - portfolio: PortfolioModel, window: str = "1y" + portfolio: PortfolioEngine, window: str = "1y" ) -> pd.DataFrame: """Get rolling volatility @@ -1509,7 +1516,7 @@ def get_rolling_sharpe( def get_rolling_sortino( - portfolio: PortfolioModel, + portfolio: PortfolioEngine, risk_free_rate: float = 0, window: str = "1y", ) -> pd.DataFrame: @@ -1517,7 +1524,7 @@ def get_rolling_sortino( Parameters ---------- - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object window: str interval for window to consider @@ -1551,14 +1558,14 @@ def get_rolling_sortino( @log_start_end(log=logger) def get_rolling_beta( - portfolio: PortfolioModel, + portfolio: PortfolioEngine, window: str = "1y", ) -> pd.DataFrame: """Get rolling beta using portfolio and benchmark returns Parameters ---------- - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object window: string Interval used for rolling values. @@ -1579,7 +1586,7 @@ def get_rolling_beta( @log_start_end(log=logger) def get_performance_vs_benchmark( - portfolio: PortfolioModel, + portfolio: PortfolioEngine, show_all_trades: bool = False, ) -> pd.DataFrame: @@ -1683,7 +1690,7 @@ def get_performance_vs_benchmark( @log_start_end(log=logger) def get_var( - portfolio: PortfolioModel, + portfolio: PortfolioEngine, use_mean: bool = False, adjusted_var: bool = False, student_t: bool = False, @@ -1721,7 +1728,7 @@ def get_var( @log_start_end(log=logger) def get_es( - portfolio: PortfolioModel, + portfolio: PortfolioEngine, use_mean: bool = False, distribution: str = "normal", percentile: float = 99.9, @@ -1755,7 +1762,7 @@ def get_es( @log_start_end(log=logger) def get_omega( - portfolio: PortfolioModel, threshold_start: float = 0, threshold_end: float = 1.5 + portfolio: PortfolioEngine, threshold_start: float = 0, threshold_end: float = 1.5 ) -> pd.DataFrame: """Get omega ratio @@ -1781,7 +1788,7 @@ def get_omega( def get_summary( - portfolio: PortfolioModel, + portfolio: PortfolioEngine, window: str = "all", risk_free_rate: float = 0, ) -> pd.DataFrame: @@ -1849,7 +1856,7 @@ def get_summary( @log_start_end(log=logger) def get_yearly_returns( - portfolio: PortfolioModel, + portfolio: PortfolioEngine, window: str = "all", ): """Get yearly returns @@ -1898,7 +1905,7 @@ def get_yearly_returns( @log_start_end(log=logger) def get_monthly_returns( - portfolio: PortfolioModel, + portfolio: PortfolioEngine, window: str = "all", ) -> pd.DataFrame: """Get monthly returns @@ -1993,7 +2000,7 @@ def get_monthly_returns( @log_start_end(log=logger) def get_daily_returns( - portfolio: PortfolioModel, + portfolio: PortfolioEngine, window: str = "all", ) -> pd.DataFrame: """Get daily returns @@ -2007,8 +2014,8 @@ def get_daily_returns( Returns ------- pd.DataFrame - """ + portfolio_returns = portfolio_helper.filter_df_by_period(portfolio.returns, window) benchmark_returns = portfolio_helper.filter_df_by_period( portfolio.benchmark_returns, window @@ -2022,6 +2029,74 @@ def get_daily_returns( return df +def generate_portfolio( + transactions_path: str, + benchmark_symbol: str = "SPY", + full_shares: bool = False, + risk_free_rate: float = 0, +) -> PortfolioEngine: + """Get PortfolioEngine object + + Parameters + ---------- + file_path : str + Path to transactions file + benchmark_symbol : str + Benchmark ticker to download data + full_shares : bool + Whether to mimic the portfolio trades exactly (partial shares) or round down the + quantity to the nearest number + risk_free_rate : float + Risk free rate in float format + + Returns + ------- + PortfolioEngine + PortfolioEngine object + """ + + transactions = PortfolioEngine.read_transactions(transactions_path) + engine = PortfolioEngine(transactions) + engine.generate_portfolio_data() + engine.load_benchmark(symbol=benchmark_symbol, full_shares=full_shares) + engine.set_risk_free_rate(risk_free_rate) + + return engine + + +def set_benchmark( + engine: PortfolioEngine, symbol: str = "SPY", full_shares: bool = False +): + """Load benchmark into portfolio + + Parameters + ---------- + engine: PortfolioEngine + PortfolioEngine object + symbol: str + Benchmark symbol to download data + full_shares: bool + Whether to mimic the portfolio trades exactly (partial shares) or round down the + quantity to the nearest number + """ + + engine.load_benchmark(symbol=symbol, full_shares=full_shares) + + +def set_risk_free_rate(engine: PortfolioEngine, risk_free_rate: float): + """Set risk-free rate + + Parameters + ---------- + engine: PortfolioEngine + PortfolioEngine object + risk_free_rate: float + Risk free rate in float format + """ + + engine.set_risk_free_rate(risk_free_rate=risk_free_rate) + + # Old code @log_start_end(log=logger) def get_main_text(data: pd.DataFrame) -> str: diff --git a/openbb_terminal/portfolio/portfolio_view.py b/openbb_terminal/portfolio/portfolio_view.py index c4a36e3e2be6..446bf2e36df6 100644 --- a/openbb_terminal/portfolio/portfolio_view.py +++ b/openbb_terminal/portfolio/portfolio_view.py @@ -14,7 +14,40 @@ from openbb_terminal.common.quantitative_analysis import qa_view from openbb_terminal.config_terminal import theme from openbb_terminal.config_plot import PLOT_DPI -from openbb_terminal.portfolio import portfolio_model +from openbb_terminal.portfolio.portfolio_model import ( + PortfolioEngine, + get_daily_returns, + get_performance_vs_benchmark, + get_yearly_returns, + get_monthly_returns, + get_distribution_returns, + get_holdings_value, + get_holdings_percentage, + get_rolling_volatility, + get_rolling_sharpe, + get_rolling_sortino, + get_rolling_beta, + get_maximum_drawdown, + get_r2_score, + get_skewness, + get_kurtosis, + get_stats, + get_volatility, + get_sharpe_ratio, + get_sortino_ratio, + get_maximum_drawdown_ratio, + get_gaintopain_ratio, + get_tracking_error, + get_information_ratio, + get_tail_ratio, + get_common_sense_ratio, + get_jensens_alpha, + get_calmar_ratio, + get_kelly_criterion, + get_payoff_ratio, + get_profit_factor, + get_summary, +) from openbb_terminal.helper_funcs import ( export_data, @@ -251,7 +284,7 @@ def display_category_allocation( @log_start_end(log=logger) def display_performance_vs_benchmark( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, show_all_trades: bool = False, ): """Display portfolio performance vs the benchmark @@ -266,7 +299,7 @@ def display_performance_vs_benchmark( Whether to also show all trades made and their performance (default is False) """ - df = portfolio_model.get_performance_vs_benchmark(portfolio, show_all_trades) + df = get_performance_vs_benchmark(portfolio, show_all_trades) if show_all_trades: print_rich_table( @@ -287,7 +320,7 @@ def display_performance_vs_benchmark( @log_start_end(log=logger) def display_yearly_returns( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, window: str = "all", raw: bool = False, export: str = "", @@ -309,7 +342,7 @@ def display_yearly_returns( Optional axes to display plot on """ - df = portfolio_model.get_yearly_returns(portfolio, window) + df = get_yearly_returns(portfolio, window) if raw: print_rich_table( @@ -367,7 +400,7 @@ def display_yearly_returns( @log_start_end(log=logger) def display_monthly_returns( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, window: str = "all", raw: bool = False, show_vals: bool = False, @@ -392,9 +425,7 @@ def display_monthly_returns( Optional axes to display plot on """ - portfolio_returns, benchmark_returns = portfolio_model.get_monthly_returns( - portfolio, window - ) + portfolio_returns, benchmark_returns = get_monthly_returns(portfolio, window) if raw: print_rich_table( @@ -469,7 +500,7 @@ def display_monthly_returns( @log_start_end(log=logger) def display_daily_returns( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, window: str = "all", raw: bool = False, limit: int = 10, @@ -494,7 +525,7 @@ def display_daily_returns( Optional axes to display plot on """ - df = portfolio_model.get_daily_returns(portfolio, window) + df = get_daily_returns(portfolio, window) if raw: print_rich_table( @@ -537,7 +568,7 @@ def display_daily_returns( @log_start_end(log=logger) def display_distribution_returns( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, window: str = "all", raw: bool = False, export: str = "", @@ -561,7 +592,7 @@ def display_distribution_returns( Optional axes to display plot on """ - df = portfolio_model.get_distribution_returns(portfolio, window) + df = get_distribution_returns(portfolio, window) df_portfolio = df["portfolio"] df_benchmark = df["benchmark"] @@ -624,7 +655,7 @@ def display_distribution_returns( @log_start_end(log=logger) def display_holdings_value( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, unstack: bool = False, raw: bool = False, limit: int = 10, @@ -649,7 +680,7 @@ def display_holdings_value( Optional axes to display plot on """ - all_holdings = portfolio_model.get_holdings_value(portfolio) + all_holdings = get_holdings_value(portfolio) if raw: print_rich_table( @@ -702,7 +733,7 @@ def display_holdings_value( @log_start_end(log=logger) def display_holdings_percentage( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, unstack: bool = False, raw: bool = False, limit: int = 10, @@ -727,7 +758,7 @@ def display_holdings_percentage( Optional axes to display plot on """ - all_holdings = portfolio_model.get_holdings_percentage(portfolio) + all_holdings = get_holdings_percentage(portfolio) if raw: # No need to account for time since this is daily data @@ -785,7 +816,7 @@ def display_holdings_percentage( @log_start_end(log=logger) def display_rolling_volatility( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, window: str = "1y", export: str = "", external_axes: Optional[List[plt.Axes]] = None, @@ -794,7 +825,7 @@ def display_rolling_volatility( Parameters ---------- - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object interval: str interval for window to consider @@ -805,7 +836,7 @@ def display_rolling_volatility( """ metric = "volatility" - df = portfolio_model.get_rolling_volatility(portfolio, window) + df = get_rolling_volatility(portfolio, window) if df.empty: return @@ -841,7 +872,7 @@ def display_rolling_volatility( @log_start_end(log=logger) def display_rolling_sharpe( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, risk_free_rate: float = 0, window: str = "1y", export: str = "", @@ -851,7 +882,7 @@ def display_rolling_sharpe( Parameters ---------- - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object risk_free_rate: float Value to use for risk free rate in sharpe/other calculations @@ -864,7 +895,7 @@ def display_rolling_sharpe( """ metric = "sharpe" - df = portfolio_model.get_rolling_sharpe(portfolio, risk_free_rate, window) + df = get_rolling_sharpe(portfolio, risk_free_rate, window) if df.empty: return @@ -900,7 +931,7 @@ def display_rolling_sharpe( @log_start_end(log=logger) def display_rolling_sortino( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, risk_free_rate: float = 0, window: str = "1y", export: str = "", @@ -910,7 +941,7 @@ def display_rolling_sortino( Parameters ---------- - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object risk_free_rate: float Value to use for risk free rate in sharpe/other calculations @@ -923,7 +954,7 @@ def display_rolling_sortino( """ metric = "sortino" - df = portfolio_model.get_rolling_sortino(portfolio, risk_free_rate, window) + df = get_rolling_sortino(portfolio, risk_free_rate, window) if df.empty: return @@ -959,7 +990,7 @@ def display_rolling_sortino( @log_start_end(log=logger) def display_rolling_beta( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, window: str = "1y", export: str = "", external_axes: Optional[List[plt.Axes]] = None, @@ -968,7 +999,7 @@ def display_rolling_beta( Parameters ---------- - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object window: str interval for window to consider @@ -979,7 +1010,7 @@ def display_rolling_beta( Optional axes to display plot on """ - rolling_beta = portfolio_model.get_rolling_beta(portfolio, window) + rolling_beta = get_rolling_beta(portfolio, window) if rolling_beta.empty: return @@ -1020,7 +1051,7 @@ def display_rolling_beta( @log_start_end(log=logger) def display_maximum_drawdown( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", external_axes: Optional[List[plt.Axes]] = None, ): @@ -1028,14 +1059,14 @@ def display_maximum_drawdown( Parameters ---------- - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object export: str Format to export data external_axes: plt.Axes Optional axes to display plot on """ - holdings, drawdown = portfolio_model.get_maximum_drawdown(portfolio) + holdings, drawdown = get_maximum_drawdown(portfolio) if external_axes is None: _, ax = plt.subplots(2, 1, figsize=plot_autoscale(), dpi=PLOT_DPI, sharex=True) else: @@ -1065,7 +1096,7 @@ def display_maximum_drawdown( @log_start_end(log=logger) def display_rsquare( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display R-square @@ -1078,7 +1109,7 @@ def display_rsquare( Export data format """ - df = portfolio_model.get_r2_score(portfolio).fillna("-") + df = get_r2_score(portfolio).fillna("-") print_rich_table( df, @@ -1097,7 +1128,7 @@ def display_rsquare( @log_start_end(log=logger) def display_skewness( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display skewness @@ -1110,7 +1141,7 @@ def display_skewness( Export data format """ - df = portfolio_model.get_skewness(portfolio).fillna("-") + df = get_skewness(portfolio).fillna("-") print_rich_table( df, @@ -1127,7 +1158,7 @@ def display_skewness( @log_start_end(log=logger) def display_kurtosis( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display kurtosis @@ -1140,7 +1171,7 @@ def display_kurtosis( Export data format """ - df = portfolio_model.get_kurtosis(portfolio).fillna("-") + df = get_kurtosis(portfolio).fillna("-") print_rich_table( df, @@ -1157,7 +1188,7 @@ def display_kurtosis( @log_start_end(log=logger) def display_stats( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, window: str = "all", export: str = "", ): @@ -1173,7 +1204,7 @@ def display_stats( Export data format """ - df = portfolio_model.get_stats(portfolio, window) + df = get_stats(portfolio, window) print_rich_table( df, @@ -1190,7 +1221,7 @@ def display_stats( @log_start_end(log=logger) def display_volatility( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display volatility for multiple intervals @@ -1202,7 +1233,8 @@ def display_volatility( export : str Export data format """ - df = portfolio_model.get_volatility(portfolio).fillna("-") + + df = get_volatility(portfolio).fillna("-") print_rich_table( df, title="Volatility for Portfolio and Benchmark", @@ -1216,7 +1248,7 @@ def display_volatility( @log_start_end(log=logger) def display_sharpe_ratio( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, risk_free_rate: float = 0, export: str = "", ): @@ -1231,7 +1263,8 @@ def display_sharpe_ratio( export : str Export data format """ - df = portfolio_model.get_sharpe_ratio(portfolio, risk_free_rate).fillna("-") + + df = get_sharpe_ratio(portfolio, risk_free_rate).fillna("-") print_rich_table( df, title="Sharpe ratio for Portfolio and Benchmark", @@ -1248,7 +1281,7 @@ def display_sharpe_ratio( @log_start_end(log=logger) def display_sortino_ratio( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, risk_free_rate: float = 0, export: str = "", ): @@ -1263,7 +1296,8 @@ def display_sortino_ratio( export : str Export data format """ - df = portfolio_model.get_sortino_ratio(portfolio, risk_free_rate).fillna("-") + + df = get_sortino_ratio(portfolio, risk_free_rate).fillna("-") print_rich_table( df, title="Sortino ratio for Portfolio and Benchmark", @@ -1280,7 +1314,7 @@ def display_sortino_ratio( @log_start_end(log=logger) def display_maximum_drawdown_ratio( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display maximum drawdown for multiple intervals @@ -1292,7 +1326,8 @@ def display_maximum_drawdown_ratio( export : str Export data format """ - df = portfolio_model.get_maximum_drawdown_ratio(portfolio).fillna("-") + + df = get_maximum_drawdown_ratio(portfolio).fillna("-") print_rich_table( df, title="Maximum drawdown for Portfolio and Benchmark", @@ -1306,7 +1341,7 @@ def display_maximum_drawdown_ratio( @log_start_end(log=logger) def display_gaintopain_ratio( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display gain-to-pain ratio for multiple intervals @@ -1318,7 +1353,8 @@ def display_gaintopain_ratio( export : str Export data format """ - df = portfolio_model.get_gaintopain_ratio(portfolio).fillna("-") + + df = get_gaintopain_ratio(portfolio).fillna("-") print_rich_table( df, title="Gain-to-pain ratio for portfolio and benchmark", @@ -1335,7 +1371,7 @@ def display_gaintopain_ratio( @log_start_end(log=logger) def display_tracking_error( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display tracking error for multiple intervals @@ -1347,7 +1383,8 @@ def display_tracking_error( export : str Export data format """ - df, _ = portfolio_model.get_tracking_error(portfolio) + + df, _ = get_tracking_error(portfolio) df = df.fillna("-") print_rich_table( df, @@ -1362,7 +1399,7 @@ def display_tracking_error( @log_start_end(log=logger) def display_information_ratio( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display information ratio for multiple intervals @@ -1374,7 +1411,8 @@ def display_information_ratio( export : str Export data format """ - df = portfolio_model.get_information_ratio(portfolio).fillna("-") + + df = get_information_ratio(portfolio).fillna("-") print_rich_table( df, title="Information ratio for portfolio", @@ -1391,7 +1429,7 @@ def display_information_ratio( @log_start_end(log=logger) def display_tail_ratio( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display tail ratio for multiple intervals @@ -1405,7 +1443,8 @@ def display_tail_ratio( export : str Export data format """ - df, _, _ = portfolio_model.get_tail_ratio(portfolio) + + df, _, _ = get_tail_ratio(portfolio) df = df.fillna("-") print_rich_table( df, @@ -1420,7 +1459,7 @@ def display_tail_ratio( @log_start_end(log=logger) def display_common_sense_ratio( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display common sense ratio for multiple intervals @@ -1432,7 +1471,8 @@ def display_common_sense_ratio( export : str Export data format """ - df = portfolio_model.get_common_sense_ratio(portfolio).fillna("-") + + df = get_common_sense_ratio(portfolio).fillna("-") print_rich_table( df, title="Common sense ratio for portfolio and benchmark", @@ -1449,7 +1489,7 @@ def display_common_sense_ratio( @log_start_end(log=logger) def display_jensens_alpha( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, risk_free_rate: float = 0, export: str = "", ): @@ -1464,7 +1504,8 @@ def display_jensens_alpha( export : str Export data format """ - df, _ = portfolio_model.get_jensens_alpha(portfolio, risk_free_rate) + + df, _ = get_jensens_alpha(portfolio, risk_free_rate) df = df.fillna("-") print_rich_table( df, @@ -1479,7 +1520,7 @@ def display_jensens_alpha( @log_start_end(log=logger) def display_calmar_ratio( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display calmar ratio for multiple intervals @@ -1491,7 +1532,8 @@ def display_calmar_ratio( export : str Export data format """ - df, _ = portfolio_model.get_calmar_ratio(portfolio) + + df, _ = get_calmar_ratio(portfolio) df = df.fillna("-") print_rich_table( df, @@ -1506,7 +1548,7 @@ def display_calmar_ratio( @log_start_end(log=logger) def display_kelly_criterion( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display kelly criterion for multiple intervals @@ -1518,7 +1560,8 @@ def display_kelly_criterion( export : str Export data format """ - df = portfolio_model.get_kelly_criterion(portfolio).fillna("-") + + df = get_kelly_criterion(portfolio).fillna("-") print_rich_table( df, title="Kelly criterion of the portfolio", @@ -1531,7 +1574,7 @@ def display_kelly_criterion( def display_payoff_ratio( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display payoff ratio for multiple intervals @@ -1543,7 +1586,8 @@ def display_payoff_ratio( export : str Export data format """ - df = portfolio_model.get_payoff_ratio(portfolio).fillna("-") + + df = get_payoff_ratio(portfolio).fillna("-") print_rich_table( df, title="Portfolio's payoff ratio", @@ -1556,7 +1600,7 @@ def display_payoff_ratio( def display_profit_factor( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, export: str = "", ): """Display profit factor for multiple intervals @@ -1568,7 +1612,8 @@ def display_profit_factor( export : str Export data format """ - df = portfolio_model.get_profit_factor(portfolio).fillna("-") + + df = get_profit_factor(portfolio).fillna("-") print_rich_table( df, title="Portfolio's profit factor", @@ -1582,7 +1627,7 @@ def display_profit_factor( @log_start_end(log=logger) def display_summary( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, window: str = "all", risk_free_rate: float = 0, export: str = "", @@ -1600,8 +1645,8 @@ def display_summary( export : str Export certain type of data """ - summary = portfolio_model.get_summary(portfolio, window, risk_free_rate) + summary = get_summary(portfolio, window, risk_free_rate) print_rich_table( summary, title=f"Summary of Portfolio vs Benchmark for {window} period", @@ -1618,7 +1663,7 @@ def display_summary( @log_start_end(log=logger) def display_var( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, use_mean: bool = True, adjusted_var: bool = False, student_t: bool = False, @@ -1653,7 +1698,7 @@ def display_var( @log_start_end(log=logger) def display_es( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, use_mean: bool = True, distribution: str = "normal", percentile: float = 99.9, @@ -1684,7 +1729,7 @@ def display_es( @log_start_end(log=logger) def display_omega( - portfolio: portfolio_model.PortfolioModel, + portfolio: PortfolioEngine, threshold_start: float = 0, threshold_end: float = 1.5, ): diff --git a/openbb_terminal/sdk.py b/openbb_terminal/sdk.py index fd838fd1135f..ca79136d8936 100644 --- a/openbb_terminal/sdk.py +++ b/openbb_terminal/sdk.py @@ -4,7 +4,7 @@ from openbb_terminal import helper_funcs as helper # noqa: F401 from openbb_terminal.reports import widget_helpers as widgets # noqa: F401 from openbb_terminal.portfolio.portfolio_model import ( # noqa: F401 - PortfolioModel as Portfolio, + PortfolioEngine as Portfolio, ) from openbb_terminal.cryptocurrency.due_diligence.pycoingecko_model import ( # noqa: F401 Coin, diff --git a/website/content/SDK/portfolio/calmar/_index.rst b/website/content/SDK/portfolio/calmar/_index.rst index 10e515f4da7a..f8deb1c26d95 100644 --- a/website/content/SDK/portfolio/calmar/_index.rst +++ b/website/content/SDK/portfolio/calmar/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.calmar( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: int = 756, chart: bool = False, ) diff --git a/website/content/SDK/portfolio/commonsense/_index.rst b/website/content/SDK/portfolio/commonsense/_index.rst index 74808b8e8a5c..85009730666f 100644 --- a/website/content/SDK/portfolio/commonsense/_index.rst +++ b/website/content/SDK/portfolio/commonsense/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.commonsense( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} diff --git a/website/content/SDK/portfolio/distr/_index.rst b/website/content/SDK/portfolio/distr/_index.rst index 1fe98accefd6..7d23e8152fd1 100644 --- a/website/content/SDK/portfolio/distr/_index.rst +++ b/website/content/SDK/portfolio/distr/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.distr( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', chart: bool = False, ) @@ -46,7 +46,7 @@ portfolio.distr( {{< highlight python >}} portfolio.distr( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', raw: bool = False, export: str = '', @@ -77,4 +77,3 @@ portfolio.distr( Optional axes to display plot on chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/dret/_index.rst b/website/content/SDK/portfolio/dret/_index.rst index a4c7b1890e3b..ac4bdaa354dc 100644 --- a/website/content/SDK/portfolio/dret/_index.rst +++ b/website/content/SDK/portfolio/dret/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.dret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -50,7 +50,7 @@ portfolio.dret( {{< highlight python >}} portfolio.dret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', raw: bool = False, limit: int = 10, @@ -82,4 +82,3 @@ portfolio.dret( Optional axes to display plot on chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/es/_index.rst b/website/content/SDK/portfolio/es/_index.rst index 53341a81d3a2..585cca656e28 100644 --- a/website/content/SDK/portfolio/es/_index.rst +++ b/website/content/SDK/portfolio/es/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.es( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, use_mean: bool = False, distribution: str = 'normal', percentile: float = 99.9, diff --git a/website/content/SDK/portfolio/gaintopain/_index.rst b/website/content/SDK/portfolio/gaintopain/_index.rst index 1b1445675ef6..408633cf70ee 100644 --- a/website/content/SDK/portfolio/gaintopain/_index.rst +++ b/website/content/SDK/portfolio/gaintopain/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.gaintopain( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} diff --git a/website/content/SDK/portfolio/holdp/_index.rst b/website/content/SDK/portfolio/holdp/_index.rst index 4e48e5b5c765..0557f1372f78 100644 --- a/website/content/SDK/portfolio/holdp/_index.rst +++ b/website/content/SDK/portfolio/holdp/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.holdp( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} @@ -43,7 +43,7 @@ portfolio.holdp( {{< highlight python >}} portfolio.holdp( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, unstack: bool = False, raw: bool = False, limit: int = 10, @@ -75,4 +75,3 @@ portfolio.holdp( Optional axes to display plot on chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/holdv/_index.rst b/website/content/SDK/portfolio/holdv/_index.rst index bcc0c1489f84..8be88fcec4ca 100644 --- a/website/content/SDK/portfolio/holdv/_index.rst +++ b/website/content/SDK/portfolio/holdv/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.holdv( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -48,7 +48,7 @@ portfolio.holdv( {{< highlight python >}} portfolio.holdv( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, unstack: bool = False, raw: bool = False, limit: int = 10, @@ -80,4 +80,3 @@ portfolio.holdv( Optional axes to display plot on chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/information/_index.rst b/website/content/SDK/portfolio/information/_index.rst index c5bb7347dd5b..71d898b07db1 100644 --- a/website/content/SDK/portfolio/information/_index.rst +++ b/website/content/SDK/portfolio/information/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.information( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} diff --git a/website/content/SDK/portfolio/jensens/_index.rst b/website/content/SDK/portfolio/jensens/_index.rst index 7b86a21cf62d..8a9027aa08b4 100644 --- a/website/content/SDK/portfolio/jensens/_index.rst +++ b/website/content/SDK/portfolio/jensens/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.jensens( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, window: str = '1y', chart: bool = False, diff --git a/website/content/SDK/portfolio/kelly/_index.rst b/website/content/SDK/portfolio/kelly/_index.rst index ea7fab686cd6..c401f2cd69ac 100644 --- a/website/content/SDK/portfolio/kelly/_index.rst +++ b/website/content/SDK/portfolio/kelly/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.kelly( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} diff --git a/website/content/SDK/portfolio/kurtosis/_index.rst b/website/content/SDK/portfolio/kurtosis/_index.rst index 41efd5a45463..b1743c23e65e 100644 --- a/website/content/SDK/portfolio/kurtosis/_index.rst +++ b/website/content/SDK/portfolio/kurtosis/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.kurtosis( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/portfolio/max_drawdown_ratio/_index.rst b/website/content/SDK/portfolio/max_drawdown_ratio/_index.rst index 155f09468bed..0a698bc25ba3 100644 --- a/website/content/SDK/portfolio/max_drawdown_ratio/_index.rst +++ b/website/content/SDK/portfolio/max_drawdown_ratio/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.max_drawdown_ratio( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, is_returns: bool = False, chart: bool = False, ) -> pandas.core.series.Series @@ -56,7 +56,7 @@ portfolio.max_drawdown_ratio( {{< highlight python >}} portfolio.max_drawdown_ratio( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, export: str = '', chart: bool = False, ) @@ -76,4 +76,3 @@ portfolio.max_drawdown_ratio( Export data format chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/maxdd/_index.rst b/website/content/SDK/portfolio/maxdd/_index.rst index 36e2bc27d88f..e1f47b37338c 100644 --- a/website/content/SDK/portfolio/maxdd/_index.rst +++ b/website/content/SDK/portfolio/maxdd/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.maxdd( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, is_returns: bool = False, chart: bool = False, ) -> pandas.core.series.Series @@ -56,7 +56,7 @@ portfolio.maxdd( {{< highlight python >}} portfolio.maxdd( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, @@ -71,7 +71,7 @@ portfolio.maxdd( * **Parameters** - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object export: str Format to export data @@ -79,4 +79,3 @@ portfolio.maxdd( Optional axes to display plot on chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/maxdrawdown/_index.rst b/website/content/SDK/portfolio/maxdrawdown/_index.rst index bb6c5e2e4b43..502bbc9d4c88 100644 --- a/website/content/SDK/portfolio/maxdrawdown/_index.rst +++ b/website/content/SDK/portfolio/maxdrawdown/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.maxdrawdown( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/portfolio/mret/_index.rst b/website/content/SDK/portfolio/mret/_index.rst index d1784df3d7fd..f36e6c98e41c 100644 --- a/website/content/SDK/portfolio/mret/_index.rst +++ b/website/content/SDK/portfolio/mret/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.mret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -50,7 +50,7 @@ portfolio.mret( {{< highlight python >}} portfolio.mret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', raw: bool = False, show_vals: bool = False, @@ -82,4 +82,3 @@ portfolio.mret( Optional axes to display plot on chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/om/_index.rst b/website/content/SDK/portfolio/om/_index.rst index 26fddd6593b1..829d67f734f4 100644 --- a/website/content/SDK/portfolio/om/_index.rst +++ b/website/content/SDK/portfolio/om/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.om( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, threshold_start: float = 0, threshold_end: float = 1.5, chart: bool = False, @@ -53,7 +53,7 @@ portfolio.om( {{< highlight python >}} portfolio.om( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, threshold_start: float = 0, threshold_end: float = 1.5, chart: bool = False, @@ -76,4 +76,3 @@ portfolio.om( annualized target return threshold end of plotted threshold range chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/payoff/_index.rst b/website/content/SDK/portfolio/payoff/_index.rst index 1772a328f5fa..a7c2cb29a320 100644 --- a/website/content/SDK/portfolio/payoff/_index.rst +++ b/website/content/SDK/portfolio/payoff/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.payoff( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} diff --git a/website/content/SDK/portfolio/perf/_index.rst b/website/content/SDK/portfolio/perf/_index.rst index 023bdd2d3ba8..64d945c8b97a 100644 --- a/website/content/SDK/portfolio/perf/_index.rst +++ b/website/content/SDK/portfolio/perf/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.perf( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, show_all_trades: bool = False, chart: bool = False, ) -> pandas.core.frame.DataFrame diff --git a/website/content/SDK/portfolio/profitfactor/_index.rst b/website/content/SDK/portfolio/profitfactor/_index.rst index b41440df5ebd..c50c0d0ce9be 100644 --- a/website/content/SDK/portfolio/profitfactor/_index.rst +++ b/website/content/SDK/portfolio/profitfactor/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.profitfactor( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} diff --git a/website/content/SDK/portfolio/rbeta/_index.rst b/website/content/SDK/portfolio/rbeta/_index.rst index 440caafa2478..fada5e026814 100644 --- a/website/content/SDK/portfolio/rbeta/_index.rst +++ b/website/content/SDK/portfolio/rbeta/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.rbeta( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = '1y', chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -28,7 +28,7 @@ portfolio.rbeta( * **Parameters** - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object window: string Interval used for rolling values. @@ -52,7 +52,7 @@ portfolio.rbeta( {{< highlight python >}} portfolio.rbeta( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = '1y', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, @@ -68,7 +68,7 @@ portfolio.rbeta( * **Parameters** - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object window: str interval for window to consider @@ -79,4 +79,3 @@ portfolio.rbeta( Optional axes to display plot on chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/rsharpe/_index.rst b/website/content/SDK/portfolio/rsharpe/_index.rst index 18a4e2c7f93d..e195fcc139c2 100644 --- a/website/content/SDK/portfolio/rsharpe/_index.rst +++ b/website/content/SDK/portfolio/rsharpe/_index.rst @@ -55,7 +55,7 @@ portfolio.rsharpe( {{< highlight python >}} portfolio.rsharpe( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, window: str = '1y', export: str = '', @@ -72,7 +72,7 @@ portfolio.rsharpe( * **Parameters** - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object risk_free_rate: float Value to use for risk free rate in sharpe/other calculations @@ -84,4 +84,3 @@ portfolio.rsharpe( Optional axes to display plot on chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/rsortino/_index.rst b/website/content/SDK/portfolio/rsortino/_index.rst index 7ce79ba1534f..7e6394f024bc 100644 --- a/website/content/SDK/portfolio/rsortino/_index.rst +++ b/website/content/SDK/portfolio/rsortino/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.rsortino( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, window: str = '1y', chart: bool = False, @@ -29,7 +29,7 @@ portfolio.rsortino( * **Parameters** - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object window: str interval for window to consider @@ -55,7 +55,7 @@ portfolio.rsortino( {{< highlight python >}} portfolio.rsortino( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, window: str = '1y', export: str = '', @@ -72,7 +72,7 @@ portfolio.rsortino( * **Parameters** - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object risk_free_rate: float Value to use for risk free rate in sharpe/other calculations @@ -84,4 +84,3 @@ portfolio.rsortino( Optional axes to display plot on chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/rsquare/_index.rst b/website/content/SDK/portfolio/rsquare/_index.rst index 728f36754f97..1b897089119e 100644 --- a/website/content/SDK/portfolio/rsquare/_index.rst +++ b/website/content/SDK/portfolio/rsquare/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.rsquare( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/portfolio/rvol/_index.rst b/website/content/SDK/portfolio/rvol/_index.rst index d9686bb7c597..945ccaf3a85e 100644 --- a/website/content/SDK/portfolio/rvol/_index.rst +++ b/website/content/SDK/portfolio/rvol/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.rvol( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = '1y', chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -47,7 +47,7 @@ portfolio.rvol( {{< highlight python >}} portfolio.rvol( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = '1y', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, @@ -63,7 +63,7 @@ portfolio.rvol( * **Parameters** - portfolio : PortfolioModel + portfolio : PortfolioEngine Portfolio object interval: str interval for window to consider @@ -73,4 +73,3 @@ portfolio.rvol( Optional axes to display plot on chart: bool Flag to display chart - diff --git a/website/content/SDK/portfolio/sharpe/_index.rst b/website/content/SDK/portfolio/sharpe/_index.rst index f54860ab8b26..cd22f1fef5c3 100644 --- a/website/content/SDK/portfolio/sharpe/_index.rst +++ b/website/content/SDK/portfolio/sharpe/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.sharpe( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, chart: bool = False, ) -> pandas.core.frame.DataFrame diff --git a/website/content/SDK/portfolio/skew/_index.rst b/website/content/SDK/portfolio/skew/_index.rst index 63010b46fe5a..9600bce4d23e 100644 --- a/website/content/SDK/portfolio/skew/_index.rst +++ b/website/content/SDK/portfolio/skew/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.skew( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/portfolio/sortino/_index.rst b/website/content/SDK/portfolio/sortino/_index.rst index 3ce251e66d11..f23f4491153a 100644 --- a/website/content/SDK/portfolio/sortino/_index.rst +++ b/website/content/SDK/portfolio/sortino/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.sortino( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, chart: bool = False, ) -> pandas.core.frame.DataFrame diff --git a/website/content/SDK/portfolio/summary/_index.rst b/website/content/SDK/portfolio/summary/_index.rst index fad9c2b55829..e776e9ef9734 100644 --- a/website/content/SDK/portfolio/summary/_index.rst +++ b/website/content/SDK/portfolio/summary/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.summary( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', risk_free_rate: float = 0, chart: bool = False, diff --git a/website/content/SDK/portfolio/tail/_index.rst b/website/content/SDK/portfolio/tail/_index.rst index bfc405e20d3f..390e5e988797 100644 --- a/website/content/SDK/portfolio/tail/_index.rst +++ b/website/content/SDK/portfolio/tail/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.tail( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: int = 252, chart: bool = False, ) diff --git a/website/content/SDK/portfolio/trackerr/_index.rst b/website/content/SDK/portfolio/trackerr/_index.rst index 762631172779..2d32e45d1f16 100644 --- a/website/content/SDK/portfolio/trackerr/_index.rst +++ b/website/content/SDK/portfolio/trackerr/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.trackerr( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: int = 252, chart: bool = False, ) diff --git a/website/content/SDK/portfolio/var/_index.rst b/website/content/SDK/portfolio/var/_index.rst index fb91b8ab21d3..84e8976cb5d8 100644 --- a/website/content/SDK/portfolio/var/_index.rst +++ b/website/content/SDK/portfolio/var/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.var( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, use_mean: bool = False, adjusted_var: bool = False, student_t: bool = False, diff --git a/website/content/SDK/portfolio/volatility/_index.rst b/website/content/SDK/portfolio/volatility/_index.rst index 8b369c64f1c3..08a6ed859326 100644 --- a/website/content/SDK/portfolio/volatility/_index.rst +++ b/website/content/SDK/portfolio/volatility/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.volatility( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/portfolio/yret/_index.rst b/website/content/SDK/portfolio/yret/_index.rst index b34cac2e2e2b..e064117991f8 100644 --- a/website/content/SDK/portfolio/yret/_index.rst +++ b/website/content/SDK/portfolio/yret/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.yret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', chart: bool = False, ) @@ -46,7 +46,7 @@ portfolio.yret( {{< highlight python >}} portfolio.yret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioModel, + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', raw: bool = False, export: str = '', @@ -75,4 +75,3 @@ portfolio.yret( Optional axes to display plot on chart: bool Flag to display chart - From bcb832f9ba08a950c30a29a7c25e52fb7592fca5 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 18:41:33 +0000 Subject: [PATCH 02/30] fix some docstrings --- openbb_terminal/portfolio/portfolio_model.py | 120 +++++++++---------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index be47e36abf5b..e9e8d8b65e97 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -804,8 +804,8 @@ def get_r2_score(portfolio: PortfolioEngine) -> pd.DataFrame: Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded Returns ------- @@ -832,8 +832,8 @@ def get_r2_score(portfolio: PortfolioEngine) -> pd.DataFrame: def get_skewness(portfolio: PortfolioEngine) -> pd.DataFrame: """Class method that retrieves skewness for portfolio and benchmark selected - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded Returns ------- @@ -871,8 +871,8 @@ def get_kurtosis(portfolio: PortfolioEngine) -> pd.DataFrame: Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded Returns ------- @@ -910,8 +910,8 @@ def get_stats(portfolio: PortfolioEngine, window: str = "all") -> pd.DataFrame: Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to consider. Choices are: mtd, qtd, ytd, 3m, 6m, 1y, 3y, 5y, 10y, all @@ -940,8 +940,8 @@ def get_volatility(portfolio: PortfolioEngine) -> pd.DataFrame: Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded Returns ------- @@ -981,8 +981,8 @@ def get_sharpe_ratio( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded risk_free_rate: float Risk free rate value @@ -1026,8 +1026,8 @@ def get_sortino_ratio( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded risk_free_rate: float Risk free rate value @@ -1069,8 +1069,8 @@ def get_maximum_drawdown_ratio(portfolio: PortfolioEngine) -> pd.DataFrame: Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded Returns ------- @@ -1108,8 +1108,8 @@ def get_gaintopain_ratio(portfolio: PortfolioEngine): Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded Returns ------- @@ -1131,8 +1131,8 @@ def get_tracking_error(portfolio: PortfolioEngine, window: int = 252): Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window: int Interval used for rolling values @@ -1156,8 +1156,8 @@ def get_information_ratio(portfolio: PortfolioEngine): Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded Returns ------- @@ -1180,8 +1180,8 @@ def get_tail_ratio(portfolio: PortfolioEngine, window: int = 252): Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window: int Interval used for rolling values @@ -1208,8 +1208,8 @@ def get_common_sense_ratio(portfolio: PortfolioEngine): Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded Returns ------- @@ -1234,8 +1234,8 @@ def get_jensens_alpha( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window: str Interval used for rolling values risk_free_rate: float @@ -1266,8 +1266,8 @@ def get_calmar_ratio(portfolio: PortfolioEngine, window: int = 756): Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window: int Interval used for rolling values @@ -1295,8 +1295,8 @@ def get_kelly_criterion(portfolio: PortfolioEngine): Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded Returns ------- @@ -1330,8 +1330,8 @@ def get_profit_factor(portfolio: PortfolioEngine): Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded Returns ------- @@ -1348,8 +1348,8 @@ def get_holdings_value(portfolio: PortfolioEngine) -> pd.DataFrame: Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded Returns ------- @@ -1372,8 +1372,8 @@ def get_holdings_percentage( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded """ all_holdings = portfolio.historical_trade_data["End Value"][portfolio.tickers_list] @@ -1427,8 +1427,8 @@ def get_distribution_returns( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark """ @@ -1451,8 +1451,8 @@ def get_rolling_volatility( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str Rolling window size to use Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y @@ -1525,7 +1525,7 @@ def get_rolling_sortino( Parameters ---------- portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object window: str interval for window to consider Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y @@ -1566,7 +1566,7 @@ def get_rolling_beta( Parameters ---------- portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object window: string Interval used for rolling values. Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y. @@ -1594,8 +1594,8 @@ def get_performance_vs_benchmark( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded show_all_trades: bool Whether to also show all trades made and their performance (default is False) Returns @@ -1701,8 +1701,8 @@ def get_var( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded use_mean: bool if one should use the data mean return adjusted_var: bool @@ -1737,8 +1737,8 @@ def get_es( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded use_mean: if one should use the data mean return distribution: str @@ -1768,8 +1768,8 @@ def get_omega( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded threshold_start: float annualized target return threshold start of plotted threshold range threshold_end: float @@ -1796,8 +1796,8 @@ def get_summary( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark risk_free_rate : float @@ -1863,8 +1863,8 @@ def get_yearly_returns( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark """ @@ -1912,8 +1912,8 @@ def get_monthly_returns( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark Returns @@ -2007,8 +2007,8 @@ def get_daily_returns( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark Returns From be86bdd0d640cf17bd41765baa5b1af09fbd74a0 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 18:44:03 +0000 Subject: [PATCH 03/30] view docstrings --- openbb_terminal/portfolio/portfolio_view.py | 120 ++++++++++---------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_view.py b/openbb_terminal/portfolio/portfolio_view.py index 446bf2e36df6..7ff7f29a60a4 100644 --- a/openbb_terminal/portfolio/portfolio_view.py +++ b/openbb_terminal/portfolio/portfolio_view.py @@ -104,7 +104,7 @@ def display_transactions( Parameters ---------- - portfolio: Portfolio + portfolio: PortfolioEngine Instance of Portfolio class show_index: bool Defaults to False. @@ -330,8 +330,8 @@ def display_yearly_returns( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark raw : False @@ -411,8 +411,8 @@ def display_monthly_returns( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark raw : False @@ -511,8 +511,8 @@ def display_daily_returns( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark raw : False @@ -666,8 +666,8 @@ def display_holdings_value( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded unstack: bool Individual assets over time raw : bool @@ -744,8 +744,8 @@ def display_holdings_percentage( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded unstack: bool Individual assets over time raw : bool @@ -826,7 +826,7 @@ def display_rolling_volatility( Parameters ---------- portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object interval: str interval for window to consider export: str @@ -883,7 +883,7 @@ def display_rolling_sharpe( Parameters ---------- portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object risk_free_rate: float Value to use for risk free rate in sharpe/other calculations window: str @@ -942,7 +942,7 @@ def display_rolling_sortino( Parameters ---------- portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object risk_free_rate: float Value to use for risk free rate in sharpe/other calculations window: str @@ -1000,7 +1000,7 @@ def display_rolling_beta( Parameters ---------- portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object window: str interval for window to consider Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y. @@ -1060,7 +1060,7 @@ def display_maximum_drawdown( Parameters ---------- portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object export: str Format to export data external_axes: plt.Axes @@ -1103,8 +1103,8 @@ def display_rsquare( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded export : str Export data format """ @@ -1135,8 +1135,8 @@ def display_skewness( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded export : str Export data format """ @@ -1165,8 +1165,8 @@ def display_kurtosis( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded export : str Export data format """ @@ -1196,8 +1196,8 @@ def display_stats( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to consider. Choices are: mtd, qtd, ytd, 3m, 6m, 1y, 3y, 5y, 10y, all export : str @@ -1228,8 +1228,8 @@ def display_volatility( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded export : str Export data format """ @@ -1256,8 +1256,8 @@ def display_sharpe_ratio( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded risk_free_rate: float Risk free rate value export : str @@ -1289,8 +1289,8 @@ def display_sortino_ratio( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded risk_free_rate: float Risk free rate value export : str @@ -1321,8 +1321,8 @@ def display_maximum_drawdown_ratio( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded export : str Export data format """ @@ -1348,8 +1348,8 @@ def display_gaintopain_ratio( Parameters ---------- - portfolio: Portfolio - Portfolio object with returns and benchmark loaded + portfolio: PortfolioEngine + PortfolioEngine object with returns and benchmark loaded export : str Export data format """ @@ -1378,8 +1378,8 @@ def display_tracking_error( Parameters ---------- - portfolio: Portfolio - Portfolio object with returns and benchmark loaded + portfolio: PortfolioEngine + PortfolioEngine object with returns and benchmark loaded export : str Export data format """ @@ -1406,8 +1406,8 @@ def display_information_ratio( Parameters ---------- - portfolio: Portfolio - Portfolio object with returns and benchmark loaded + portfolio: PortfolioEngine + PortfolioEngine object with returns and benchmark loaded export : str Export data format """ @@ -1436,8 +1436,8 @@ def display_tail_ratio( Parameters ---------- - portfolio: Portfolio - Portfolio object with returns and benchmark loaded + portfolio: PortfolioEngine + PortfolioEngine object with returns and benchmark loaded window: str interval for window to consider export : str @@ -1466,8 +1466,8 @@ def display_common_sense_ratio( Parameters ---------- - portfolio: Portfolio - Portfolio object with returns and benchmark loaded + portfolio: PortfolioEngine + PortfolioEngine object with returns and benchmark loaded export : str Export data format """ @@ -1497,8 +1497,8 @@ def display_jensens_alpha( Parameters ---------- - portfolio: Portfolio - Portfolio object with returns and benchmark loaded + portfolio: PortfolioEngine + PortfolioEngine object with returns and benchmark loaded risk_free_rate: float Risk free rate export : str @@ -1527,8 +1527,8 @@ def display_calmar_ratio( Parameters ---------- - portfolio: Portfolio - Portfolio object with returns and benchmark loaded + portfolio: PortfolioEngine + PortfolioEngine object with returns and benchmark loaded export : str Export data format """ @@ -1555,8 +1555,8 @@ def display_kelly_criterion( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades and returns loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades and returns loaded export : str Export data format """ @@ -1581,8 +1581,8 @@ def display_payoff_ratio( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded export : str Export data format """ @@ -1607,8 +1607,8 @@ def display_profit_factor( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded export : str Export data format """ @@ -1636,8 +1636,8 @@ def display_summary( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark risk_free_rate : float @@ -1673,8 +1673,8 @@ def display_var( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded use_mean: bool if one should use the data mean return adjusted_var: bool @@ -1707,8 +1707,8 @@ def display_es( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded use_mean: if one should use the data mean return distribution: str @@ -1737,8 +1737,8 @@ def display_omega( Parameters ---------- - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded threshold_start: float annualized target return threshold start of plotted threshold range threshold_end: float From 1cfe534d8640881eff294223cd0e2fdc1d52a4a7 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 20:08:45 +0000 Subject: [PATCH 04/30] make portfolio loading available in sdk --- .../miscellaneous/library/trail_map.csv | 42 +++++++-------- openbb_terminal/portfolio/portfolio_model.py | 51 ++++++++++++++++--- openbb_terminal/portfolio/portfolio_view.py | 5 +- 3 files changed, 70 insertions(+), 28 deletions(-) diff --git a/openbb_terminal/miscellaneous/library/trail_map.csv b/openbb_terminal/miscellaneous/library/trail_map.csv index 2929418a5aa2..70e336c774b6 100644 --- a/openbb_terminal/miscellaneous/library/trail_map.csv +++ b/openbb_terminal/miscellaneous/library/trail_map.csv @@ -295,36 +295,38 @@ forex.oanda.listorders,openbb_terminal.forex.oanda.oanda_model.order_history_req forex.oanda.orderbook,openbb_terminal.forex.oanda.oanda_model.orderbook_plot_data_request,openbb_terminal.forex.oanda.oanda_view.get_order_book forex.oanda.pending,openbb_terminal.forex.oanda.oanda_model.pending_orders_request,openbb_terminal.forex.oanda.oanda_view.get_pending_orders forex.oanda.positionbook,openbb_terminal.forex.oanda.oanda_model.positionbook_plot_data_request,openbb_terminal.forex.oanda.oanda_view.get_position_book +portfolio.load,openbb_terminal.portfolio.portfolio_model.generate_portfolio, +portfolio.show,openbb_terminal.portfolio.portfolio_model.get_transactions, +portfolio.bench,openbb_terminal.portfolio.portfolio_model.set_benchmark, portfolio.holdv,openbb_terminal.portfolio.portfolio_model.get_holdings_value,openbb_terminal.portfolio.portfolio_view.display_holdings_value portfolio.holdp,openbb_terminal.portfolio.portfolio_model.get_holdings_percentage,openbb_terminal.portfolio.portfolio_view.display_holdings_percentage -portfolio.yret,openbb_terminal.portfolio.portfolio_model.get_yearly_returns,openbb_terminal.portfolio.portfolio_view.display_yearly_returns portfolio.mret,openbb_terminal.portfolio.portfolio_model.get_monthly_returns,openbb_terminal.portfolio.portfolio_view.display_monthly_returns +portfolio.yret,openbb_terminal.portfolio.portfolio_model.get_yearly_returns,openbb_terminal.portfolio.portfolio_view.display_yearly_returns portfolio.dret,openbb_terminal.portfolio.portfolio_model.get_daily_returns,openbb_terminal.portfolio.portfolio_view.display_daily_returns -portfolio.max_drawdown_ratio,openbb_terminal.portfolio.portfolio_model.get_maximum_drawdown,openbb_terminal.portfolio.portfolio_view.display_maximum_drawdown_ratio portfolio.distr,openbb_terminal.portfolio.portfolio_model.get_distribution_returns,openbb_terminal.portfolio.portfolio_view.display_distribution_returns portfolio.maxdd,openbb_terminal.portfolio.portfolio_model.get_maximum_drawdown,openbb_terminal.portfolio.portfolio_view.display_maximum_drawdown portfolio.rvol,openbb_terminal.portfolio.portfolio_model.get_rolling_volatility,openbb_terminal.portfolio.portfolio_view.display_rolling_volatility portfolio.rsharpe,openbb_terminal.portfolio.portfolio_model.get_rolling_sharpe,openbb_terminal.portfolio.portfolio_view.display_rolling_sharpe -portfolio.rsortino,openbb_terminal.portfolio.portfolio_model.get_rolling_sortino,openbb_terminal.portfolio.portfolio_view.display_rolling_sortino +portfolio.rsort,openbb_terminal.portfolio.portfolio_model.get_rolling_sortino,openbb_terminal.portfolio.portfolio_view.display_rolling_sortino portfolio.rbeta,openbb_terminal.portfolio.portfolio_model.get_rolling_beta,openbb_terminal.portfolio.portfolio_view.display_rolling_beta portfolio.summary,openbb_terminal.portfolio.portfolio_model.get_summary, -portfolio.skew,openbb_terminal.portfolio.portfolio_model.get_skewness, -portfolio.kurtosis,openbb_terminal.portfolio.portfolio_model.get_kurtosis, -portfolio.volatility,openbb_terminal.portfolio.portfolio_model.get_volatility, -portfolio.sharpe,openbb_terminal.portfolio.portfolio_model.get_sharpe_ratio, -portfolio.sortino,openbb_terminal.portfolio.portfolio_model.get_sortino_ratio, -portfolio.maxdrawdown,openbb_terminal.portfolio.portfolio_model.get_maximum_drawdown_ratio, -portfolio.rsquare,openbb_terminal.portfolio.portfolio_model.get_r2_score, -portfolio.gaintopain,openbb_terminal.portfolio.portfolio_model.get_gaintopain_ratio, -portfolio.trackerr,openbb_terminal.portfolio.portfolio_model.get_tracking_error, -portfolio.information,openbb_terminal.portfolio.portfolio_model.get_information_ratio, -portfolio.tail,openbb_terminal.portfolio.portfolio_model.get_tail_ratio, -portfolio.commonsense,openbb_terminal.portfolio.portfolio_model.get_common_sense_ratio, -portfolio.jensens,openbb_terminal.portfolio.portfolio_model.get_jensens_alpha, -portfolio.calmar,openbb_terminal.portfolio.portfolio_model.get_calmar_ratio, -portfolio.kelly,openbb_terminal.portfolio.portfolio_model.get_kelly_criterion, -portfolio.payoff,openbb_terminal.portfolio.portfolio_model.get_payoff_ratio, -portfolio.profitfactor,openbb_terminal.portfolio.portfolio_model.get_profit_factor, +portfolio.metric.volatility,openbb_terminal.portfolio.portfolio_model.get_volatility, +portfolio.metric.sharpe,openbb_terminal.portfolio.portfolio_model.get_sharpe_ratio, +portfolio.metric.sortino,openbb_terminal.portfolio.portfolio_model.get_sortino_ratio, +portfolio.metric.maxdrawdown,openbb_terminal.portfolio.portfolio_model.get_maximum_drawdown_ratio, +portfolio.metric.rsquare,openbb_terminal.portfolio.portfolio_model.get_r2_score, +portfolio.metric.skew,openbb_terminal.portfolio.portfolio_model.get_skewness, +portfolio.metric.kurtosis,openbb_terminal.portfolio.portfolio_model.get_kurtosis, +portfolio.metric.gaintopain,openbb_terminal.portfolio.portfolio_model.get_gaintopain_ratio, +portfolio.metric.trackerr,openbb_terminal.portfolio.portfolio_model.get_tracking_error, +portfolio.metric.information,openbb_terminal.portfolio.portfolio_model.get_information_ratio, +portfolio.metric.tail,openbb_terminal.portfolio.portfolio_model.get_tail_ratio, +portfolio.metric.commonsense,openbb_terminal.portfolio.portfolio_model.get_common_sense_ratio, +portfolio.metric.jensens,openbb_terminal.portfolio.portfolio_model.get_jensens_alpha, +portfolio.metric.calmar,openbb_terminal.portfolio.portfolio_model.get_calmar_ratio, +portfolio.metric.kelly,openbb_terminal.portfolio.portfolio_model.get_kelly_criterion, +portfolio.metric.payoff,openbb_terminal.portfolio.portfolio_model.get_payoff_ratio, +portfolio.metric.profitfactor,openbb_terminal.portfolio.portfolio_model.get_profit_factor, portfolio.perf,openbb_terminal.portfolio.portfolio_model.get_performance_vs_benchmark, portfolio.var,openbb_terminal.portfolio.portfolio_model.get_var, portfolio.es,openbb_terminal.portfolio.portfolio_model.get_es, diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index e9e8d8b65e97..2af23db34e60 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -484,6 +484,7 @@ def load_benchmark(self, symbol: str = "SPY", full_shares: bool = False): @log_start_end(log=logger) def mimic_trades_for_benchmark(self, full_shares: bool = False): """Mimic trades from the transactions based on chosen benchmark assuming partial shares + Parameters ---------- full_shares: bool @@ -752,7 +753,6 @@ def calculate_allocations(self, category: str): ---------- category: str chosen allocation category from asset, sector, country or region - """ if category == "asset": @@ -794,6 +794,7 @@ def set_risk_free_rate(self, risk_free_rate: float): risk_free_rate : float Risk free rate in float format """ + self.risk_free_rate = risk_free_rate @@ -812,6 +813,7 @@ def get_r2_score(portfolio: PortfolioEngine) -> pd.DataFrame: pd.DataFrame DataFrame with R2 Score between portfolio and benchmark for different periods """ + vals = list() for period in portfolio_helper.PERIODS: vals.append( @@ -840,6 +842,7 @@ def get_skewness(portfolio: PortfolioEngine) -> pd.DataFrame: pd.DataFrame DataFrame with skewness for portfolio and benchmark for different periods """ + vals = list() for period in portfolio_helper.PERIODS: vals.append( @@ -879,6 +882,7 @@ def get_kurtosis(portfolio: PortfolioEngine) -> pd.DataFrame: pd.DataFrame DataFrame with kurtosis for portfolio and benchmark for different periods """ + vals = list() for period in portfolio_helper.PERIODS: vals.append( @@ -920,6 +924,7 @@ def get_stats(portfolio: PortfolioEngine, window: str = "all") -> pd.DataFrame: pd.DataFrame DataFrame with overall stats for portfolio and benchmark for a certain period """ + df = ( portfolio_helper.filter_df_by_period(portfolio.returns, window) .describe() @@ -948,6 +953,7 @@ def get_volatility(portfolio: PortfolioEngine) -> pd.DataFrame: pd.DataFrame DataFrame with volatility for portfolio and benchmark for different periods """ + vals = list() for period in portfolio_helper.PERIODS: port_rets = portfolio_helper.filter_df_by_period(portfolio.returns, period) @@ -991,6 +997,7 @@ def get_sharpe_ratio( pd.DataFrame DataFrame with sharpe ratio for portfolio and benchmark for different periods """ + vals = list() for period in portfolio_helper.PERIODS: vals.append( @@ -1036,6 +1043,7 @@ def get_sortino_ratio( pd.DataFrame DataFrame with sortino ratio for portfolio and benchmark for different periods """ + vals = list() for period in portfolio_helper.PERIODS: vals.append( @@ -1077,6 +1085,7 @@ def get_maximum_drawdown_ratio(portfolio: PortfolioEngine) -> pd.DataFrame: pd.DataFrame DataFrame with maximum drawdown for portfolio and benchmark for different periods """ + vals = list() for period in portfolio_helper.PERIODS: vals.append( @@ -1116,6 +1125,7 @@ def get_gaintopain_ratio(portfolio: PortfolioEngine): pd.DataFrame DataFrame of the portfolio's gain-to-pain ratio """ + gtp_period_df = portfolio_helper.get_gaintopain_ratio( portfolio.historical_trade_data, portfolio.benchmark_trades, @@ -1143,6 +1153,7 @@ def get_tracking_error(portfolio: PortfolioEngine, window: int = 252): pd.Series Series of rolling tracking error """ + trackr_period_df, trackr_rolling = portfolio_helper.get_tracking_error( portfolio.returns, portfolio.benchmark_returns, window ) @@ -1164,6 +1175,7 @@ def get_information_ratio(portfolio: PortfolioEngine): pd.DataFrame DataFrame of the information ratio during different time periods """ + ir_period_df = portfolio_helper.get_information_ratio( portfolio.returns, portfolio.historical_trade_data, @@ -1195,6 +1207,7 @@ def get_tail_ratio(portfolio: PortfolioEngine, window: int = 252): pd.Series Series of the benchmarks rolling tail ratio """ + tailr_period_df, portfolio_tr, benchmark_tr = portfolio_helper.get_tail_ratio( portfolio.returns, portfolio.benchmark_returns, window ) @@ -1216,6 +1229,7 @@ def get_common_sense_ratio(portfolio: PortfolioEngine): pd.DataFrame DataFrame of the portfolios and the benchmarks common sense ratio during different time periods """ + csr_period_df = portfolio_helper.get_common_sense_ratio( portfolio.returns, portfolio.historical_trade_data, @@ -1248,6 +1262,7 @@ def get_jensens_alpha( pd.Series Series of jensens's alpha data """ + ja_period_df, ja_rolling = portfolio_helper.jensens_alpha( portfolio.returns, portfolio.historical_trade_data, @@ -1278,6 +1293,7 @@ def get_calmar_ratio(portfolio: PortfolioEngine, window: int = 756): pd.Series Series of calmar ratio data """ + cr_period_df, cr_rolling = portfolio_helper.get_calmar_ratio( portfolio.returns, portfolio.historical_trade_data, @@ -1303,6 +1319,7 @@ def get_kelly_criterion(portfolio: PortfolioEngine): pd.DataFrame DataFrame of kelly criterion of the portfolio during different time periods """ + kc_period_df = portfolio_helper.get_kelly_criterion( portfolio.returns, portfolio.portfolio_trades ) @@ -1319,6 +1336,7 @@ def get_payoff_ratio(portfolio: PortfolioEngine): pd.DataFrame DataFrame of payoff ratio of the portfolio during different time periods """ + pr_period_ratio = portfolio_helper.get_payoff_ratio(portfolio.portfolio_trades) return pr_period_ratio @@ -1338,6 +1356,7 @@ def get_profit_factor(portfolio: PortfolioEngine): pd.DataFrame DataFrame of profit factor of the portfolio during different time periods """ + pf_period_df = portfolio_helper.get_profit_factor(portfolio.portfolio_trades) return pf_period_df @@ -1356,6 +1375,7 @@ def get_holdings_value(portfolio: PortfolioEngine) -> pd.DataFrame: pd.DataFrame DataFrame of holdings """ + all_holdings = portfolio.historical_trade_data["End Value"][portfolio.tickers_list] all_holdings["Total Value"] = all_holdings.sum(axis=1) @@ -1403,12 +1423,13 @@ def get_maximum_drawdown( Flag to indicate inputs are returns Returns - ---------- + ------- pd.Series Holdings series pd.Series Drawdown series """ + holdings: pd.Series = portfolio.portfolio_value if is_returns: holdings = (1 + holdings).cumprod() @@ -1432,6 +1453,7 @@ def get_distribution_returns( window : str interval to compare cumulative returns and benchmark """ + portfolio_returns = portfolio_helper.filter_df_by_period(portfolio.returns, window) benchmark_returns = portfolio_helper.filter_df_by_period( portfolio.benchmark_returns, window @@ -1601,7 +1623,6 @@ def get_performance_vs_benchmark( Returns ------- pd.DataFrame - """ portfolio_trades = portfolio.portfolio_trades @@ -1714,8 +1735,8 @@ def get_var( Returns ------- pd.DataFrame - """ + return qa_model.get_var( data=portfolio.returns, use_mean=use_mean, @@ -1748,7 +1769,6 @@ def get_es( Returns ------- pd.DataFrame - """ return qa_model.get_es( @@ -1777,7 +1797,6 @@ def get_omega( Returns ------- pd.DataFrame - """ return qa_model.get_omega( @@ -1868,6 +1887,7 @@ def get_yearly_returns( window : str interval to compare cumulative returns and benchmark """ + portfolio_returns = portfolio_helper.filter_df_by_period(portfolio.returns, window) benchmark_returns = portfolio_helper.filter_df_by_period( portfolio.benchmark_returns, window @@ -1919,8 +1939,8 @@ def get_monthly_returns( Returns ------- pd.DataFrame - """ + portfolio_returns = portfolio_helper.filter_df_by_period(portfolio.returns, window) benchmark_returns = portfolio_helper.filter_df_by_period( portfolio.benchmark_returns, window @@ -2064,6 +2084,23 @@ def generate_portfolio( return engine +def get_transactions(engine: PortfolioEngine) -> pd.DataFrame: + """Get portfolio transactions + + Parameters + ---------- + engine: PortfolioEngine + PortfolioEngine object + + Returns + ------- + pd.DataFrame + Portfolio transactions + """ + + return engine.get_transactions() + + def set_benchmark( engine: PortfolioEngine, symbol: str = "SPY", full_shares: bool = False ): diff --git a/openbb_terminal/portfolio/portfolio_view.py b/openbb_terminal/portfolio/portfolio_view.py index 7ff7f29a60a4..e5d91661abb3 100644 --- a/openbb_terminal/portfolio/portfolio_view.py +++ b/openbb_terminal/portfolio/portfolio_view.py @@ -16,6 +16,7 @@ from openbb_terminal.config_plot import PLOT_DPI from openbb_terminal.portfolio.portfolio_model import ( PortfolioEngine, + get_transactions, get_daily_returns, get_performance_vs_benchmark, get_yearly_returns, @@ -117,8 +118,10 @@ def display_transactions( if portfolio.empty: logger.warning("No transactions file loaded.") console.print("[red]No transactions file loaded.[/red]\n") + else: - df = portfolio.get_transactions() + + df = get_transactions() print_rich_table( df=df[:limit], show_index=show_index, From 5763ea663d34a77f15b06f40d77740ecab8b10b3 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 20:19:26 +0000 Subject: [PATCH 05/30] reorder some methods --- CONTRIBUTING.md | 2 +- .../portfolio/portfolio_controller.py | 2 +- openbb_terminal/portfolio/portfolio_model.py | 52 +++++++++++-------- .../reports/templates/portfolio.ipynb | 2 +- website/content/SDK/portfolio/_index.md | 10 ++-- 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5d31907d323f..900cfe6c9442 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -681,7 +681,7 @@ With: transactions = Portfolio.read_orderbook("../../portfolio/holdings/example.csv") P = Portfolio(transactions) P.generate_portfolio_data() - P.load_benchmark() + P.set_benchmark() # SDK endpoint access openbb.portfolio.gaintopain(P) diff --git a/openbb_terminal/portfolio/portfolio_controller.py b/openbb_terminal/portfolio/portfolio_controller.py index 0ec16a16e130..059487ff5221 100644 --- a/openbb_terminal/portfolio/portfolio_controller.py +++ b/openbb_terminal/portfolio/portfolio_controller.py @@ -538,7 +538,7 @@ def call_bench(self, other_args: List[str]): else: benchmark_ticker = chosen_benchmark - self.portfolio.load_benchmark(benchmark_ticker, ns_parser.full_shares) + self.portfolio.set_benchmark(benchmark_ticker, ns_parser.full_shares) self.benchmark_name = chosen_benchmark diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 2af23db34e60..6dbf991f3d4c 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -40,11 +40,11 @@ class PortfolioEngine: read_transactions: Class method to read transactions from file __set_transactions: - preprocess_transactions: Method to preprocess, format and compute auxiliary fields + __preprocess_transactions: Method to preprocess, format and compute auxiliary fields get_transactions: Outputs the formatted transactions DataFrame - load_benchmark: Adds benchmark ticker, info, prices and returns + set_benchmark: Adds benchmark ticker, info, prices and returns mimic_trades_for_benchmark: Mimic trades from the transactions based on chosen benchmark assuming partial shares generate_portfolio_data: Generates portfolio data from transactions @@ -52,12 +52,11 @@ class PortfolioEngine: populate_historical_trade_data: Create a new dataframe to store historical prices by ticker calculate_value: Calculate value end of day from historical data + set_risk_free_rate: Sets risk free rate + calculate_reserves: Takes dividends into account for returns calculation calculate_allocations: Determine allocations based on assets, sectors, countries and region - - set_risk_free_rate: Sets risk free rate - """ def __init__(self, transactions: pd.DataFrame = pd.DataFrame()): @@ -100,7 +99,7 @@ def __init__(self, transactions: pd.DataFrame = pd.DataFrame()): def __set_transactions(self, transactions): self.__transactions = transactions - self.preprocess_transactions() + self.__preprocess_transactions() self.empty = False def get_transactions(self): @@ -110,6 +109,7 @@ def get_transactions(self): ------- pd.DataFrame: formatted transactions """ + df = self.__transactions[ [ "Date", @@ -155,7 +155,7 @@ def read_transactions(path: str) -> pd.DataFrame: return transactions @log_start_end(log=logger) - def preprocess_transactions(self): + def __preprocess_transactions(self): """Method to preprocess, format and compute auxiliary fields. Preprocessing steps: @@ -434,7 +434,7 @@ def load_company_data(self): ] = info_list @log_start_end(log=logger) - def load_benchmark(self, symbol: str = "SPY", full_shares: bool = False): + def set_benchmark(self, symbol: str = "SPY", full_shares: bool = False): """Load benchmark into portfolio. Parameters @@ -739,6 +739,18 @@ def calculate_value(self): self.historical_trade_data = trade_data + @log_start_end(log=logger) + def set_risk_free_rate(self, risk_free_rate: float): + """Sets risk free rate + + Parameters + ---------- + risk_free_rate : float + Risk free rate in float format + """ + + self.risk_free_rate = risk_free_rate + @log_start_end(log=logger) def calculate_reserves(self): """Takes dividends into account for returns calculation""" @@ -785,18 +797,6 @@ def calculate_allocations(self, category: str): self.portfolio_trades ) - @log_start_end(log=logger) - def set_risk_free_rate(self, risk_free_rate: float): - """Sets risk free rate - - Parameters - ---------- - risk_free_rate : float - Risk free rate in float format - """ - - self.risk_free_rate = risk_free_rate - # Metrics @log_start_end(log=logger) @@ -1553,6 +1553,7 @@ def get_rolling_sortino( Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y risk_free_rate: float Value to use for risk free rate in sharpe/other calculations + Returns ------- pd.DataFrame @@ -1620,6 +1621,7 @@ def get_performance_vs_benchmark( PortfolioEngine object with trades loaded show_all_trades: bool Whether to also show all trades made and their performance (default is False) + Returns ------- pd.DataFrame @@ -1732,6 +1734,7 @@ def get_var( If one should use the student-t distribution percentile: float var percentile (%) + Returns ------- pd.DataFrame @@ -1766,6 +1769,7 @@ def get_es( choose distribution to use: logistic, laplace, normal percentile: float es percentile (%) + Returns ------- pd.DataFrame @@ -1794,6 +1798,7 @@ def get_omega( annualized target return threshold start of plotted threshold range threshold_end: float annualized target return threshold end of plotted threshold range + Returns ------- pd.DataFrame @@ -1821,6 +1826,7 @@ def get_summary( interval to compare cumulative returns and benchmark risk_free_rate : float Risk free rate for calculations + Returns ------- pd.DataFrame @@ -1936,6 +1942,7 @@ def get_monthly_returns( PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark + Returns ------- pd.DataFrame @@ -2031,6 +2038,7 @@ def get_daily_returns( PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark + Returns ------- pd.DataFrame @@ -2078,7 +2086,7 @@ def generate_portfolio( transactions = PortfolioEngine.read_transactions(transactions_path) engine = PortfolioEngine(transactions) engine.generate_portfolio_data() - engine.load_benchmark(symbol=benchmark_symbol, full_shares=full_shares) + engine.set_benchmark(symbol=benchmark_symbol, full_shares=full_shares) engine.set_risk_free_rate(risk_free_rate) return engine @@ -2117,7 +2125,7 @@ def set_benchmark( quantity to the nearest number """ - engine.load_benchmark(symbol=symbol, full_shares=full_shares) + engine.set_benchmark(symbol=symbol, full_shares=full_shares) def set_risk_free_rate(engine: PortfolioEngine, risk_free_rate: float): diff --git a/openbb_terminal/reports/templates/portfolio.ipynb b/openbb_terminal/reports/templates/portfolio.ipynb index bd38c5d74ed7..58a6aca08eb2 100644 --- a/openbb_terminal/reports/templates/portfolio.ipynb +++ b/openbb_terminal/reports/templates/portfolio.ipynb @@ -141,7 +141,7 @@ " transactions = Portfolio.read_transactions(transactions_path)\n", " P = Portfolio(transactions)\n", " P.generate_portfolio_data()\n", - " P.load_benchmark()\n", + " P.set_benchmark()\n", " P.get_transactions()\n", "except ValueError:\n", " raise ValueError(\n", diff --git a/website/content/SDK/portfolio/_index.md b/website/content/SDK/portfolio/_index.md index 3000aeb6e526..9e495dd4fcef 100644 --- a/website/content/SDK/portfolio/_index.md +++ b/website/content/SDK/portfolio/_index.md @@ -1,7 +1,7 @@ --- title: Introduction to Portfolio keywords: "portfolio, attribution, optimization, pnl, benchmark, return, volatility, metrics, broker, integration, report" -excerpt: "The Introduction to Portfolio explains how to use the +excerpt: "The Introduction to Portfolio explains how to use the menu and provides a brief description of its sub-menus" geekdocCollapseSection: true --- @@ -50,7 +50,7 @@ in the following: from openbb_terminal.sdk import Portfolio # Define your own orderbook location here -orderbook_path = "Public_Equity_Orderbook.xlsx" +orderbook_path = "Public_Equity_Orderbook.xlsx" # Load in the transactions transactions = Portfolio.read_orderbook(orderbook_path) @@ -58,7 +58,7 @@ P = Portfolio(transactions) P.generate_portfolio_data() # Load in the benchmark, by default this is the SPY ETF -P.load_benchmark() +P.set_benchmark() ``` Note that the Excel sheet requires the following columns: @@ -134,7 +134,7 @@ takes a bit longer to load. from openbb_terminal.sdk import Portfolio # Define your own orderbook location here -orderbook_path = "Public_Equity_Orderbook_No_Categorization.xlsx" +orderbook_path = "Public_Equity_Orderbook_No_Categorization.xlsx" # Load in the transactions transactions = Portfolio.read_orderbook(orderbook_path) @@ -142,7 +142,7 @@ P = Portfolio(transactions) P.generate_portfolio_data() # Load in the benchmark, by default this is the SPY ETF -P.load_benchmark() +P.set_benchmark() ``` Then, we can show our performance compared to that of the benchmark. From 61803a79a1d0bca35bb312450b7c9521783e6f82 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 20:21:30 +0000 Subject: [PATCH 06/30] fix bug --- openbb_terminal/portfolio/portfolio_view.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_view.py b/openbb_terminal/portfolio/portfolio_view.py index e5d91661abb3..3c57f69a7290 100644 --- a/openbb_terminal/portfolio/portfolio_view.py +++ b/openbb_terminal/portfolio/portfolio_view.py @@ -106,7 +106,7 @@ def display_transactions( Parameters ---------- portfolio: PortfolioEngine - Instance of Portfolio class + Instance of PortfolioEngine class show_index: bool Defaults to False. limit: int @@ -120,8 +120,7 @@ def display_transactions( console.print("[red]No transactions file loaded.[/red]\n") else: - - df = get_transactions() + df = get_transactions(portfolio) print_rich_table( df=df[:limit], show_index=show_index, From 4d55b43c16a1d0e82b23ee5d73e4da36af2bcb63 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 21:08:56 +0000 Subject: [PATCH 07/30] update controller --- .../portfolio/portfolio_controller.py | 32 +++++-------------- openbb_terminal/portfolio/portfolio_model.py | 17 +++++++--- .../reports/templates/portfolio.ipynb | 2 +- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_controller.py b/openbb_terminal/portfolio/portfolio_controller.py index 059487ff5221..dd9d6a04998e 100644 --- a/openbb_terminal/portfolio/portfolio_controller.py +++ b/openbb_terminal/portfolio/portfolio_controller.py @@ -442,33 +442,26 @@ def call_load(self, other_args: List[str]): else: file_location = ns_parser.file # type: ignore - transactions = portfolio_model.PortfolioEngine.read_transactions( - str(file_location) + self.portfolio = portfolio_model.generate_portfolio( + transactions_file_path=str(file_location), + benchmark_symbol="SPY", + risk_free_rate=ns_parser.risk_free_rate / 100, ) - self.portfolio = portfolio_model.PortfolioEngine(transactions) - self.benchmark_name = "" if ns_parser.name: self.portfolio_name = ns_parser.name else: self.portfolio_name = ns_parser.file - - # Generate holdings from trades - self.portfolio.generate_portfolio_data() - - # Add in the Risk-free rate - self.portfolio.set_risk_free_rate(ns_parser.risk_free_rate / 100) - self.risk_free_rate = ns_parser.risk_free_rate / 100 - - # Load benchmark - self.call_bench(["-b", "SPDR S&P 500 ETF Trust (SPY)"]) - console.print( f"\n[bold][param]Portfolio:[/param][/bold] {self.portfolio_name}" ) + + self.benchmark_name = "SPDR S&P 500 ETF Trust (SPY)" console.print( f"[bold][param]Risk Free Rate:[/param][/bold] {self.risk_free_rate:.2%}" ) + + self.risk_free_rate = ns_parser.risk_free_rate / 100 console.print( f"[bold][param]Benchmark:[/param][/bold] {self.benchmark_name}\n" ) @@ -542,15 +535,6 @@ def call_bench(self, other_args: List[str]): self.benchmark_name = chosen_benchmark - # Make it so that there is no chance of there being a difference in length between - # the portfolio and benchmark return DataFrames - ( - self.portfolio.returns, - self.portfolio.benchmark_returns, - ) = portfolio_helper.make_equal_length( - self.portfolio.returns, self.portfolio.benchmark_returns - ) - else: console.print( "[red]Please first load transactions file using 'load'[/red]\n" diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 6dbf991f3d4c..28844342034c 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -18,6 +18,7 @@ from openbb_terminal.portfolio import ( portfolio_helper, allocation_model, + statics, ) from openbb_terminal.rich_config import console @@ -446,7 +447,7 @@ def set_benchmark(self, symbol: str = "SPY", full_shares: bool = False): quantity to the nearest number """ - p_bar = tqdm(range(3), desc=" Loading benchmark") + p_bar = tqdm(range(4), desc=" Loading benchmark") self.benchmark_ticker = symbol @@ -481,6 +482,14 @@ def set_benchmark(self, symbol: str = "SPY", full_shares: bool = False): p_bar.n += 1 p_bar.refresh() + ( + self.returns, + self.benchmark_returns, + ) = portfolio_helper.make_equal_length(self.returns, self.benchmark_returns) + + p_bar.n += 1 + p_bar.refresh() + @log_start_end(log=logger) def mimic_trades_for_benchmark(self, full_shares: bool = False): """Mimic trades from the transactions based on chosen benchmark assuming partial shares @@ -2058,7 +2067,7 @@ def get_daily_returns( def generate_portfolio( - transactions_path: str, + transactions_file_path: str, benchmark_symbol: str = "SPY", full_shares: bool = False, risk_free_rate: float = 0, @@ -2067,7 +2076,7 @@ def generate_portfolio( Parameters ---------- - file_path : str + transactions_file_path : str Path to transactions file benchmark_symbol : str Benchmark ticker to download data @@ -2083,7 +2092,7 @@ def generate_portfolio( PortfolioEngine object """ - transactions = PortfolioEngine.read_transactions(transactions_path) + transactions = PortfolioEngine.read_transactions(transactions_file_path) engine = PortfolioEngine(transactions) engine.generate_portfolio_data() engine.set_benchmark(symbol=benchmark_symbol, full_shares=full_shares) diff --git a/openbb_terminal/reports/templates/portfolio.ipynb b/openbb_terminal/reports/templates/portfolio.ipynb index 58a6aca08eb2..ebd7cddf07e6 100644 --- a/openbb_terminal/reports/templates/portfolio.ipynb +++ b/openbb_terminal/reports/templates/portfolio.ipynb @@ -205,7 +205,7 @@ "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(11, 5), dpi=150)\n", - "openbb.portfolio.rsortino(P, chart=True, external_axes=[ax])\n", + "openbb.portfolio.rsort(P, chart=True, external_axes=[ax])\n", "\n", "fig.tight_layout()\n", "f = io.BytesIO()\n", From b2769b1a6e8c0591fc1b800e7042c55d67b27392 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 21:09:18 +0000 Subject: [PATCH 08/30] update website --- website/content/SDK/portfolio/_index.md | 2 +- website/content/SDK/portfolio/rsortino/_index.rst | 4 ++-- website/data/menu/main.yml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/website/content/SDK/portfolio/_index.md b/website/content/SDK/portfolio/_index.md index 9e495dd4fcef..9a73484e311d 100644 --- a/website/content/SDK/portfolio/_index.md +++ b/website/content/SDK/portfolio/_index.md @@ -33,7 +33,7 @@ The SDK commands of the the menu: .portfolio.maxdd .portfolio.rvol .portfolio.rsharpe - .portfolio.rsortino + .portfolio.rsort .portfolio.rbeta .portfolio.summary .portfolio.skew diff --git a/website/content/SDK/portfolio/rsortino/_index.rst b/website/content/SDK/portfolio/rsortino/_index.rst index 7e6394f024bc..5c50e133218e 100644 --- a/website/content/SDK/portfolio/rsortino/_index.rst +++ b/website/content/SDK/portfolio/rsortino/_index.rst @@ -13,7 +13,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} -portfolio.rsortino( +portfolio.rsort( portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, window: str = '1y', @@ -54,7 +54,7 @@ portfolio.rsortino( {{< highlight python >}} -portfolio.rsortino( +portfolio.rsort( portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, window: str = '1y', diff --git a/website/data/menu/main.yml b/website/data/menu/main.yml index ef3ad06a0deb..910930fee29f 100644 --- a/website/data/menu/main.yml +++ b/website/data/menu/main.yml @@ -2572,8 +2572,8 @@ main: ref: /SDK/portfolio/rbeta - name: rsharpe ref: /SDK/portfolio/rsharpe - - name: rsortino - ref: /SDK/portfolio/rsortino + - name: rsort + ref: /SDK/portfolio/rsort - name: rsquare ref: /SDK/portfolio/rsquare - name: rvol From e4905b4b4456f076d2af090a06414ab27ecbfaf1 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 21:13:32 +0000 Subject: [PATCH 09/30] remove import --- openbb_terminal/portfolio/portfolio_model.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 28844342034c..fa1570c17185 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -18,7 +18,6 @@ from openbb_terminal.portfolio import ( portfolio_helper, allocation_model, - statics, ) from openbb_terminal.rich_config import console @@ -810,7 +809,7 @@ def calculate_allocations(self, category: str): # Metrics @log_start_end(log=logger) def get_r2_score(portfolio: PortfolioEngine) -> pd.DataFrame: - """Class method that retrieves R2 Score for portfolio and benchmark selected + """Method that retrieves R2 Score for portfolio and benchmark selected Parameters ---------- @@ -841,7 +840,7 @@ def get_r2_score(portfolio: PortfolioEngine) -> pd.DataFrame: @log_start_end(log=logger) def get_skewness(portfolio: PortfolioEngine) -> pd.DataFrame: - """Class method that retrieves skewness for portfolio and benchmark selected + """Method that retrieves skewness for portfolio and benchmark selected portfolio: PortfolioEngine PortfolioEngine object with trades loaded @@ -879,7 +878,7 @@ def get_skewness(portfolio: PortfolioEngine) -> pd.DataFrame: @log_start_end(log=logger) def get_kurtosis(portfolio: PortfolioEngine) -> pd.DataFrame: - """Class method that retrieves kurtosis for portfolio and benchmark selected + """Method that retrieves kurtosis for portfolio and benchmark selected Parameters ---------- @@ -919,7 +918,7 @@ def get_kurtosis(portfolio: PortfolioEngine) -> pd.DataFrame: @log_start_end(log=logger) def get_stats(portfolio: PortfolioEngine, window: str = "all") -> pd.DataFrame: - """Class method that retrieves stats for portfolio and benchmark selected based on a certain interval + """Method that retrieves stats for portfolio and benchmark selected based on a certain interval Parameters ---------- @@ -950,7 +949,7 @@ def get_stats(portfolio: PortfolioEngine, window: str = "all") -> pd.DataFrame: @log_start_end(log=logger) def get_volatility(portfolio: PortfolioEngine) -> pd.DataFrame: - """Class method that retrieves volatility for portfolio and benchmark selected + """Method that retrieves volatility for portfolio and benchmark selected Parameters ---------- @@ -992,7 +991,7 @@ def get_volatility(portfolio: PortfolioEngine) -> pd.DataFrame: def get_sharpe_ratio( portfolio: PortfolioEngine, risk_free_rate: float = 0 ) -> pd.DataFrame: - """Class method that retrieves sharpe ratio for portfolio and benchmark selected + """Method that retrieves sharpe ratio for portfolio and benchmark selected Parameters ---------- @@ -1038,7 +1037,7 @@ def get_sharpe_ratio( def get_sortino_ratio( portfolio: PortfolioEngine, risk_free_rate: float = 0 ) -> pd.DataFrame: - """Class method that retrieves sortino ratio for portfolio and benchmark selected + """Method that retrieves sortino ratio for portfolio and benchmark selected Parameters ---------- @@ -1082,7 +1081,7 @@ def get_sortino_ratio( @log_start_end(log=logger) def get_maximum_drawdown_ratio(portfolio: PortfolioEngine) -> pd.DataFrame: - """Class method that retrieves maximum drawdown ratio for portfolio and benchmark selected + """Method that retrieves maximum drawdown ratio for portfolio and benchmark selected Parameters ---------- From eef48e73d0d7fe757e627a5ab1d13acc34225c29 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 21:35:01 +0000 Subject: [PATCH 10/30] change input name --- .../portfolio/portfolio_controller.py | 6 +- openbb_terminal/portfolio/portfolio_model.py | 28 +-- openbb_terminal/portfolio/portfolio_view.py | 198 +++++++++--------- openbb_terminal/sdk.py | 3 - 4 files changed, 116 insertions(+), 119 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_controller.py b/openbb_terminal/portfolio/portfolio_controller.py index dd9d6a04998e..fd8333e25d32 100644 --- a/openbb_terminal/portfolio/portfolio_controller.py +++ b/openbb_terminal/portfolio/portfolio_controller.py @@ -893,7 +893,7 @@ def call_var(self, other_args: List[str]): ) else: portfolio_view.display_var( - portfolio=self.portfolio, + portfolio_engine=self.portfolio, use_mean=ns_parser.use_mean, adjusted_var=ns_parser.adjusted, student_t=ns_parser.student_t, @@ -950,7 +950,7 @@ def call_es(self, other_args: List[str]): if ns_parser and self.portfolio is not None: if self.portfolio_name: portfolio_view.display_es( - portfolio=self.portfolio, + portfolio_engine=self.portfolio, use_mean=ns_parser.use_mean, distribution=ns_parser.distribution, percentile=ns_parser.percentile, @@ -1261,7 +1261,7 @@ def call_rsort(self, other_args: List[str]): self.portfolio_name, self.benchmark_name ): portfolio_view.display_rolling_sortino( - portfolio=self.portfolio, + portfolio_engine=self.portfolio, risk_free_rate=ns_parser.risk_free_rate / 100, window=ns_parser.period, export=ns_parser.export, diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index fa1570c17185..4b2bf7a8cdc7 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -2092,20 +2092,20 @@ def generate_portfolio( """ transactions = PortfolioEngine.read_transactions(transactions_file_path) - engine = PortfolioEngine(transactions) - engine.generate_portfolio_data() - engine.set_benchmark(symbol=benchmark_symbol, full_shares=full_shares) - engine.set_risk_free_rate(risk_free_rate) + portfolio_engine = PortfolioEngine(transactions) + portfolio_engine.generate_portfolio_data() + portfolio_engine.set_benchmark(symbol=benchmark_symbol, full_shares=full_shares) + portfolio_engine.set_risk_free_rate(risk_free_rate) - return engine + return portfolio_engine -def get_transactions(engine: PortfolioEngine) -> pd.DataFrame: +def get_transactions(portfolio_engine: PortfolioEngine) -> pd.DataFrame: """Get portfolio transactions Parameters ---------- - engine: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object Returns @@ -2114,17 +2114,17 @@ def get_transactions(engine: PortfolioEngine) -> pd.DataFrame: Portfolio transactions """ - return engine.get_transactions() + return portfolio_engine.get_transactions() def set_benchmark( - engine: PortfolioEngine, symbol: str = "SPY", full_shares: bool = False + portfolio_engine: PortfolioEngine, symbol: str, full_shares: bool = False ): """Load benchmark into portfolio Parameters ---------- - engine: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object symbol: str Benchmark symbol to download data @@ -2133,21 +2133,21 @@ def set_benchmark( quantity to the nearest number """ - engine.set_benchmark(symbol=symbol, full_shares=full_shares) + portfolio_engine.set_benchmark(symbol=symbol, full_shares=full_shares) -def set_risk_free_rate(engine: PortfolioEngine, risk_free_rate: float): +def set_risk_free_rate(portfolio_engine: PortfolioEngine, risk_free_rate: float): """Set risk-free rate Parameters ---------- - engine: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object risk_free_rate: float Risk free rate in float format """ - engine.set_risk_free_rate(risk_free_rate=risk_free_rate) + portfolio_engine.set_risk_free_rate(risk_free_rate=risk_free_rate) # Old code diff --git a/openbb_terminal/portfolio/portfolio_view.py b/openbb_terminal/portfolio/portfolio_view.py index 3c57f69a7290..6f2600909a60 100644 --- a/openbb_terminal/portfolio/portfolio_view.py +++ b/openbb_terminal/portfolio/portfolio_view.py @@ -96,7 +96,7 @@ def load_info(): @log_start_end(log=logger) def display_transactions( - portfolio=None, + portfolio_engine=None, show_index=False, limit: int = 10, export: str = "", @@ -105,7 +105,7 @@ def display_transactions( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine Instance of PortfolioEngine class show_index: bool Defaults to False. @@ -115,12 +115,12 @@ def display_transactions( Export certain type of data """ - if portfolio.empty: + if portfolio_engine.empty: logger.warning("No transactions file loaded.") console.print("[red]No transactions file loaded.[/red]\n") else: - df = get_transactions(portfolio) + df = get_transactions(portfolio_engine) print_rich_table( df=df[:limit], show_index=show_index, @@ -286,7 +286,7 @@ def display_category_allocation( @log_start_end(log=logger) def display_performance_vs_benchmark( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, show_all_trades: bool = False, ): """Display portfolio performance vs the benchmark @@ -301,7 +301,7 @@ def display_performance_vs_benchmark( Whether to also show all trades made and their performance (default is False) """ - df = get_performance_vs_benchmark(portfolio, show_all_trades) + df = get_performance_vs_benchmark(portfolio_engine, show_all_trades) if show_all_trades: print_rich_table( @@ -322,7 +322,7 @@ def display_performance_vs_benchmark( @log_start_end(log=logger) def display_yearly_returns( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "all", raw: bool = False, export: str = "", @@ -332,7 +332,7 @@ def display_yearly_returns( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark @@ -344,7 +344,7 @@ def display_yearly_returns( Optional axes to display plot on """ - df = get_yearly_returns(portfolio, window) + df = get_yearly_returns(portfolio_engine, window) if raw: print_rich_table( @@ -402,7 +402,7 @@ def display_yearly_returns( @log_start_end(log=logger) def display_monthly_returns( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "all", raw: bool = False, show_vals: bool = False, @@ -413,7 +413,7 @@ def display_monthly_returns( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark @@ -427,7 +427,7 @@ def display_monthly_returns( Optional axes to display plot on """ - portfolio_returns, benchmark_returns = get_monthly_returns(portfolio, window) + portfolio_returns, benchmark_returns = get_monthly_returns(portfolio_engine, window) if raw: print_rich_table( @@ -502,7 +502,7 @@ def display_monthly_returns( @log_start_end(log=logger) def display_daily_returns( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "all", raw: bool = False, limit: int = 10, @@ -513,7 +513,7 @@ def display_daily_returns( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark @@ -527,7 +527,7 @@ def display_daily_returns( Optional axes to display plot on """ - df = get_daily_returns(portfolio, window) + df = get_daily_returns(portfolio_engine, window) if raw: print_rich_table( @@ -570,7 +570,7 @@ def display_daily_returns( @log_start_end(log=logger) def display_distribution_returns( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "all", raw: bool = False, export: str = "", @@ -594,7 +594,7 @@ def display_distribution_returns( Optional axes to display plot on """ - df = get_distribution_returns(portfolio, window) + df = get_distribution_returns(portfolio_engine, window) df_portfolio = df["portfolio"] df_benchmark = df["benchmark"] @@ -657,7 +657,7 @@ def display_distribution_returns( @log_start_end(log=logger) def display_holdings_value( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, unstack: bool = False, raw: bool = False, limit: int = 10, @@ -668,7 +668,7 @@ def display_holdings_value( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded unstack: bool Individual assets over time @@ -682,7 +682,7 @@ def display_holdings_value( Optional axes to display plot on """ - all_holdings = get_holdings_value(portfolio) + all_holdings = get_holdings_value(portfolio_engine) if raw: print_rich_table( @@ -735,7 +735,7 @@ def display_holdings_value( @log_start_end(log=logger) def display_holdings_percentage( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, unstack: bool = False, raw: bool = False, limit: int = 10, @@ -746,7 +746,7 @@ def display_holdings_percentage( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded unstack: bool Individual assets over time @@ -760,7 +760,7 @@ def display_holdings_percentage( Optional axes to display plot on """ - all_holdings = get_holdings_percentage(portfolio) + all_holdings = get_holdings_percentage(portfolio_engine) if raw: # No need to account for time since this is daily data @@ -818,7 +818,7 @@ def display_holdings_percentage( @log_start_end(log=logger) def display_rolling_volatility( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "1y", export: str = "", external_axes: Optional[List[plt.Axes]] = None, @@ -838,7 +838,7 @@ def display_rolling_volatility( """ metric = "volatility" - df = get_rolling_volatility(portfolio, window) + df = get_rolling_volatility(portfolio_engine, window) if df.empty: return @@ -874,7 +874,7 @@ def display_rolling_volatility( @log_start_end(log=logger) def display_rolling_sharpe( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, risk_free_rate: float = 0, window: str = "1y", export: str = "", @@ -897,7 +897,7 @@ def display_rolling_sharpe( """ metric = "sharpe" - df = get_rolling_sharpe(portfolio, risk_free_rate, window) + df = get_rolling_sharpe(portfolio_engine, risk_free_rate, window) if df.empty: return @@ -933,7 +933,7 @@ def display_rolling_sharpe( @log_start_end(log=logger) def display_rolling_sortino( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, risk_free_rate: float = 0, window: str = "1y", export: str = "", @@ -956,7 +956,7 @@ def display_rolling_sortino( """ metric = "sortino" - df = get_rolling_sortino(portfolio, risk_free_rate, window) + df = get_rolling_sortino(portfolio_engine, risk_free_rate, window) if df.empty: return @@ -992,7 +992,7 @@ def display_rolling_sortino( @log_start_end(log=logger) def display_rolling_beta( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "1y", export: str = "", external_axes: Optional[List[plt.Axes]] = None, @@ -1012,7 +1012,7 @@ def display_rolling_beta( Optional axes to display plot on """ - rolling_beta = get_rolling_beta(portfolio, window) + rolling_beta = get_rolling_beta(portfolio_engine, window) if rolling_beta.empty: return @@ -1053,7 +1053,7 @@ def display_rolling_beta( @log_start_end(log=logger) def display_maximum_drawdown( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", external_axes: Optional[List[plt.Axes]] = None, ): @@ -1068,7 +1068,7 @@ def display_maximum_drawdown( external_axes: plt.Axes Optional axes to display plot on """ - holdings, drawdown = get_maximum_drawdown(portfolio) + holdings, drawdown = get_maximum_drawdown(portfolio_engine) if external_axes is None: _, ax = plt.subplots(2, 1, figsize=plot_autoscale(), dpi=PLOT_DPI, sharex=True) else: @@ -1098,20 +1098,20 @@ def display_maximum_drawdown( @log_start_end(log=logger) def display_rsquare( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display R-square Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded export : str Export data format """ - df = get_r2_score(portfolio).fillna("-") + df = get_r2_score(portfolio_engine).fillna("-") print_rich_table( df, @@ -1130,20 +1130,20 @@ def display_rsquare( @log_start_end(log=logger) def display_skewness( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display skewness Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded export : str Export data format """ - df = get_skewness(portfolio).fillna("-") + df = get_skewness(portfolio_engine).fillna("-") print_rich_table( df, @@ -1160,20 +1160,20 @@ def display_skewness( @log_start_end(log=logger) def display_kurtosis( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display kurtosis Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded export : str Export data format """ - df = get_kurtosis(portfolio).fillna("-") + df = get_kurtosis(portfolio_engine).fillna("-") print_rich_table( df, @@ -1190,7 +1190,7 @@ def display_kurtosis( @log_start_end(log=logger) def display_stats( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "all", export: str = "", ): @@ -1198,7 +1198,7 @@ def display_stats( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded window : str interval to consider. Choices are: mtd, qtd, ytd, 3m, 6m, 1y, 3y, 5y, 10y, all @@ -1206,7 +1206,7 @@ def display_stats( Export data format """ - df = get_stats(portfolio, window) + df = get_stats(portfolio_engine, window) print_rich_table( df, @@ -1223,20 +1223,20 @@ def display_stats( @log_start_end(log=logger) def display_volatility( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display volatility for multiple intervals Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded export : str Export data format """ - df = get_volatility(portfolio).fillna("-") + df = get_volatility(portfolio_engine).fillna("-") print_rich_table( df, title="Volatility for Portfolio and Benchmark", @@ -1250,7 +1250,7 @@ def display_volatility( @log_start_end(log=logger) def display_sharpe_ratio( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, risk_free_rate: float = 0, export: str = "", ): @@ -1258,7 +1258,7 @@ def display_sharpe_ratio( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded risk_free_rate: float Risk free rate value @@ -1266,7 +1266,7 @@ def display_sharpe_ratio( Export data format """ - df = get_sharpe_ratio(portfolio, risk_free_rate).fillna("-") + df = get_sharpe_ratio(portfolio_engine, risk_free_rate).fillna("-") print_rich_table( df, title="Sharpe ratio for Portfolio and Benchmark", @@ -1283,7 +1283,7 @@ def display_sharpe_ratio( @log_start_end(log=logger) def display_sortino_ratio( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, risk_free_rate: float = 0, export: str = "", ): @@ -1291,7 +1291,7 @@ def display_sortino_ratio( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded risk_free_rate: float Risk free rate value @@ -1299,7 +1299,7 @@ def display_sortino_ratio( Export data format """ - df = get_sortino_ratio(portfolio, risk_free_rate).fillna("-") + df = get_sortino_ratio(portfolio_engine, risk_free_rate).fillna("-") print_rich_table( df, title="Sortino ratio for Portfolio and Benchmark", @@ -1316,20 +1316,20 @@ def display_sortino_ratio( @log_start_end(log=logger) def display_maximum_drawdown_ratio( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display maximum drawdown for multiple intervals Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded export : str Export data format """ - df = get_maximum_drawdown_ratio(portfolio).fillna("-") + df = get_maximum_drawdown_ratio(portfolio_engine).fillna("-") print_rich_table( df, title="Maximum drawdown for Portfolio and Benchmark", @@ -1343,20 +1343,20 @@ def display_maximum_drawdown_ratio( @log_start_end(log=logger) def display_gaintopain_ratio( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display gain-to-pain ratio for multiple intervals Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with returns and benchmark loaded export : str Export data format """ - df = get_gaintopain_ratio(portfolio).fillna("-") + df = get_gaintopain_ratio(portfolio_engine).fillna("-") print_rich_table( df, title="Gain-to-pain ratio for portfolio and benchmark", @@ -1373,20 +1373,20 @@ def display_gaintopain_ratio( @log_start_end(log=logger) def display_tracking_error( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display tracking error for multiple intervals Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with returns and benchmark loaded export : str Export data format """ - df, _ = get_tracking_error(portfolio) + df, _ = get_tracking_error(portfolio_engine) df = df.fillna("-") print_rich_table( df, @@ -1401,20 +1401,20 @@ def display_tracking_error( @log_start_end(log=logger) def display_information_ratio( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display information ratio for multiple intervals Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with returns and benchmark loaded export : str Export data format """ - df = get_information_ratio(portfolio).fillna("-") + df = get_information_ratio(portfolio_engine).fillna("-") print_rich_table( df, title="Information ratio for portfolio", @@ -1431,14 +1431,14 @@ def display_information_ratio( @log_start_end(log=logger) def display_tail_ratio( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display tail ratio for multiple intervals Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with returns and benchmark loaded window: str interval for window to consider @@ -1446,7 +1446,7 @@ def display_tail_ratio( Export data format """ - df, _, _ = get_tail_ratio(portfolio) + df, _, _ = get_tail_ratio(portfolio_engine) df = df.fillna("-") print_rich_table( df, @@ -1461,20 +1461,20 @@ def display_tail_ratio( @log_start_end(log=logger) def display_common_sense_ratio( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display common sense ratio for multiple intervals Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with returns and benchmark loaded export : str Export data format """ - df = get_common_sense_ratio(portfolio).fillna("-") + df = get_common_sense_ratio(portfolio_engine).fillna("-") print_rich_table( df, title="Common sense ratio for portfolio and benchmark", @@ -1491,7 +1491,7 @@ def display_common_sense_ratio( @log_start_end(log=logger) def display_jensens_alpha( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, risk_free_rate: float = 0, export: str = "", ): @@ -1499,7 +1499,7 @@ def display_jensens_alpha( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with returns and benchmark loaded risk_free_rate: float Risk free rate @@ -1507,7 +1507,7 @@ def display_jensens_alpha( Export data format """ - df, _ = get_jensens_alpha(portfolio, risk_free_rate) + df, _ = get_jensens_alpha(portfolio_engine, risk_free_rate) df = df.fillna("-") print_rich_table( df, @@ -1522,20 +1522,20 @@ def display_jensens_alpha( @log_start_end(log=logger) def display_calmar_ratio( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display calmar ratio for multiple intervals Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with returns and benchmark loaded export : str Export data format """ - df, _ = get_calmar_ratio(portfolio) + df, _ = get_calmar_ratio(portfolio_engine) df = df.fillna("-") print_rich_table( df, @@ -1550,20 +1550,20 @@ def display_calmar_ratio( @log_start_end(log=logger) def display_kelly_criterion( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display kelly criterion for multiple intervals Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades and returns loaded export : str Export data format """ - df = get_kelly_criterion(portfolio).fillna("-") + df = get_kelly_criterion(portfolio_engine).fillna("-") print_rich_table( df, title="Kelly criterion of the portfolio", @@ -1576,20 +1576,20 @@ def display_kelly_criterion( def display_payoff_ratio( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display payoff ratio for multiple intervals Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded export : str Export data format """ - df = get_payoff_ratio(portfolio).fillna("-") + df = get_payoff_ratio(portfolio_engine).fillna("-") print_rich_table( df, title="Portfolio's payoff ratio", @@ -1602,20 +1602,20 @@ def display_payoff_ratio( def display_profit_factor( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, export: str = "", ): """Display profit factor for multiple intervals Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded export : str Export data format """ - df = get_profit_factor(portfolio).fillna("-") + df = get_profit_factor(portfolio_engine).fillna("-") print_rich_table( df, title="Portfolio's profit factor", @@ -1629,7 +1629,7 @@ def display_profit_factor( @log_start_end(log=logger) def display_summary( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "all", risk_free_rate: float = 0, export: str = "", @@ -1638,7 +1638,7 @@ def display_summary( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark @@ -1648,7 +1648,7 @@ def display_summary( Export certain type of data """ - summary = get_summary(portfolio, window, risk_free_rate) + summary = get_summary(portfolio_engine, window, risk_free_rate) print_rich_table( summary, title=f"Summary of Portfolio vs Benchmark for {window} period", @@ -1665,7 +1665,7 @@ def display_summary( @log_start_end(log=logger) def display_var( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, use_mean: bool = True, adjusted_var: bool = False, student_t: bool = False, @@ -1675,7 +1675,7 @@ def display_var( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded use_mean: bool if one should use the data mean return @@ -1688,7 +1688,7 @@ def display_var( """ qa_view.display_var( - data=portfolio.returns, + data=portfolio_engine.returns, symbol="Portfolio", use_mean=use_mean, adjusted_var=adjusted_var, @@ -1700,7 +1700,7 @@ def display_var( @log_start_end(log=logger) def display_es( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, use_mean: bool = True, distribution: str = "normal", percentile: float = 99.9, @@ -1709,7 +1709,7 @@ def display_es( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded use_mean: if one should use the data mean return @@ -1720,7 +1720,7 @@ def display_es( """ qa_view.display_es( - data=portfolio.returns, + data=portfolio_engine.returns, symbol="Portfolio", use_mean=use_mean, distribution=distribution, @@ -1731,7 +1731,7 @@ def display_es( @log_start_end(log=logger) def display_omega( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, threshold_start: float = 0, threshold_end: float = 1.5, ): @@ -1739,7 +1739,7 @@ def display_omega( Parameters ---------- - portfolio: PortfolioEngine + portfolio_engine: PortfolioEngine PortfolioEngine object with trades loaded threshold_start: float annualized target return threshold start of plotted threshold range @@ -1748,7 +1748,7 @@ def display_omega( """ qa_view.display_omega( - data=portfolio.returns, + data=portfolio_engine.returns, threshold_start=threshold_start, threshold_end=threshold_end, ) diff --git a/openbb_terminal/sdk.py b/openbb_terminal/sdk.py index ca79136d8936..913c9a41c697 100644 --- a/openbb_terminal/sdk.py +++ b/openbb_terminal/sdk.py @@ -3,9 +3,6 @@ from openbb_terminal.helper_classes import TerminalStyle from openbb_terminal import helper_funcs as helper # noqa: F401 from openbb_terminal.reports import widget_helpers as widgets # noqa: F401 -from openbb_terminal.portfolio.portfolio_model import ( # noqa: F401 - PortfolioEngine as Portfolio, -) from openbb_terminal.cryptocurrency.due_diligence.pycoingecko_model import ( # noqa: F401 Coin, ) From bc8770806778529c4bb895ab04f7dd70d5796a62 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 21:36:24 +0000 Subject: [PATCH 11/30] regenerate website --- .../content/SDK/crypto/dd/active/_index.rst | 2 +- .../content/SDK/crypto/dd/change/_index.rst | 2 +- .../content/SDK/crypto/dd/close/_index.rst | 2 +- website/content/SDK/crypto/dd/eb/_index.rst | 2 +- website/content/SDK/crypto/dd/gh/_index.rst | 8 +- .../content/SDK/crypto/dd/mcapdom/_index.rst | 8 +- website/content/SDK/crypto/dd/mt/_index.rst | 8 +- .../content/SDK/crypto/dd/nonzero/_index.rst | 2 +- website/content/SDK/crypto/load/_index.rst | 4 +- .../SDK/crypto/onchain/btc_supply/_index.rst | 2 +- .../SDK/crypto/onchain/btc_transac/_index.rst | 2 +- .../content/SDK/crypto/onchain/hr/_index.rst | 8 +- .../content/SDK/crypto/ov/altindex/_index.rst | 4 +- .../content/SDK/crypto/ov/btcrb/_index.rst | 4 +- website/content/SDK/economy/events/_index.rst | 4 +- website/content/SDK/economy/macro/_index.rst | 4 +- .../content/SDK/economy/treasury/_index.rst | 4 +- website/content/SDK/etf/candle/_index.rst | 4 +- website/content/SDK/etf/load/_index.rst | 4 +- website/content/SDK/etf/news/_index.rst | 4 +- website/content/SDK/forex/load/_index.rst | 2 +- .../content/SDK/futures/historical/_index.rst | 2 +- .../content/SDK/portfolio/bench/_index.rst | 36 ++++++++ .../content/SDK/portfolio/distr/_index.rst | 7 +- website/content/SDK/portfolio/dret/_index.rst | 11 +-- website/content/SDK/portfolio/es/_index.rst | 4 +- .../content/SDK/portfolio/holdp/_index.rst | 11 +-- .../content/SDK/portfolio/holdv/_index.rst | 11 +-- website/content/SDK/portfolio/load/_index.rst | 44 ++++++++++ .../content/SDK/portfolio/maxdd/_index.rst | 5 +- .../SDK/portfolio/metric/calmar/_index.rst | 39 +++++++++ .../portfolio/metric/commonsense/_index.rst | 34 ++++++++ .../portfolio/metric/gaintopain/_index.rst | 34 ++++++++ .../portfolio/metric/information/_index.rst | 34 ++++++++ .../SDK/portfolio/metric/jensens/_index.rst | 42 +++++++++ .../SDK/portfolio/metric/kelly/_index.rst | 34 ++++++++ .../SDK/portfolio/metric/kurtosis/_index.rst | 34 ++++++++ .../portfolio/metric/maxdrawdown/_index.rst | 34 ++++++++ .../SDK/portfolio/metric/payoff/_index.rst | 34 ++++++++ .../portfolio/metric/profitfactor/_index.rst | 34 ++++++++ .../SDK/portfolio/metric/rsquare/_index.rst | 34 ++++++++ .../SDK/portfolio/metric/sharpe/_index.rst | 37 ++++++++ .../SDK/portfolio/metric/skew/_index.rst | 37 ++++++++ .../SDK/portfolio/metric/sortino/_index.rst | 37 ++++++++ .../SDK/portfolio/metric/tail/_index.rst | 42 +++++++++ .../SDK/portfolio/metric/trackerr/_index.rst | 39 +++++++++ .../portfolio/metric/volatility/_index.rst | 34 ++++++++ website/content/SDK/portfolio/mret/_index.rst | 11 +-- website/content/SDK/portfolio/om/_index.rst | 11 +-- website/content/SDK/portfolio/perf/_index.rst | 4 +- .../content/SDK/portfolio/rbeta/_index.rst | 7 +- .../content/SDK/portfolio/rsharpe/_index.rst | 5 +- .../content/SDK/portfolio/rsort/_index.rst | 87 +++++++++++++++++++ website/content/SDK/portfolio/rvol/_index.rst | 9 +- website/content/SDK/portfolio/show/_index.rst | 34 ++++++++ .../content/SDK/portfolio/summary/_index.rst | 4 +- website/content/SDK/portfolio/var/_index.rst | 4 +- website/content/SDK/portfolio/yret/_index.rst | 11 +-- .../content/SDK/stocks/ba/cnews/_index.rst | 4 +- website/content/SDK/stocks/ba/hist/_index.rst | 8 +- .../content/SDK/stocks/ba/trend/_index.rst | 4 +- .../content/SDK/stocks/ca/hcorr/_index.rst | 4 +- website/content/SDK/stocks/ca/hist/_index.rst | 4 +- .../content/SDK/stocks/ca/volume/_index.rst | 4 +- website/content/SDK/stocks/candle/_index.rst | 4 +- website/content/SDK/stocks/dd/pt/_index.rst | 2 +- .../SDK/stocks/disc/dividends/_index.rst | 2 +- .../content/SDK/stocks/disc/ipo/_index.rst | 4 +- website/content/SDK/stocks/dps/ftd/_index.rst | 8 +- .../content/SDK/stocks/fa/mktcap/_index.rst | 4 +- website/content/SDK/stocks/ins/act/_index.rst | 2 +- website/content/SDK/stocks/load/_index.rst | 4 +- .../content/SDK/stocks/options/pcr/_index.rst | 4 +- .../SDK/stocks/screener/historical/_index.rst | 4 +- website/data/menu/main.yml | 4 +- 75 files changed, 955 insertions(+), 130 deletions(-) create mode 100644 website/content/SDK/portfolio/bench/_index.rst create mode 100644 website/content/SDK/portfolio/load/_index.rst create mode 100644 website/content/SDK/portfolio/metric/calmar/_index.rst create mode 100644 website/content/SDK/portfolio/metric/commonsense/_index.rst create mode 100644 website/content/SDK/portfolio/metric/gaintopain/_index.rst create mode 100644 website/content/SDK/portfolio/metric/information/_index.rst create mode 100644 website/content/SDK/portfolio/metric/jensens/_index.rst create mode 100644 website/content/SDK/portfolio/metric/kelly/_index.rst create mode 100644 website/content/SDK/portfolio/metric/kurtosis/_index.rst create mode 100644 website/content/SDK/portfolio/metric/maxdrawdown/_index.rst create mode 100644 website/content/SDK/portfolio/metric/payoff/_index.rst create mode 100644 website/content/SDK/portfolio/metric/profitfactor/_index.rst create mode 100644 website/content/SDK/portfolio/metric/rsquare/_index.rst create mode 100644 website/content/SDK/portfolio/metric/sharpe/_index.rst create mode 100644 website/content/SDK/portfolio/metric/skew/_index.rst create mode 100644 website/content/SDK/portfolio/metric/sortino/_index.rst create mode 100644 website/content/SDK/portfolio/metric/tail/_index.rst create mode 100644 website/content/SDK/portfolio/metric/trackerr/_index.rst create mode 100644 website/content/SDK/portfolio/metric/volatility/_index.rst create mode 100644 website/content/SDK/portfolio/rsort/_index.rst create mode 100644 website/content/SDK/portfolio/show/_index.rst diff --git a/website/content/SDK/crypto/dd/active/_index.rst b/website/content/SDK/crypto/dd/active/_index.rst index 3063231800bf..5b842db8db5d 100644 --- a/website/content/SDK/crypto/dd/active/_index.rst +++ b/website/content/SDK/crypto/dd/active/_index.rst @@ -17,7 +17,7 @@ crypto.dd.active( symbol: str, interval: str = '24h', start_date: int = 1262304000, - end_date: int = 1668077823, + end_date: int = 1668288912, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/dd/change/_index.rst b/website/content/SDK/crypto/dd/change/_index.rst index 05782687aa10..ad39c2a19685 100644 --- a/website/content/SDK/crypto/dd/change/_index.rst +++ b/website/content/SDK/crypto/dd/change/_index.rst @@ -17,7 +17,7 @@ crypto.dd.change( symbol: str, exchange: str = 'binance', start_date: int = 1262304000, - end_date: int = 1668077823, + end_date: int = 1668288912, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/dd/close/_index.rst b/website/content/SDK/crypto/dd/close/_index.rst index 4644b8e1ccb6..23c42edd7dc8 100644 --- a/website/content/SDK/crypto/dd/close/_index.rst +++ b/website/content/SDK/crypto/dd/close/_index.rst @@ -14,7 +14,7 @@ crypto.dd.close( symbol: str, start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-12', print_errors: bool = True, chart: bool = False, ) -> pandas.core.frame.DataFrame diff --git a/website/content/SDK/crypto/dd/eb/_index.rst b/website/content/SDK/crypto/dd/eb/_index.rst index e5f70fabbb74..7cdc5e968e6a 100644 --- a/website/content/SDK/crypto/dd/eb/_index.rst +++ b/website/content/SDK/crypto/dd/eb/_index.rst @@ -17,7 +17,7 @@ crypto.dd.eb( symbol: str, exchange: str = 'binance', start_date: int = 1262304000, - end_date: int = 1668077823, + end_date: int = 1668288912, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/dd/gh/_index.rst b/website/content/SDK/crypto/dd/gh/_index.rst index 03316656cc7c..3243616d1b91 100644 --- a/website/content/SDK/crypto/dd/gh/_index.rst +++ b/website/content/SDK/crypto/dd/gh/_index.rst @@ -17,8 +17,8 @@ crypto.dd.gh( symbol: str, dev_activity: bool = False, interval: str = '1d', - start_date: str = '2021-11-10T10:57:03Z', - end_date: str = '2022-11-10T10:57:03Z', + start_date: str = '2021-11-12T21:35:12Z', + end_date: str = '2022-11-12T21:35:12Z', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -63,9 +63,9 @@ crypto.dd.gh( {{< highlight python >}} crypto.dd.gh( symbol: str, - start_date: str = '2021-11-10T10:57:03Z', + start_date: str = '2021-11-12T21:35:12Z', dev_activity: bool = False, - end_date: str = '2022-11-10T10:57:03Z', + end_date: str = '2022-11-12T21:35:12Z', interval: str = '1d', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/mcapdom/_index.rst b/website/content/SDK/crypto/dd/mcapdom/_index.rst index eed095de1c13..9dfd974fc827 100644 --- a/website/content/SDK/crypto/dd/mcapdom/_index.rst +++ b/website/content/SDK/crypto/dd/mcapdom/_index.rst @@ -16,8 +16,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.dd.mcapdom( symbol: str, interval: str = '1d', - start_date: str = '2021-11-10', - end_date: str = '2022-11-10', + start_date: str = '2021-11-12', + end_date: str = '2022-11-12', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -59,8 +59,8 @@ crypto.dd.mcapdom( {{< highlight python >}} crypto.dd.mcapdom( symbol: str, - start_date: str = '2021-11-10', - end_date: str = '2022-11-10', + start_date: str = '2021-11-12', + end_date: str = '2022-11-12', interval: str = '1d', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/mt/_index.rst b/website/content/SDK/crypto/dd/mt/_index.rst index a83999212fb3..8d696eb91550 100644 --- a/website/content/SDK/crypto/dd/mt/_index.rst +++ b/website/content/SDK/crypto/dd/mt/_index.rst @@ -17,8 +17,8 @@ crypto.dd.mt( symbol: str, timeseries_id: str, interval: str = '1d', - start_date: str = '2021-11-10', - end_date: str = '2022-11-10', + start_date: str = '2021-11-12', + end_date: str = '2022-11-12', chart: bool = False, ) -> Tuple[pandas.core.frame.DataFrame, str] {{< /highlight >}} @@ -65,8 +65,8 @@ crypto.dd.mt( crypto.dd.mt( symbol: str, timeseries_id: str, - start_date: str = '2021-11-10', - end_date: str = '2022-11-10', + start_date: str = '2021-11-12', + end_date: str = '2022-11-12', interval: str = '1d', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/nonzero/_index.rst b/website/content/SDK/crypto/dd/nonzero/_index.rst index 795aa45afd03..359291460a43 100644 --- a/website/content/SDK/crypto/dd/nonzero/_index.rst +++ b/website/content/SDK/crypto/dd/nonzero/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.dd.nonzero( symbol: str, start_date: int = 1262304000, - end_date: int = 1668077823, + end_date: int = 1668288912, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/load/_index.rst b/website/content/SDK/crypto/load/_index.rst index f48a0c805b57..cf61f7d2d426 100644 --- a/website/content/SDK/crypto/load/_index.rst +++ b/website/content/SDK/crypto/load/_index.rst @@ -14,12 +14,12 @@ crypto.load( symbol: 'str', start_date: 'datetime' = datetime.datetime( - 2019, 11, 6, 10, 57, 3, 350989, chart: bool = False, + 2019, 11, 8, 21, 35, 12, 153014, chart: bool = False, ), interval: 'str' = '1440', exchange: 'str' = 'binance', vs_currency: 'str' = 'usdt', end_date: 'datetime' = datetime.datetime( - 2022, 11, 10, 10, 57, 3, 350990, chart: bool = False, + 2022, 11, 12, 21, 35, 12, 153015, chart: bool = False, ), source: 'str' = 'CCXT', chart: bool = False, ) -> 'pd.DataFrame' diff --git a/website/content/SDK/crypto/onchain/btc_supply/_index.rst b/website/content/SDK/crypto/onchain/btc_supply/_index.rst index 896ab8783597..062d1451dd5e 100644 --- a/website/content/SDK/crypto/onchain/btc_supply/_index.rst +++ b/website/content/SDK/crypto/onchain/btc_supply/_index.rst @@ -38,7 +38,7 @@ crypto.onchain.btc_supply() -> pandas.core.frame.DataFrame {{< highlight python >}} crypto.onchain.btc_supply( start_date: int = 1262304000, - end_date: int = 1668077823, + end_date: int = 1668288912, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/onchain/btc_transac/_index.rst b/website/content/SDK/crypto/onchain/btc_transac/_index.rst index c6123af388e9..aaff6c9fe11d 100644 --- a/website/content/SDK/crypto/onchain/btc_transac/_index.rst +++ b/website/content/SDK/crypto/onchain/btc_transac/_index.rst @@ -38,7 +38,7 @@ crypto.onchain.btc_transac() -> pandas.core.frame.DataFrame {{< highlight python >}} crypto.onchain.btc_transac( start_date: int = 1262304000, - end_date: int = 1668077823, + end_date: int = 1668288912, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/onchain/hr/_index.rst b/website/content/SDK/crypto/onchain/hr/_index.rst index e36764e70005..93dfa17edbaf 100644 --- a/website/content/SDK/crypto/onchain/hr/_index.rst +++ b/website/content/SDK/crypto/onchain/hr/_index.rst @@ -16,8 +16,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.onchain.hr( symbol: str, interval: str = '24h', - start_date: int = 1289645823, - end_date: int = 1668077823, + start_date: int = 1289856912, + end_date: int = 1668288912, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -59,8 +59,8 @@ crypto.onchain.hr( {{< highlight python >}} crypto.onchain.hr( symbol: str, - start_date: int = 1636541823, - end_date: int = 1668077823, + start_date: int = 1636752912, + end_date: int = 1668288912, interval: str = '24h', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/ov/altindex/_index.rst b/website/content/SDK/crypto/ov/altindex/_index.rst index 0f27aaef181a..da9d184b2f96 100644 --- a/website/content/SDK/crypto/ov/altindex/_index.rst +++ b/website/content/SDK/crypto/ov/altindex/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.ov.altindex( period: int = 30, start_date: int = 1262304000, - end_date: int = 1668077823, + end_date: int = 1668288912, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -59,7 +59,7 @@ crypto.ov.altindex( crypto.ov.altindex( period: int = 365, start_date: int = 1262304000, - end_date: int = 1668077823, + end_date: int = 1668288912, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/ov/btcrb/_index.rst b/website/content/SDK/crypto/ov/btcrb/_index.rst index beb41ecbcfde..5981eaa1ff7f 100644 --- a/website/content/SDK/crypto/ov/btcrb/_index.rst +++ b/website/content/SDK/crypto/ov/btcrb/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} crypto.ov.btcrb( start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-12', chart: bool = False, ) {{< /highlight >}} @@ -49,7 +49,7 @@ crypto.ov.btcrb( {{< highlight python >}} crypto.ov.btcrb( start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-12', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/economy/events/_index.rst b/website/content/SDK/economy/events/_index.rst index 16836a2e383f..51516856f10e 100644 --- a/website/content/SDK/economy/events/_index.rst +++ b/website/content/SDK/economy/events/_index.rst @@ -13,8 +13,8 @@ {{< highlight python >}} economy.events( countries: Union[List[str], str] = '', - start_date: str = '2022-11-10', - end_date: str = '2022-11-10', + start_date: str = '2022-11-12', + end_date: str = '2022-11-12', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/economy/macro/_index.rst b/website/content/SDK/economy/macro/_index.rst index 8e9f0830adf7..7b388c5a7e5f 100644 --- a/website/content/SDK/economy/macro/_index.rst +++ b/website/content/SDK/economy/macro/_index.rst @@ -19,7 +19,7 @@ economy.macro( transform: str = '', start_date: str = '1900-01-01', end_date=datetime.date( - 2022, 11, 10, chart: bool = False, + 2022, 11, 12, chart: bool = False, ), symbol: str = '', chart: bool = False, ) -> Tuple[Any, Dict[Any, Dict[Any, Any]], str] @@ -72,7 +72,7 @@ economy.macro( countries: list = None, transform: str = '', start_date: str = '1900-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-12', symbol: str = '', raw: bool = False, external_axes: Optional[List[axes]] = None, diff --git a/website/content/SDK/economy/treasury/_index.rst b/website/content/SDK/economy/treasury/_index.rst index ef3949159b7f..bff395439d73 100644 --- a/website/content/SDK/economy/treasury/_index.rst +++ b/website/content/SDK/economy/treasury/_index.rst @@ -18,7 +18,7 @@ economy.treasury( maturities: list = None, frequency: str = 'monthly', start_date: str = '1900-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-12', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -65,7 +65,7 @@ economy.treasury( maturities: list = None, frequency: str = 'monthly', start_date: str = '1900-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-12', raw: bool = False, external_axes: Optional[List[axes]] = None, export: str = '', diff --git a/website/content/SDK/etf/candle/_index.rst b/website/content/SDK/etf/candle/_index.rst index 6d8234dcb2b2..51c0f469d292 100644 --- a/website/content/SDK/etf/candle/_index.rst +++ b/website/content/SDK/etf/candle/_index.rst @@ -21,11 +21,11 @@ etf.candle( asset_type: str = '', start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 6, 10, 57, 3, 415209, chart: bool = False, + 2019, 11, 8, 21, 35, 12, 215151, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 10, 10, 57, 3, 415211, chart: bool = False, + 2022, 11, 12, 21, 35, 12, 215152, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/etf/load/_index.rst b/website/content/SDK/etf/load/_index.rst index b556833a108d..8dd3e1b0ecbb 100644 --- a/website/content/SDK/etf/load/_index.rst +++ b/website/content/SDK/etf/load/_index.rst @@ -15,11 +15,11 @@ etf.load( symbol: str, start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 6, 10, 57, 3, 415198, chart: bool = False, + 2019, 11, 8, 21, 35, 12, 215141, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 10, 10, 57, 3, 415206, chart: bool = False, + 2022, 11, 12, 21, 35, 12, 215148, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/etf/news/_index.rst b/website/content/SDK/etf/news/_index.rst index 77288c7903ec..72b3c96e142a 100644 --- a/website/content/SDK/etf/news/_index.rst +++ b/website/content/SDK/etf/news/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. etf.news( query: str, limit: int = 10, - start_date: str = '2022-11-03', + start_date: str = '2022-11-05', show_newest: bool = True, sources: str = '', chart: bool = False, @@ -60,7 +60,7 @@ etf.news( etf.news( query: str, limit: int = 3, - start_date: str = '2022-11-03', + start_date: str = '2022-11-05', show_newest: bool = True, sources: str = '', export: str = '', diff --git a/website/content/SDK/forex/load/_index.rst b/website/content/SDK/forex/load/_index.rst index 655d20099719..bb0146219a81 100644 --- a/website/content/SDK/forex/load/_index.rst +++ b/website/content/SDK/forex/load/_index.rst @@ -16,7 +16,7 @@ forex.load( from_symbol: str, resolution: str = 'd', interval: str = '1day', - start_date: str = '2021-11-10', + start_date: str = '2021-11-12', source: str = 'YahooFinance', verbose: bool = False, chart: bool = False, diff --git a/website/content/SDK/futures/historical/_index.rst b/website/content/SDK/futures/historical/_index.rst index 7e9f2210832a..3828ceac08f3 100644 --- a/website/content/SDK/futures/historical/_index.rst +++ b/website/content/SDK/futures/historical/_index.rst @@ -53,7 +53,7 @@ futures.historical( futures.historical( symbols: List[str], expiry: str = '', - start_date: str = '2019-11-11', + start_date: str = '2019-11-13', raw: bool = False, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/portfolio/bench/_index.rst b/website/content/SDK/portfolio/bench/_index.rst new file mode 100644 index 000000000000..a4a38c71b9fb --- /dev/null +++ b/website/content/SDK/portfolio/bench/_index.rst @@ -0,0 +1,36 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.bench( + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + symbol: str, + full_shares: bool = False, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Load benchmark into portfolio +

+ +* **Parameters** + + portfolio_engine: PortfolioEngine + PortfolioEngine object + symbol: str + Benchmark symbol to download data + full_shares: bool + Whether to mimic the portfolio trades exactly (partial shares) or round down the + quantity to the nearest number diff --git a/website/content/SDK/portfolio/distr/_index.rst b/website/content/SDK/portfolio/distr/_index.rst index 7d23e8152fd1..f04dceb8aa16 100644 --- a/website/content/SDK/portfolio/distr/_index.rst +++ b/website/content/SDK/portfolio/distr/_index.rst @@ -28,8 +28,8 @@ portfolio.distr( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark chart: bool @@ -46,7 +46,7 @@ portfolio.distr( {{< highlight python >}} portfolio.distr( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', raw: bool = False, export: str = '', @@ -77,3 +77,4 @@ portfolio.distr( Optional axes to display plot on chart: bool Flag to display chart + diff --git a/website/content/SDK/portfolio/dret/_index.rst b/website/content/SDK/portfolio/dret/_index.rst index ac4bdaa354dc..5962ce46d403 100644 --- a/website/content/SDK/portfolio/dret/_index.rst +++ b/website/content/SDK/portfolio/dret/_index.rst @@ -28,8 +28,8 @@ portfolio.dret( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark chart: bool @@ -50,7 +50,7 @@ portfolio.dret( {{< highlight python >}} portfolio.dret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', raw: bool = False, limit: int = 10, @@ -68,8 +68,8 @@ portfolio.dret( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark raw : False @@ -82,3 +82,4 @@ portfolio.dret( Optional axes to display plot on chart: bool Flag to display chart + diff --git a/website/content/SDK/portfolio/es/_index.rst b/website/content/SDK/portfolio/es/_index.rst index 585cca656e28..7fcf73688763 100644 --- a/website/content/SDK/portfolio/es/_index.rst +++ b/website/content/SDK/portfolio/es/_index.rst @@ -28,8 +28,8 @@ portfolio.es( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded use_mean: if one should use the data mean return distribution: str diff --git a/website/content/SDK/portfolio/holdp/_index.rst b/website/content/SDK/portfolio/holdp/_index.rst index 0557f1372f78..7830e39ab6d3 100644 --- a/website/content/SDK/portfolio/holdp/_index.rst +++ b/website/content/SDK/portfolio/holdp/_index.rst @@ -27,8 +27,8 @@ portfolio.holdp( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded chart: bool Flag to display chart @@ -43,7 +43,7 @@ portfolio.holdp( {{< highlight python >}} portfolio.holdp( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, unstack: bool = False, raw: bool = False, limit: int = 10, @@ -61,8 +61,8 @@ portfolio.holdp( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine object with trades loaded unstack: bool Individual assets over time raw : bool @@ -75,3 +75,4 @@ portfolio.holdp( Optional axes to display plot on chart: bool Flag to display chart + diff --git a/website/content/SDK/portfolio/holdv/_index.rst b/website/content/SDK/portfolio/holdv/_index.rst index 8be88fcec4ca..c0ef1b396fac 100644 --- a/website/content/SDK/portfolio/holdv/_index.rst +++ b/website/content/SDK/portfolio/holdv/_index.rst @@ -27,8 +27,8 @@ portfolio.holdv( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded chart: bool Flag to display chart @@ -48,7 +48,7 @@ portfolio.holdv( {{< highlight python >}} portfolio.holdv( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, unstack: bool = False, raw: bool = False, limit: int = 10, @@ -66,8 +66,8 @@ portfolio.holdv( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine object with trades loaded unstack: bool Individual assets over time raw : bool @@ -80,3 +80,4 @@ portfolio.holdv( Optional axes to display plot on chart: bool Flag to display chart + diff --git a/website/content/SDK/portfolio/load/_index.rst b/website/content/SDK/portfolio/load/_index.rst new file mode 100644 index 000000000000..5838d968d754 --- /dev/null +++ b/website/content/SDK/portfolio/load/_index.rst @@ -0,0 +1,44 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.load( + transactions_file_path: str, + benchmark_symbol: str = 'SPY', + full_shares: bool = False, + risk_free_rate: float = 0, + chart: bool = False, +) -> openbb_terminal.portfolio.portfolio_model.PortfolioEngine +{{< /highlight >}} + +.. raw:: html + +

+ Get PortfolioEngine object +

+ +* **Parameters** + + transactions_file_path : str + Path to transactions file + benchmark_symbol : str + Benchmark ticker to download data + full_shares : bool + Whether to mimic the portfolio trades exactly (partial shares) or round down the + quantity to the nearest number + risk_free_rate : float + Risk free rate in float format + +* **Returns** + + PortfolioEngine + PortfolioEngine object diff --git a/website/content/SDK/portfolio/maxdd/_index.rst b/website/content/SDK/portfolio/maxdd/_index.rst index e1f47b37338c..f8c76bd1910d 100644 --- a/website/content/SDK/portfolio/maxdd/_index.rst +++ b/website/content/SDK/portfolio/maxdd/_index.rst @@ -56,7 +56,7 @@ portfolio.maxdd( {{< highlight python >}} portfolio.maxdd( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, @@ -72,10 +72,11 @@ portfolio.maxdd( * **Parameters** portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object export: str Format to export data external_axes: plt.Axes Optional axes to display plot on chart: bool Flag to display chart + diff --git a/website/content/SDK/portfolio/metric/calmar/_index.rst b/website/content/SDK/portfolio/metric/calmar/_index.rst new file mode 100644 index 000000000000..be795db4ccae --- /dev/null +++ b/website/content/SDK/portfolio/metric/calmar/_index.rst @@ -0,0 +1,39 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.calmar( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + window: int = 756, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Get calmar ratio +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + window: int + Interval used for rolling values + +* **Returns** + + pd.DataFrame + DataFrame of calmar ratio of the benchmark and portfolio during different time periods + pd.Series + Series of calmar ratio data diff --git a/website/content/SDK/portfolio/metric/commonsense/_index.rst b/website/content/SDK/portfolio/metric/commonsense/_index.rst new file mode 100644 index 000000000000..8f57a74a71ce --- /dev/null +++ b/website/content/SDK/portfolio/metric/commonsense/_index.rst @@ -0,0 +1,34 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.commonsense( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Get common sense ratio +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + +* **Returns** + + pd.DataFrame + DataFrame of the portfolios and the benchmarks common sense ratio during different time periods diff --git a/website/content/SDK/portfolio/metric/gaintopain/_index.rst b/website/content/SDK/portfolio/metric/gaintopain/_index.rst new file mode 100644 index 000000000000..a17ffbf30fcb --- /dev/null +++ b/website/content/SDK/portfolio/metric/gaintopain/_index.rst @@ -0,0 +1,34 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.gaintopain( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Get Pain-to-Gain ratio based on historical data +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + +* **Returns** + + pd.DataFrame + DataFrame of the portfolio's gain-to-pain ratio diff --git a/website/content/SDK/portfolio/metric/information/_index.rst b/website/content/SDK/portfolio/metric/information/_index.rst new file mode 100644 index 000000000000..621ec1fd3540 --- /dev/null +++ b/website/content/SDK/portfolio/metric/information/_index.rst @@ -0,0 +1,34 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.information( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Get information ratio +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + +* **Returns** + + pd.DataFrame + DataFrame of the information ratio during different time periods diff --git a/website/content/SDK/portfolio/metric/jensens/_index.rst b/website/content/SDK/portfolio/metric/jensens/_index.rst new file mode 100644 index 000000000000..cbad28c2a2b4 --- /dev/null +++ b/website/content/SDK/portfolio/metric/jensens/_index.rst @@ -0,0 +1,42 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.jensens( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + risk_free_rate: float = 0, + window: str = '1y', + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Get jensen's alpha +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + window: str + Interval used for rolling values + risk_free_rate: float + Risk free rate + +* **Returns** + + pd.DataFrame + DataFrame of jensens's alpha during different time windows + pd.Series + Series of jensens's alpha data diff --git a/website/content/SDK/portfolio/metric/kelly/_index.rst b/website/content/SDK/portfolio/metric/kelly/_index.rst new file mode 100644 index 000000000000..b5e63bb52562 --- /dev/null +++ b/website/content/SDK/portfolio/metric/kelly/_index.rst @@ -0,0 +1,34 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.kelly( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Gets kelly criterion +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + +* **Returns** + + pd.DataFrame + DataFrame of kelly criterion of the portfolio during different time periods diff --git a/website/content/SDK/portfolio/metric/kurtosis/_index.rst b/website/content/SDK/portfolio/metric/kurtosis/_index.rst new file mode 100644 index 000000000000..9e2a939a00ec --- /dev/null +++ b/website/content/SDK/portfolio/metric/kurtosis/_index.rst @@ -0,0 +1,34 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.kurtosis( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) -> pandas.core.frame.DataFrame +{{< /highlight >}} + +.. raw:: html + +

+ Method that retrieves kurtosis for portfolio and benchmark selected +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + +* **Returns** + + pd.DataFrame + DataFrame with kurtosis for portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/metric/maxdrawdown/_index.rst b/website/content/SDK/portfolio/metric/maxdrawdown/_index.rst new file mode 100644 index 000000000000..8d20e10df5a1 --- /dev/null +++ b/website/content/SDK/portfolio/metric/maxdrawdown/_index.rst @@ -0,0 +1,34 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.maxdrawdown( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) -> pandas.core.frame.DataFrame +{{< /highlight >}} + +.. raw:: html + +

+ Method that retrieves maximum drawdown ratio for portfolio and benchmark selected +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + +* **Returns** + + pd.DataFrame + DataFrame with maximum drawdown for portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/metric/payoff/_index.rst b/website/content/SDK/portfolio/metric/payoff/_index.rst new file mode 100644 index 000000000000..862532ea4077 --- /dev/null +++ b/website/content/SDK/portfolio/metric/payoff/_index.rst @@ -0,0 +1,34 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.payoff( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Gets payoff ratio + + Returns + ------- + pd.DataFrame + DataFrame of payoff ratio of the portfolio during different time periods +

+ +* **Returns** + + pd.DataFrame + DataFrame of payoff ratio of the portfolio during different time periods diff --git a/website/content/SDK/portfolio/metric/profitfactor/_index.rst b/website/content/SDK/portfolio/metric/profitfactor/_index.rst new file mode 100644 index 000000000000..6354dd3a8b1b --- /dev/null +++ b/website/content/SDK/portfolio/metric/profitfactor/_index.rst @@ -0,0 +1,34 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.profitfactor( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Gets profit factor +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + +* **Returns** + + pd.DataFrame + DataFrame of profit factor of the portfolio during different time periods diff --git a/website/content/SDK/portfolio/metric/rsquare/_index.rst b/website/content/SDK/portfolio/metric/rsquare/_index.rst new file mode 100644 index 000000000000..e86acdfad18a --- /dev/null +++ b/website/content/SDK/portfolio/metric/rsquare/_index.rst @@ -0,0 +1,34 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.rsquare( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) -> pandas.core.frame.DataFrame +{{< /highlight >}} + +.. raw:: html + +

+ Method that retrieves R2 Score for portfolio and benchmark selected +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + +* **Returns** + + pd.DataFrame + DataFrame with R2 Score between portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/metric/sharpe/_index.rst b/website/content/SDK/portfolio/metric/sharpe/_index.rst new file mode 100644 index 000000000000..0834ee390457 --- /dev/null +++ b/website/content/SDK/portfolio/metric/sharpe/_index.rst @@ -0,0 +1,37 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.sharpe( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + risk_free_rate: float = 0, + chart: bool = False, +) -> pandas.core.frame.DataFrame +{{< /highlight >}} + +.. raw:: html + +

+ Method that retrieves sharpe ratio for portfolio and benchmark selected +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + risk_free_rate: float + Risk free rate value + +* **Returns** + + pd.DataFrame + DataFrame with sharpe ratio for portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/metric/skew/_index.rst b/website/content/SDK/portfolio/metric/skew/_index.rst new file mode 100644 index 000000000000..c2a08bcb569f --- /dev/null +++ b/website/content/SDK/portfolio/metric/skew/_index.rst @@ -0,0 +1,37 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.skew( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) -> pandas.core.frame.DataFrame +{{< /highlight >}} + +.. raw:: html + +

+ Method that retrieves skewness for portfolio and benchmark selected + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + + Returns + ------- + pd.DataFrame + DataFrame with skewness for portfolio and benchmark for different periods +

+ +* **Returns** + + pd.DataFrame + DataFrame with skewness for portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/metric/sortino/_index.rst b/website/content/SDK/portfolio/metric/sortino/_index.rst new file mode 100644 index 000000000000..51f2bd51a7c0 --- /dev/null +++ b/website/content/SDK/portfolio/metric/sortino/_index.rst @@ -0,0 +1,37 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.sortino( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + risk_free_rate: float = 0, + chart: bool = False, +) -> pandas.core.frame.DataFrame +{{< /highlight >}} + +.. raw:: html + +

+ Method that retrieves sortino ratio for portfolio and benchmark selected +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + risk_free_rate: float + Risk free rate value + +* **Returns** + + pd.DataFrame + DataFrame with sortino ratio for portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/metric/tail/_index.rst b/website/content/SDK/portfolio/metric/tail/_index.rst new file mode 100644 index 000000000000..deeacde22acc --- /dev/null +++ b/website/content/SDK/portfolio/metric/tail/_index.rst @@ -0,0 +1,42 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.tail( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + window: int = 252, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Get tail ratio +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + + window: int + Interval used for rolling values + +* **Returns** + + pd.DataFrame + DataFrame of the portfolios and the benchmarks tail ratio during different time windows + pd.Series + Series of the portfolios rolling tail ratio + pd.Series + Series of the benchmarks rolling tail ratio diff --git a/website/content/SDK/portfolio/metric/trackerr/_index.rst b/website/content/SDK/portfolio/metric/trackerr/_index.rst new file mode 100644 index 000000000000..6b60beb774ed --- /dev/null +++ b/website/content/SDK/portfolio/metric/trackerr/_index.rst @@ -0,0 +1,39 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.trackerr( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + window: int = 252, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Get tracking error +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + window: int + Interval used for rolling values + +* **Returns** + + pd.DataFrame + DataFrame of tracking errors during different time windows + pd.Series + Series of rolling tracking error diff --git a/website/content/SDK/portfolio/metric/volatility/_index.rst b/website/content/SDK/portfolio/metric/volatility/_index.rst new file mode 100644 index 000000000000..da872368dd9e --- /dev/null +++ b/website/content/SDK/portfolio/metric/volatility/_index.rst @@ -0,0 +1,34 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.metric.volatility( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) -> pandas.core.frame.DataFrame +{{< /highlight >}} + +.. raw:: html + +

+ Method that retrieves volatility for portfolio and benchmark selected +

+ +* **Parameters** + + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded + +* **Returns** + + pd.DataFrame + DataFrame with volatility for portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/mret/_index.rst b/website/content/SDK/portfolio/mret/_index.rst index f36e6c98e41c..ae259ad6151a 100644 --- a/website/content/SDK/portfolio/mret/_index.rst +++ b/website/content/SDK/portfolio/mret/_index.rst @@ -28,8 +28,8 @@ portfolio.mret( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark chart: bool @@ -50,7 +50,7 @@ portfolio.mret( {{< highlight python >}} portfolio.mret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', raw: bool = False, show_vals: bool = False, @@ -68,8 +68,8 @@ portfolio.mret( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark raw : False @@ -82,3 +82,4 @@ portfolio.mret( Optional axes to display plot on chart: bool Flag to display chart + diff --git a/website/content/SDK/portfolio/om/_index.rst b/website/content/SDK/portfolio/om/_index.rst index 829d67f734f4..ec1f05eac73d 100644 --- a/website/content/SDK/portfolio/om/_index.rst +++ b/website/content/SDK/portfolio/om/_index.rst @@ -29,8 +29,8 @@ portfolio.om( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded threshold_start: float annualized target return threshold start of plotted threshold range threshold_end: float @@ -53,7 +53,7 @@ portfolio.om( {{< highlight python >}} portfolio.om( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, threshold_start: float = 0, threshold_end: float = 1.5, chart: bool = False, @@ -68,11 +68,12 @@ portfolio.om( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine object with trades loaded threshold_start: float annualized target return threshold start of plotted threshold range threshold_end: float annualized target return threshold end of plotted threshold range chart: bool Flag to display chart + diff --git a/website/content/SDK/portfolio/perf/_index.rst b/website/content/SDK/portfolio/perf/_index.rst index 64d945c8b97a..b29538fd440e 100644 --- a/website/content/SDK/portfolio/perf/_index.rst +++ b/website/content/SDK/portfolio/perf/_index.rst @@ -26,8 +26,8 @@ portfolio.perf( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded show_all_trades: bool Whether to also show all trades made and their performance (default is False) diff --git a/website/content/SDK/portfolio/rbeta/_index.rst b/website/content/SDK/portfolio/rbeta/_index.rst index fada5e026814..15de83068e6d 100644 --- a/website/content/SDK/portfolio/rbeta/_index.rst +++ b/website/content/SDK/portfolio/rbeta/_index.rst @@ -29,7 +29,7 @@ portfolio.rbeta( * **Parameters** portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object window: string Interval used for rolling values. Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y. @@ -52,7 +52,7 @@ portfolio.rbeta( {{< highlight python >}} portfolio.rbeta( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = '1y', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, @@ -69,7 +69,7 @@ portfolio.rbeta( * **Parameters** portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object window: str interval for window to consider Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y. @@ -79,3 +79,4 @@ portfolio.rbeta( Optional axes to display plot on chart: bool Flag to display chart + diff --git a/website/content/SDK/portfolio/rsharpe/_index.rst b/website/content/SDK/portfolio/rsharpe/_index.rst index e195fcc139c2..42c55143be4f 100644 --- a/website/content/SDK/portfolio/rsharpe/_index.rst +++ b/website/content/SDK/portfolio/rsharpe/_index.rst @@ -55,7 +55,7 @@ portfolio.rsharpe( {{< highlight python >}} portfolio.rsharpe( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, window: str = '1y', export: str = '', @@ -73,7 +73,7 @@ portfolio.rsharpe( * **Parameters** portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object risk_free_rate: float Value to use for risk free rate in sharpe/other calculations window: str @@ -84,3 +84,4 @@ portfolio.rsharpe( Optional axes to display plot on chart: bool Flag to display chart + diff --git a/website/content/SDK/portfolio/rsort/_index.rst b/website/content/SDK/portfolio/rsort/_index.rst new file mode 100644 index 000000000000..43f5ba1474c6 --- /dev/null +++ b/website/content/SDK/portfolio/rsort/_index.rst @@ -0,0 +1,87 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +To obtain charts, make sure to add :python:`chart = True` as the last parameter. + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.rsort( + portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + risk_free_rate: float = 0, + window: str = '1y', + chart: bool = False, +) -> pandas.core.frame.DataFrame +{{< /highlight >}} + +.. raw:: html + +

+ Get rolling sortino +

+ +* **Parameters** + + portfolio : PortfolioEngine + PortfolioEngine object + window: str + interval for window to consider + Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y + risk_free_rate: float + Value to use for risk free rate in sharpe/other calculations + chart: bool + Flag to display chart + + +* **Returns** + + pd.DataFrame + Rolling sortino ratio DataFrame + +| + +.. raw:: html + +

+ > Getting charts +

+ +{{< highlight python >}} +portfolio.rsort( + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + risk_free_rate: float = 0, + window: str = '1y', + export: str = '', + external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Display rolling sortino +

+ +* **Parameters** + + portfolio : PortfolioEngine + PortfolioEngine object + risk_free_rate: float + Value to use for risk free rate in sharpe/other calculations + window: str + interval for window to consider + export: str + Export to file + external_axes: Optional[List[plt.Axes]] + Optional axes to display plot on + chart: bool + Flag to display chart + diff --git a/website/content/SDK/portfolio/rvol/_index.rst b/website/content/SDK/portfolio/rvol/_index.rst index 945ccaf3a85e..afe4689618d7 100644 --- a/website/content/SDK/portfolio/rvol/_index.rst +++ b/website/content/SDK/portfolio/rvol/_index.rst @@ -28,8 +28,8 @@ portfolio.rvol( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str Rolling window size to use Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y @@ -47,7 +47,7 @@ portfolio.rvol( {{< highlight python >}} portfolio.rvol( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = '1y', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, @@ -64,7 +64,7 @@ portfolio.rvol( * **Parameters** portfolio : PortfolioEngine - Portfolio object + PortfolioEngine object interval: str interval for window to consider export: str @@ -73,3 +73,4 @@ portfolio.rvol( Optional axes to display plot on chart: bool Flag to display chart + diff --git a/website/content/SDK/portfolio/show/_index.rst b/website/content/SDK/portfolio/show/_index.rst new file mode 100644 index 000000000000..53133d3e0fa6 --- /dev/null +++ b/website/content/SDK/portfolio/show/_index.rst @@ -0,0 +1,34 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.show( + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + chart: bool = False, +) -> pandas.core.frame.DataFrame +{{< /highlight >}} + +.. raw:: html + +

+ Get portfolio transactions +

+ +* **Parameters** + + portfolio_engine: PortfolioEngine + PortfolioEngine object + +* **Returns** + + pd.DataFrame + Portfolio transactions diff --git a/website/content/SDK/portfolio/summary/_index.rst b/website/content/SDK/portfolio/summary/_index.rst index e776e9ef9734..8c2c66fe5178 100644 --- a/website/content/SDK/portfolio/summary/_index.rst +++ b/website/content/SDK/portfolio/summary/_index.rst @@ -27,8 +27,8 @@ portfolio.summary( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark risk_free_rate : float diff --git a/website/content/SDK/portfolio/var/_index.rst b/website/content/SDK/portfolio/var/_index.rst index 84e8976cb5d8..38418525e2db 100644 --- a/website/content/SDK/portfolio/var/_index.rst +++ b/website/content/SDK/portfolio/var/_index.rst @@ -29,8 +29,8 @@ portfolio.var( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded use_mean: bool if one should use the data mean return adjusted_var: bool diff --git a/website/content/SDK/portfolio/yret/_index.rst b/website/content/SDK/portfolio/yret/_index.rst index e064117991f8..e083ca9f0cad 100644 --- a/website/content/SDK/portfolio/yret/_index.rst +++ b/website/content/SDK/portfolio/yret/_index.rst @@ -28,8 +28,8 @@ portfolio.yret( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark chart: bool @@ -46,7 +46,7 @@ portfolio.yret( {{< highlight python >}} portfolio.yret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', raw: bool = False, export: str = '', @@ -63,8 +63,8 @@ portfolio.yret( * **Parameters** - portfolio: Portfolio - Portfolio object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine object with trades loaded window : str interval to compare cumulative returns and benchmark raw : False @@ -75,3 +75,4 @@ portfolio.yret( Optional axes to display plot on chart: bool Flag to display chart + diff --git a/website/content/SDK/stocks/ba/cnews/_index.rst b/website/content/SDK/stocks/ba/cnews/_index.rst index 1c1cb537c33b..50dcf920f610 100644 --- a/website/content/SDK/stocks/ba/cnews/_index.rst +++ b/website/content/SDK/stocks/ba/cnews/_index.rst @@ -13,8 +13,8 @@ {{< highlight python >}} stocks.ba.cnews( symbol: str, - start_date: str = '2022-10-11', - end_date: str = '2022-11-10', + start_date: str = '2022-10-13', + end_date: str = '2022-11-12', chart: bool = False, ) -> List[Dict] {{< /highlight >}} diff --git a/website/content/SDK/stocks/ba/hist/_index.rst b/website/content/SDK/stocks/ba/hist/_index.rst index a269fea4275f..4f1b6fdb28ad 100644 --- a/website/content/SDK/stocks/ba/hist/_index.rst +++ b/website/content/SDK/stocks/ba/hist/_index.rst @@ -15,8 +15,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ba.hist( symbol: str, - start_date: str = '2022-11-03', - end_date: str = '2022-11-10', + start_date: str = '2022-11-05', + end_date: str = '2022-11-12', number: int = 100, chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -61,8 +61,8 @@ stocks.ba.hist( {{< highlight python >}} stocks.ba.hist( symbol: str, - start_date: str = '2022-11-03', - end_date: str = '2022-11-10', + start_date: str = '2022-11-05', + end_date: str = '2022-11-12', number: int = 100, raw: bool = False, limit: int = 10, diff --git a/website/content/SDK/stocks/ba/trend/_index.rst b/website/content/SDK/stocks/ba/trend/_index.rst index 9d902b87403b..b4213027e8ca 100644 --- a/website/content/SDK/stocks/ba/trend/_index.rst +++ b/website/content/SDK/stocks/ba/trend/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ba.trend( start_date: datetime.datetime = datetime.datetime( - 2022, 11, 10, 10, 57, 3, 4358, chart: bool = False, + 2022, 11, 12, 21, 35, 11, 689469, chart: bool = False, ), hour: int = 0, number: int = 10, chart: bool = False, @@ -60,7 +60,7 @@ stocks.ba.trend( {{< highlight python >}} stocks.ba.trend( start_date: datetime.datetime = datetime.datetime( - 2022, 11, 10, 10, 57, 3, 4582, chart: bool = False, + 2022, 11, 12, 21, 35, 11, 689630, chart: bool = False, ), hour: int = 0, number: int = 10, limit: int = 10, diff --git a/website/content/SDK/stocks/ca/hcorr/_index.rst b/website/content/SDK/stocks/ca/hcorr/_index.rst index 97e905431783..0b072cce5023 100644 --- a/website/content/SDK/stocks/ca/hcorr/_index.rst +++ b/website/content/SDK/stocks/ca/hcorr/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ca.hcorr( similar: List[str], - start_date: str = '2021-11-09', + start_date: str = '2021-11-11', candle_type: str = 'a', chart: bool = False, ) @@ -52,7 +52,7 @@ stocks.ca.hcorr( {{< highlight python >}} stocks.ca.hcorr( similar: List[str], - start_date: str = '2021-11-09', + start_date: str = '2021-11-11', candle_type: str = 'a', display_full_matrix: bool = False, raw: bool = False, diff --git a/website/content/SDK/stocks/ca/hist/_index.rst b/website/content/SDK/stocks/ca/hist/_index.rst index 1b25bfa16ef8..c25ded4ee251 100644 --- a/website/content/SDK/stocks/ca/hist/_index.rst +++ b/website/content/SDK/stocks/ca/hist/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ca.hist( similar: List[str], - start_date: str = '2021-11-09', + start_date: str = '2021-11-11', candle_type: str = 'a', chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -57,7 +57,7 @@ stocks.ca.hist( {{< highlight python >}} stocks.ca.hist( similar: List[str], - start_date: str = '2021-11-09', + start_date: str = '2021-11-11', candle_type: str = 'a', normalize: bool = True, export: str = '', diff --git a/website/content/SDK/stocks/ca/volume/_index.rst b/website/content/SDK/stocks/ca/volume/_index.rst index d2c39fcdd024..084566a43c59 100644 --- a/website/content/SDK/stocks/ca/volume/_index.rst +++ b/website/content/SDK/stocks/ca/volume/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ca.volume( similar: List[str], - start_date: str = '2021-11-09', + start_date: str = '2021-11-11', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -49,7 +49,7 @@ stocks.ca.volume( {{< highlight python >}} stocks.ca.volume( similar: List[str], - start_date: str = '2021-11-09', + start_date: str = '2021-11-11', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/stocks/candle/_index.rst b/website/content/SDK/stocks/candle/_index.rst index b0f4bc7233d2..a5c7a729e6d3 100644 --- a/website/content/SDK/stocks/candle/_index.rst +++ b/website/content/SDK/stocks/candle/_index.rst @@ -21,11 +21,11 @@ stocks.candle( asset_type: str = '', start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 6, 10, 57, 3, 415209, chart: bool = False, + 2019, 11, 8, 21, 35, 12, 215151, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 10, 10, 57, 3, 415211, chart: bool = False, + 2022, 11, 12, 21, 35, 12, 215152, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/stocks/dd/pt/_index.rst b/website/content/SDK/stocks/dd/pt/_index.rst index 0ff3cc2a16ae..854a78524443 100644 --- a/website/content/SDK/stocks/dd/pt/_index.rst +++ b/website/content/SDK/stocks/dd/pt/_index.rst @@ -50,7 +50,7 @@ stocks.dd.pt( stocks.dd.pt( symbol: str, data: pandas.core.frame.DataFrame, - start_date: str = '2022-11-10', + start_date: str = '2022-11-12', limit: int = 10, raw: bool = False, export: str = '', diff --git a/website/content/SDK/stocks/disc/dividends/_index.rst b/website/content/SDK/stocks/disc/dividends/_index.rst index b0e5c32a57e1..645edb3753be 100644 --- a/website/content/SDK/stocks/disc/dividends/_index.rst +++ b/website/content/SDK/stocks/disc/dividends/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} stocks.disc.dividends( - date: str = '2022-11-10', + date: str = '2022-11-12', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/stocks/disc/ipo/_index.rst b/website/content/SDK/stocks/disc/ipo/_index.rst index 40c39f95e467..d80b8efec8ed 100644 --- a/website/content/SDK/stocks/disc/ipo/_index.rst +++ b/website/content/SDK/stocks/disc/ipo/_index.rst @@ -12,8 +12,8 @@ {{< highlight python >}} stocks.disc.ipo( - start_date: str = '2022-11-05', - end_date: str = '2022-11-10', + start_date: str = '2022-11-07', + end_date: str = '2022-11-12', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/stocks/dps/ftd/_index.rst b/website/content/SDK/stocks/dps/ftd/_index.rst index 8d31c0231253..b5054406630d 100644 --- a/website/content/SDK/stocks/dps/ftd/_index.rst +++ b/website/content/SDK/stocks/dps/ftd/_index.rst @@ -15,8 +15,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.dps.ftd( symbol: str, - start_date: str = '2022-09-11', - end_date: str = '2022-11-10', + start_date: str = '2022-09-13', + end_date: str = '2022-11-12', limit: int = 0, chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -59,8 +59,8 @@ stocks.dps.ftd( stocks.dps.ftd( symbol: str, data: pandas.core.frame.DataFrame, - start_date: str = '2022-09-11', - end_date: str = '2022-11-10', + start_date: str = '2022-09-13', + end_date: str = '2022-11-12', limit: int = 0, raw: bool = False, export: str = '', diff --git a/website/content/SDK/stocks/fa/mktcap/_index.rst b/website/content/SDK/stocks/fa/mktcap/_index.rst index ff59eac27581..c0693a6a0e33 100644 --- a/website/content/SDK/stocks/fa/mktcap/_index.rst +++ b/website/content/SDK/stocks/fa/mktcap/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.fa.mktcap( symbol: str, - start_date: str = '2019-11-08', + start_date: str = '2019-11-10', chart: bool = False, ) -> Tuple[pandas.core.frame.DataFrame, str] {{< /highlight >}} @@ -54,7 +54,7 @@ stocks.fa.mktcap( {{< highlight python >}} stocks.fa.mktcap( symbol: str, - start_date: str = '2019-11-08', + start_date: str = '2019-11-10', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/stocks/ins/act/_index.rst b/website/content/SDK/stocks/ins/act/_index.rst index eb806443c39b..a1b5c2613027 100644 --- a/website/content/SDK/stocks/ins/act/_index.rst +++ b/website/content/SDK/stocks/ins/act/_index.rst @@ -50,7 +50,7 @@ stocks.ins.act( stocks.ins.act( data: pandas.core.frame.DataFrame, symbol: str, - start_date: str = '2019-11-06', + start_date: str = '2019-11-08', interval: str = '1440min', limit: int = 10, raw: bool = False, diff --git a/website/content/SDK/stocks/load/_index.rst b/website/content/SDK/stocks/load/_index.rst index 9764bb9971a5..efdf981be502 100644 --- a/website/content/SDK/stocks/load/_index.rst +++ b/website/content/SDK/stocks/load/_index.rst @@ -15,11 +15,11 @@ stocks.load( symbol: str, start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 6, 10, 57, 3, 415198, chart: bool = False, + 2019, 11, 8, 21, 35, 12, 215141, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 10, 10, 57, 3, 415206, chart: bool = False, + 2022, 11, 12, 21, 35, 12, 215148, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/stocks/options/pcr/_index.rst b/website/content/SDK/stocks/options/pcr/_index.rst index 80cd448b8066..c2b6ae47df96 100644 --- a/website/content/SDK/stocks/options/pcr/_index.rst +++ b/website/content/SDK/stocks/options/pcr/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. stocks.options.pcr( symbol: str, window: int = 30, - start_date: str = '2021-11-09', + start_date: str = '2021-11-11', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -51,7 +51,7 @@ stocks.options.pcr( stocks.options.pcr( symbol: str, window: int = 30, - start_date: str = '2021-11-09', + start_date: str = '2021-11-11', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/stocks/screener/historical/_index.rst b/website/content/SDK/stocks/screener/historical/_index.rst index a6ee8cb61c2b..2e740bb04ba5 100644 --- a/website/content/SDK/stocks/screener/historical/_index.rst +++ b/website/content/SDK/stocks/screener/historical/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. stocks.screener.historical( preset_loaded: str = 'top_gainers', limit: int = 10, - start_date: str = '2022-05-14', + start_date: str = '2022-05-16', type_candle: str = 'a', normalize: bool = True, chart: bool = False, @@ -66,7 +66,7 @@ stocks.screener.historical( stocks.screener.historical( preset_loaded: str = 'top_gainers', limit: int = 10, - start_date: str = '2022-05-14', + start_date: str = '2022-05-16', type_candle: str = 'a', normalize: bool = True, export: str = '', diff --git a/website/data/menu/main.yml b/website/data/menu/main.yml index 910930fee29f..ef3ad06a0deb 100644 --- a/website/data/menu/main.yml +++ b/website/data/menu/main.yml @@ -2572,8 +2572,8 @@ main: ref: /SDK/portfolio/rbeta - name: rsharpe ref: /SDK/portfolio/rsharpe - - name: rsort - ref: /SDK/portfolio/rsort + - name: rsortino + ref: /SDK/portfolio/rsortino - name: rsquare ref: /SDK/portfolio/rsquare - name: rvol From 8a3c771004eb30b5356ace8a709d3f20c963add4 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 21:48:48 +0000 Subject: [PATCH 12/30] change portfolio arg name --- openbb_terminal/portfolio/portfolio_model.py | 377 ++++++++++-------- openbb_terminal/portfolio/portfolio_view.py | 57 ++- .../content/SDK/crypto/dd/active/_index.rst | 2 +- .../content/SDK/crypto/dd/change/_index.rst | 2 +- website/content/SDK/crypto/dd/eb/_index.rst | 2 +- website/content/SDK/crypto/dd/gh/_index.rst | 8 +- .../content/SDK/crypto/dd/nonzero/_index.rst | 2 +- website/content/SDK/crypto/load/_index.rst | 4 +- .../SDK/crypto/onchain/btc_supply/_index.rst | 2 +- .../SDK/crypto/onchain/btc_transac/_index.rst | 2 +- .../content/SDK/crypto/onchain/hr/_index.rst | 8 +- .../content/SDK/crypto/ov/altindex/_index.rst | 4 +- website/content/SDK/etf/candle/_index.rst | 4 +- website/content/SDK/etf/load/_index.rst | 4 +- .../content/SDK/portfolio/distr/_index.rst | 7 +- website/content/SDK/portfolio/dret/_index.rst | 10 +- website/content/SDK/portfolio/es/_index.rst | 7 +- .../content/SDK/portfolio/holdp/_index.rst | 10 +- .../content/SDK/portfolio/holdv/_index.rst | 10 +- .../content/SDK/portfolio/maxdd/_index.rst | 2 +- .../content/SDK/portfolio/metric/_index.md | 6 + .../SDK/portfolio/metric/calmar/_index.rst | 7 +- .../portfolio/metric/commonsense/_index.rst | 7 +- .../portfolio/metric/gaintopain/_index.rst | 7 +- .../portfolio/metric/information/_index.rst | 7 +- .../SDK/portfolio/metric/jensens/_index.rst | 7 +- .../SDK/portfolio/metric/kelly/_index.rst | 7 +- .../SDK/portfolio/metric/kurtosis/_index.rst | 7 +- .../portfolio/metric/maxdrawdown/_index.rst | 7 +- .../SDK/portfolio/metric/payoff/_index.rst | 2 +- .../portfolio/metric/profitfactor/_index.rst | 7 +- .../SDK/portfolio/metric/rsquare/_index.rst | 7 +- .../SDK/portfolio/metric/sharpe/_index.rst | 7 +- .../SDK/portfolio/metric/skew/_index.rst | 7 +- .../SDK/portfolio/metric/sortino/_index.rst | 7 +- .../SDK/portfolio/metric/tail/_index.rst | 7 +- .../SDK/portfolio/metric/trackerr/_index.rst | 7 +- .../portfolio/metric/volatility/_index.rst | 7 +- website/content/SDK/portfolio/mret/_index.rst | 10 +- website/content/SDK/portfolio/om/_index.rst | 10 +- website/content/SDK/portfolio/perf/_index.rst | 7 +- .../content/SDK/portfolio/rbeta/_index.rst | 2 +- .../content/SDK/portfolio/rsharpe/_index.rst | 2 +- .../content/SDK/portfolio/rsort/_index.rst | 2 +- website/content/SDK/portfolio/rvol/_index.rst | 7 +- .../content/SDK/portfolio/summary/_index.rst | 7 +- website/content/SDK/portfolio/var/_index.rst | 7 +- website/content/SDK/portfolio/yret/_index.rst | 10 +- .../content/SDK/stocks/ba/trend/_index.rst | 4 +- website/content/SDK/stocks/candle/_index.rst | 4 +- website/content/SDK/stocks/load/_index.rst | 4 +- website/data/menu/main.yml | 45 +++ 52 files changed, 466 insertions(+), 299 deletions(-) create mode 100644 website/content/SDK/portfolio/metric/_index.md diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 4b2bf7a8cdc7..110693c88407 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -808,13 +808,14 @@ def calculate_allocations(self, category: str): # Metrics @log_start_end(log=logger) -def get_r2_score(portfolio: PortfolioEngine) -> pd.DataFrame: +def get_r2_score(portfolio_engine: PortfolioEngine) -> pd.DataFrame: """Method that retrieves R2 Score for portfolio and benchmark selected Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- @@ -827,9 +828,11 @@ def get_r2_score(portfolio: PortfolioEngine) -> pd.DataFrame: vals.append( round( r2_score( - portfolio_helper.filter_df_by_period(portfolio.returns, period), portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, period + portfolio_engine.returns, period + ), + portfolio_helper.filter_df_by_period( + portfolio_engine.benchmark_returns, period ), ), 3, @@ -839,11 +842,12 @@ def get_r2_score(portfolio: PortfolioEngine) -> pd.DataFrame: @log_start_end(log=logger) -def get_skewness(portfolio: PortfolioEngine) -> pd.DataFrame: +def get_skewness(portfolio_engine: PortfolioEngine) -> pd.DataFrame: """Method that retrieves skewness for portfolio and benchmark selected - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- @@ -857,14 +861,16 @@ def get_skewness(portfolio: PortfolioEngine) -> pd.DataFrame: [ round( scipy.stats.skew( - portfolio_helper.filter_df_by_period(portfolio.returns, period) + portfolio_helper.filter_df_by_period( + portfolio_engine.returns, period + ) ), 3, ), round( scipy.stats.skew( portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, period + portfolio_engine.benchmark_returns, period ) ), 3, @@ -877,13 +883,14 @@ def get_skewness(portfolio: PortfolioEngine) -> pd.DataFrame: @log_start_end(log=logger) -def get_kurtosis(portfolio: PortfolioEngine) -> pd.DataFrame: +def get_kurtosis(portfolio_engine: PortfolioEngine) -> pd.DataFrame: """Method that retrieves kurtosis for portfolio and benchmark selected Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- @@ -897,14 +904,16 @@ def get_kurtosis(portfolio: PortfolioEngine) -> pd.DataFrame: [ round( scipy.stats.kurtosis( - portfolio_helper.filter_df_by_period(portfolio.returns, period) + portfolio_helper.filter_df_by_period( + portfolio_engine.returns, period + ) ), 3, ), round( scipy.stats.skew( portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, period + portfolio_engine.benchmark_returns, period ) ), 3, @@ -917,13 +926,14 @@ def get_kurtosis(portfolio: PortfolioEngine) -> pd.DataFrame: @log_start_end(log=logger) -def get_stats(portfolio: PortfolioEngine, window: str = "all") -> pd.DataFrame: +def get_stats(portfolio_engine: PortfolioEngine, window: str = "all") -> pd.DataFrame: """Method that retrieves stats for portfolio and benchmark selected based on a certain interval Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to consider. Choices are: mtd, qtd, ytd, 3m, 6m, 1y, 3y, 5y, 10y, all @@ -934,12 +944,12 @@ def get_stats(portfolio: PortfolioEngine, window: str = "all") -> pd.DataFrame: """ df = ( - portfolio_helper.filter_df_by_period(portfolio.returns, window) + portfolio_helper.filter_df_by_period(portfolio_engine.returns, window) .describe() .to_frame() .join( portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, window + portfolio_engine.benchmark_returns, window ).describe() ) ) @@ -948,13 +958,14 @@ def get_stats(portfolio: PortfolioEngine, window: str = "all") -> pd.DataFrame: @log_start_end(log=logger) -def get_volatility(portfolio: PortfolioEngine) -> pd.DataFrame: +def get_volatility(portfolio_engine: PortfolioEngine) -> pd.DataFrame: """Method that retrieves volatility for portfolio and benchmark selected Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- @@ -964,9 +975,11 @@ def get_volatility(portfolio: PortfolioEngine) -> pd.DataFrame: vals = list() for period in portfolio_helper.PERIODS: - port_rets = portfolio_helper.filter_df_by_period(portfolio.returns, period) + port_rets = portfolio_helper.filter_df_by_period( + portfolio_engine.returns, period + ) bench_rets = portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, period + portfolio_engine.benchmark_returns, period ) vals.append( [ @@ -989,14 +1002,15 @@ def get_volatility(portfolio: PortfolioEngine) -> pd.DataFrame: @log_start_end(log=logger) def get_sharpe_ratio( - portfolio: PortfolioEngine, risk_free_rate: float = 0 + portfolio_engine: PortfolioEngine, risk_free_rate: float = 0 ) -> pd.DataFrame: """Method that retrieves sharpe ratio for portfolio and benchmark selected Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. risk_free_rate: float Risk free rate value @@ -1012,7 +1026,9 @@ def get_sharpe_ratio( [ round( portfolio_helper.sharpe_ratio( - portfolio_helper.filter_df_by_period(portfolio.returns, period), + portfolio_helper.filter_df_by_period( + portfolio_engine.returns, period + ), risk_free_rate, ), 3, @@ -1020,7 +1036,7 @@ def get_sharpe_ratio( round( portfolio_helper.sharpe_ratio( portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, period + portfolio_engine.benchmark_returns, period ), risk_free_rate, ), @@ -1035,14 +1051,15 @@ def get_sharpe_ratio( @log_start_end(log=logger) def get_sortino_ratio( - portfolio: PortfolioEngine, risk_free_rate: float = 0 + portfolio_engine: PortfolioEngine, risk_free_rate: float = 0 ) -> pd.DataFrame: """Method that retrieves sortino ratio for portfolio and benchmark selected Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. risk_free_rate: float Risk free rate value @@ -1058,7 +1075,9 @@ def get_sortino_ratio( [ round( portfolio_helper.sortino_ratio( - portfolio_helper.filter_df_by_period(portfolio.returns, period), + portfolio_helper.filter_df_by_period( + portfolio_engine.returns, period + ), risk_free_rate, ), 3, @@ -1066,7 +1085,7 @@ def get_sortino_ratio( round( portfolio_helper.sortino_ratio( portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, period + portfolio_engine.benchmark_returns, period ), risk_free_rate, ), @@ -1080,13 +1099,14 @@ def get_sortino_ratio( @log_start_end(log=logger) -def get_maximum_drawdown_ratio(portfolio: PortfolioEngine) -> pd.DataFrame: +def get_maximum_drawdown_ratio(portfolio_engine: PortfolioEngine) -> pd.DataFrame: """Method that retrieves maximum drawdown ratio for portfolio and benchmark selected Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- @@ -1100,14 +1120,16 @@ def get_maximum_drawdown_ratio(portfolio: PortfolioEngine) -> pd.DataFrame: [ round( portfolio_helper.maximum_drawdown( - portfolio_helper.filter_df_by_period(portfolio.returns, period) + portfolio_helper.filter_df_by_period( + portfolio_engine.returns, period + ) ), 3, ), round( portfolio_helper.maximum_drawdown( portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, period + portfolio_engine.benchmark_returns, period ) ), 3, @@ -1120,13 +1142,14 @@ def get_maximum_drawdown_ratio(portfolio: PortfolioEngine) -> pd.DataFrame: @log_start_end(log=logger) -def get_gaintopain_ratio(portfolio: PortfolioEngine): +def get_gaintopain_ratio(portfolio_engine: PortfolioEngine): """Get Pain-to-Gain ratio based on historical data Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- @@ -1135,22 +1158,23 @@ def get_gaintopain_ratio(portfolio: PortfolioEngine): """ gtp_period_df = portfolio_helper.get_gaintopain_ratio( - portfolio.historical_trade_data, - portfolio.benchmark_trades, - portfolio.benchmark_returns, + portfolio_engine.historical_trade_data, + portfolio_engine.benchmark_trades, + portfolio_engine.benchmark_returns, ) return gtp_period_df @log_start_end(log=logger) -def get_tracking_error(portfolio: PortfolioEngine, window: int = 252): +def get_tracking_error(portfolio_engine: PortfolioEngine, window: int = 252): """Get tracking error Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window: int Interval used for rolling values @@ -1163,20 +1187,21 @@ def get_tracking_error(portfolio: PortfolioEngine, window: int = 252): """ trackr_period_df, trackr_rolling = portfolio_helper.get_tracking_error( - portfolio.returns, portfolio.benchmark_returns, window + portfolio_engine.returns, portfolio_engine.benchmark_returns, window ) return trackr_period_df, trackr_rolling @log_start_end(log=logger) -def get_information_ratio(portfolio: PortfolioEngine): +def get_information_ratio(portfolio_engine: PortfolioEngine): """Get information ratio Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- @@ -1185,23 +1210,24 @@ def get_information_ratio(portfolio: PortfolioEngine): """ ir_period_df = portfolio_helper.get_information_ratio( - portfolio.returns, - portfolio.historical_trade_data, - portfolio.benchmark_trades, - portfolio.benchmark_returns, + portfolio_engine.returns, + portfolio_engine.historical_trade_data, + portfolio_engine.benchmark_trades, + portfolio_engine.benchmark_returns, ) return ir_period_df @log_start_end(log=logger) -def get_tail_ratio(portfolio: PortfolioEngine, window: int = 252): +def get_tail_ratio(portfolio_engine: PortfolioEngine, window: int = 252): """Get tail ratio Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window: int Interval used for rolling values @@ -1217,20 +1243,21 @@ def get_tail_ratio(portfolio: PortfolioEngine, window: int = 252): """ tailr_period_df, portfolio_tr, benchmark_tr = portfolio_helper.get_tail_ratio( - portfolio.returns, portfolio.benchmark_returns, window + portfolio_engine.returns, portfolio_engine.benchmark_returns, window ) return tailr_period_df, portfolio_tr, benchmark_tr @log_start_end(log=logger) -def get_common_sense_ratio(portfolio: PortfolioEngine): +def get_common_sense_ratio(portfolio_engine: PortfolioEngine): """Get common sense ratio Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- @@ -1239,10 +1266,10 @@ def get_common_sense_ratio(portfolio: PortfolioEngine): """ csr_period_df = portfolio_helper.get_common_sense_ratio( - portfolio.returns, - portfolio.historical_trade_data, - portfolio.benchmark_trades, - portfolio.benchmark_returns, + portfolio_engine.returns, + portfolio_engine.historical_trade_data, + portfolio_engine.benchmark_trades, + portfolio_engine.benchmark_returns, ) return csr_period_df @@ -1250,14 +1277,15 @@ def get_common_sense_ratio(portfolio: PortfolioEngine): @log_start_end(log=logger) def get_jensens_alpha( - portfolio: PortfolioEngine, risk_free_rate: float = 0, window: str = "1y" + portfolio_engine: PortfolioEngine, risk_free_rate: float = 0, window: str = "1y" ): """Get jensen's alpha Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window: str Interval used for rolling values risk_free_rate: float @@ -1272,10 +1300,10 @@ def get_jensens_alpha( """ ja_period_df, ja_rolling = portfolio_helper.jensens_alpha( - portfolio.returns, - portfolio.historical_trade_data, - portfolio.benchmark_trades, - portfolio.benchmark_returns, + portfolio_engine.returns, + portfolio_engine.historical_trade_data, + portfolio_engine.benchmark_trades, + portfolio_engine.benchmark_returns, risk_free_rate, window, ) @@ -1284,13 +1312,14 @@ def get_jensens_alpha( @log_start_end(log=logger) -def get_calmar_ratio(portfolio: PortfolioEngine, window: int = 756): +def get_calmar_ratio(portfolio_engine: PortfolioEngine, window: int = 756): """Get calmar ratio Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window: int Interval used for rolling values @@ -1303,10 +1332,10 @@ def get_calmar_ratio(portfolio: PortfolioEngine, window: int = 756): """ cr_period_df, cr_rolling = portfolio_helper.get_calmar_ratio( - portfolio.returns, - portfolio.historical_trade_data, - portfolio.benchmark_trades, - portfolio.benchmark_returns, + portfolio_engine.returns, + portfolio_engine.historical_trade_data, + portfolio_engine.benchmark_trades, + portfolio_engine.benchmark_returns, window, ) @@ -1314,13 +1343,14 @@ def get_calmar_ratio(portfolio: PortfolioEngine, window: int = 756): @log_start_end(log=logger) -def get_kelly_criterion(portfolio: PortfolioEngine): +def get_kelly_criterion(portfolio_engine: PortfolioEngine): """Gets kelly criterion Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- @@ -1329,14 +1359,14 @@ def get_kelly_criterion(portfolio: PortfolioEngine): """ kc_period_df = portfolio_helper.get_kelly_criterion( - portfolio.returns, portfolio.portfolio_trades + portfolio_engine.returns, portfolio_engine.portfolio_trades ) return kc_period_df @log_start_end(log=logger) -def get_payoff_ratio(portfolio: PortfolioEngine): +def get_payoff_ratio(portfolio_engine: PortfolioEngine): """Gets payoff ratio Returns @@ -1345,19 +1375,22 @@ def get_payoff_ratio(portfolio: PortfolioEngine): DataFrame of payoff ratio of the portfolio during different time periods """ - pr_period_ratio = portfolio_helper.get_payoff_ratio(portfolio.portfolio_trades) + pr_period_ratio = portfolio_helper.get_payoff_ratio( + portfolio_engine.portfolio_trades + ) return pr_period_ratio @log_start_end(log=logger) -def get_profit_factor(portfolio: PortfolioEngine): +def get_profit_factor(portfolio_engine: PortfolioEngine): """Gets profit factor Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- @@ -1365,18 +1398,19 @@ def get_profit_factor(portfolio: PortfolioEngine): DataFrame of profit factor of the portfolio during different time periods """ - pf_period_df = portfolio_helper.get_profit_factor(portfolio.portfolio_trades) + pf_period_df = portfolio_helper.get_profit_factor(portfolio_engine.portfolio_trades) return pf_period_df -def get_holdings_value(portfolio: PortfolioEngine) -> pd.DataFrame: +def get_holdings_value(portfolio_engine: PortfolioEngine) -> pd.DataFrame: """Get holdings of assets (absolute value) Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- @@ -1384,7 +1418,9 @@ def get_holdings_value(portfolio: PortfolioEngine) -> pd.DataFrame: DataFrame of holdings """ - all_holdings = portfolio.historical_trade_data["End Value"][portfolio.tickers_list] + all_holdings = portfolio_engine.historical_trade_data["End Value"][ + portfolio_engine.tickers_list + ] all_holdings["Total Value"] = all_holdings.sum(axis=1) # No need to account for time since this is daily data @@ -1394,17 +1430,20 @@ def get_holdings_value(portfolio: PortfolioEngine) -> pd.DataFrame: def get_holdings_percentage( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, ): """Get holdings of assets (in percentage) Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. """ - all_holdings = portfolio.historical_trade_data["End Value"][portfolio.tickers_list] + all_holdings = portfolio_engine.historical_trade_data["End Value"][ + portfolio_engine.tickers_list + ] all_holdings = all_holdings.divide(all_holdings.sum(axis=1), axis=0) * 100 @@ -1416,7 +1455,7 @@ def get_holdings_percentage( @log_start_end(log=logger) def get_maximum_drawdown( - portfolio: PortfolioEngine, is_returns: bool = False + portfolio_engine: PortfolioEngine, is_returns: bool = False ) -> pd.Series: """Calculate the drawdown (MDD) of historical series. Note that the calculation is done on cumulative returns (or prices). The definition of drawdown is @@ -1438,7 +1477,7 @@ def get_maximum_drawdown( Drawdown series """ - holdings: pd.Series = portfolio.portfolio_value + holdings: pd.Series = portfolio_engine.portfolio_value if is_returns: holdings = (1 + holdings).cumprod() @@ -1449,22 +1488,25 @@ def get_maximum_drawdown( def get_distribution_returns( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "all", ): """Display daily returns Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark """ - portfolio_returns = portfolio_helper.filter_df_by_period(portfolio.returns, window) + portfolio_returns = portfolio_helper.filter_df_by_period( + portfolio_engine.returns, window + ) benchmark_returns = portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, window + portfolio_engine.benchmark_returns, window ) df = pd.DataFrame(portfolio_returns).join(pd.DataFrame(benchmark_returns)) @@ -1475,25 +1517,28 @@ def get_distribution_returns( def get_rolling_volatility( - portfolio: PortfolioEngine, window: str = "1y" + portfolio_engine: PortfolioEngine, window: str = "1y" ) -> pd.DataFrame: """Get rolling volatility Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str Rolling window size to use Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y """ - portfolio_rvol = portfolio_helper.rolling_volatility(portfolio.returns, window) + portfolio_rvol = portfolio_helper.rolling_volatility( + portfolio_engine.returns, window + ) if portfolio_rvol.empty: return pd.DataFrame() benchmark_rvol = portfolio_helper.rolling_volatility( - portfolio.benchmark_returns, window + portfolio_engine.benchmark_returns, window ) if benchmark_rvol.empty: return pd.DataFrame() @@ -1506,7 +1551,7 @@ def get_rolling_volatility( def get_rolling_sharpe( - portfolio: pd.DataFrame, risk_free_rate: float = 0, window: str = "1y" + portfolio_engine: pd.DataFrame, risk_free_rate: float = 0, window: str = "1y" ) -> pd.DataFrame: """Get rolling sharpe ratio @@ -1527,13 +1572,13 @@ def get_rolling_sharpe( """ portfolio_rsharpe = portfolio_helper.rolling_sharpe( - portfolio.returns, risk_free_rate, window + portfolio_engine.returns, risk_free_rate, window ) if portfolio_rsharpe.empty: return pd.DataFrame() benchmark_rsharpe = portfolio_helper.rolling_sharpe( - portfolio.benchmark_returns, risk_free_rate, window + portfolio_engine.benchmark_returns, risk_free_rate, window ) if benchmark_rsharpe.empty: return pd.DataFrame() @@ -1546,7 +1591,7 @@ def get_rolling_sharpe( def get_rolling_sortino( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, risk_free_rate: float = 0, window: str = "1y", ) -> pd.DataFrame: @@ -1569,13 +1614,13 @@ def get_rolling_sortino( """ portfolio_rsortino = portfolio_helper.rolling_sortino( - portfolio.returns, risk_free_rate, window + portfolio_engine.returns, risk_free_rate, window ) if portfolio_rsortino.empty: return pd.DataFrame() benchmark_rsortino = portfolio_helper.rolling_sortino( - portfolio.benchmark_returns, risk_free_rate, window + portfolio_engine.benchmark_returns, risk_free_rate, window ) if benchmark_rsortino.empty: return pd.DataFrame() @@ -1589,7 +1634,7 @@ def get_rolling_sortino( @log_start_end(log=logger) def get_rolling_beta( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "1y", ) -> pd.DataFrame: """Get rolling beta using portfolio and benchmark returns @@ -1609,7 +1654,7 @@ def get_rolling_beta( """ df = portfolio_helper.rolling_beta( - portfolio.returns, portfolio.benchmark_returns, window + portfolio_engine.returns, portfolio_engine.benchmark_returns, window ) return df @@ -1617,7 +1662,7 @@ def get_rolling_beta( @log_start_end(log=logger) def get_performance_vs_benchmark( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, show_all_trades: bool = False, ) -> pd.DataFrame: @@ -1625,8 +1670,9 @@ def get_performance_vs_benchmark( Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. show_all_trades: bool Whether to also show all trades made and their performance (default is False) @@ -1635,8 +1681,8 @@ def get_performance_vs_benchmark( pd.DataFrame """ - portfolio_trades = portfolio.portfolio_trades - benchmark_trades = portfolio.benchmark_trades + portfolio_trades = portfolio_engine.portfolio_trades + benchmark_trades = portfolio_engine.benchmark_trades portfolio_trades.index = pd.to_datetime(portfolio_trades["Date"].values) benchmark_trades.index = pd.to_datetime(benchmark_trades["Date"].values) @@ -1721,7 +1767,7 @@ def get_performance_vs_benchmark( @log_start_end(log=logger) def get_var( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, use_mean: bool = False, adjusted_var: bool = False, student_t: bool = False, @@ -1732,8 +1778,9 @@ def get_var( Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. use_mean: bool if one should use the data mean return adjusted_var: bool @@ -1749,7 +1796,7 @@ def get_var( """ return qa_model.get_var( - data=portfolio.returns, + data=portfolio_engine.returns, use_mean=use_mean, adjusted_var=adjusted_var, student_t=student_t, @@ -1760,7 +1807,7 @@ def get_var( @log_start_end(log=logger) def get_es( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, use_mean: bool = False, distribution: str = "normal", percentile: float = 99.9, @@ -1769,8 +1816,9 @@ def get_es( Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. use_mean: if one should use the data mean return distribution: str @@ -1784,7 +1832,7 @@ def get_es( """ return qa_model.get_es( - data=portfolio.returns, + data=portfolio_engine.returns, use_mean=use_mean, distribution=distribution, percentile=percentile, @@ -1794,14 +1842,17 @@ def get_es( @log_start_end(log=logger) def get_omega( - portfolio: PortfolioEngine, threshold_start: float = 0, threshold_end: float = 1.5 + portfolio_engine: PortfolioEngine, + threshold_start: float = 0, + threshold_end: float = 1.5, ) -> pd.DataFrame: """Get omega ratio Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. threshold_start: float annualized target return threshold start of plotted threshold range threshold_end: float @@ -1813,14 +1864,14 @@ def get_omega( """ return qa_model.get_omega( - data=portfolio.returns, + data=portfolio_engine.returns, threshold_start=threshold_start, threshold_end=threshold_end, ) def get_summary( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "all", risk_free_rate: float = 0, ) -> pd.DataFrame: @@ -1828,8 +1879,9 @@ def get_summary( Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark risk_free_rate : float @@ -1841,9 +1893,11 @@ def get_summary( """ - portfolio_returns = portfolio_helper.filter_df_by_period(portfolio.returns, window) + portfolio_returns = portfolio_helper.filter_df_by_period( + portfolio_engine.returns, window + ) benchmark_returns = portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, window + portfolio_engine.benchmark_returns, window ) metrics = { @@ -1889,22 +1943,25 @@ def get_summary( @log_start_end(log=logger) def get_yearly_returns( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "all", ): """Get yearly returns Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark """ - portfolio_returns = portfolio_helper.filter_df_by_period(portfolio.returns, window) + portfolio_returns = portfolio_helper.filter_df_by_period( + portfolio_engine.returns, window + ) benchmark_returns = portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, window + portfolio_engine.benchmark_returns, window ) creturns_year_val = list() @@ -1939,15 +1996,16 @@ def get_yearly_returns( @log_start_end(log=logger) def get_monthly_returns( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "all", ) -> pd.DataFrame: """Get monthly returns Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark @@ -1956,9 +2014,11 @@ def get_monthly_returns( pd.DataFrame """ - portfolio_returns = portfolio_helper.filter_df_by_period(portfolio.returns, window) + portfolio_returns = portfolio_helper.filter_df_by_period( + portfolio_engine.returns, window + ) benchmark_returns = portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, window + portfolio_engine.benchmark_returns, window ) creturns_month_val = list() @@ -2035,15 +2095,16 @@ def get_monthly_returns( @log_start_end(log=logger) def get_daily_returns( - portfolio: PortfolioEngine, + portfolio_engine: PortfolioEngine, window: str = "all", ) -> pd.DataFrame: """Get daily returns Parameters ---------- - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark @@ -2052,9 +2113,11 @@ def get_daily_returns( pd.DataFrame """ - portfolio_returns = portfolio_helper.filter_df_by_period(portfolio.returns, window) + portfolio_returns = portfolio_helper.filter_df_by_period( + portfolio_engine.returns, window + ) benchmark_returns = portfolio_helper.filter_df_by_period( - portfolio.benchmark_returns, window + portfolio_engine.benchmark_returns, window ) df = portfolio_returns.to_frame() diff --git a/openbb_terminal/portfolio/portfolio_view.py b/openbb_terminal/portfolio/portfolio_view.py index 6f2600909a60..7e38cd1d6b4f 100644 --- a/openbb_terminal/portfolio/portfolio_view.py +++ b/openbb_terminal/portfolio/portfolio_view.py @@ -333,7 +333,8 @@ def display_yearly_returns( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark raw : False @@ -414,7 +415,8 @@ def display_monthly_returns( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark raw : False @@ -514,7 +516,8 @@ def display_daily_returns( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark raw : False @@ -669,7 +672,8 @@ def display_holdings_value( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. unstack: bool Individual assets over time raw : bool @@ -747,7 +751,8 @@ def display_holdings_percentage( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. unstack: bool Individual assets over time raw : bool @@ -1106,7 +1111,8 @@ def display_rsquare( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. export : str Export data format """ @@ -1138,7 +1144,8 @@ def display_skewness( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. export : str Export data format """ @@ -1168,7 +1175,8 @@ def display_kurtosis( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. export : str Export data format """ @@ -1199,7 +1207,8 @@ def display_stats( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to consider. Choices are: mtd, qtd, ytd, 3m, 6m, 1y, 3y, 5y, 10y, all export : str @@ -1231,7 +1240,8 @@ def display_volatility( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. export : str Export data format """ @@ -1259,7 +1269,8 @@ def display_sharpe_ratio( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. risk_free_rate: float Risk free rate value export : str @@ -1292,7 +1303,8 @@ def display_sortino_ratio( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. risk_free_rate: float Risk free rate value export : str @@ -1324,7 +1336,8 @@ def display_maximum_drawdown_ratio( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. export : str Export data format """ @@ -1584,7 +1597,8 @@ def display_payoff_ratio( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. export : str Export data format """ @@ -1610,7 +1624,8 @@ def display_profit_factor( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. export : str Export data format """ @@ -1639,7 +1654,8 @@ def display_summary( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark risk_free_rate : float @@ -1676,7 +1692,8 @@ def display_var( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. use_mean: bool if one should use the data mean return adjusted_var: bool @@ -1710,7 +1727,8 @@ def display_es( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. use_mean: if one should use the data mean return distribution: str @@ -1740,7 +1758,8 @@ def display_omega( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. threshold_start: float annualized target return threshold start of plotted threshold range threshold_end: float diff --git a/website/content/SDK/crypto/dd/active/_index.rst b/website/content/SDK/crypto/dd/active/_index.rst index 5b842db8db5d..65d84bbee561 100644 --- a/website/content/SDK/crypto/dd/active/_index.rst +++ b/website/content/SDK/crypto/dd/active/_index.rst @@ -17,7 +17,7 @@ crypto.dd.active( symbol: str, interval: str = '24h', start_date: int = 1262304000, - end_date: int = 1668288912, + end_date: int = 1668289667, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/dd/change/_index.rst b/website/content/SDK/crypto/dd/change/_index.rst index ad39c2a19685..08ec500a8bc4 100644 --- a/website/content/SDK/crypto/dd/change/_index.rst +++ b/website/content/SDK/crypto/dd/change/_index.rst @@ -17,7 +17,7 @@ crypto.dd.change( symbol: str, exchange: str = 'binance', start_date: int = 1262304000, - end_date: int = 1668288912, + end_date: int = 1668289667, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/dd/eb/_index.rst b/website/content/SDK/crypto/dd/eb/_index.rst index 7cdc5e968e6a..f5f57279a5b4 100644 --- a/website/content/SDK/crypto/dd/eb/_index.rst +++ b/website/content/SDK/crypto/dd/eb/_index.rst @@ -17,7 +17,7 @@ crypto.dd.eb( symbol: str, exchange: str = 'binance', start_date: int = 1262304000, - end_date: int = 1668288912, + end_date: int = 1668289667, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/dd/gh/_index.rst b/website/content/SDK/crypto/dd/gh/_index.rst index 3243616d1b91..a8271d047371 100644 --- a/website/content/SDK/crypto/dd/gh/_index.rst +++ b/website/content/SDK/crypto/dd/gh/_index.rst @@ -17,8 +17,8 @@ crypto.dd.gh( symbol: str, dev_activity: bool = False, interval: str = '1d', - start_date: str = '2021-11-12T21:35:12Z', - end_date: str = '2022-11-12T21:35:12Z', + start_date: str = '2021-11-12T21:47:47Z', + end_date: str = '2022-11-12T21:47:47Z', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -63,9 +63,9 @@ crypto.dd.gh( {{< highlight python >}} crypto.dd.gh( symbol: str, - start_date: str = '2021-11-12T21:35:12Z', + start_date: str = '2021-11-12T21:47:47Z', dev_activity: bool = False, - end_date: str = '2022-11-12T21:35:12Z', + end_date: str = '2022-11-12T21:47:47Z', interval: str = '1d', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/nonzero/_index.rst b/website/content/SDK/crypto/dd/nonzero/_index.rst index 359291460a43..6f279f7f2cb3 100644 --- a/website/content/SDK/crypto/dd/nonzero/_index.rst +++ b/website/content/SDK/crypto/dd/nonzero/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.dd.nonzero( symbol: str, start_date: int = 1262304000, - end_date: int = 1668288912, + end_date: int = 1668289667, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/load/_index.rst b/website/content/SDK/crypto/load/_index.rst index cf61f7d2d426..5052d40d0dd6 100644 --- a/website/content/SDK/crypto/load/_index.rst +++ b/website/content/SDK/crypto/load/_index.rst @@ -14,12 +14,12 @@ crypto.load( symbol: 'str', start_date: 'datetime' = datetime.datetime( - 2019, 11, 8, 21, 35, 12, 153014, chart: bool = False, + 2019, 11, 8, 21, 47, 47, 885225, chart: bool = False, ), interval: 'str' = '1440', exchange: 'str' = 'binance', vs_currency: 'str' = 'usdt', end_date: 'datetime' = datetime.datetime( - 2022, 11, 12, 21, 35, 12, 153015, chart: bool = False, + 2022, 11, 12, 21, 47, 47, 885226, chart: bool = False, ), source: 'str' = 'CCXT', chart: bool = False, ) -> 'pd.DataFrame' diff --git a/website/content/SDK/crypto/onchain/btc_supply/_index.rst b/website/content/SDK/crypto/onchain/btc_supply/_index.rst index 062d1451dd5e..1898e118e985 100644 --- a/website/content/SDK/crypto/onchain/btc_supply/_index.rst +++ b/website/content/SDK/crypto/onchain/btc_supply/_index.rst @@ -38,7 +38,7 @@ crypto.onchain.btc_supply() -> pandas.core.frame.DataFrame {{< highlight python >}} crypto.onchain.btc_supply( start_date: int = 1262304000, - end_date: int = 1668288912, + end_date: int = 1668289667, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/onchain/btc_transac/_index.rst b/website/content/SDK/crypto/onchain/btc_transac/_index.rst index aaff6c9fe11d..0807b9fb054e 100644 --- a/website/content/SDK/crypto/onchain/btc_transac/_index.rst +++ b/website/content/SDK/crypto/onchain/btc_transac/_index.rst @@ -38,7 +38,7 @@ crypto.onchain.btc_transac() -> pandas.core.frame.DataFrame {{< highlight python >}} crypto.onchain.btc_transac( start_date: int = 1262304000, - end_date: int = 1668288912, + end_date: int = 1668289667, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/onchain/hr/_index.rst b/website/content/SDK/crypto/onchain/hr/_index.rst index 93dfa17edbaf..fabcc56a704a 100644 --- a/website/content/SDK/crypto/onchain/hr/_index.rst +++ b/website/content/SDK/crypto/onchain/hr/_index.rst @@ -16,8 +16,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.onchain.hr( symbol: str, interval: str = '24h', - start_date: int = 1289856912, - end_date: int = 1668288912, + start_date: int = 1289857667, + end_date: int = 1668289667, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -59,8 +59,8 @@ crypto.onchain.hr( {{< highlight python >}} crypto.onchain.hr( symbol: str, - start_date: int = 1636752912, - end_date: int = 1668288912, + start_date: int = 1636753667, + end_date: int = 1668289667, interval: str = '24h', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/ov/altindex/_index.rst b/website/content/SDK/crypto/ov/altindex/_index.rst index da9d184b2f96..df2562befec2 100644 --- a/website/content/SDK/crypto/ov/altindex/_index.rst +++ b/website/content/SDK/crypto/ov/altindex/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.ov.altindex( period: int = 30, start_date: int = 1262304000, - end_date: int = 1668288912, + end_date: int = 1668289667, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -59,7 +59,7 @@ crypto.ov.altindex( crypto.ov.altindex( period: int = 365, start_date: int = 1262304000, - end_date: int = 1668288912, + end_date: int = 1668289667, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/etf/candle/_index.rst b/website/content/SDK/etf/candle/_index.rst index 51c0f469d292..9010011064fb 100644 --- a/website/content/SDK/etf/candle/_index.rst +++ b/website/content/SDK/etf/candle/_index.rst @@ -21,11 +21,11 @@ etf.candle( asset_type: str = '', start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 8, 21, 35, 12, 215151, chart: bool = False, + 2019, 11, 8, 21, 47, 47, 956712, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 12, 21, 35, 12, 215152, chart: bool = False, + 2022, 11, 12, 21, 47, 47, 956713, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/etf/load/_index.rst b/website/content/SDK/etf/load/_index.rst index 8dd3e1b0ecbb..1435eabe26e5 100644 --- a/website/content/SDK/etf/load/_index.rst +++ b/website/content/SDK/etf/load/_index.rst @@ -15,11 +15,11 @@ etf.load( symbol: str, start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 8, 21, 35, 12, 215141, chart: bool = False, + 2019, 11, 8, 21, 47, 47, 956698, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 12, 21, 35, 12, 215148, chart: bool = False, + 2022, 11, 12, 21, 47, 47, 956708, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/portfolio/distr/_index.rst b/website/content/SDK/portfolio/distr/_index.rst index f04dceb8aa16..347b2a1fe538 100644 --- a/website/content/SDK/portfolio/distr/_index.rst +++ b/website/content/SDK/portfolio/distr/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.distr( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', chart: bool = False, ) @@ -28,8 +28,9 @@ portfolio.distr( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark chart: bool diff --git a/website/content/SDK/portfolio/dret/_index.rst b/website/content/SDK/portfolio/dret/_index.rst index 5962ce46d403..8e162b9974fd 100644 --- a/website/content/SDK/portfolio/dret/_index.rst +++ b/website/content/SDK/portfolio/dret/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.dret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -28,8 +28,9 @@ portfolio.dret( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark chart: bool @@ -69,7 +70,8 @@ portfolio.dret( * **Parameters** portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark raw : False diff --git a/website/content/SDK/portfolio/es/_index.rst b/website/content/SDK/portfolio/es/_index.rst index 7fcf73688763..dd6d8c2148d2 100644 --- a/website/content/SDK/portfolio/es/_index.rst +++ b/website/content/SDK/portfolio/es/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.es( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, use_mean: bool = False, distribution: str = 'normal', percentile: float = 99.9, @@ -28,8 +28,9 @@ portfolio.es( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. use_mean: if one should use the data mean return distribution: str diff --git a/website/content/SDK/portfolio/holdp/_index.rst b/website/content/SDK/portfolio/holdp/_index.rst index 7830e39ab6d3..4c0b949bed58 100644 --- a/website/content/SDK/portfolio/holdp/_index.rst +++ b/website/content/SDK/portfolio/holdp/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.holdp( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} @@ -27,8 +27,9 @@ portfolio.holdp( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. chart: bool Flag to display chart @@ -62,7 +63,8 @@ portfolio.holdp( * **Parameters** portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. unstack: bool Individual assets over time raw : bool diff --git a/website/content/SDK/portfolio/holdv/_index.rst b/website/content/SDK/portfolio/holdv/_index.rst index c0ef1b396fac..82d1377006a8 100644 --- a/website/content/SDK/portfolio/holdv/_index.rst +++ b/website/content/SDK/portfolio/holdv/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.holdv( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -27,8 +27,9 @@ portfolio.holdv( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. chart: bool Flag to display chart @@ -67,7 +68,8 @@ portfolio.holdv( * **Parameters** portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. unstack: bool Individual assets over time raw : bool diff --git a/website/content/SDK/portfolio/maxdd/_index.rst b/website/content/SDK/portfolio/maxdd/_index.rst index f8c76bd1910d..ecebf137cd92 100644 --- a/website/content/SDK/portfolio/maxdd/_index.rst +++ b/website/content/SDK/portfolio/maxdd/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.maxdd( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, is_returns: bool = False, chart: bool = False, ) -> pandas.core.series.Series diff --git a/website/content/SDK/portfolio/metric/_index.md b/website/content/SDK/portfolio/metric/_index.md new file mode 100644 index 000000000000..d55ad10c586f --- /dev/null +++ b/website/content/SDK/portfolio/metric/_index.md @@ -0,0 +1,6 @@ +--- +title: metric +keywords: "" +excerpt: "" +geekdocCollapseSection: true +--- diff --git a/website/content/SDK/portfolio/metric/calmar/_index.rst b/website/content/SDK/portfolio/metric/calmar/_index.rst index be795db4ccae..a351bf066943 100644 --- a/website/content/SDK/portfolio/metric/calmar/_index.rst +++ b/website/content/SDK/portfolio/metric/calmar/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.calmar( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: int = 756, chart: bool = False, ) @@ -26,8 +26,9 @@ portfolio.metric.calmar( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window: int Interval used for rolling values diff --git a/website/content/SDK/portfolio/metric/commonsense/_index.rst b/website/content/SDK/portfolio/metric/commonsense/_index.rst index 8f57a74a71ce..61b2d3fe2c03 100644 --- a/website/content/SDK/portfolio/metric/commonsense/_index.rst +++ b/website/content/SDK/portfolio/metric/commonsense/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.commonsense( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} @@ -25,8 +25,9 @@ portfolio.metric.commonsense( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. * **Returns** diff --git a/website/content/SDK/portfolio/metric/gaintopain/_index.rst b/website/content/SDK/portfolio/metric/gaintopain/_index.rst index a17ffbf30fcb..ddbb5129a3b5 100644 --- a/website/content/SDK/portfolio/metric/gaintopain/_index.rst +++ b/website/content/SDK/portfolio/metric/gaintopain/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.gaintopain( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} @@ -25,8 +25,9 @@ portfolio.metric.gaintopain( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. * **Returns** diff --git a/website/content/SDK/portfolio/metric/information/_index.rst b/website/content/SDK/portfolio/metric/information/_index.rst index 621ec1fd3540..ad5af2ce67da 100644 --- a/website/content/SDK/portfolio/metric/information/_index.rst +++ b/website/content/SDK/portfolio/metric/information/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.information( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} @@ -25,8 +25,9 @@ portfolio.metric.information( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. * **Returns** diff --git a/website/content/SDK/portfolio/metric/jensens/_index.rst b/website/content/SDK/portfolio/metric/jensens/_index.rst index cbad28c2a2b4..5d11bc657c31 100644 --- a/website/content/SDK/portfolio/metric/jensens/_index.rst +++ b/website/content/SDK/portfolio/metric/jensens/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.jensens( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, window: str = '1y', chart: bool = False, @@ -27,8 +27,9 @@ portfolio.metric.jensens( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window: str Interval used for rolling values risk_free_rate: float diff --git a/website/content/SDK/portfolio/metric/kelly/_index.rst b/website/content/SDK/portfolio/metric/kelly/_index.rst index b5e63bb52562..94be15e87605 100644 --- a/website/content/SDK/portfolio/metric/kelly/_index.rst +++ b/website/content/SDK/portfolio/metric/kelly/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.kelly( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} @@ -25,8 +25,9 @@ portfolio.metric.kelly( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. * **Returns** diff --git a/website/content/SDK/portfolio/metric/kurtosis/_index.rst b/website/content/SDK/portfolio/metric/kurtosis/_index.rst index 9e2a939a00ec..6334d42d1be4 100644 --- a/website/content/SDK/portfolio/metric/kurtosis/_index.rst +++ b/website/content/SDK/portfolio/metric/kurtosis/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.kurtosis( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -25,8 +25,9 @@ portfolio.metric.kurtosis( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. * **Returns** diff --git a/website/content/SDK/portfolio/metric/maxdrawdown/_index.rst b/website/content/SDK/portfolio/metric/maxdrawdown/_index.rst index 8d20e10df5a1..29f22c33bdad 100644 --- a/website/content/SDK/portfolio/metric/maxdrawdown/_index.rst +++ b/website/content/SDK/portfolio/metric/maxdrawdown/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.maxdrawdown( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -25,8 +25,9 @@ portfolio.metric.maxdrawdown( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. * **Returns** diff --git a/website/content/SDK/portfolio/metric/payoff/_index.rst b/website/content/SDK/portfolio/metric/payoff/_index.rst index 862532ea4077..152562416b86 100644 --- a/website/content/SDK/portfolio/metric/payoff/_index.rst +++ b/website/content/SDK/portfolio/metric/payoff/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.payoff( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/profitfactor/_index.rst b/website/content/SDK/portfolio/metric/profitfactor/_index.rst index 6354dd3a8b1b..42b8581a1181 100644 --- a/website/content/SDK/portfolio/metric/profitfactor/_index.rst +++ b/website/content/SDK/portfolio/metric/profitfactor/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.profitfactor( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) {{< /highlight >}} @@ -25,8 +25,9 @@ portfolio.metric.profitfactor( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. * **Returns** diff --git a/website/content/SDK/portfolio/metric/rsquare/_index.rst b/website/content/SDK/portfolio/metric/rsquare/_index.rst index e86acdfad18a..7d1985ad3375 100644 --- a/website/content/SDK/portfolio/metric/rsquare/_index.rst +++ b/website/content/SDK/portfolio/metric/rsquare/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.rsquare( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -25,8 +25,9 @@ portfolio.metric.rsquare( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. * **Returns** diff --git a/website/content/SDK/portfolio/metric/sharpe/_index.rst b/website/content/SDK/portfolio/metric/sharpe/_index.rst index 0834ee390457..ca761c6464a4 100644 --- a/website/content/SDK/portfolio/metric/sharpe/_index.rst +++ b/website/content/SDK/portfolio/metric/sharpe/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.sharpe( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -26,8 +26,9 @@ portfolio.metric.sharpe( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. risk_free_rate: float Risk free rate value diff --git a/website/content/SDK/portfolio/metric/skew/_index.rst b/website/content/SDK/portfolio/metric/skew/_index.rst index c2a08bcb569f..875adc59df24 100644 --- a/website/content/SDK/portfolio/metric/skew/_index.rst +++ b/website/content/SDK/portfolio/metric/skew/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.skew( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -22,8 +22,9 @@ portfolio.metric.skew(

Method that retrieves skewness for portfolio and benchmark selected - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. Returns ------- diff --git a/website/content/SDK/portfolio/metric/sortino/_index.rst b/website/content/SDK/portfolio/metric/sortino/_index.rst index 51f2bd51a7c0..334054bf9104 100644 --- a/website/content/SDK/portfolio/metric/sortino/_index.rst +++ b/website/content/SDK/portfolio/metric/sortino/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.sortino( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -26,8 +26,9 @@ portfolio.metric.sortino( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. risk_free_rate: float Risk free rate value diff --git a/website/content/SDK/portfolio/metric/tail/_index.rst b/website/content/SDK/portfolio/metric/tail/_index.rst index deeacde22acc..3c2ae9e7d4a1 100644 --- a/website/content/SDK/portfolio/metric/tail/_index.rst +++ b/website/content/SDK/portfolio/metric/tail/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.tail( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: int = 252, chart: bool = False, ) @@ -26,8 +26,9 @@ portfolio.metric.tail( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window: int Interval used for rolling values diff --git a/website/content/SDK/portfolio/metric/trackerr/_index.rst b/website/content/SDK/portfolio/metric/trackerr/_index.rst index 6b60beb774ed..3a09a70a6080 100644 --- a/website/content/SDK/portfolio/metric/trackerr/_index.rst +++ b/website/content/SDK/portfolio/metric/trackerr/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.trackerr( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: int = 252, chart: bool = False, ) @@ -26,8 +26,9 @@ portfolio.metric.trackerr( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window: int Interval used for rolling values diff --git a/website/content/SDK/portfolio/metric/volatility/_index.rst b/website/content/SDK/portfolio/metric/volatility/_index.rst index da872368dd9e..f0e7d01905d3 100644 --- a/website/content/SDK/portfolio/metric/volatility/_index.rst +++ b/website/content/SDK/portfolio/metric/volatility/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.metric.volatility( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -25,8 +25,9 @@ portfolio.metric.volatility( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. * **Returns** diff --git a/website/content/SDK/portfolio/mret/_index.rst b/website/content/SDK/portfolio/mret/_index.rst index ae259ad6151a..43ee27aa5b6f 100644 --- a/website/content/SDK/portfolio/mret/_index.rst +++ b/website/content/SDK/portfolio/mret/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.mret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -28,8 +28,9 @@ portfolio.mret( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark chart: bool @@ -69,7 +70,8 @@ portfolio.mret( * **Parameters** portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark raw : False diff --git a/website/content/SDK/portfolio/om/_index.rst b/website/content/SDK/portfolio/om/_index.rst index ec1f05eac73d..9dae23cd07cd 100644 --- a/website/content/SDK/portfolio/om/_index.rst +++ b/website/content/SDK/portfolio/om/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.om( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, threshold_start: float = 0, threshold_end: float = 1.5, chart: bool = False, @@ -29,8 +29,9 @@ portfolio.om( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. threshold_start: float annualized target return threshold start of plotted threshold range threshold_end: float @@ -69,7 +70,8 @@ portfolio.om( * **Parameters** portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. threshold_start: float annualized target return threshold start of plotted threshold range threshold_end: float diff --git a/website/content/SDK/portfolio/perf/_index.rst b/website/content/SDK/portfolio/perf/_index.rst index b29538fd440e..a514d97be180 100644 --- a/website/content/SDK/portfolio/perf/_index.rst +++ b/website/content/SDK/portfolio/perf/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.perf( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, show_all_trades: bool = False, chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -26,8 +26,9 @@ portfolio.perf( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. show_all_trades: bool Whether to also show all trades made and their performance (default is False) diff --git a/website/content/SDK/portfolio/rbeta/_index.rst b/website/content/SDK/portfolio/rbeta/_index.rst index 15de83068e6d..638bc5ec3857 100644 --- a/website/content/SDK/portfolio/rbeta/_index.rst +++ b/website/content/SDK/portfolio/rbeta/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.rbeta( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = '1y', chart: bool = False, ) -> pandas.core.frame.DataFrame diff --git a/website/content/SDK/portfolio/rsharpe/_index.rst b/website/content/SDK/portfolio/rsharpe/_index.rst index 42c55143be4f..9af51bbc5e6d 100644 --- a/website/content/SDK/portfolio/rsharpe/_index.rst +++ b/website/content/SDK/portfolio/rsharpe/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.rsharpe( - portfolio: pandas.core.frame.DataFrame, + portfolio_engine: pandas.core.frame.DataFrame, risk_free_rate: float = 0, window: str = '1y', chart: bool = False, diff --git a/website/content/SDK/portfolio/rsort/_index.rst b/website/content/SDK/portfolio/rsort/_index.rst index 43f5ba1474c6..a0d39ab2c79b 100644 --- a/website/content/SDK/portfolio/rsort/_index.rst +++ b/website/content/SDK/portfolio/rsort/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.rsort( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, risk_free_rate: float = 0, window: str = '1y', chart: bool = False, diff --git a/website/content/SDK/portfolio/rvol/_index.rst b/website/content/SDK/portfolio/rvol/_index.rst index afe4689618d7..4cf42ae0d230 100644 --- a/website/content/SDK/portfolio/rvol/_index.rst +++ b/website/content/SDK/portfolio/rvol/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.rvol( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = '1y', chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -28,8 +28,9 @@ portfolio.rvol( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str Rolling window size to use Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y diff --git a/website/content/SDK/portfolio/summary/_index.rst b/website/content/SDK/portfolio/summary/_index.rst index 8c2c66fe5178..2a0ed9feb17e 100644 --- a/website/content/SDK/portfolio/summary/_index.rst +++ b/website/content/SDK/portfolio/summary/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.summary( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', risk_free_rate: float = 0, chart: bool = False, @@ -27,8 +27,9 @@ portfolio.summary( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark risk_free_rate : float diff --git a/website/content/SDK/portfolio/var/_index.rst b/website/content/SDK/portfolio/var/_index.rst index 38418525e2db..0e2d971efc24 100644 --- a/website/content/SDK/portfolio/var/_index.rst +++ b/website/content/SDK/portfolio/var/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} portfolio.var( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, use_mean: bool = False, adjusted_var: bool = False, student_t: bool = False, @@ -29,8 +29,9 @@ portfolio.var( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. use_mean: bool if one should use the data mean return adjusted_var: bool diff --git a/website/content/SDK/portfolio/yret/_index.rst b/website/content/SDK/portfolio/yret/_index.rst index e083ca9f0cad..2e09073ba4a4 100644 --- a/website/content/SDK/portfolio/yret/_index.rst +++ b/website/content/SDK/portfolio/yret/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} portfolio.yret( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', chart: bool = False, ) @@ -28,8 +28,9 @@ portfolio.yret( * **Parameters** - portfolio: PortfolioEngine - PortfolioEngine object with trades loaded + portfolio_engine: PortfolioEngine + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark chart: bool @@ -64,7 +65,8 @@ portfolio.yret( * **Parameters** portfolio_engine: PortfolioEngine - PortfolioEngine object with trades loaded + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark raw : False diff --git a/website/content/SDK/stocks/ba/trend/_index.rst b/website/content/SDK/stocks/ba/trend/_index.rst index b4213027e8ca..98d4f29b32ba 100644 --- a/website/content/SDK/stocks/ba/trend/_index.rst +++ b/website/content/SDK/stocks/ba/trend/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ba.trend( start_date: datetime.datetime = datetime.datetime( - 2022, 11, 12, 21, 35, 11, 689469, chart: bool = False, + 2022, 11, 12, 21, 47, 47, 374237, chart: bool = False, ), hour: int = 0, number: int = 10, chart: bool = False, @@ -60,7 +60,7 @@ stocks.ba.trend( {{< highlight python >}} stocks.ba.trend( start_date: datetime.datetime = datetime.datetime( - 2022, 11, 12, 21, 35, 11, 689630, chart: bool = False, + 2022, 11, 12, 21, 47, 47, 374405, chart: bool = False, ), hour: int = 0, number: int = 10, limit: int = 10, diff --git a/website/content/SDK/stocks/candle/_index.rst b/website/content/SDK/stocks/candle/_index.rst index a5c7a729e6d3..c7713319b147 100644 --- a/website/content/SDK/stocks/candle/_index.rst +++ b/website/content/SDK/stocks/candle/_index.rst @@ -21,11 +21,11 @@ stocks.candle( asset_type: str = '', start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 8, 21, 35, 12, 215151, chart: bool = False, + 2019, 11, 8, 21, 47, 47, 956712, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 12, 21, 35, 12, 215152, chart: bool = False, + 2022, 11, 12, 21, 47, 47, 956713, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/stocks/load/_index.rst b/website/content/SDK/stocks/load/_index.rst index efdf981be502..53db730c991d 100644 --- a/website/content/SDK/stocks/load/_index.rst +++ b/website/content/SDK/stocks/load/_index.rst @@ -15,11 +15,11 @@ stocks.load( symbol: str, start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 8, 21, 35, 12, 215141, chart: bool = False, + 2019, 11, 8, 21, 47, 47, 956698, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 12, 21, 35, 12, 215148, chart: bool = False, + 2022, 11, 12, 21, 47, 47, 956708, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/data/menu/main.yml b/website/data/menu/main.yml index ef3ad06a0deb..9c083b34dc0c 100644 --- a/website/data/menu/main.yml +++ b/website/data/menu/main.yml @@ -2483,6 +2483,8 @@ main: - name: portfolio ref: /SDK/portfolio sub: + - name: bench + ref: /SDK/portfolio/bench - name: calmar ref: /SDK/portfolio/calmar - name: commonsense @@ -2507,12 +2509,51 @@ main: ref: /SDK/portfolio/kelly - name: kurtosis ref: /SDK/portfolio/kurtosis + - name: load + ref: /SDK/portfolio/load - name: max_drawdown_ratio ref: /SDK/portfolio/max_drawdown_ratio - name: maxdd ref: /SDK/portfolio/maxdd - name: maxdrawdown ref: /SDK/portfolio/maxdrawdown + - name: metric + ref: /SDK/portfolio/metric + sub: + - name: calmar + ref: /SDK/portfolio/metric/calmar + - name: commonsense + ref: /SDK/portfolio/metric/commonsense + - name: gaintopain + ref: /SDK/portfolio/metric/gaintopain + - name: information + ref: /SDK/portfolio/metric/information + - name: jensens + ref: /SDK/portfolio/metric/jensens + - name: kelly + ref: /SDK/portfolio/metric/kelly + - name: kurtosis + ref: /SDK/portfolio/metric/kurtosis + - name: maxdrawdown + ref: /SDK/portfolio/metric/maxdrawdown + - name: payoff + ref: /SDK/portfolio/metric/payoff + - name: profitfactor + ref: /SDK/portfolio/metric/profitfactor + - name: rsquare + ref: /SDK/portfolio/metric/rsquare + - name: sharpe + ref: /SDK/portfolio/metric/sharpe + - name: skew + ref: /SDK/portfolio/metric/skew + - name: sortino + ref: /SDK/portfolio/metric/sortino + - name: tail + ref: /SDK/portfolio/metric/tail + - name: trackerr + ref: /SDK/portfolio/metric/trackerr + - name: volatility + ref: /SDK/portfolio/metric/volatility - name: mret ref: /SDK/portfolio/mret - name: om @@ -2572,6 +2613,8 @@ main: ref: /SDK/portfolio/rbeta - name: rsharpe ref: /SDK/portfolio/rsharpe + - name: rsort + ref: /SDK/portfolio/rsort - name: rsortino ref: /SDK/portfolio/rsortino - name: rsquare @@ -2580,6 +2623,8 @@ main: ref: /SDK/portfolio/rvol - name: sharpe ref: /SDK/portfolio/sharpe + - name: show + ref: /SDK/portfolio/show - name: skew ref: /SDK/portfolio/skew - name: sortino From 46a703194aaf78fa419f77fcd0b8a9b3840b9adc Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 22:04:49 +0000 Subject: [PATCH 13/30] fix metrics bugs --- openbb_terminal/portfolio/portfolio_helper.py | 10 +++++----- website/content/terminal/portfolio/perf/_index.md | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_helper.py b/openbb_terminal/portfolio/portfolio_helper.py index cf76687668f6..45bdaf8c9164 100644 --- a/openbb_terminal/portfolio/portfolio_helper.py +++ b/openbb_terminal/portfolio/portfolio_helper.py @@ -1046,7 +1046,7 @@ def get_kelly_criterion( if (not period_return.empty) and (not period_portfolio_tr.empty): w = len(period_return[period_return > 0]) / len(period_return) r = len( - period_portfolio_tr[period_portfolio_tr["% Portfolio Return"] > 0] + period_portfolio_tr[period_portfolio_tr["Portfolio % Return"] > 0] ) / len( period_portfolio_tr[period_portfolio_tr["Type"].str.upper() != "CASH"] ) @@ -1086,10 +1086,10 @@ def get_payoff_ratio(portfolio_trades: pd.DataFrame) -> pd.DataFrame: period_portfolio_tr = filter_df_by_period(portfolio_trades, period) if not portfolio_trades.empty: portfolio_wins = period_portfolio_tr[ - period_portfolio_tr["% Portfolio Return"] > 0 + period_portfolio_tr["Portfolio % Return"] > 0 ] portfolio_loses = period_portfolio_tr[ - period_portfolio_tr["% Portfolio Return"] < 0 + period_portfolio_tr["Portfolio % Return"] < 0 ] if portfolio_loses.empty: vals.append(["-"]) @@ -1140,10 +1140,10 @@ def get_profit_factor(portfolio_trades: pd.DataFrame) -> pd.DataFrame: period_portfolio_tr = filter_df_by_period(portfolio_trades, period) if not portfolio_trades.empty: portfolio_wins = period_portfolio_tr[ - period_portfolio_tr["% Portfolio Return"] > 0 + period_portfolio_tr["Portfolio % Return"] > 0 ] portfolio_loses = period_portfolio_tr[ - period_portfolio_tr["% Portfolio Return"] < 0 + period_portfolio_tr["Portfolio % Return"] < 0 ] if portfolio_loses.empty: vals.append(["-"]) diff --git a/website/content/terminal/portfolio/perf/_index.md b/website/content/terminal/portfolio/perf/_index.md index 393aaf160b36..02e32475d840 100644 --- a/website/content/terminal/portfolio/perf/_index.md +++ b/website/content/terminal/portfolio/perf/_index.md @@ -29,7 +29,7 @@ Example: Portfolio vs. Benchmark - Individual Trades ┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓ -┃ Date ┃ Name ┃ Portfolio Value ┃ % Portfolio Return ┃ Benchmark Value ┃ % Benchmark Return ┃ Alpha ┃ +┃ Date ┃ Name ┃ Portfolio Value ┃ Portfolio % Return ┃ Benchmark Value ┃ % Benchmark Return ┃ Alpha ┃ ┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩ │ 2010-05-03 00:00:00 │ CASH │ 0.00e+00 │ 0.00e+00 │ 0.00e+00 │ 0.00e+00 │ 0.00e+00 │ ├─────────────────────┼───────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼──────────┤ From 8fa7caed4e3bbe30c4bf2a6d6eab4958842f35b3 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 22:17:11 +0000 Subject: [PATCH 14/30] fix report --- .../reports/templates/portfolio.ipynb | 442 ++++++++++++++++-- 1 file changed, 396 insertions(+), 46 deletions(-) diff --git a/openbb_terminal/reports/templates/portfolio.ipynb b/openbb_terminal/reports/templates/portfolio.ipynb index ebd7cddf07e6..213418e1c234 100644 --- a/openbb_terminal/reports/templates/portfolio.ipynb +++ b/openbb_terminal/reports/templates/portfolio.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "driven-billion", "metadata": {}, "outputs": [], @@ -35,8 +35,7 @@ "\n", "from openbb_terminal.reports import widget_helpers as widgets\n", "from openbb_terminal.sdk import openbb\n", - "from openbb_terminal.sdk import openbb import helper\n", - "from openbb_terminal.sdk import openbb import Portfolio\n", + "from openbb_terminal.sdk import helper\n", "from openbb_terminal.helper_classes import TerminalStyle\n", "from openbb_terminal.core.config.paths import REPOSITORY_DIRECTORY\n", "\n", @@ -67,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "c3fe7db5-ec6a-42cf-9e66-52dc1de22370", "metadata": {}, "outputs": [], @@ -79,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "daef64ec", "metadata": { "tags": [ @@ -96,10 +95,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "1be26dae-cafe-4a22-80aa-eff296fc1a9b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "('Portfolio report for Public_Equity_Orderbook.xlsx',\n", + " '12 November, 2022',\n", + " '17:09',\n", + " )" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "holdings = (\n", " str(REPOSITORY_DIRECTORY)\n", @@ -132,17 +145,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "b139556d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Preprocessing transactions: 100%|██████████| 14/14 [00:02<00:00, 6.24it/s] \n", + " Loading price data: 100%|██████████| 1/1 [00:00<00:00, 1.98it/s]\n", + " Calculating returns: 100%|██████████| 1/1 [00:00<00:00, 51.80it/s]\n", + " Loading benchmark: 100%|██████████| 4/4 [00:04<00:00, 1.21s/it]\n" + ] + } + ], "source": [ "try:\n", - " transactions = Portfolio.read_transactions(transactions_path)\n", - " P = Portfolio(transactions)\n", - " P.generate_portfolio_data()\n", - " P.set_benchmark()\n", - " P.get_transactions()\n", + " P = openbb.portfolio.load(transactions_path)\n", + " openbb.portfolio.show(P)\n", + " # transactions = Portfolio.read_transactions(transactions_path)\n", + " # P = Portfolio(transactions)\n", + " # P.generate_portfolio_data()\n", + " # P.set_benchmark()\n", + " # P.get_transactions()\n", "except ValueError:\n", " raise ValueError(\n", " \"Failed to load the transactions. Is this file inside the 'holdings' folder?\"\n", @@ -151,10 +177,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "af24ed22", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:09:58.445267\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", + "text/plain": [ + "

" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "fig, ax = plt.subplots(figsize=(11, 5), dpi=150)\n", "openbb.portfolio.rbeta(P, chart=True, external_axes=[ax])\n", @@ -167,10 +204,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "636c743d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:09:59.229112\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "fig, ax = plt.subplots(figsize=(11, 5), dpi=150)\n", "openbb.portfolio.rsharpe(P, chart=True, external_axes=[ax])\n", @@ -183,10 +231,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "ae0d9381", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:09:59.406325\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "fig, ax = plt.subplots(figsize=(11, 5), dpi=150)\n", "openbb.portfolio.rvol(P, chart=True, external_axes=[ax])\n", @@ -199,10 +258,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "id": "7e5e6fff", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:10:00.720201\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "fig, ax = plt.subplots(figsize=(11, 5), dpi=150)\n", "openbb.portfolio.rsort(P, chart=True, external_axes=[ax])\n", @@ -215,10 +285,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "3567b0ca", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:10:00.974412\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "fig, ax = plt.subplots(nrows=2, ncols=1, figsize=(11, 5), dpi=150)\n", "openbb.portfolio.maxdd(P, chart=True, external_axes=ax)\n", @@ -231,10 +312,119 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "5dbcc1eb", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Loading country/region data: 100%|██████████| 3/3 [00:00<00:00, 362.76it/s]" + ] + }, + { + "data": { + "text/html": [ + "
\n",
+       "\n",
+       "
\n" + ], + "text/plain": [ + "\n", + "\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PortfolioBenchmark
Netherlands42.6%0.12%
United States32.3%99.0%
Taiwan12.5%---%
China7.55%---%
Germany5.05%---%
United Kingdom---%0.53%
Switzerland---%0.37%
Singapore---%0.03%
\n", + "
" + ], + "text/plain": [ + " Portfolio Benchmark\n", + "Netherlands 42.6% 0.12%\n", + "United States 32.3% 99.0%\n", + "Taiwan 12.5% ---%\n", + "China 7.55% ---%\n", + "Germany 5.05% ---%\n", + "United Kingdom ---% 0.53%\n", + "Switzerland ---% 0.37%\n", + "Singapore ---% 0.03%" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "P.calculate_allocations(\"country\")\n", "\n", @@ -255,10 +445,137 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "8e1a67a6", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Loading sector data: 100%|██████████| 3/3 [00:00<00:00, 514.74it/s]" + ] + }, + { + "data": { + "text/html": [ + "
\n",
+       "\n",
+       "
\n" + ], + "text/plain": [ + "\n", + "\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PortfolioBenchmark
Technology62.2%23.6%
Consumer Cyclical25.4%10.6%
Healthcare11.2%15.4%
Communication Services1.27%7.35%
Financial Services---%13.7%
Industrials---%8.68%
Consumer Defensive---%7.38%
Energy---%5.36%
Realestate---%2.74%
Utilities---%2.45%
Basic Materials---%2.27%
\n", + "
" + ], + "text/plain": [ + " Portfolio Benchmark\n", + "Technology 62.2% 23.6%\n", + "Consumer Cyclical 25.4% 10.6%\n", + "Healthcare 11.2% 15.4%\n", + "Communication Services 1.27% 7.35%\n", + "Financial Services ---% 13.7%\n", + "Industrials ---% 8.68%\n", + "Consumer Defensive ---% 7.38%\n", + "Energy ---% 5.36%\n", + "Realestate ---% 2.74%\n", + "Utilities ---% 2.45%\n", + "Basic Materials ---% 2.27%" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "P.calculate_allocations(\"sector\")\n", "\n", @@ -279,10 +596,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "6e1260b4", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:10:02.580188\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "fig, ax = plt.subplots(figsize=(10, 4), dpi=150)\n", "openbb.portfolio.distr(P, chart=True, external_axes=[ax])\n", @@ -295,10 +623,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "a668a58b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:10:02.837335\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(10, 4), dpi=150)\n", "openbb.portfolio.dret(P, chart=True, external_axes=[ax1, ax2])\n", @@ -311,10 +650,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "1ea71ca6", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:10:03.060634\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "fig, ax = plt.subplots(figsize=(10, 4), dpi=150)\n", "openbb.portfolio.yret(P, chart=True, external_axes=[ax])\n", @@ -335,7 +685,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "ebe0799e", "metadata": {}, "outputs": [], @@ -413,24 +763,24 @@ ")\n", "\n", "htmlcode += widgets.row(\n", - " [widgets.h(3, \"Tracking Error\") + openbb.portfolio.trackerr(P)[0].to_html()]\n", + " [widgets.h(3, \"Tracking Error\") + openbb.portfolio.metric.trackerr(P)[0].to_html()]\n", ")\n", "htmlcode += widgets.row(\n", - " [widgets.h(3, \"Information Ratio\") + openbb.portfolio.information(P).to_html()]\n", + " [widgets.h(3, \"Information Ratio\") + openbb.portfolio.metric.information(P).to_html()]\n", ")\n", "\n", "htmlcode += widgets.row([widgets.h(3, \"Beta Chart\") + beta_chart])\n", "\n", "htmlcode += widgets.row(\n", - " [widgets.h(3, \"Sharpe Ratio\") + openbb.portfolio.sharpe(P).to_html()]\n", + " [widgets.h(3, \"Sharpe Ratio\") + openbb.portfolio.metric.sharpe(P).to_html()]\n", ")\n", "htmlcode += widgets.row([widgets.h(3, \"Sharpe Ratio Chart\") + sharpe_chart])\n", "htmlcode += widgets.row(\n", - " [widgets.h(3, \"Volatility\") + openbb.portfolio.volatility(P).to_html()]\n", + " [widgets.h(3, \"Volatility\") + openbb.portfolio.metric.volatility(P).to_html()]\n", ")\n", "htmlcode += widgets.row([widgets.h(3, \"Volatility Chart\") + volatility_chart])\n", "htmlcode += widgets.row(\n", - " [widgets.h(3, \"Sortino Ratio\") + openbb.portfolio.sortino(P).to_html()]\n", + " [widgets.h(3, \"Sortino Ratio\") + openbb.portfolio.metric.sortino(P).to_html()]\n", ")\n", "htmlcode += widgets.row([widgets.h(3, \"Sortino Chart\") + sortino_chart])\n", "\n", @@ -443,12 +793,12 @@ "htmlcode = widgets.row([widgets.h(3, \"Distribution\") + distr_chart])\n", "htmlcode += widgets.row([widgets.h(3, \"Daily Returns\") + dret_chart])\n", "htmlcode += widgets.row(\n", - " [widgets.h(3, \"Volatility\") + openbb.portfolio.volatility(P).to_html()]\n", + " [widgets.h(3, \"Volatility\") + openbb.portfolio.metric.volatility(P).to_html()]\n", ")\n", "htmlcode += widgets.row(\n", - " [widgets.h(3, \"Kurtosis\") + openbb.portfolio.kurtosis(P).to_html()]\n", + " [widgets.h(3, \"Kurtosis\") + openbb.portfolio.metric.kurtosis(P).to_html()]\n", ")\n", - "htmlcode += widgets.row([widgets.h(3, \"Skew\") + openbb.portfolio.skew(P).to_html()])\n", + "htmlcode += widgets.row([widgets.h(3, \"Skew\") + openbb.portfolio.metric.skew(P).to_html()])\n", "htmlcode += widgets.row(\n", " [widgets.h(3, \"Value at Risk (VaR)\") + openbb.portfolio.var(P).to_html()]\n", ")\n", @@ -474,7 +824,7 @@ "metadata": { "celltoolbar": "Tags", "kernelspec": { - "display_name": "Python 3.10.4 ('obb')", + "display_name": "Python 3.9.13 ('obb')", "language": "python", "name": "python3" }, @@ -488,11 +838,11 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.4" + "version": "3.9.13" }, "vscode": { "interpreter": { - "hash": "1a8cc6b6e60740679b24fc1ea93bdeb94d949a22102a80c99b7fd3f0d572afd6" + "hash": "e784374cc4f9a84ed6af2983247aaf351b155c82bcc2188134a65f3c99031000" } } }, From ebd1ed38c1bc2239eb55f61ef528a7c2cf79522a Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sat, 12 Nov 2022 23:29:13 +0000 Subject: [PATCH 15/30] refactor assets alloc --- .../portfolio/portfolio_controller.py | 5 +-- openbb_terminal/portfolio/portfolio_model.py | 44 ++++++++++++++++++- openbb_terminal/portfolio/portfolio_view.py | 37 ++++++++-------- 3 files changed, 64 insertions(+), 22 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_controller.py b/openbb_terminal/portfolio/portfolio_controller.py index fd8333e25d32..8d45e258769e 100644 --- a/openbb_terminal/portfolio/portfolio_controller.py +++ b/openbb_terminal/portfolio/portfolio_controller.py @@ -583,10 +583,9 @@ def call_alloc(self, other_args: List[str]): if self.portfolio.portfolio_assets_allocation.empty: self.portfolio.calculate_allocations("asset") portfolio_view.display_assets_allocation( - self.portfolio.portfolio_assets_allocation, - self.portfolio.benchmark_assets_allocation, - ns_parser.limit, + self.portfolio, ns_parser.tables, + ns_parser.limit, ) elif ns_parser.agg == "sectors": if self.portfolio.portfolio_sectors_allocation.empty: diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 110693c88407..1c366029aa34 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -3,7 +3,7 @@ import contextlib import logging -from typing import Dict, Any +from typing import Dict, Any, Tuple, Union import datetime import numpy as np @@ -2128,6 +2128,7 @@ def get_daily_returns( return df +@log_start_end(log=logger) def generate_portfolio( transactions_file_path: str, benchmark_symbol: str = "SPY", @@ -2163,6 +2164,7 @@ def generate_portfolio( return portfolio_engine +@log_start_end(log=logger) def get_transactions(portfolio_engine: PortfolioEngine) -> pd.DataFrame: """Get portfolio transactions @@ -2180,6 +2182,7 @@ def get_transactions(portfolio_engine: PortfolioEngine) -> pd.DataFrame: return portfolio_engine.get_transactions() +@log_start_end(log=logger) def set_benchmark( portfolio_engine: PortfolioEngine, symbol: str, full_shares: bool = False ): @@ -2199,6 +2202,7 @@ def set_benchmark( portfolio_engine.set_benchmark(symbol=symbol, full_shares=full_shares) +@log_start_end(log=logger) def set_risk_free_rate(portfolio_engine: PortfolioEngine, risk_free_rate: float): """Set risk-free rate @@ -2213,6 +2217,44 @@ def set_risk_free_rate(portfolio_engine: PortfolioEngine, risk_free_rate: float) portfolio_engine.set_risk_free_rate(risk_free_rate=risk_free_rate) +@log_start_end(log=logger) +def get_assets_allocation( + portfolio_engine: PortfolioEngine, + include_separate_tables: bool = False, + limit: int = 10, +) -> Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]]: + """Display portfolio asset allocation compared to the benchmark + + Parameters + ---------- + portfolio_engine: PortfolioEngine + PortfolioEngine object + include_separate_tables: bool + Whether to include separate asset allocation tables + limit: int + The amount of assets you wish to show, by default this is set to 10. + + Returns + ------- + Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] + DataFrame with combined allocation plus individual allocation if include_separate_tables is `True`. + """ + + portfolio_allocation = portfolio_engine.portfolio_assets_allocation.iloc[:limit] + benchmark_allocation = portfolio_engine.benchmark_assets_allocation.iloc[:limit] + + combined = pd.merge( + portfolio_allocation, benchmark_allocation, on="Symbol", how="left" + ) + combined["Difference"] = combined["Portfolio"] - combined["Benchmark"] + combined = combined.replace(np.nan, "-") + combined = combined.replace(0, "-") + + if include_separate_tables: + return combined, portfolio_allocation, benchmark_allocation + return combined + + # Old code @log_start_end(log=logger) def get_main_text(data: pd.DataFrame) -> str: diff --git a/openbb_terminal/portfolio/portfolio_view.py b/openbb_terminal/portfolio/portfolio_view.py index 7e38cd1d6b4f..90a381e14a8d 100644 --- a/openbb_terminal/portfolio/portfolio_view.py +++ b/openbb_terminal/portfolio/portfolio_view.py @@ -16,6 +16,7 @@ from openbb_terminal.config_plot import PLOT_DPI from openbb_terminal.portfolio.portfolio_model import ( PortfolioEngine, + get_assets_allocation, get_transactions, get_daily_returns, get_performance_vs_benchmark, @@ -137,34 +138,34 @@ def display_transactions( @log_start_end(log=logger) def display_assets_allocation( - portfolio_allocation: pd.DataFrame, - benchmark_allocation: pd.DataFrame, - limit: int = 10, + portfolio_engine=None, include_separate_tables: bool = False, + limit: int = 10, ): """Display portfolio asset allocation compared to the benchmark Parameters ---------- - portfolio_allocation: pd.DataFrame - The asset allocation of the portfolio - benchmark_allocation: pd.DataFrame - The asset allocation of the benchmark - limit: int - The amount of assets you wish to show, by default this is set to 10. + portfolio_engine: PortfolioEngine + Instance of PortfolioEngine class include_separate_tables: bool Whether to include separate asset allocation tables + limit: int + The amount of assets you wish to show, by default this is set to 10. """ - benchmark_allocation = benchmark_allocation.iloc[:limit] - portfolio_allocation = portfolio_allocation.iloc[:limit] - - combined = pd.merge( - portfolio_allocation, benchmark_allocation, on="Symbol", how="left" - ) - combined["Difference"] = combined["Portfolio"] - combined["Benchmark"] - combined = combined.replace(np.nan, "-") - combined = combined.replace(0, "-") + if include_separate_tables: + combined, portfolio_allocation, benchmark_allocation = get_assets_allocation( + portfolio_engine=portfolio_engine, + include_separate_tables=include_separate_tables, + limit=limit, + ) + else: + combined = get_assets_allocation( + portfolio_engine=portfolio_engine, + include_separate_tables=include_separate_tables, + limit=limit, + ) print_rich_table( combined, From e25ebb0b50fd0fe0025ba86a00be28778a96e1bf Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 13 Nov 2022 01:53:37 +0000 Subject: [PATCH 16/30] refactor assets sectors alloc --- .../miscellaneous/library/trail_map.csv | 4 + openbb_terminal/portfolio/allocation_model.py | 8 +- .../portfolio/portfolio_controller.py | 28 +-- openbb_terminal/portfolio/portfolio_model.py | 199 +++++++++++---- openbb_terminal/portfolio/portfolio_view.py | 237 +++++++++++------- 5 files changed, 303 insertions(+), 173 deletions(-) diff --git a/openbb_terminal/miscellaneous/library/trail_map.csv b/openbb_terminal/miscellaneous/library/trail_map.csv index 70e336c774b6..c8d61a1fcef9 100644 --- a/openbb_terminal/miscellaneous/library/trail_map.csv +++ b/openbb_terminal/miscellaneous/library/trail_map.csv @@ -310,6 +310,10 @@ portfolio.rsharpe,openbb_terminal.portfolio.portfolio_model.get_rolling_sharpe,o portfolio.rsort,openbb_terminal.portfolio.portfolio_model.get_rolling_sortino,openbb_terminal.portfolio.portfolio_view.display_rolling_sortino portfolio.rbeta,openbb_terminal.portfolio.portfolio_model.get_rolling_beta,openbb_terminal.portfolio.portfolio_view.display_rolling_beta portfolio.summary,openbb_terminal.portfolio.portfolio_model.get_summary, +portfolio.alloc.assets,openbb_terminal.portfolio.portfolio_model.get_assets_allocation, +portfolio.alloc.sectors,openbb_terminal.portfolio.portfolio_model.get_sectors_allocation, +portfolio.alloc.countries,openbb_terminal.portfolio.portfolio_model.get_countries_allocation, +portfolio.alloc.regions,openbb_terminal.portfolio.portfolio_model.get_regions_allocation, portfolio.metric.volatility,openbb_terminal.portfolio.portfolio_model.get_volatility, portfolio.metric.sharpe,openbb_terminal.portfolio.portfolio_model.get_sharpe_ratio, portfolio.metric.sortino,openbb_terminal.portfolio.portfolio_model.get_sortino_ratio, diff --git a/openbb_terminal/portfolio/allocation_model.py b/openbb_terminal/portfolio/allocation_model.py index c4f2616e7c9e..9dcb2c9dcacf 100644 --- a/openbb_terminal/portfolio/allocation_model.py +++ b/openbb_terminal/portfolio/allocation_model.py @@ -51,7 +51,7 @@ def get_assets_allocation(benchmark_info: Dict, portfolio_trades: pd.DataFrame): @log_start_end(log=logger) -def get_sector_allocation(benchmark_info: Dict, portfolio_trades: pd.DataFrame): +def get_sectors_allocation(benchmark_info: Dict, portfolio_trades: pd.DataFrame): """Obtain the sector allocation of the benchmark and portfolio [Source: Yahoo Finance] Parameters @@ -91,6 +91,9 @@ def get_sector_allocation(benchmark_info: Dict, portfolio_trades: pd.DataFrame): ] benchmark_sectors_allocation.index = prettified + benchmark_sectors_allocation = pd.DataFrame(benchmark_sectors_allocation) + benchmark_sectors_allocation.reset_index(inplace=True) + benchmark_sectors_allocation.columns = ["Sector", "Benchmark"] # Define portfolio sector allocation # Aggregate sector value for stocks and crypto @@ -182,6 +185,9 @@ def get_sector_allocation(benchmark_info: Dict, portfolio_trades: pd.DataFrame): ) portfolio_sectors_allocation.fillna(0, inplace=True) + portfolio_sectors_allocation = pd.DataFrame(portfolio_sectors_allocation) + portfolio_sectors_allocation.reset_index(inplace=True) + portfolio_sectors_allocation.columns = ["Sector", "Portfolio"] p_bar.n += 1 p_bar.refresh() diff --git a/openbb_terminal/portfolio/portfolio_controller.py b/openbb_terminal/portfolio/portfolio_controller.py index 8d45e258769e..9827ef110b93 100644 --- a/openbb_terminal/portfolio/portfolio_controller.py +++ b/openbb_terminal/portfolio/portfolio_controller.py @@ -580,40 +580,26 @@ def call_alloc(self, other_args: List[str]): self.portfolio_name, self.benchmark_name ): if ns_parser.agg == "assets": - if self.portfolio.portfolio_assets_allocation.empty: - self.portfolio.calculate_allocations("asset") portfolio_view.display_assets_allocation( self.portfolio, - ns_parser.tables, ns_parser.limit, + ns_parser.tables, ) elif ns_parser.agg == "sectors": - if self.portfolio.portfolio_sectors_allocation.empty: - self.portfolio.calculate_allocations("sector") - portfolio_view.display_category_allocation( - self.portfolio.portfolio_sectors_allocation, - self.portfolio.benchmark_sectors_allocation, - ns_parser.agg, + portfolio_view.display_sectors_allocation( + self.portfolio, ns_parser.limit, ns_parser.tables, ) elif ns_parser.agg == "countries": - if self.portfolio.portfolio_country_allocation.empty: - self.portfolio.calculate_allocations("country") - portfolio_view.display_category_allocation( - self.portfolio.portfolio_country_allocation, - self.portfolio.benchmark_country_allocation, - ns_parser.agg, + portfolio_view.display_countries_allocation( + self.portfolio, ns_parser.limit, ns_parser.tables, ) elif ns_parser.agg == "regions": - if self.portfolio.portfolio_region_allocation.empty: - self.portfolio.calculate_allocations("region") - portfolio_view.display_category_allocation( - self.portfolio.portfolio_region_allocation, - self.portfolio.benchmark_region_allocation, - ns_parser.agg, + portfolio_view.display_regions_allocation( + self.portfolio, ns_parser.limit, ns_parser.tables, ) diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 1c366029aa34..1729e3815736 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -55,8 +55,6 @@ class PortfolioEngine: set_risk_free_rate: Sets risk free rate calculate_reserves: Takes dividends into account for returns calculation - - calculate_allocations: Determine allocations based on assets, sectors, countries and region """ def __init__(self, transactions: pd.DataFrame = pd.DataFrame()): @@ -765,46 +763,6 @@ def calculate_reserves(self): # TODO: Add back cash dividends and deduct exchange costs console.print("Still has to be build.") - @log_start_end(log=logger) - def calculate_allocations(self, category: str): - """Determine allocations based on assets, sectors, countries and region. - - Parameters - ---------- - category: str - chosen allocation category from asset, sector, country or region - """ - - if category == "asset": - # Determine asset allocation - ( - self.benchmark_assets_allocation, - self.portfolio_assets_allocation, - ) = allocation_model.get_assets_allocation( - self.benchmark_info, self.portfolio_trades - ) - elif category == "sector": - # Determine sector allocation - ( - self.benchmark_sectors_allocation, - self.portfolio_sectors_allocation, - ) = allocation_model.get_sector_allocation( - self.benchmark_info, self.portfolio_trades - ) - elif category in ("country", "region"): - # Determine region and country allocations - ( - self.benchmark_region_allocation, - self.benchmark_country_allocation, - ) = allocation_model.get_region_country_allocation(self.benchmark_ticker) - - ( - self.portfolio_region_allocation, - self.portfolio_country_allocation, - ) = allocation_model.get_portfolio_region_country_allocation( - self.portfolio_trades - ) - # Metrics @log_start_end(log=logger) @@ -2217,10 +2175,37 @@ def set_risk_free_rate(portfolio_engine: PortfolioEngine, risk_free_rate: float) portfolio_engine.set_risk_free_rate(risk_free_rate=risk_free_rate) +def join_allocation( + portfolio: pd.DataFrame, benchmark: pd.DataFrame, column: str +) -> pd.DataFrame: + """Helper method to join portfolio and benchmark allocation by column + + Parameters + ---------- + portfolio: pd.DataFrame + Portfolio allocation + benchmark: pd.DataFrame + Benchmark allocation + column: str + Column to join DataFrames + + Returns + ------- + pd.DataFrame + DataFrame with portfolio and benchmark allocations + """ + combined = pd.merge(portfolio, benchmark, on=column, how="left") + combined["Difference"] = combined["Portfolio"] - combined["Benchmark"] + combined = combined.replace(np.nan, "-") + combined = combined.replace(0, "-") + + return combined + + @log_start_end(log=logger) def get_assets_allocation( portfolio_engine: PortfolioEngine, - include_separate_tables: bool = False, + tables: bool = False, limit: int = 10, ) -> Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]]: """Display portfolio asset allocation compared to the benchmark @@ -2229,32 +2214,138 @@ def get_assets_allocation( ---------- portfolio_engine: PortfolioEngine PortfolioEngine object - include_separate_tables: bool - Whether to include separate asset allocation tables + tables: bool + Whether to include separate allocation tables limit: int The amount of assets you wish to show, by default this is set to 10. Returns ------- Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] - DataFrame with combined allocation plus individual allocation if include_separate_tables is `True`. + DataFrame with combined allocation plus individual allocation if tables is `True`. """ - portfolio_allocation = portfolio_engine.portfolio_assets_allocation.iloc[:limit] - benchmark_allocation = portfolio_engine.benchmark_assets_allocation.iloc[:limit] + ( + benchmark_assets_allocation, + portfolio_assets_allocation, + ) = allocation_model.get_assets_allocation( + portfolio_engine.benchmark_info, portfolio_engine.portfolio_trades + ) + + benchmark_allocation = benchmark_assets_allocation.iloc[:limit] + portfolio_allocation = portfolio_assets_allocation.iloc[:limit] - combined = pd.merge( - portfolio_allocation, benchmark_allocation, on="Symbol", how="left" + combined = join_allocation( + portfolio_allocation, benchmark_allocation, "Symbol" ) - combined["Difference"] = combined["Portfolio"] - combined["Benchmark"] - combined = combined.replace(np.nan, "-") - combined = combined.replace(0, "-") - if include_separate_tables: + if tables: return combined, portfolio_allocation, benchmark_allocation return combined +def get_sectors_allocation( + portfolio_engine=None, + limit: int = 10, + tables: bool = False, +): + """Display portfolio sector allocation compared to the benchmark + + Parameters + ---------- + portfolio_engine: PortfolioEngine + PortfolioEngine object + tables: bool + Whether to include separate allocation tables + limit: int + The amount of assets you wish to show, by default this is set to 10. + + Returns + ------- + Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] + DataFrame with combined allocation plus individual allocation if tables is `True`. + """ + + ( + benchmark_sectors_allocation, + portfolio_sectors_allocation, + ) = allocation_model.get_sectors_allocation( + portfolio_engine.benchmark_info, portfolio_engine.portfolio_trades + ) + + benchmark_allocation = benchmark_sectors_allocation.iloc[:limit] + portfolio_allocation = portfolio_sectors_allocation.iloc[:limit] + + combined = join_allocation(portfolio_allocation, benchmark_allocation, "Sector") + + if tables: + return combined, portfolio_allocation, benchmark_allocation + return combined + + +def get_countries_allocation( + portfolio_engine=None, + limit: int = 10, + tables: bool = False, +): + """Display portfolio country allocation compared to the benchmark + + Parameters + ---------- + portfolio_engine: PortfolioEngine + PortfolioEngine object + tables: bool + Whether to include separate allocation tables + limit: int + The amount of assets you wish to show, by default this is set to 10. + + Returns + ------- + Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] + DataFrame with combined allocation plus individual allocation if tables is `True`. + """ + + ( + benchmark_region_allocation, + benchmark_country_allocation, + ) = allocation_model.get_region_country_allocation( + portfolio_engine.benchmark_ticker + ) + # Must return country (bench, portf) + + +def get_regions_allocation( + portfolio_engine=None, + limit: int = 10, + tables: bool = False, +): + """Display portfolio region allocation compared to the benchmark + + Parameters + ---------- + portfolio_engine: PortfolioEngine + PortfolioEngine object + tables: bool + Whether to include separate allocation tables + limit: int + The amount of assets you wish to show, by default this is set to 10. + + Returns + ------- + Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] + DataFrame with combined allocation plus individual allocation if tables is `True`. + """ + + ( + portfolio_region_allocation, + portfolio_country_allocation, + ) = allocation_model.get_portfolio_region_country_allocation( + portfolio_engine.portfolio_trades + ) + + # Must return region (bench, portf) + + # Old code @log_start_end(log=logger) def get_main_text(data: pd.DataFrame) -> str: diff --git a/openbb_terminal/portfolio/portfolio_view.py b/openbb_terminal/portfolio/portfolio_view.py index 90a381e14a8d..90033f3ab97c 100644 --- a/openbb_terminal/portfolio/portfolio_view.py +++ b/openbb_terminal/portfolio/portfolio_view.py @@ -16,7 +16,6 @@ from openbb_terminal.config_plot import PLOT_DPI from openbb_terminal.portfolio.portfolio_model import ( PortfolioEngine, - get_assets_allocation, get_transactions, get_daily_returns, get_performance_vs_benchmark, @@ -34,6 +33,10 @@ get_skewness, get_kurtosis, get_stats, + get_assets_allocation, + get_sectors_allocation, + get_countries_allocation, + get_regions_allocation, get_volatility, get_sharpe_ratio, get_sortino_ratio, @@ -139,8 +142,8 @@ def display_transactions( @log_start_end(log=logger) def display_assets_allocation( portfolio_engine=None, - include_separate_tables: bool = False, limit: int = 10, + tables: bool = False, ): """Display portfolio asset allocation compared to the benchmark @@ -148,141 +151,181 @@ def display_assets_allocation( ---------- portfolio_engine: PortfolioEngine Instance of PortfolioEngine class - include_separate_tables: bool + tables: bool Whether to include separate asset allocation tables limit: int The amount of assets you wish to show, by default this is set to 10. """ - if include_separate_tables: - combined, portfolio_allocation, benchmark_allocation = get_assets_allocation( - portfolio_engine=portfolio_engine, - include_separate_tables=include_separate_tables, - limit=limit, - ) - else: - combined = get_assets_allocation( - portfolio_engine=portfolio_engine, - include_separate_tables=include_separate_tables, - limit=limit, - ) + combined, portfolio_allocation, benchmark_allocation = get_assets_allocation( + portfolio_engine=portfolio_engine, + limit=limit, + tables=True, + ) - print_rich_table( - combined, - headers=list(combined.columns), - title=f"Portfolio vs. Benchmark - Top {len(combined) if len(combined) < limit else limit} Assets Allocation", - floatfmt=["", ".2%", ".2%", ".2%"], - show_index=False, + display_category( + category="assets", + df0=combined, + df1=portfolio_allocation, + df2=benchmark_allocation, + tables=tables, + limit=limit, ) - if include_separate_tables: - console.print("") - print_rich_table( - portfolio_allocation, - headers=list(portfolio_allocation.columns), - title=f"Portfolio - Top {len(portfolio_allocation) if len(benchmark_allocation) < limit else limit} " - f"Assets Allocation", - floatfmt=[".2%", ".2%"], - show_index=False, - ) - console.print("") - print_rich_table( - benchmark_allocation, - headers=list(benchmark_allocation.columns), - title=f"Benchmark - Top {len(benchmark_allocation) if len(benchmark_allocation) < limit else limit} " - f"Assets Allocation", - floatfmt=[".2%", ".2%"], - show_index=False, - ) + +@log_start_end(log=logger) +def display_sectors_allocation( + portfolio_engine=None, + limit: int = 10, + tables: bool = False, +): + """Display portfolio sector allocation compared to the benchmark + + Parameters + ---------- + portfolio_engine: PortfolioEngine + Instance of PortfolioEngine class + limit: int + The amount of assets you wish to show, by default this is set to 10. + tables: bool + Whether to include separate asset allocation tables + """ + + combined, portfolio_allocation, benchmark_allocation = get_sectors_allocation( + portfolio_engine=portfolio_engine, + limit=limit, + tables=True, + ) + + display_category( + category="sectors", + df0=combined, + df1=portfolio_allocation, + df2=benchmark_allocation, + tables=tables, + limit=limit, + ) @log_start_end(log=logger) -def display_category_allocation( - portfolio_allocation: pd.DataFrame, - benchmark_allocation: pd.DataFrame, - category: str = "sectors", +def display_countries_allocation( + portfolio_engine=None, limit: int = 10, - include_separate_tables: bool = False, + tables: bool = False, ): - """Display portfolio sector, country or region allocation compared to the benchmark + """Display portfolio country allocation compared to the benchmark Parameters ---------- - portfolio_allocation: pd.DataFrame - The allocation to the set category of the portfolio - benchmark_allocation: pd.DataFrame - The allocation to the set category of the benchmark - category: str - Whether you want to show sectors, countries or regions + portfolio_engine: PortfolioEngine + Instance of PortfolioEngine class limit: int The amount of assets you wish to show, by default this is set to 10. - include_separate_tables: bool + tables: bool Whether to include separate asset allocation tables """ - if benchmark_allocation.empty: - console.print(f"[red]Benchmark data for {category} is empty.\n[/red]") - return + combined, portfolio_allocation, benchmark_allocation = get_countries_allocation( + portfolio_engine=portfolio_engine, + limit=limit, + tables=True, + ) - if portfolio_allocation.empty: - console.print(f"[red]Portfolio data for {category} is empty.\n[/red]") - return + display_category( + category="countries", + df0=combined, + df1=portfolio_allocation, + df2=benchmark_allocation, + tables=tables, + limit=limit, + ) - benchmark_allocation = benchmark_allocation.iloc[:limit] - portfolio_allocation = portfolio_allocation.iloc[:limit] - combined = pd.DataFrame() +@log_start_end(log=logger) +def display_regions_allocation( + portfolio_engine=None, + limit: int = 10, + tables: bool = False, +): + """Display portfolio region allocation compared to the benchmark - for category_name, allocation in portfolio_allocation.items(): - if category_name in benchmark_allocation.index: - benchmark_allocation_value = float( - benchmark_allocation[benchmark_allocation.index == category_name] - ) - else: - benchmark_allocation_value = 0 - - combined = combined.append( - [ - [ - category_name, - allocation, - benchmark_allocation_value, - allocation - benchmark_allocation_value, - ] - ] - ) + Parameters + ---------- + portfolio_engine: PortfolioEngine + Instance of PortfolioEngine class + limit: int + The amount of assets you wish to show, by default this is set to 10. + tables: bool + Whether to include separate asset allocation tables + """ - combined.columns = [category.capitalize(), "Portfolio", "Benchmark", "Difference"] + combined, portfolio_allocation, benchmark_allocation = get_regions_allocation( + portfolio_engine=portfolio_engine, + limit=limit, + tables=True, + ) - print_rich_table( - combined.replace(0, "-"), - headers=list(combined.columns), - title=f"Portfolio vs. Benchmark - Top {len(combined) if len(combined) < limit else limit} " - f"{category.capitalize()} Allocation", - floatfmt=[".2f", ".2%", ".2%", ".2%"], - show_index=False, + display_category( + category="regions", + df0=combined, + df1=portfolio_allocation, + df2=benchmark_allocation, + tables=tables, + limit=limit, ) - if include_separate_tables: +def display_category(**kwargs): + """Display category tables + + Parameters + ---------- + **kwargs + """ + + category = kwargs["category"] + combined = kwargs["df0"] + portfolio_allocation = kwargs["df1"] + benchmark_allocation = kwargs["df2"] + tables = kwargs["tables"] + limit = kwargs["limit"] + + if tables: + print_rich_table( + combined.replace(0, "-"), + headers=list(combined.columns), + title=f"Portfolio vs. Benchmark - Top {len(combined) if len(combined) < limit else limit} " + f"{category.capitalize()} Allocation", + floatfmt=[".2f", ".2%", ".2%", ".2%"], + show_index=False, + ) + console.print("") print_rich_table( pd.DataFrame(portfolio_allocation), - headers=list(["Allocation"]), + headers=["Symbol", "Allocation"], title=f"Portfolio - Top {len(portfolio_allocation) if len(portfolio_allocation) < limit else limit} " f"{category.capitalize()} Allocation", - floatfmt=[".2%"], - show_index=True, + floatfmt=["", ".2%"], + show_index=False, ) - + console.print("") print_rich_table( pd.DataFrame(benchmark_allocation), - headers=list(["Allocation"]), + headers=["Symbol", "Allocation"], title=f"Benchmark - Top {len(benchmark_allocation) if len(benchmark_allocation) < limit else limit} " f"{category.capitalize()} Allocation", - floatfmt=[".2%"], - show_index=True, + floatfmt=["", ".2%"], + show_index=False, + ) + else: + print_rich_table( + combined.replace(0, "-"), + headers=list(combined.columns), + title=f"Portfolio vs. Benchmark - Top {len(combined) if len(combined) < limit else limit} " + f"{category.capitalize()} Allocation", + floatfmt=[".2f", ".2%", ".2%", ".2%"], + show_index=False, ) - console.print("\n") @log_start_end(log=logger) From 27caf2ddc48414ffaeff46b08e1c25f32fc0dd9e Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 13 Nov 2022 01:59:00 +0000 Subject: [PATCH 17/30] remove unecessary attributes --- openbb_terminal/portfolio/portfolio_model.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 1729e3815736..755fc8c4b69c 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -80,17 +80,6 @@ def __init__(self, transactions: pd.DataFrame = pd.DataFrame()): self.benchmark_returns = pd.DataFrame() self.benchmark_trades = pd.DataFrame() - # Allocations - self.portfolio_assets_allocation = pd.DataFrame() - self.portfolio_sectors_allocation = pd.DataFrame() - self.portfolio_region_allocation = pd.DataFrame() - self.portfolio_country_allocation = pd.DataFrame() - - self.benchmark_assets_allocation = pd.DataFrame() - self.benchmark_sectors_allocation = pd.DataFrame() - self.benchmark_region_allocation = pd.DataFrame() - self.benchmark_country_allocation = pd.DataFrame() - # Set and preprocess transactions if not transactions.empty: self.__set_transactions(transactions) @@ -2235,9 +2224,7 @@ def get_assets_allocation( benchmark_allocation = benchmark_assets_allocation.iloc[:limit] portfolio_allocation = portfolio_assets_allocation.iloc[:limit] - combined = join_allocation( - portfolio_allocation, benchmark_allocation, "Symbol" - ) + combined = join_allocation(portfolio_allocation, benchmark_allocation, "Symbol") if tables: return combined, portfolio_allocation, benchmark_allocation From 43fbe39c982ced80556111da1225119cec0aa8c1 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 13 Nov 2022 14:13:15 +0000 Subject: [PATCH 18/30] refactor allocaasset sector --- openbb_terminal/portfolio/portfolio_model.py | 144 ++++++++++++++----- 1 file changed, 110 insertions(+), 34 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 755fc8c4b69c..154422b3d83c 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -55,6 +55,8 @@ class PortfolioEngine: set_risk_free_rate: Sets risk free rate calculate_reserves: Takes dividends into account for returns calculation + + calculate_allocation: Determine allocation based on assets, sectors, countries and regions. """ def __init__(self, transactions: pd.DataFrame = pd.DataFrame()): @@ -80,6 +82,17 @@ def __init__(self, transactions: pd.DataFrame = pd.DataFrame()): self.benchmark_returns = pd.DataFrame() self.benchmark_trades = pd.DataFrame() + # Allocations + self.portfolio_assets_allocation = pd.DataFrame() + self.portfolio_sectors_allocation = pd.DataFrame() + self.portfolio_regions_allocation = pd.DataFrame() + self.portfolio_countries_allocation = pd.DataFrame() + + self.benchmark_assets_allocation = pd.DataFrame() + self.benchmark_sectors_allocation = pd.DataFrame() + self.benchmark_regions_allocation = pd.DataFrame() + self.benchmark_countries_allocation = pd.DataFrame() + # Set and preprocess transactions if not transactions.empty: self.__set_transactions(transactions) @@ -752,6 +765,62 @@ def calculate_reserves(self): # TODO: Add back cash dividends and deduct exchange costs console.print("Still has to be build.") + @log_start_end(log=logger) + def calculate_allocation(self, category: str, recalculate: bool = False): + """Determine allocation based on assets, sectors, countries and regions. + + Parameters + ---------- + category: str + Chosen allocation category from assets, sectors, countries or regions + recalculate: bool + Flag to force recalculate allocation if already exists + """ + + if category == "assets": + if ( + self.benchmark_assets_allocation.empty + or self.portfolio_assets_allocation.empty + or recalculate + ): + ( + self.benchmark_assets_allocation, + self.portfolio_assets_allocation, + ) = allocation_model.get_assets_allocation( + self.benchmark_info, self.portfolio_trades + ) + elif category == "sectors": + if ( + self.benchmark_sectors_allocation.empty + or self.portfolio_sectors_allocation.empty + or recalculate + ): + # Determine sector allocation + ( + self.benchmark_sectors_allocation, + self.portfolio_sectors_allocation, + ) = allocation_model.get_sectors_allocation( + self.benchmark_info, self.portfolio_trades + ) + elif category == "countries": + if ( + self.benchmark_countries_allocation.empty + or self.portfolio_countries_allocation.empty + or recalculate + ): + pass + elif category == "regions": + if ( + self.benchmark_regions_allocation.empty + or self.portfolio_regions_allocation.empty + or recalculate + ): + pass + else: + console.print( + "Category not available. Choose from: assets, sectors, countries or regions" + ) + # Metrics @log_start_end(log=logger) @@ -2196,6 +2265,7 @@ def get_assets_allocation( portfolio_engine: PortfolioEngine, tables: bool = False, limit: int = 10, + recalculate: bool = False, ) -> Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]]: """Display portfolio asset allocation compared to the benchmark @@ -2206,7 +2276,9 @@ def get_assets_allocation( tables: bool Whether to include separate allocation tables limit: int - The amount of assets you wish to show, by default this is set to 10. + The amount of assets you wish to show, by default this is set to 10 + recalculate: bool + Flag to force recalculate allocation if already exists Returns ------- @@ -2214,15 +2286,10 @@ def get_assets_allocation( DataFrame with combined allocation plus individual allocation if tables is `True`. """ - ( - benchmark_assets_allocation, - portfolio_assets_allocation, - ) = allocation_model.get_assets_allocation( - portfolio_engine.benchmark_info, portfolio_engine.portfolio_trades - ) + portfolio_engine.calculate_allocation(category="assets", recalculate=recalculate) - benchmark_allocation = benchmark_assets_allocation.iloc[:limit] - portfolio_allocation = portfolio_assets_allocation.iloc[:limit] + benchmark_allocation = portfolio_engine.benchmark_assets_allocation.iloc[:limit] + portfolio_allocation = portfolio_engine.portfolio_assets_allocation.iloc[:limit] combined = join_allocation(portfolio_allocation, benchmark_allocation, "Symbol") @@ -2235,6 +2302,7 @@ def get_sectors_allocation( portfolio_engine=None, limit: int = 10, tables: bool = False, + recalculate: bool = False, ): """Display portfolio sector allocation compared to the benchmark @@ -2245,7 +2313,9 @@ def get_sectors_allocation( tables: bool Whether to include separate allocation tables limit: int - The amount of assets you wish to show, by default this is set to 10. + The amount of assets you wish to show, by default this is set to 10 + recalculate: bool + Flag to force recalculate allocation if already exists Returns ------- @@ -2253,15 +2323,10 @@ def get_sectors_allocation( DataFrame with combined allocation plus individual allocation if tables is `True`. """ - ( - benchmark_sectors_allocation, - portfolio_sectors_allocation, - ) = allocation_model.get_sectors_allocation( - portfolio_engine.benchmark_info, portfolio_engine.portfolio_trades - ) + portfolio_engine.calculate_allocation(category="sectors", recalculate=recalculate) - benchmark_allocation = benchmark_sectors_allocation.iloc[:limit] - portfolio_allocation = portfolio_sectors_allocation.iloc[:limit] + benchmark_allocation = portfolio_engine.benchmark_sectors_allocation.iloc[:limit] + portfolio_allocation = portfolio_engine.portfolio_sectors_allocation.iloc[:limit] combined = join_allocation(portfolio_allocation, benchmark_allocation, "Sector") @@ -2274,6 +2339,7 @@ def get_countries_allocation( portfolio_engine=None, limit: int = 10, tables: bool = False, + recalculate: bool = False, ): """Display portfolio country allocation compared to the benchmark @@ -2284,7 +2350,9 @@ def get_countries_allocation( tables: bool Whether to include separate allocation tables limit: int - The amount of assets you wish to show, by default this is set to 10. + The amount of assets you wish to show, by default this is set to 10 + recalculate: bool + Flag to force recalculate allocation if already exists Returns ------- @@ -2292,19 +2360,23 @@ def get_countries_allocation( DataFrame with combined allocation plus individual allocation if tables is `True`. """ - ( - benchmark_region_allocation, - benchmark_country_allocation, - ) = allocation_model.get_region_country_allocation( - portfolio_engine.benchmark_ticker - ) - # Must return country (bench, portf) + portfolio_engine.calculate_allocation(category="countries", recalculate=recalculate) + + benchmark_allocation = portfolio_engine.benchmark_sectors_allocation.iloc[:limit] + portfolio_allocation = portfolio_engine.portfolio_sectors_allocation.iloc[:limit] + + combined = join_allocation(portfolio_allocation, benchmark_allocation, "Country") + + if tables: + return combined, portfolio_allocation, benchmark_allocation + return combined def get_regions_allocation( portfolio_engine=None, limit: int = 10, tables: bool = False, + recalculate: bool = False, ): """Display portfolio region allocation compared to the benchmark @@ -2315,7 +2387,9 @@ def get_regions_allocation( tables: bool Whether to include separate allocation tables limit: int - The amount of assets you wish to show, by default this is set to 10. + The amount of assets you wish to show, by default this is set to 10 + recalculate: bool + Flag to force recalculate allocation if already exists Returns ------- @@ -2323,14 +2397,16 @@ def get_regions_allocation( DataFrame with combined allocation plus individual allocation if tables is `True`. """ - ( - portfolio_region_allocation, - portfolio_country_allocation, - ) = allocation_model.get_portfolio_region_country_allocation( - portfolio_engine.portfolio_trades - ) + portfolio_engine.calculate_allocation(category="regions", recalculate=recalculate) + + benchmark_allocation = portfolio_engine.benchmark_sectors_allocation.iloc[:limit] + portfolio_allocation = portfolio_engine.portfolio_sectors_allocation.iloc[:limit] - # Must return region (bench, portf) + combined = join_allocation(portfolio_allocation, benchmark_allocation, "Region") + + if tables: + return combined, portfolio_allocation, benchmark_allocation + return combined # Old code From eaabc4259e4ce83ba15aa4b51d2136f05b782c3a Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 13 Nov 2022 14:20:30 +0000 Subject: [PATCH 19/30] reorganize class --- openbb_terminal/portfolio/portfolio_model.py | 19 ++++++++----------- openbb_terminal/portfolio/portfolio_view.py | 8 ++++---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 154422b3d83c..5aa5da782f23 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -63,17 +63,21 @@ def __init__(self, transactions: pd.DataFrame = pd.DataFrame()): """Initialize PortfolioEngine class""" # Portfolio + self.empty = True self.tickers_list = None self.tickers: Dict[Any, Any] = {} self.inception_date = datetime.date(1970, 1, 1) self.historical_trade_data = pd.DataFrame() - self.returns = pd.DataFrame() self.itemized_value = pd.DataFrame() - self.portfolio_trades = pd.DataFrame() self.portfolio_value = None self.portfolio_historical_prices = pd.DataFrame() - self.empty = True + self.returns = pd.DataFrame() + self.portfolio_trades = pd.DataFrame() self.risk_free_rate = float(0) + self.portfolio_assets_allocation = pd.DataFrame() + self.portfolio_sectors_allocation = pd.DataFrame() + self.portfolio_regions_allocation = pd.DataFrame() + self.portfolio_countries_allocation = pd.DataFrame() # Benchmark self.benchmark_ticker: str = "" @@ -81,13 +85,6 @@ def __init__(self, transactions: pd.DataFrame = pd.DataFrame()): self.benchmark_historical_prices = pd.DataFrame() self.benchmark_returns = pd.DataFrame() self.benchmark_trades = pd.DataFrame() - - # Allocations - self.portfolio_assets_allocation = pd.DataFrame() - self.portfolio_sectors_allocation = pd.DataFrame() - self.portfolio_regions_allocation = pd.DataFrame() - self.portfolio_countries_allocation = pd.DataFrame() - self.benchmark_assets_allocation = pd.DataFrame() self.benchmark_sectors_allocation = pd.DataFrame() self.benchmark_regions_allocation = pd.DataFrame() @@ -2168,7 +2165,7 @@ def generate_portfolio( Returns ------- PortfolioEngine - PortfolioEngine object + PortfolioEngine class instance, this will hold transactions and perform calculations """ transactions = PortfolioEngine.read_transactions(transactions_file_path) diff --git a/openbb_terminal/portfolio/portfolio_view.py b/openbb_terminal/portfolio/portfolio_view.py index 90033f3ab97c..fd1d42da9e07 100644 --- a/openbb_terminal/portfolio/portfolio_view.py +++ b/openbb_terminal/portfolio/portfolio_view.py @@ -154,7 +154,7 @@ def display_assets_allocation( tables: bool Whether to include separate asset allocation tables limit: int - The amount of assets you wish to show, by default this is set to 10. + The amount of assets you wish to show, by default this is set to 10 """ combined, portfolio_allocation, benchmark_allocation = get_assets_allocation( @@ -186,7 +186,7 @@ def display_sectors_allocation( portfolio_engine: PortfolioEngine Instance of PortfolioEngine class limit: int - The amount of assets you wish to show, by default this is set to 10. + The amount of assets you wish to show, by default this is set to 10 tables: bool Whether to include separate asset allocation tables """ @@ -220,7 +220,7 @@ def display_countries_allocation( portfolio_engine: PortfolioEngine Instance of PortfolioEngine class limit: int - The amount of assets you wish to show, by default this is set to 10. + The amount of assets you wish to show, by default this is set to 10 tables: bool Whether to include separate asset allocation tables """ @@ -254,7 +254,7 @@ def display_regions_allocation( portfolio_engine: PortfolioEngine Instance of PortfolioEngine class limit: int - The amount of assets you wish to show, by default this is set to 10. + The amount of assets you wish to show, by default this is set to 10 tables: bool Whether to include separate asset allocation tables """ From 253bb931dadbebdc03e5a80c30c4ace6ffea4234 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 13 Nov 2022 14:56:16 +0000 Subject: [PATCH 20/30] first refactor alloc --- openbb_terminal/portfolio/allocation_model.py | 340 ++++++++++++------ 1 file changed, 236 insertions(+), 104 deletions(-) diff --git a/openbb_terminal/portfolio/allocation_model.py b/openbb_terminal/portfolio/allocation_model.py index 9dcb2c9dcacf..825c1b2fb6a5 100644 --- a/openbb_terminal/portfolio/allocation_model.py +++ b/openbb_terminal/portfolio/allocation_model.py @@ -1,5 +1,5 @@ import logging -from typing import Dict +from typing import Dict, Tuple import pandas as pd import requests @@ -12,22 +12,24 @@ @log_start_end(log=logger) -def get_assets_allocation(benchmark_info: Dict, portfolio_trades: pd.DataFrame): +def get_assets_allocation( + benchmark_info: Dict, portfolio_trades: pd.DataFrame +) -> Tuple[pd.DataFrame, pd.DataFrame]: """Obtain the assets allocation of the benchmark and portfolio [Source: Yahoo Finance] Parameters ---------- benchmark_info: Dict - Dictionary containing Yahoo Finance information. + Dictionary containing Yahoo Finance information portfolio_trades: pd.DataFrame - Object containing trades made within the portfolio. + Object containing trades made within the portfolio Returns ------- - benchmark_assets_allocation: dict - Dictionary with the top 10 of the benchmark's asset allocations. - portfolio_assets_allocation: dict - Dictionary with the portfolio's asset allocations + pd.DataFrame + DataFrame with the top 10 of the benchmark's asset allocations + pd.DataFrame + DataFrame with the portfolio's asset allocations """ benchmark_assets_allocation = pd.DataFrame(benchmark_info["holdings"]) benchmark_assets_allocation.rename( @@ -51,22 +53,24 @@ def get_assets_allocation(benchmark_info: Dict, portfolio_trades: pd.DataFrame): @log_start_end(log=logger) -def get_sectors_allocation(benchmark_info: Dict, portfolio_trades: pd.DataFrame): +def get_sectors_allocation( + benchmark_info: Dict, portfolio_trades: pd.DataFrame +) -> Tuple[pd.DataFrame, pd.DataFrame]: """Obtain the sector allocation of the benchmark and portfolio [Source: Yahoo Finance] Parameters ---------- benchmark_info: Dict - Dictionary containing Yahoo Finance information. + Dictionary containing Yahoo Finance information portfolio_trades: pd.DataFrame - Object containing trades made within the portfolio. + Object containing trades made within the portfolio Returns ------- - regional_allocation: dict - Dictionary with regional allocations. - country_allocation: dict - Dictionary with country allocations + pd.DataFrame + DataFrame with regional allocations. + pd.DataFrame + DataFrame with country allocations """ p_bar = tqdm(range(3), desc="Loading sector data") @@ -198,9 +202,63 @@ def get_sectors_allocation(benchmark_info: Dict, portfolio_trades: pd.DataFrame) @log_start_end(log=logger) -def get_region_country_allocation( - ticker: str, region_test: list = None, country_test: list = None -): +def get_countries_allocation( + benchmark_info: Dict, portfolio_trades: pd.DataFrame +) -> Tuple[pd.DataFrame, pd.DataFrame]: + """Obtain the countries allocation of the benchmark and portfolio [Source: Yahoo Finance] + + Parameters + ---------- + benchmark_info: Dict + Dictionary containing Yahoo Finance information + portfolio_trades: pd.DataFrame + Object containing trades made within the portfolio + + Returns + ------- + pd.DataFrame + DataFrame with regional allocations. + pd.DataFrame + DataFrame with country allocations + """ + benchmark_countries_allocation = get_ticker_country_allocation( + benchmark_info["symbol"] + ) + portfolio_countries_allocation = get_portfolio_country_allocation(portfolio_trades) + + return benchmark_countries_allocation, portfolio_countries_allocation + + +@log_start_end(log=logger) +def get_regions_allocation( + benchmark_info: Dict, portfolio_trades: pd.DataFrame +) -> Tuple[pd.DataFrame, pd.DataFrame]: + """Obtain the regions allocation of the benchmark and portfolio [Source: Yahoo Finance] + + Parameters + ---------- + benchmark_info: Dict + Dictionary containing Yahoo Finance information + portfolio_trades: pd.DataFrame + Object containing trades made within the portfolio + + Returns + ------- + pd.DataFrame + DataFrame with regional allocations. + pd.DataFrame + DataFrame with country allocations + """ + benchmark_regions_allocation = get_ticker_region_allocation( + benchmark_info["symbol"] + ) + portfolio_regions_allocation = get_portfolio_region_allocation(portfolio_trades) + + return benchmark_regions_allocation, portfolio_regions_allocation + + +@log_start_end(log=logger) +def get_ticker_country_allocation(ticker: str, country_test: list = None): """Obtain the region and country allocation for ETF ticker. [Source: Fidelity.com] @@ -208,19 +266,71 @@ def get_region_country_allocation( ---------- benchmark_ticker: str The ticker, e.g. "SPY" - region_test: list - This includes a list of region names that should be used to discover - which list on the Fidelity page is the correct one country_test: list This includes a list of country names that should be used to discover which list on the Fidelity page is the correct one Returns ------- - region_allocation: dict - Dictionary with regional allocations. - country_allocation: dict - Dictionary with country allocations + pd.DataFrame + Dictionary with country allocation + """ + + # Initialize variables + if not country_test: + country_test = [ + "United States", + "United Kingdom", + "Japan", + "Switzerland", + "China", + ] + + country_list = 0 + + # Collect data from Fidelity about the portfolio composition of the benchmark + URL = f"https://screener.fidelity.com/ftgw/etf/goto/snapshot/portfolioComposition.jhtml?symbols={ticker}" + html = requests.get(URL).content + df_list = pd.read_html(html) + + # Find the ones that contain regions and countries + for index, item in enumerate(df_list): + for country in country_test: + if country in item.values: + country_list = index + break + + if country_list: + country_allocation = { + row[1]: float(row[2].strip("%")) / 100 + for _, row in df_list[country_list].dropna(axis="columns").iterrows() + } + country_allocation = pd.DataFrame.from_dict( + country_allocation, orient="index" + ).squeeze() + else: + country_allocation = pd.DataFrame() + + return country_allocation + + +@log_start_end(log=logger) +def get_ticker_region_allocation(ticker: str, region_test: list = None) -> pd.DataFrame: + + """Obtain the region and country allocation for ETF ticker. [Source: Fidelity.com] + + Parameters + ---------- + benchmark_ticker: str + The ticker, e.g. "SPY" + region_test: list + This includes a list of region names that should be used to discover + which list on the Fidelity page is the correct one + + Returns + ------- + pd.DataFrame + Dictionary with region allocations """ # Initialize variables @@ -233,17 +343,8 @@ def get_region_country_allocation( "Africa", "Middle East", ] - if not country_test: - country_test = [ - "United States", - "United Kingdom", - "Japan", - "Switzerland", - "China", - ] region_list = 0 - country_list = 0 # Collect data from Fidelity about the portfolio composition of the benchmark URL = f"https://screener.fidelity.com/ftgw/etf/goto/snapshot/portfolioComposition.jhtml?symbols={ticker}" @@ -256,10 +357,6 @@ def get_region_country_allocation( if region in item.values: region_list = index break - for country in country_test: - if country in item.values: - country_list = index - break if region_list: region_allocation = { @@ -272,48 +369,25 @@ def get_region_country_allocation( else: region_allocation = pd.DataFrame() - if country_list: - country_allocation = { - row[1]: float(row[2].strip("%")) / 100 - for _, row in df_list[country_list].dropna(axis="columns").iterrows() - } - country_allocation = pd.DataFrame.from_dict( - country_allocation, orient="index" - ).squeeze() - else: - country_allocation = pd.DataFrame() - - return region_allocation, country_allocation + return region_allocation @log_start_end(log=logger) -def get_portfolio_region_country_allocation(portfolio_trades: pd.DataFrame): - """Obtain the regional and country allocation of the portfolio. +def get_portfolio_country_allocation(portfolio_trades: pd.DataFrame) -> pd.DataFrame: + """Obtain the country allocation of the portfolio. Parameters ---------- portfolio_trades: pd.DataFrame - Object containing trades made within the portfolio. + Object containing trades made within the portfolio Returns ------ - portfolio_regional_allocation: pd.DataFrame - Dictionary with regional allocations. - portfolio_country_allocation: pd.DataFrame + pd.DataFrame Dictionary with country allocations """ - p_bar = tqdm(range(3), desc="Loading country/region data") - - # Define portfolio regional allocation - if not portfolio_trades["Region"].isnull().any(): - portfolio_region_allocation = ( - portfolio_trades[portfolio_trades["Type"].isin(["STOCK", "CRYPTO"])] - .groupby(by="Region") - .agg({"Portfolio Value": "sum"}) - ) - else: - portfolio_region_allocation = pd.DataFrame() + p_bar = tqdm(range(3), desc="Loading country data") # Define portfolio country allocation if not portfolio_trades["Country"].isnull().any(): @@ -335,19 +409,12 @@ def get_portfolio_region_country_allocation(portfolio_trades: pd.DataFrame): .groupby(by="Ticker") .agg({"Portfolio Value": "sum"}) ) - etf_global_region_alloc = pd.DataFrame() etf_global_country_alloc = pd.DataFrame() # Loop through each etf and multiply sector weights by current value for item in etf_ticker_value.index.values: - etf_region_weight, etf_country_weight = get_region_country_allocation(item) - - if etf_region_weight.empty: - # If ETF has no sectors like VIX for example or it was not found, add to Other - etf_region_weight = pd.DataFrame.from_dict( - data={"Other": 1}, orient="index", columns=["Portfolio Value"] - ) + etf_country_weight = get_ticker_country_allocation(item) if etf_country_weight.empty: etf_country_weight = pd.DataFrame.from_dict( @@ -356,14 +423,6 @@ def get_portfolio_region_country_allocation(portfolio_trades: pd.DataFrame): etf_value = etf_ticker_value["Portfolio Value"][item] - # Aggregate etf region allocation by value - etf_ticker_region_alloc = etf_region_weight * etf_value - etf_global_region_alloc = pd.concat( - [etf_global_region_alloc, etf_ticker_region_alloc], axis=1 - ) - etf_global_region_alloc.fillna(0, inplace=True) - etf_global_region_alloc = etf_global_region_alloc.sum(axis=1) - # Aggregate etf country allocation by value etf_ticker_country_alloc = etf_country_weight * etf_value etf_global_country_alloc = pd.concat( @@ -375,22 +434,10 @@ def get_portfolio_region_country_allocation(portfolio_trades: pd.DataFrame): p_bar.n += 1 p_bar.refresh() - etf_global_region_alloc = pd.DataFrame( - etf_global_region_alloc, columns=["Portfolio Value"] - ) etf_global_country_alloc = pd.DataFrame( etf_global_country_alloc, columns=["Portfolio Value"] ) - # Aggregate region allocation for stocks and crypto with ETFs - portfolio_region_allocation = pd.merge( - portfolio_region_allocation, - etf_global_region_alloc, - how="outer", - left_index=True, - right_index=True, - ).sum(axis=1) - # Aggregate country allocation for stocks and crypto with ETFs portfolio_country_allocation = pd.merge( portfolio_country_allocation, @@ -400,31 +447,116 @@ def get_portfolio_region_country_allocation(portfolio_trades: pd.DataFrame): right_index=True, ).sum(axis=1) - portfolio_region_allocation = pd.DataFrame( - portfolio_region_allocation, columns=["Portfolio Value"] - ) portfolio_country_allocation = pd.DataFrame( portfolio_country_allocation, columns=["Portfolio Value"] ) - portfolio_region_allocation = ( - portfolio_region_allocation.div(portfolio_trades["Portfolio Value"].sum()) + portfolio_country_allocation = ( + portfolio_country_allocation.div(portfolio_trades["Portfolio Value"].sum()) .squeeze(axis=1) .sort_values(ascending=False) ) - portfolio_country_allocation = ( - portfolio_country_allocation.div(portfolio_trades["Portfolio Value"].sum()) + portfolio_country_allocation.fillna(0, inplace=True) + + p_bar.n += 1 + p_bar.refresh() + p_bar.disable = True + console.print("\n") + + return portfolio_country_allocation + + +@log_start_end(log=logger) +def get_portfolio_region_allocation(portfolio_trades: pd.DataFrame) -> pd.DataFrame: + """Obtain the region allocation of the portfolio. + + Parameters + ---------- + portfolio_trades: pd.DataFrame + Object containing trades made within the portfolio + + Returns + ------ + pd.DataFrame + Dictionary with region allocations + """ + + p_bar = tqdm(range(3), desc="Loading region data") + + # Define portfolio region allocation + if not portfolio_trades["Region"].isnull().any(): + portfolio_region_allocation = ( + portfolio_trades[portfolio_trades["Type"].isin(["STOCK", "CRYPTO"])] + .groupby(by="Region") + .agg({"Portfolio Value": "sum"}) + ) + else: + portfolio_region_allocation = pd.DataFrame() + + p_bar.n += 1 + p_bar.refresh() + + # Aggregate sector value for ETFs + # Start by getting value by ticker + etf_ticker_value = ( + portfolio_trades[portfolio_trades["Type"].isin(["ETF"])] + .groupby(by="Ticker") + .agg({"Portfolio Value": "sum"}) + ) + etf_global_region_alloc = pd.DataFrame() + + # Loop through each etf and multiply sector weights by current value + for item in etf_ticker_value.index.values: + + etf_region_weight = get_ticker_region_allocation(item) + + if etf_region_weight.empty: + etf_region_weight = pd.DataFrame.from_dict( + data={"Other": 1}, orient="index", columns=["Portfolio Value"] + ) + + etf_value = etf_ticker_value["Portfolio Value"][item] + + # Aggregate etf region allocation by value + etf_ticker_region_alloc = etf_region_weight * etf_value + etf_global_region_alloc = pd.concat( + [etf_global_region_alloc, etf_ticker_region_alloc], axis=1 + ) + etf_global_region_alloc.fillna(0, inplace=True) + etf_global_region_alloc = etf_global_region_alloc.sum(axis=1) + + p_bar.n += 1 + p_bar.refresh() + + etf_global_region_alloc = pd.DataFrame( + etf_global_region_alloc, columns=["Portfolio Value"] + ) + + # Aggregate region allocation for stocks and crypto with ETFs + portfolio_region_allocation = pd.merge( + portfolio_region_allocation, + etf_global_region_alloc, + how="outer", + left_index=True, + right_index=True, + ).sum(axis=1) + + portfolio_region_allocation = pd.DataFrame( + portfolio_region_allocation, columns=["Portfolio Value"] + ) + + portfolio_region_allocation = ( + portfolio_region_allocation.div(portfolio_trades["Portfolio Value"].sum()) .squeeze(axis=1) .sort_values(ascending=False) ) portfolio_region_allocation.fillna(0, inplace=True) - portfolio_country_allocation.fillna(0, inplace=True) p_bar.n += 1 p_bar.refresh() p_bar.disable = True console.print("\n") - return portfolio_region_allocation, portfolio_country_allocation + return portfolio_region_allocation From f5b287ed44d83a80c2c758f84bd2e3976ac6d004 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 13 Nov 2022 17:15:00 +0000 Subject: [PATCH 21/30] refactor portfolio alloc --- openbb_terminal/portfolio/allocation_model.py | 334 ++++++------------ .../portfolio/portfolio_controller.py | 8 +- openbb_terminal/portfolio/portfolio_model.py | 59 ++-- 3 files changed, 153 insertions(+), 248 deletions(-) diff --git a/openbb_terminal/portfolio/allocation_model.py b/openbb_terminal/portfolio/allocation_model.py index 825c1b2fb6a5..0a9876d12476 100644 --- a/openbb_terminal/portfolio/allocation_model.py +++ b/openbb_terminal/portfolio/allocation_model.py @@ -11,11 +11,48 @@ logger = logging.getLogger(__name__) +@log_start_end(log=logger) +def get_allocation( + category: str, benchmark_info: Dict, portfolio_trades: pd.DataFrame +) -> Tuple[pd.DataFrame, pd.DataFrame]: + """Get category allocation for benchmark and portfolio + + Parameters + ---------- + category: str + Chosen category: Asset, Sector, Country or Region + benchmark_info: Dict + Dictionary containing Yahoo Finance information + portfolio_trades: pd.DataFrame + Object containing trades made within the portfolio + + Returns + ------- + pd.DataFrame + DataFrame with the top 10 of the benchmark's asset allocations + pd.DataFrame + DataFrame with the portfolio's asset allocations + """ + + if category == "Asset": + return get_assets_allocation(benchmark_info, portfolio_trades) + if category == "Sector": + return get_sectors_allocation(benchmark_info, portfolio_trades) + if category == "Country": + return get_countries_allocation(benchmark_info, portfolio_trades) + if category == "Region": + return get_regions_allocation(benchmark_info, portfolio_trades) + console.print( + "Category not available. Choose from: Asset, Sector, Country or Region." + ) + return pd.DataFrame(), pd.DataFrame() + + @log_start_end(log=logger) def get_assets_allocation( benchmark_info: Dict, portfolio_trades: pd.DataFrame ) -> Tuple[pd.DataFrame, pd.DataFrame]: - """Obtain the assets allocation of the benchmark and portfolio [Source: Yahoo Finance] + """Get assets allocation for benchmark and portfolio [Source: Yahoo Finance] Parameters ---------- @@ -56,7 +93,7 @@ def get_assets_allocation( def get_sectors_allocation( benchmark_info: Dict, portfolio_trades: pd.DataFrame ) -> Tuple[pd.DataFrame, pd.DataFrame]: - """Obtain the sector allocation of the benchmark and portfolio [Source: Yahoo Finance] + """Get sector allocation for benchmark and portfolio [Source: Yahoo Finance] Parameters ---------- @@ -110,7 +147,7 @@ def get_sectors_allocation( p_bar.refresh() # Aggregate sector value for ETFs - # Start by getting value by isin/ticker + # Start by getting value by isin/symbol etf_ticker_value = ( portfolio_trades[portfolio_trades["Type"].isin(["ETF"])] .groupby(by="Ticker") @@ -182,11 +219,9 @@ def get_sectors_allocation( portfolio_sectors_allocation, columns=["Portfolio Value"] ) - portfolio_sectors_allocation = ( - portfolio_sectors_allocation.div(portfolio_trades["Portfolio Value"].sum()) - .squeeze(axis=1) - .sort_values(ascending=False) - ) + portfolio_sectors_allocation = portfolio_sectors_allocation.div( + portfolio_trades["Portfolio Value"].sum() + ).sort_values(by="Portfolio Value", ascending=False) portfolio_sectors_allocation.fillna(0, inplace=True) portfolio_sectors_allocation = pd.DataFrame(portfolio_sectors_allocation) @@ -205,7 +240,7 @@ def get_sectors_allocation( def get_countries_allocation( benchmark_info: Dict, portfolio_trades: pd.DataFrame ) -> Tuple[pd.DataFrame, pd.DataFrame]: - """Obtain the countries allocation of the benchmark and portfolio [Source: Yahoo Finance] + """Get countries allocation for benchmark and portfolio [Source: Yahoo Finance] Parameters ---------- @@ -221,19 +256,23 @@ def get_countries_allocation( pd.DataFrame DataFrame with country allocations """ - benchmark_countries_allocation = get_ticker_country_allocation( - benchmark_info["symbol"] + + benchmark_allocation = get_symbol_allocation( + symbol=benchmark_info["symbol"], category="Country" ) - portfolio_countries_allocation = get_portfolio_country_allocation(portfolio_trades) - return benchmark_countries_allocation, portfolio_countries_allocation + portfolio_allocation = get_portfolio_allocation( + category="Country", portfolio_trades=portfolio_trades + ) + + return benchmark_allocation, portfolio_allocation @log_start_end(log=logger) def get_regions_allocation( benchmark_info: Dict, portfolio_trades: pd.DataFrame ) -> Tuple[pd.DataFrame, pd.DataFrame]: - """Obtain the regions allocation of the benchmark and portfolio [Source: Yahoo Finance] + """Get regions allocation for benchmark and portfolio [Source: Yahoo Finance] Parameters ---------- @@ -249,93 +288,35 @@ def get_regions_allocation( pd.DataFrame DataFrame with country allocations """ - benchmark_regions_allocation = get_ticker_region_allocation( - benchmark_info["symbol"] + benchmark_allocation = get_symbol_allocation( + symbol=benchmark_info["symbol"], category="Region" ) - portfolio_regions_allocation = get_portfolio_region_allocation(portfolio_trades) - - return benchmark_regions_allocation, portfolio_regions_allocation - -@log_start_end(log=logger) -def get_ticker_country_allocation(ticker: str, country_test: list = None): - - """Obtain the region and country allocation for ETF ticker. [Source: Fidelity.com] - - Parameters - ---------- - benchmark_ticker: str - The ticker, e.g. "SPY" - country_test: list - This includes a list of country names that should be used to discover - which list on the Fidelity page is the correct one - - Returns - ------- - pd.DataFrame - Dictionary with country allocation - """ - - # Initialize variables - if not country_test: - country_test = [ - "United States", - "United Kingdom", - "Japan", - "Switzerland", - "China", - ] - - country_list = 0 - - # Collect data from Fidelity about the portfolio composition of the benchmark - URL = f"https://screener.fidelity.com/ftgw/etf/goto/snapshot/portfolioComposition.jhtml?symbols={ticker}" - html = requests.get(URL).content - df_list = pd.read_html(html) - - # Find the ones that contain regions and countries - for index, item in enumerate(df_list): - for country in country_test: - if country in item.values: - country_list = index - break - - if country_list: - country_allocation = { - row[1]: float(row[2].strip("%")) / 100 - for _, row in df_list[country_list].dropna(axis="columns").iterrows() - } - country_allocation = pd.DataFrame.from_dict( - country_allocation, orient="index" - ).squeeze() - else: - country_allocation = pd.DataFrame() - - return country_allocation + portfolio_allocation = get_portfolio_allocation( + category="Region", portfolio_trades=portfolio_trades + ) + return benchmark_allocation, portfolio_allocation -@log_start_end(log=logger) -def get_ticker_region_allocation(ticker: str, region_test: list = None) -> pd.DataFrame: - """Obtain the region and country allocation for ETF ticker. [Source: Fidelity.com] +def get_symbol_allocation(symbol: str, category: str) -> pd.DataFrame: + """Get benchmark allocation [Source: Fidelity] Parameters ---------- - benchmark_ticker: str - The ticker, e.g. "SPY" - region_test: list - This includes a list of region names that should be used to discover - which list on the Fidelity page is the correct one + symbol: str + ETF symbol to get allocation + category: str + Chosen category: Country or Region Returns ------- pd.DataFrame - Dictionary with region allocations + Dictionary with country allocations """ - # Initialize variables - if not region_test: - region_test = [ + if category == "Region": + category_list = [ "North America", "Europe", "Asia", @@ -344,66 +325,80 @@ def get_ticker_region_allocation(ticker: str, region_test: list = None) -> pd.Da "Middle East", ] - region_list = 0 + if category == "Country": + category_list = [ + "United States", + "United Kingdom", + "Japan", + "Switzerland", + "China", + ] + + item_list = 0 # Collect data from Fidelity about the portfolio composition of the benchmark - URL = f"https://screener.fidelity.com/ftgw/etf/goto/snapshot/portfolioComposition.jhtml?symbols={ticker}" + URL = f"https://screener.fidelity.com/ftgw/etf/goto/snapshot/portfolioComposition.jhtml?symbols={symbol}" html = requests.get(URL).content df_list = pd.read_html(html) # Find the ones that contain regions and countries for index, item in enumerate(df_list): - for region in region_test: - if region in item.values: - region_list = index + for category_item in category_list: + if category_item in item.values: + item_list = index break - if region_list: - region_allocation = { + if item_list: + allocation = { row[1]: float(row[2].strip("%")) / 100 - for _, row in df_list[region_list].dropna(axis="columns").iterrows() + for _, row in df_list[item_list].dropna(axis="columns").iterrows() } - region_allocation = pd.DataFrame.from_dict( - region_allocation, orient="index" - ).squeeze() + allocation_df = pd.DataFrame.from_dict(allocation, orient="index").reset_index( + inplace=True + ) + allocation_df.columns = [category, "Benchmark"] else: - region_allocation = pd.DataFrame() + allocation_df = pd.DataFrame() - return region_allocation + return allocation_df @log_start_end(log=logger) -def get_portfolio_country_allocation(portfolio_trades: pd.DataFrame) -> pd.DataFrame: - """Obtain the country allocation of the portfolio. +def get_portfolio_allocation( + category: str, portfolio_trades: pd.DataFrame +) -> pd.DataFrame: + """Get portfolio allocation Parameters ---------- + category: str + Chosen category: Country or Region portfolio_trades: pd.DataFrame Object containing trades made within the portfolio Returns - ------ + ------- pd.DataFrame Dictionary with country allocations """ - p_bar = tqdm(range(3), desc="Loading country data") + p_bar = tqdm(range(3), desc=f"Loading {category.lower()} data") - # Define portfolio country allocation - if not portfolio_trades["Country"].isnull().any(): - portfolio_country_allocation = ( + # Define portfolio allocation + if not portfolio_trades[category].isnull().any(): + allocation = ( portfolio_trades[portfolio_trades["Type"].isin(["STOCK", "CRYPTO"])] - .groupby(by="Country") + .groupby(by=category) .agg({"Portfolio Value": "sum"}) ) else: - portfolio_country_allocation = pd.DataFrame() + allocation = pd.DataFrame() p_bar.n += 1 p_bar.refresh() # Aggregate sector value for ETFs - # Start by getting value by ticker + # Start by getting value by symbol etf_ticker_value = ( portfolio_trades[portfolio_trades["Type"].isin(["ETF"])] .groupby(by="Ticker") @@ -414,7 +409,7 @@ def get_portfolio_country_allocation(portfolio_trades: pd.DataFrame) -> pd.DataF # Loop through each etf and multiply sector weights by current value for item in etf_ticker_value.index.values: - etf_country_weight = get_ticker_country_allocation(item) + etf_country_weight = get_symbol_allocation(symbol=item, category=category) if etf_country_weight.empty: etf_country_weight = pd.DataFrame.from_dict( @@ -423,7 +418,7 @@ def get_portfolio_country_allocation(portfolio_trades: pd.DataFrame) -> pd.DataF etf_value = etf_ticker_value["Portfolio Value"][item] - # Aggregate etf country allocation by value + # Aggregate etf allocation by value etf_ticker_country_alloc = etf_country_weight * etf_value etf_global_country_alloc = pd.concat( [etf_global_country_alloc, etf_ticker_country_alloc], axis=1 @@ -438,125 +433,30 @@ def get_portfolio_country_allocation(portfolio_trades: pd.DataFrame) -> pd.DataF etf_global_country_alloc, columns=["Portfolio Value"] ) - # Aggregate country allocation for stocks and crypto with ETFs - portfolio_country_allocation = pd.merge( - portfolio_country_allocation, + # Aggregate allocation for stocks and crypto with ETFs + allocation = pd.merge( + allocation, etf_global_country_alloc, how="outer", left_index=True, right_index=True, ).sum(axis=1) - portfolio_country_allocation = pd.DataFrame( - portfolio_country_allocation, columns=["Portfolio Value"] - ) + allocation = pd.DataFrame(allocation, columns=["Portfolio Value"]) - portfolio_country_allocation = ( - portfolio_country_allocation.div(portfolio_trades["Portfolio Value"].sum()) - .squeeze(axis=1) - .sort_values(ascending=False) + allocation = allocation.div(portfolio_trades["Portfolio Value"].sum()).sort_values( + by="Portfolio Value", ascending=False ) - portfolio_country_allocation.fillna(0, inplace=True) + allocation.fillna(0, inplace=True) p_bar.n += 1 p_bar.refresh() p_bar.disable = True console.print("\n") - return portfolio_country_allocation - - -@log_start_end(log=logger) -def get_portfolio_region_allocation(portfolio_trades: pd.DataFrame) -> pd.DataFrame: - """Obtain the region allocation of the portfolio. - - Parameters - ---------- - portfolio_trades: pd.DataFrame - Object containing trades made within the portfolio - - Returns - ------ - pd.DataFrame - Dictionary with region allocations - """ - - p_bar = tqdm(range(3), desc="Loading region data") - - # Define portfolio region allocation - if not portfolio_trades["Region"].isnull().any(): - portfolio_region_allocation = ( - portfolio_trades[portfolio_trades["Type"].isin(["STOCK", "CRYPTO"])] - .groupby(by="Region") - .agg({"Portfolio Value": "sum"}) - ) - else: - portfolio_region_allocation = pd.DataFrame() + allocation.reset_index(inplace=True) - p_bar.n += 1 - p_bar.refresh() - - # Aggregate sector value for ETFs - # Start by getting value by ticker - etf_ticker_value = ( - portfolio_trades[portfolio_trades["Type"].isin(["ETF"])] - .groupby(by="Ticker") - .agg({"Portfolio Value": "sum"}) - ) - etf_global_region_alloc = pd.DataFrame() - - # Loop through each etf and multiply sector weights by current value - for item in etf_ticker_value.index.values: - - etf_region_weight = get_ticker_region_allocation(item) - - if etf_region_weight.empty: - etf_region_weight = pd.DataFrame.from_dict( - data={"Other": 1}, orient="index", columns=["Portfolio Value"] - ) - - etf_value = etf_ticker_value["Portfolio Value"][item] - - # Aggregate etf region allocation by value - etf_ticker_region_alloc = etf_region_weight * etf_value - etf_global_region_alloc = pd.concat( - [etf_global_region_alloc, etf_ticker_region_alloc], axis=1 - ) - etf_global_region_alloc.fillna(0, inplace=True) - etf_global_region_alloc = etf_global_region_alloc.sum(axis=1) - - p_bar.n += 1 - p_bar.refresh() - - etf_global_region_alloc = pd.DataFrame( - etf_global_region_alloc, columns=["Portfolio Value"] - ) - - # Aggregate region allocation for stocks and crypto with ETFs - portfolio_region_allocation = pd.merge( - portfolio_region_allocation, - etf_global_region_alloc, - how="outer", - left_index=True, - right_index=True, - ).sum(axis=1) - - portfolio_region_allocation = pd.DataFrame( - portfolio_region_allocation, columns=["Portfolio Value"] - ) - - portfolio_region_allocation = ( - portfolio_region_allocation.div(portfolio_trades["Portfolio Value"].sum()) - .squeeze(axis=1) - .sort_values(ascending=False) - ) - - portfolio_region_allocation.fillna(0, inplace=True) - - p_bar.n += 1 - p_bar.refresh() - p_bar.disable = True - console.print("\n") + allocation.columns = [category, "Portfolio"] - return portfolio_region_allocation + return allocation diff --git a/openbb_terminal/portfolio/portfolio_controller.py b/openbb_terminal/portfolio/portfolio_controller.py index 9827ef110b93..f16f7013a46e 100644 --- a/openbb_terminal/portfolio/portfolio_controller.py +++ b/openbb_terminal/portfolio/portfolio_controller.py @@ -22,7 +22,7 @@ from openbb_terminal.menu import session from openbb_terminal.core.config.paths import MISCELLANEOUS_DIRECTORY from openbb_terminal.parent_classes import BaseController -from openbb_terminal.portfolio import portfolio_model +from openbb_terminal.portfolio.portfolio_model import generate_portfolio from openbb_terminal.portfolio import statics from openbb_terminal.portfolio import portfolio_view from openbb_terminal.portfolio import portfolio_helper @@ -139,9 +139,7 @@ def __init__(self, queue: List[str] = None): self.original_benchmark_name = "" self.risk_free_rate = 0 self.portlist: List[str] = os.listdir(self.DEFAULT_HOLDINGS_PATH) - self.portfolio: portfolio_model.PortfolioEngine = ( - portfolio_model.PortfolioEngine() - ) + self.portfolio = None if session and obbff.USE_PROMPT_TOOLKIT: self.update_choices() @@ -442,7 +440,7 @@ def call_load(self, other_args: List[str]): else: file_location = ns_parser.file # type: ignore - self.portfolio = portfolio_model.generate_portfolio( + self.portfolio = generate_portfolio( transactions_file_path=str(file_location), benchmark_symbol="SPY", risk_free_rate=ns_parser.risk_free_rate / 100, diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 5aa5da782f23..a81c850ff159 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -15,10 +15,8 @@ from pycoingecko import CoinGeckoAPI from openbb_terminal.common.quantitative_analysis import qa_model from openbb_terminal.decorators import log_start_end -from openbb_terminal.portfolio import ( - portfolio_helper, - allocation_model, -) +from openbb_terminal.portfolio import portfolio_helper +from openbb_terminal.portfolio.allocation_model import get_allocation from openbb_terminal.rich_config import console # pylint: disable=E1136,W0201,R0902,C0302 @@ -764,17 +762,17 @@ def calculate_reserves(self): @log_start_end(log=logger) def calculate_allocation(self, category: str, recalculate: bool = False): - """Determine allocation based on assets, sectors, countries and regions. + """Determine allocation based on Asset, Sector, Country or Region Parameters ---------- category: str - Chosen allocation category from assets, sectors, countries or regions + Chosen allocation category from Asset, Sector, Country or Region recalculate: bool Flag to force recalculate allocation if already exists """ - if category == "assets": + if category == "Asset": if ( self.benchmark_assets_allocation.empty or self.portfolio_assets_allocation.empty @@ -783,39 +781,48 @@ def calculate_allocation(self, category: str, recalculate: bool = False): ( self.benchmark_assets_allocation, self.portfolio_assets_allocation, - ) = allocation_model.get_assets_allocation( - self.benchmark_info, self.portfolio_trades + ) = get_allocation( + category, self.benchmark_info, self.portfolio_trades ) - elif category == "sectors": + elif category == "Sector": if ( self.benchmark_sectors_allocation.empty or self.portfolio_sectors_allocation.empty or recalculate ): - # Determine sector allocation ( self.benchmark_sectors_allocation, self.portfolio_sectors_allocation, - ) = allocation_model.get_sectors_allocation( - self.benchmark_info, self.portfolio_trades + ) = get_allocation( + category, self.benchmark_info, self.portfolio_trades ) - elif category == "countries": + elif category == "Country": if ( self.benchmark_countries_allocation.empty or self.portfolio_countries_allocation.empty or recalculate ): - pass - elif category == "regions": + ( + self.benchmark_countries_allocation, + self.portfolio_countries_allocation, + ) = get_allocation( + category, self.benchmark_info, self.portfolio_trades + ) + elif category == "Region": if ( self.benchmark_regions_allocation.empty or self.portfolio_regions_allocation.empty or recalculate ): - pass + ( + self.benchmark_regions_allocation, + self.portfolio_regions_allocation, + ) = get_allocation( + category, self.benchmark_info, self.portfolio_trades + ) else: console.print( - "Category not available. Choose from: assets, sectors, countries or regions" + "Category not available. Choose from: Asset, Sector, Country or Region" ) @@ -2283,7 +2290,7 @@ def get_assets_allocation( DataFrame with combined allocation plus individual allocation if tables is `True`. """ - portfolio_engine.calculate_allocation(category="assets", recalculate=recalculate) + portfolio_engine.calculate_allocation(category="Asset", recalculate=recalculate) benchmark_allocation = portfolio_engine.benchmark_assets_allocation.iloc[:limit] portfolio_allocation = portfolio_engine.portfolio_assets_allocation.iloc[:limit] @@ -2320,7 +2327,7 @@ def get_sectors_allocation( DataFrame with combined allocation plus individual allocation if tables is `True`. """ - portfolio_engine.calculate_allocation(category="sectors", recalculate=recalculate) + portfolio_engine.calculate_allocation(category="Sector", recalculate=recalculate) benchmark_allocation = portfolio_engine.benchmark_sectors_allocation.iloc[:limit] portfolio_allocation = portfolio_engine.portfolio_sectors_allocation.iloc[:limit] @@ -2357,10 +2364,10 @@ def get_countries_allocation( DataFrame with combined allocation plus individual allocation if tables is `True`. """ - portfolio_engine.calculate_allocation(category="countries", recalculate=recalculate) + portfolio_engine.calculate_allocation(category="Country", recalculate=recalculate) - benchmark_allocation = portfolio_engine.benchmark_sectors_allocation.iloc[:limit] - portfolio_allocation = portfolio_engine.portfolio_sectors_allocation.iloc[:limit] + benchmark_allocation = portfolio_engine.benchmark_countries_allocation.iloc[:limit] + portfolio_allocation = portfolio_engine.portfolio_countries_allocation.iloc[:limit] combined = join_allocation(portfolio_allocation, benchmark_allocation, "Country") @@ -2394,10 +2401,10 @@ def get_regions_allocation( DataFrame with combined allocation plus individual allocation if tables is `True`. """ - portfolio_engine.calculate_allocation(category="regions", recalculate=recalculate) + portfolio_engine.calculate_allocation(category="Region", recalculate=recalculate) - benchmark_allocation = portfolio_engine.benchmark_sectors_allocation.iloc[:limit] - portfolio_allocation = portfolio_engine.portfolio_sectors_allocation.iloc[:limit] + benchmark_allocation = portfolio_engine.benchmark_regions_allocation.iloc[:limit] + portfolio_allocation = portfolio_engine.portfolio_regions_allocation.iloc[:limit] combined = join_allocation(portfolio_allocation, benchmark_allocation, "Region") From cac281a0024e5274a40ab31c6b0ef64854e9d541 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 13 Nov 2022 17:18:55 +0000 Subject: [PATCH 22/30] black --- openbb_terminal/portfolio/portfolio_model.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index a81c850ff159..0dd6cae3b48a 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -781,9 +781,7 @@ def calculate_allocation(self, category: str, recalculate: bool = False): ( self.benchmark_assets_allocation, self.portfolio_assets_allocation, - ) = get_allocation( - category, self.benchmark_info, self.portfolio_trades - ) + ) = get_allocation(category, self.benchmark_info, self.portfolio_trades) elif category == "Sector": if ( self.benchmark_sectors_allocation.empty @@ -793,9 +791,7 @@ def calculate_allocation(self, category: str, recalculate: bool = False): ( self.benchmark_sectors_allocation, self.portfolio_sectors_allocation, - ) = get_allocation( - category, self.benchmark_info, self.portfolio_trades - ) + ) = get_allocation(category, self.benchmark_info, self.portfolio_trades) elif category == "Country": if ( self.benchmark_countries_allocation.empty @@ -805,9 +801,7 @@ def calculate_allocation(self, category: str, recalculate: bool = False): ( self.benchmark_countries_allocation, self.portfolio_countries_allocation, - ) = get_allocation( - category, self.benchmark_info, self.portfolio_trades - ) + ) = get_allocation(category, self.benchmark_info, self.portfolio_trades) elif category == "Region": if ( self.benchmark_regions_allocation.empty @@ -817,9 +811,7 @@ def calculate_allocation(self, category: str, recalculate: bool = False): ( self.benchmark_regions_allocation, self.portfolio_regions_allocation, - ) = get_allocation( - category, self.benchmark_info, self.portfolio_trades - ) + ) = get_allocation(category, self.benchmark_info, self.portfolio_trades) else: console.print( "Category not available. Choose from: Asset, Sector, Country or Region" From 9b9698738a674fb7db5ff2cedd2bb2568caa9d37 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 13 Nov 2022 17:56:01 +0000 Subject: [PATCH 23/30] fix alloc bug --- openbb_terminal/portfolio/allocation_model.py | 5 ++--- openbb_terminal/portfolio/portfolio_model.py | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/openbb_terminal/portfolio/allocation_model.py b/openbb_terminal/portfolio/allocation_model.py index 0a9876d12476..14b121d33463 100644 --- a/openbb_terminal/portfolio/allocation_model.py +++ b/openbb_terminal/portfolio/allocation_model.py @@ -353,9 +353,8 @@ def get_symbol_allocation(symbol: str, category: str) -> pd.DataFrame: row[1]: float(row[2].strip("%")) / 100 for _, row in df_list[item_list].dropna(axis="columns").iterrows() } - allocation_df = pd.DataFrame.from_dict(allocation, orient="index").reset_index( - inplace=True - ) + allocation_df = pd.DataFrame.from_dict(allocation, orient="index") + allocation_df.reset_index(inplace=True) allocation_df.columns = [category, "Benchmark"] else: allocation_df = pd.DataFrame() diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index 0dd6cae3b48a..b24cc232ef1c 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -1240,7 +1240,6 @@ def get_tail_ratio(portfolio_engine: PortfolioEngine, window: int = 252): portfolio_engine: PortfolioEngine PortfolioEngine class instance, this will hold transactions and perform calculations. Use `portfolio.load` to create a PortfolioEngine. - window: int Interval used for rolling values From 8e41b089a5c8d18bce0d51877f6f2220d766b57a Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 13 Nov 2022 18:03:12 +0000 Subject: [PATCH 24/30] regenerate sdk website --- .../content/SDK/crypto/dd/active/_index.rst | 2 +- .../content/SDK/crypto/dd/change/_index.rst | 2 +- .../content/SDK/crypto/dd/close/_index.rst | 2 +- website/content/SDK/crypto/dd/eb/_index.rst | 2 +- website/content/SDK/crypto/dd/gh/_index.rst | 8 ++-- .../content/SDK/crypto/dd/mcapdom/_index.rst | 8 ++-- website/content/SDK/crypto/dd/mt/_index.rst | 8 ++-- .../content/SDK/crypto/dd/nonzero/_index.rst | 2 +- website/content/SDK/crypto/load/_index.rst | 4 +- .../SDK/crypto/onchain/btc_supply/_index.rst | 2 +- .../SDK/crypto/onchain/btc_transac/_index.rst | 2 +- .../content/SDK/crypto/onchain/hr/_index.rst | 8 ++-- .../content/SDK/crypto/ov/altindex/_index.rst | 4 +- .../content/SDK/crypto/ov/btcrb/_index.rst | 4 +- website/content/SDK/economy/events/_index.rst | 4 +- website/content/SDK/economy/macro/_index.rst | 4 +- .../content/SDK/economy/treasury/_index.rst | 4 +- website/content/SDK/etf/candle/_index.rst | 4 +- website/content/SDK/etf/load/_index.rst | 4 +- website/content/SDK/etf/news/_index.rst | 4 +- website/content/SDK/forex/load/_index.rst | 2 +- .../content/SDK/futures/historical/_index.rst | 2 +- .../SDK/portfolio/alloc/assets/_index.rst | 43 +++++++++++++++++++ .../SDK/portfolio/alloc/countries/_index.rst | 42 ++++++++++++++++++ .../SDK/portfolio/alloc/regions/_index.rst | 42 ++++++++++++++++++ .../SDK/portfolio/alloc/sectors/_index.rst | 42 ++++++++++++++++++ website/content/SDK/portfolio/load/_index.rst | 2 +- .../SDK/portfolio/metric/tail/_index.rst | 1 - .../content/SDK/stocks/ba/cnews/_index.rst | 4 +- website/content/SDK/stocks/ba/hist/_index.rst | 8 ++-- .../content/SDK/stocks/ba/trend/_index.rst | 4 +- .../content/SDK/stocks/ca/hcorr/_index.rst | 4 +- website/content/SDK/stocks/ca/hist/_index.rst | 4 +- .../content/SDK/stocks/ca/volume/_index.rst | 4 +- website/content/SDK/stocks/candle/_index.rst | 4 +- website/content/SDK/stocks/dd/pt/_index.rst | 2 +- .../SDK/stocks/disc/dividends/_index.rst | 2 +- .../content/SDK/stocks/disc/ipo/_index.rst | 4 +- website/content/SDK/stocks/dps/ftd/_index.rst | 8 ++-- .../content/SDK/stocks/fa/mktcap/_index.rst | 4 +- website/content/SDK/stocks/ins/act/_index.rst | 2 +- website/content/SDK/stocks/load/_index.rst | 4 +- .../content/SDK/stocks/options/pcr/_index.rst | 4 +- .../SDK/stocks/screener/historical/_index.rst | 4 +- 44 files changed, 246 insertions(+), 78 deletions(-) create mode 100644 website/content/SDK/portfolio/alloc/assets/_index.rst create mode 100644 website/content/SDK/portfolio/alloc/countries/_index.rst create mode 100644 website/content/SDK/portfolio/alloc/regions/_index.rst create mode 100644 website/content/SDK/portfolio/alloc/sectors/_index.rst diff --git a/website/content/SDK/crypto/dd/active/_index.rst b/website/content/SDK/crypto/dd/active/_index.rst index 65d84bbee561..5e7a3591936c 100644 --- a/website/content/SDK/crypto/dd/active/_index.rst +++ b/website/content/SDK/crypto/dd/active/_index.rst @@ -17,7 +17,7 @@ crypto.dd.active( symbol: str, interval: str = '24h', start_date: int = 1262304000, - end_date: int = 1668289667, + end_date: int = 1668362499, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/dd/change/_index.rst b/website/content/SDK/crypto/dd/change/_index.rst index 08ec500a8bc4..63fa5161f116 100644 --- a/website/content/SDK/crypto/dd/change/_index.rst +++ b/website/content/SDK/crypto/dd/change/_index.rst @@ -17,7 +17,7 @@ crypto.dd.change( symbol: str, exchange: str = 'binance', start_date: int = 1262304000, - end_date: int = 1668289667, + end_date: int = 1668362499, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/dd/close/_index.rst b/website/content/SDK/crypto/dd/close/_index.rst index 23c42edd7dc8..8a07bec6cc27 100644 --- a/website/content/SDK/crypto/dd/close/_index.rst +++ b/website/content/SDK/crypto/dd/close/_index.rst @@ -14,7 +14,7 @@ crypto.dd.close( symbol: str, start_date: str = '2010-01-01', - end_date: str = '2022-11-12', + end_date: str = '2022-11-13', print_errors: bool = True, chart: bool = False, ) -> pandas.core.frame.DataFrame diff --git a/website/content/SDK/crypto/dd/eb/_index.rst b/website/content/SDK/crypto/dd/eb/_index.rst index f5f57279a5b4..97b4882e76e5 100644 --- a/website/content/SDK/crypto/dd/eb/_index.rst +++ b/website/content/SDK/crypto/dd/eb/_index.rst @@ -17,7 +17,7 @@ crypto.dd.eb( symbol: str, exchange: str = 'binance', start_date: int = 1262304000, - end_date: int = 1668289667, + end_date: int = 1668362499, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/dd/gh/_index.rst b/website/content/SDK/crypto/dd/gh/_index.rst index a8271d047371..d3bf26356658 100644 --- a/website/content/SDK/crypto/dd/gh/_index.rst +++ b/website/content/SDK/crypto/dd/gh/_index.rst @@ -17,8 +17,8 @@ crypto.dd.gh( symbol: str, dev_activity: bool = False, interval: str = '1d', - start_date: str = '2021-11-12T21:47:47Z', - end_date: str = '2022-11-12T21:47:47Z', + start_date: str = '2021-11-13T18:01:39Z', + end_date: str = '2022-11-13T18:01:39Z', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -63,9 +63,9 @@ crypto.dd.gh( {{< highlight python >}} crypto.dd.gh( symbol: str, - start_date: str = '2021-11-12T21:47:47Z', + start_date: str = '2021-11-13T18:01:39Z', dev_activity: bool = False, - end_date: str = '2022-11-12T21:47:47Z', + end_date: str = '2022-11-13T18:01:39Z', interval: str = '1d', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/mcapdom/_index.rst b/website/content/SDK/crypto/dd/mcapdom/_index.rst index 9dfd974fc827..020cb24bb496 100644 --- a/website/content/SDK/crypto/dd/mcapdom/_index.rst +++ b/website/content/SDK/crypto/dd/mcapdom/_index.rst @@ -16,8 +16,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.dd.mcapdom( symbol: str, interval: str = '1d', - start_date: str = '2021-11-12', - end_date: str = '2022-11-12', + start_date: str = '2021-11-13', + end_date: str = '2022-11-13', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -59,8 +59,8 @@ crypto.dd.mcapdom( {{< highlight python >}} crypto.dd.mcapdom( symbol: str, - start_date: str = '2021-11-12', - end_date: str = '2022-11-12', + start_date: str = '2021-11-13', + end_date: str = '2022-11-13', interval: str = '1d', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/mt/_index.rst b/website/content/SDK/crypto/dd/mt/_index.rst index 8d696eb91550..e4b7b2924638 100644 --- a/website/content/SDK/crypto/dd/mt/_index.rst +++ b/website/content/SDK/crypto/dd/mt/_index.rst @@ -17,8 +17,8 @@ crypto.dd.mt( symbol: str, timeseries_id: str, interval: str = '1d', - start_date: str = '2021-11-12', - end_date: str = '2022-11-12', + start_date: str = '2021-11-13', + end_date: str = '2022-11-13', chart: bool = False, ) -> Tuple[pandas.core.frame.DataFrame, str] {{< /highlight >}} @@ -65,8 +65,8 @@ crypto.dd.mt( crypto.dd.mt( symbol: str, timeseries_id: str, - start_date: str = '2021-11-12', - end_date: str = '2022-11-12', + start_date: str = '2021-11-13', + end_date: str = '2022-11-13', interval: str = '1d', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/nonzero/_index.rst b/website/content/SDK/crypto/dd/nonzero/_index.rst index 6f279f7f2cb3..019ba84d2b58 100644 --- a/website/content/SDK/crypto/dd/nonzero/_index.rst +++ b/website/content/SDK/crypto/dd/nonzero/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.dd.nonzero( symbol: str, start_date: int = 1262304000, - end_date: int = 1668289667, + end_date: int = 1668362499, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/crypto/load/_index.rst b/website/content/SDK/crypto/load/_index.rst index 5052d40d0dd6..7e3984dd8f8a 100644 --- a/website/content/SDK/crypto/load/_index.rst +++ b/website/content/SDK/crypto/load/_index.rst @@ -14,12 +14,12 @@ crypto.load( symbol: 'str', start_date: 'datetime' = datetime.datetime( - 2019, 11, 8, 21, 47, 47, 885225, chart: bool = False, + 2019, 11, 9, 18, 1, 39, 728615, chart: bool = False, ), interval: 'str' = '1440', exchange: 'str' = 'binance', vs_currency: 'str' = 'usdt', end_date: 'datetime' = datetime.datetime( - 2022, 11, 12, 21, 47, 47, 885226, chart: bool = False, + 2022, 11, 13, 18, 1, 39, 728616, chart: bool = False, ), source: 'str' = 'CCXT', chart: bool = False, ) -> 'pd.DataFrame' diff --git a/website/content/SDK/crypto/onchain/btc_supply/_index.rst b/website/content/SDK/crypto/onchain/btc_supply/_index.rst index 1898e118e985..19da8636bfe9 100644 --- a/website/content/SDK/crypto/onchain/btc_supply/_index.rst +++ b/website/content/SDK/crypto/onchain/btc_supply/_index.rst @@ -38,7 +38,7 @@ crypto.onchain.btc_supply() -> pandas.core.frame.DataFrame {{< highlight python >}} crypto.onchain.btc_supply( start_date: int = 1262304000, - end_date: int = 1668289667, + end_date: int = 1668362499, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/onchain/btc_transac/_index.rst b/website/content/SDK/crypto/onchain/btc_transac/_index.rst index 0807b9fb054e..11ba728f7e5e 100644 --- a/website/content/SDK/crypto/onchain/btc_transac/_index.rst +++ b/website/content/SDK/crypto/onchain/btc_transac/_index.rst @@ -38,7 +38,7 @@ crypto.onchain.btc_transac() -> pandas.core.frame.DataFrame {{< highlight python >}} crypto.onchain.btc_transac( start_date: int = 1262304000, - end_date: int = 1668289667, + end_date: int = 1668362499, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/onchain/hr/_index.rst b/website/content/SDK/crypto/onchain/hr/_index.rst index fabcc56a704a..18bb91208348 100644 --- a/website/content/SDK/crypto/onchain/hr/_index.rst +++ b/website/content/SDK/crypto/onchain/hr/_index.rst @@ -16,8 +16,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.onchain.hr( symbol: str, interval: str = '24h', - start_date: int = 1289857667, - end_date: int = 1668289667, + start_date: int = 1289930499, + end_date: int = 1668362499, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -59,8 +59,8 @@ crypto.onchain.hr( {{< highlight python >}} crypto.onchain.hr( symbol: str, - start_date: int = 1636753667, - end_date: int = 1668289667, + start_date: int = 1636826499, + end_date: int = 1668362499, interval: str = '24h', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/ov/altindex/_index.rst b/website/content/SDK/crypto/ov/altindex/_index.rst index df2562befec2..aed27c343194 100644 --- a/website/content/SDK/crypto/ov/altindex/_index.rst +++ b/website/content/SDK/crypto/ov/altindex/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.ov.altindex( period: int = 30, start_date: int = 1262304000, - end_date: int = 1668289667, + end_date: int = 1668362499, chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -59,7 +59,7 @@ crypto.ov.altindex( crypto.ov.altindex( period: int = 365, start_date: int = 1262304000, - end_date: int = 1668289667, + end_date: int = 1668362499, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/ov/btcrb/_index.rst b/website/content/SDK/crypto/ov/btcrb/_index.rst index 5981eaa1ff7f..ad0bfd9122ac 100644 --- a/website/content/SDK/crypto/ov/btcrb/_index.rst +++ b/website/content/SDK/crypto/ov/btcrb/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} crypto.ov.btcrb( start_date: str = '2010-01-01', - end_date: str = '2022-11-12', + end_date: str = '2022-11-13', chart: bool = False, ) {{< /highlight >}} @@ -49,7 +49,7 @@ crypto.ov.btcrb( {{< highlight python >}} crypto.ov.btcrb( start_date: str = '2010-01-01', - end_date: str = '2022-11-12', + end_date: str = '2022-11-13', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/economy/events/_index.rst b/website/content/SDK/economy/events/_index.rst index 51516856f10e..2bef62f0958e 100644 --- a/website/content/SDK/economy/events/_index.rst +++ b/website/content/SDK/economy/events/_index.rst @@ -13,8 +13,8 @@ {{< highlight python >}} economy.events( countries: Union[List[str], str] = '', - start_date: str = '2022-11-12', - end_date: str = '2022-11-12', + start_date: str = '2022-11-13', + end_date: str = '2022-11-13', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/economy/macro/_index.rst b/website/content/SDK/economy/macro/_index.rst index 7b388c5a7e5f..068338f41e46 100644 --- a/website/content/SDK/economy/macro/_index.rst +++ b/website/content/SDK/economy/macro/_index.rst @@ -19,7 +19,7 @@ economy.macro( transform: str = '', start_date: str = '1900-01-01', end_date=datetime.date( - 2022, 11, 12, chart: bool = False, + 2022, 11, 13, chart: bool = False, ), symbol: str = '', chart: bool = False, ) -> Tuple[Any, Dict[Any, Dict[Any, Any]], str] @@ -72,7 +72,7 @@ economy.macro( countries: list = None, transform: str = '', start_date: str = '1900-01-01', - end_date: str = '2022-11-12', + end_date: str = '2022-11-13', symbol: str = '', raw: bool = False, external_axes: Optional[List[axes]] = None, diff --git a/website/content/SDK/economy/treasury/_index.rst b/website/content/SDK/economy/treasury/_index.rst index bff395439d73..5b6d66900d03 100644 --- a/website/content/SDK/economy/treasury/_index.rst +++ b/website/content/SDK/economy/treasury/_index.rst @@ -18,7 +18,7 @@ economy.treasury( maturities: list = None, frequency: str = 'monthly', start_date: str = '1900-01-01', - end_date: str = '2022-11-12', + end_date: str = '2022-11-13', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -65,7 +65,7 @@ economy.treasury( maturities: list = None, frequency: str = 'monthly', start_date: str = '1900-01-01', - end_date: str = '2022-11-12', + end_date: str = '2022-11-13', raw: bool = False, external_axes: Optional[List[axes]] = None, export: str = '', diff --git a/website/content/SDK/etf/candle/_index.rst b/website/content/SDK/etf/candle/_index.rst index 9010011064fb..608e67abd895 100644 --- a/website/content/SDK/etf/candle/_index.rst +++ b/website/content/SDK/etf/candle/_index.rst @@ -21,11 +21,11 @@ etf.candle( asset_type: str = '', start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 8, 21, 47, 47, 956712, chart: bool = False, + 2019, 11, 9, 18, 1, 39, 804653, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 12, 21, 47, 47, 956713, chart: bool = False, + 2022, 11, 13, 18, 1, 39, 804654, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/etf/load/_index.rst b/website/content/SDK/etf/load/_index.rst index 1435eabe26e5..9cf0f84c91cb 100644 --- a/website/content/SDK/etf/load/_index.rst +++ b/website/content/SDK/etf/load/_index.rst @@ -15,11 +15,11 @@ etf.load( symbol: str, start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 8, 21, 47, 47, 956698, chart: bool = False, + 2019, 11, 9, 18, 1, 39, 804639, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 12, 21, 47, 47, 956708, chart: bool = False, + 2022, 11, 13, 18, 1, 39, 804648, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/etf/news/_index.rst b/website/content/SDK/etf/news/_index.rst index 72b3c96e142a..dfd66dea5b6d 100644 --- a/website/content/SDK/etf/news/_index.rst +++ b/website/content/SDK/etf/news/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. etf.news( query: str, limit: int = 10, - start_date: str = '2022-11-05', + start_date: str = '2022-11-06', show_newest: bool = True, sources: str = '', chart: bool = False, @@ -60,7 +60,7 @@ etf.news( etf.news( query: str, limit: int = 3, - start_date: str = '2022-11-05', + start_date: str = '2022-11-06', show_newest: bool = True, sources: str = '', export: str = '', diff --git a/website/content/SDK/forex/load/_index.rst b/website/content/SDK/forex/load/_index.rst index bb0146219a81..b0d82217caff 100644 --- a/website/content/SDK/forex/load/_index.rst +++ b/website/content/SDK/forex/load/_index.rst @@ -16,7 +16,7 @@ forex.load( from_symbol: str, resolution: str = 'd', interval: str = '1day', - start_date: str = '2021-11-12', + start_date: str = '2021-11-13', source: str = 'YahooFinance', verbose: bool = False, chart: bool = False, diff --git a/website/content/SDK/futures/historical/_index.rst b/website/content/SDK/futures/historical/_index.rst index 3828ceac08f3..3dec8d1bc884 100644 --- a/website/content/SDK/futures/historical/_index.rst +++ b/website/content/SDK/futures/historical/_index.rst @@ -53,7 +53,7 @@ futures.historical( futures.historical( symbols: List[str], expiry: str = '', - start_date: str = '2019-11-13', + start_date: str = '2019-11-14', raw: bool = False, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/portfolio/alloc/assets/_index.rst b/website/content/SDK/portfolio/alloc/assets/_index.rst new file mode 100644 index 000000000000..a4b5f7320d6e --- /dev/null +++ b/website/content/SDK/portfolio/alloc/assets/_index.rst @@ -0,0 +1,43 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.alloc.assets( + portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, + tables: bool = False, + limit: int = 10, + recalculate: bool = False, + chart: bool = False, +) -> Union[pandas.core.frame.DataFrame, Tuple[pandas.core.frame.DataFrame, pandas.core.frame.DataFrame, pandas.core.frame.DataFrame]] +{{< /highlight >}} + +.. raw:: html + +

+ Display portfolio asset allocation compared to the benchmark +

+ +* **Parameters** + + portfolio_engine: PortfolioEngine + PortfolioEngine object + tables: bool + Whether to include separate allocation tables + limit: int + The amount of assets you wish to show, by default this is set to 10 + recalculate: bool + Flag to force recalculate allocation if already exists + +* **Returns** + + Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] + DataFrame with combined allocation plus individual allocation if tables is `True`. diff --git a/website/content/SDK/portfolio/alloc/countries/_index.rst b/website/content/SDK/portfolio/alloc/countries/_index.rst new file mode 100644 index 000000000000..fccb0aa0df1e --- /dev/null +++ b/website/content/SDK/portfolio/alloc/countries/_index.rst @@ -0,0 +1,42 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.alloc.countries( + portfolio_engine=None, limit: int = 10, + tables: bool = False, + recalculate: bool = False, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Display portfolio country allocation compared to the benchmark +

+ +* **Parameters** + + portfolio_engine: PortfolioEngine + PortfolioEngine object + tables: bool + Whether to include separate allocation tables + limit: int + The amount of assets you wish to show, by default this is set to 10 + recalculate: bool + Flag to force recalculate allocation if already exists + +* **Returns** + + Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] + DataFrame with combined allocation plus individual allocation if tables is `True`. diff --git a/website/content/SDK/portfolio/alloc/regions/_index.rst b/website/content/SDK/portfolio/alloc/regions/_index.rst new file mode 100644 index 000000000000..b1a05723e078 --- /dev/null +++ b/website/content/SDK/portfolio/alloc/regions/_index.rst @@ -0,0 +1,42 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.alloc.regions( + portfolio_engine=None, limit: int = 10, + tables: bool = False, + recalculate: bool = False, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Display portfolio region allocation compared to the benchmark +

+ +* **Parameters** + + portfolio_engine: PortfolioEngine + PortfolioEngine object + tables: bool + Whether to include separate allocation tables + limit: int + The amount of assets you wish to show, by default this is set to 10 + recalculate: bool + Flag to force recalculate allocation if already exists + +* **Returns** + + Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] + DataFrame with combined allocation plus individual allocation if tables is `True`. diff --git a/website/content/SDK/portfolio/alloc/sectors/_index.rst b/website/content/SDK/portfolio/alloc/sectors/_index.rst new file mode 100644 index 000000000000..f4ce09a0ceb1 --- /dev/null +++ b/website/content/SDK/portfolio/alloc/sectors/_index.rst @@ -0,0 +1,42 @@ +.. role:: python(code) + :language: python + :class: highlight + +| + +.. raw:: html + +

+ > Getting data +

+ +{{< highlight python >}} +portfolio.alloc.sectors( + portfolio_engine=None, limit: int = 10, + tables: bool = False, + recalculate: bool = False, + chart: bool = False, +) +{{< /highlight >}} + +.. raw:: html + +

+ Display portfolio sector allocation compared to the benchmark +

+ +* **Parameters** + + portfolio_engine: PortfolioEngine + PortfolioEngine object + tables: bool + Whether to include separate allocation tables + limit: int + The amount of assets you wish to show, by default this is set to 10 + recalculate: bool + Flag to force recalculate allocation if already exists + +* **Returns** + + Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] + DataFrame with combined allocation plus individual allocation if tables is `True`. diff --git a/website/content/SDK/portfolio/load/_index.rst b/website/content/SDK/portfolio/load/_index.rst index 5838d968d754..b5246b99fc90 100644 --- a/website/content/SDK/portfolio/load/_index.rst +++ b/website/content/SDK/portfolio/load/_index.rst @@ -41,4 +41,4 @@ portfolio.load( * **Returns** PortfolioEngine - PortfolioEngine object + PortfolioEngine class instance, this will hold transactions and perform calculations diff --git a/website/content/SDK/portfolio/metric/tail/_index.rst b/website/content/SDK/portfolio/metric/tail/_index.rst index 3c2ae9e7d4a1..da1e16c158b6 100644 --- a/website/content/SDK/portfolio/metric/tail/_index.rst +++ b/website/content/SDK/portfolio/metric/tail/_index.rst @@ -29,7 +29,6 @@ portfolio.metric.tail( portfolio_engine: PortfolioEngine PortfolioEngine class instance, this will hold transactions and perform calculations. Use `portfolio.load` to create a PortfolioEngine. - window: int Interval used for rolling values diff --git a/website/content/SDK/stocks/ba/cnews/_index.rst b/website/content/SDK/stocks/ba/cnews/_index.rst index 50dcf920f610..f96209f5ed1f 100644 --- a/website/content/SDK/stocks/ba/cnews/_index.rst +++ b/website/content/SDK/stocks/ba/cnews/_index.rst @@ -13,8 +13,8 @@ {{< highlight python >}} stocks.ba.cnews( symbol: str, - start_date: str = '2022-10-13', - end_date: str = '2022-11-12', + start_date: str = '2022-10-14', + end_date: str = '2022-11-13', chart: bool = False, ) -> List[Dict] {{< /highlight >}} diff --git a/website/content/SDK/stocks/ba/hist/_index.rst b/website/content/SDK/stocks/ba/hist/_index.rst index 4f1b6fdb28ad..4114342795fc 100644 --- a/website/content/SDK/stocks/ba/hist/_index.rst +++ b/website/content/SDK/stocks/ba/hist/_index.rst @@ -15,8 +15,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ba.hist( symbol: str, - start_date: str = '2022-11-05', - end_date: str = '2022-11-12', + start_date: str = '2022-11-06', + end_date: str = '2022-11-13', number: int = 100, chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -61,8 +61,8 @@ stocks.ba.hist( {{< highlight python >}} stocks.ba.hist( symbol: str, - start_date: str = '2022-11-05', - end_date: str = '2022-11-12', + start_date: str = '2022-11-06', + end_date: str = '2022-11-13', number: int = 100, raw: bool = False, limit: int = 10, diff --git a/website/content/SDK/stocks/ba/trend/_index.rst b/website/content/SDK/stocks/ba/trend/_index.rst index 98d4f29b32ba..1b1779dce525 100644 --- a/website/content/SDK/stocks/ba/trend/_index.rst +++ b/website/content/SDK/stocks/ba/trend/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ba.trend( start_date: datetime.datetime = datetime.datetime( - 2022, 11, 12, 21, 47, 47, 374237, chart: bool = False, + 2022, 11, 13, 18, 1, 39, 204990, chart: bool = False, ), hour: int = 0, number: int = 10, chart: bool = False, @@ -60,7 +60,7 @@ stocks.ba.trend( {{< highlight python >}} stocks.ba.trend( start_date: datetime.datetime = datetime.datetime( - 2022, 11, 12, 21, 47, 47, 374405, chart: bool = False, + 2022, 11, 13, 18, 1, 39, 205183, chart: bool = False, ), hour: int = 0, number: int = 10, limit: int = 10, diff --git a/website/content/SDK/stocks/ca/hcorr/_index.rst b/website/content/SDK/stocks/ca/hcorr/_index.rst index 0b072cce5023..8e7ea202b7c0 100644 --- a/website/content/SDK/stocks/ca/hcorr/_index.rst +++ b/website/content/SDK/stocks/ca/hcorr/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ca.hcorr( similar: List[str], - start_date: str = '2021-11-11', + start_date: str = '2021-11-12', candle_type: str = 'a', chart: bool = False, ) @@ -52,7 +52,7 @@ stocks.ca.hcorr( {{< highlight python >}} stocks.ca.hcorr( similar: List[str], - start_date: str = '2021-11-11', + start_date: str = '2021-11-12', candle_type: str = 'a', display_full_matrix: bool = False, raw: bool = False, diff --git a/website/content/SDK/stocks/ca/hist/_index.rst b/website/content/SDK/stocks/ca/hist/_index.rst index c25ded4ee251..7fa86fe5fbd0 100644 --- a/website/content/SDK/stocks/ca/hist/_index.rst +++ b/website/content/SDK/stocks/ca/hist/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ca.hist( similar: List[str], - start_date: str = '2021-11-11', + start_date: str = '2021-11-12', candle_type: str = 'a', chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -57,7 +57,7 @@ stocks.ca.hist( {{< highlight python >}} stocks.ca.hist( similar: List[str], - start_date: str = '2021-11-11', + start_date: str = '2021-11-12', candle_type: str = 'a', normalize: bool = True, export: str = '', diff --git a/website/content/SDK/stocks/ca/volume/_index.rst b/website/content/SDK/stocks/ca/volume/_index.rst index 084566a43c59..2f8672761bd6 100644 --- a/website/content/SDK/stocks/ca/volume/_index.rst +++ b/website/content/SDK/stocks/ca/volume/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ca.volume( similar: List[str], - start_date: str = '2021-11-11', + start_date: str = '2021-11-12', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -49,7 +49,7 @@ stocks.ca.volume( {{< highlight python >}} stocks.ca.volume( similar: List[str], - start_date: str = '2021-11-11', + start_date: str = '2021-11-12', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/stocks/candle/_index.rst b/website/content/SDK/stocks/candle/_index.rst index c7713319b147..60807646c223 100644 --- a/website/content/SDK/stocks/candle/_index.rst +++ b/website/content/SDK/stocks/candle/_index.rst @@ -21,11 +21,11 @@ stocks.candle( asset_type: str = '', start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 8, 21, 47, 47, 956712, chart: bool = False, + 2019, 11, 9, 18, 1, 39, 804653, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 12, 21, 47, 47, 956713, chart: bool = False, + 2022, 11, 13, 18, 1, 39, 804654, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/stocks/dd/pt/_index.rst b/website/content/SDK/stocks/dd/pt/_index.rst index 854a78524443..424a9d911fcc 100644 --- a/website/content/SDK/stocks/dd/pt/_index.rst +++ b/website/content/SDK/stocks/dd/pt/_index.rst @@ -50,7 +50,7 @@ stocks.dd.pt( stocks.dd.pt( symbol: str, data: pandas.core.frame.DataFrame, - start_date: str = '2022-11-12', + start_date: str = '2022-11-13', limit: int = 10, raw: bool = False, export: str = '', diff --git a/website/content/SDK/stocks/disc/dividends/_index.rst b/website/content/SDK/stocks/disc/dividends/_index.rst index 645edb3753be..d77d33fa0e3a 100644 --- a/website/content/SDK/stocks/disc/dividends/_index.rst +++ b/website/content/SDK/stocks/disc/dividends/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} stocks.disc.dividends( - date: str = '2022-11-12', + date: str = '2022-11-13', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/stocks/disc/ipo/_index.rst b/website/content/SDK/stocks/disc/ipo/_index.rst index d80b8efec8ed..2cf51709f705 100644 --- a/website/content/SDK/stocks/disc/ipo/_index.rst +++ b/website/content/SDK/stocks/disc/ipo/_index.rst @@ -12,8 +12,8 @@ {{< highlight python >}} stocks.disc.ipo( - start_date: str = '2022-11-07', - end_date: str = '2022-11-12', + start_date: str = '2022-11-08', + end_date: str = '2022-11-13', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/stocks/dps/ftd/_index.rst b/website/content/SDK/stocks/dps/ftd/_index.rst index b5054406630d..821afcfb3b74 100644 --- a/website/content/SDK/stocks/dps/ftd/_index.rst +++ b/website/content/SDK/stocks/dps/ftd/_index.rst @@ -15,8 +15,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.dps.ftd( symbol: str, - start_date: str = '2022-09-13', - end_date: str = '2022-11-12', + start_date: str = '2022-09-14', + end_date: str = '2022-11-13', limit: int = 0, chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -59,8 +59,8 @@ stocks.dps.ftd( stocks.dps.ftd( symbol: str, data: pandas.core.frame.DataFrame, - start_date: str = '2022-09-13', - end_date: str = '2022-11-12', + start_date: str = '2022-09-14', + end_date: str = '2022-11-13', limit: int = 0, raw: bool = False, export: str = '', diff --git a/website/content/SDK/stocks/fa/mktcap/_index.rst b/website/content/SDK/stocks/fa/mktcap/_index.rst index c0693a6a0e33..1c1416f7d229 100644 --- a/website/content/SDK/stocks/fa/mktcap/_index.rst +++ b/website/content/SDK/stocks/fa/mktcap/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.fa.mktcap( symbol: str, - start_date: str = '2019-11-10', + start_date: str = '2019-11-11', chart: bool = False, ) -> Tuple[pandas.core.frame.DataFrame, str] {{< /highlight >}} @@ -54,7 +54,7 @@ stocks.fa.mktcap( {{< highlight python >}} stocks.fa.mktcap( symbol: str, - start_date: str = '2019-11-10', + start_date: str = '2019-11-11', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/stocks/ins/act/_index.rst b/website/content/SDK/stocks/ins/act/_index.rst index a1b5c2613027..2d1352c16371 100644 --- a/website/content/SDK/stocks/ins/act/_index.rst +++ b/website/content/SDK/stocks/ins/act/_index.rst @@ -50,7 +50,7 @@ stocks.ins.act( stocks.ins.act( data: pandas.core.frame.DataFrame, symbol: str, - start_date: str = '2019-11-08', + start_date: str = '2019-11-09', interval: str = '1440min', limit: int = 10, raw: bool = False, diff --git a/website/content/SDK/stocks/load/_index.rst b/website/content/SDK/stocks/load/_index.rst index 53db730c991d..9d9af2ee477b 100644 --- a/website/content/SDK/stocks/load/_index.rst +++ b/website/content/SDK/stocks/load/_index.rst @@ -15,11 +15,11 @@ stocks.load( symbol: str, start_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2019, 11, 8, 21, 47, 47, 956698, chart: bool = False, + 2019, 11, 9, 18, 1, 39, 804639, chart: bool = False, ), interval: int = 1440, end_date: Union[datetime.datetime, str, NoneType] = datetime.datetime( - 2022, 11, 12, 21, 47, 47, 956708, chart: bool = False, + 2022, 11, 13, 18, 1, 39, 804648, chart: bool = False, ), prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/stocks/options/pcr/_index.rst b/website/content/SDK/stocks/options/pcr/_index.rst index c2b6ae47df96..560e8d08b521 100644 --- a/website/content/SDK/stocks/options/pcr/_index.rst +++ b/website/content/SDK/stocks/options/pcr/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. stocks.options.pcr( symbol: str, window: int = 30, - start_date: str = '2021-11-11', + start_date: str = '2021-11-12', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -51,7 +51,7 @@ stocks.options.pcr( stocks.options.pcr( symbol: str, window: int = 30, - start_date: str = '2021-11-11', + start_date: str = '2021-11-12', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/stocks/screener/historical/_index.rst b/website/content/SDK/stocks/screener/historical/_index.rst index 2e740bb04ba5..b532798b4fdc 100644 --- a/website/content/SDK/stocks/screener/historical/_index.rst +++ b/website/content/SDK/stocks/screener/historical/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. stocks.screener.historical( preset_loaded: str = 'top_gainers', limit: int = 10, - start_date: str = '2022-05-16', + start_date: str = '2022-05-17', type_candle: str = 'a', normalize: bool = True, chart: bool = False, @@ -66,7 +66,7 @@ stocks.screener.historical( stocks.screener.historical( preset_loaded: str = 'top_gainers', limit: int = 10, - start_date: str = '2022-05-16', + start_date: str = '2022-05-17', type_candle: str = 'a', normalize: bool = True, export: str = '', From 4064beebb8f36e14f5767bac4102855439fb4df0 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 13 Nov 2022 19:13:37 +0000 Subject: [PATCH 25/30] fix alloc bugs --- openbb_terminal/portfolio/allocation_model.py | 26 +- .../reports/templates/portfolio.ipynb | 427 ++---------------- 2 files changed, 49 insertions(+), 404 deletions(-) diff --git a/openbb_terminal/portfolio/allocation_model.py b/openbb_terminal/portfolio/allocation_model.py index 14b121d33463..9299efa9ec5f 100644 --- a/openbb_terminal/portfolio/allocation_model.py +++ b/openbb_terminal/portfolio/allocation_model.py @@ -403,39 +403,37 @@ def get_portfolio_allocation( .groupby(by="Ticker") .agg({"Portfolio Value": "sum"}) ) - etf_global_country_alloc = pd.DataFrame() + etf_global_alloc = pd.DataFrame() # Loop through each etf and multiply sector weights by current value for item in etf_ticker_value.index.values: - etf_country_weight = get_symbol_allocation(symbol=item, category=category) + etf_weight = get_symbol_allocation(symbol=item, category=category) + etf_weight.set_index(category, inplace=True) - if etf_country_weight.empty: - etf_country_weight = pd.DataFrame.from_dict( + if etf_weight.empty: + etf_weight = pd.DataFrame.from_dict( data={"Other": 1}, orient="index", columns=["Portfolio Value"] ) etf_value = etf_ticker_value["Portfolio Value"][item] # Aggregate etf allocation by value - etf_ticker_country_alloc = etf_country_weight * etf_value - etf_global_country_alloc = pd.concat( - [etf_global_country_alloc, etf_ticker_country_alloc], axis=1 - ) - etf_global_country_alloc.fillna(0, inplace=True) - etf_global_country_alloc = etf_global_country_alloc.sum(axis=1) + etf_ticker_alloc = etf_weight + etf_ticker_alloc["Benchmark"] = etf_ticker_alloc["Benchmark"] * etf_value + etf_global_alloc = pd.concat([etf_global_alloc, etf_ticker_alloc], axis=1) + etf_global_alloc.fillna(0, inplace=True) + etf_global_alloc = etf_global_alloc.sum(axis=1) p_bar.n += 1 p_bar.refresh() - etf_global_country_alloc = pd.DataFrame( - etf_global_country_alloc, columns=["Portfolio Value"] - ) + etf_global_alloc = pd.DataFrame(etf_global_alloc, columns=["Portfolio Value"]) # Aggregate allocation for stocks and crypto with ETFs allocation = pd.merge( allocation, - etf_global_country_alloc, + etf_global_alloc, how="outer", left_index=True, right_index=True, diff --git a/openbb_terminal/reports/templates/portfolio.ipynb b/openbb_terminal/reports/templates/portfolio.ipynb index 213418e1c234..23496c41b663 100644 --- a/openbb_terminal/reports/templates/portfolio.ipynb +++ b/openbb_terminal/reports/templates/portfolio.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "driven-billion", "metadata": {}, "outputs": [], @@ -66,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "c3fe7db5-ec6a-42cf-9e66-52dc1de22370", "metadata": {}, "outputs": [], @@ -78,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "daef64ec", "metadata": { "tags": [ @@ -89,30 +89,16 @@ "source": [ "# Parameters that will be replaced when calling this notebook\n", "# Do not leave parameters blank as notebook will not run otherwise\n", - "transactions = \"Public_Equity_Orderbook.xlsx\"\n", + "transactions = \"market.csv\"\n", "report_name = \"Portfolio Report\"" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "1be26dae-cafe-4a22-80aa-eff296fc1a9b", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "('Portfolio report for Public_Equity_Orderbook.xlsx',\n", - " '12 November, 2022',\n", - " '17:09',\n", - " )" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "holdings = (\n", " str(REPOSITORY_DIRECTORY)\n", @@ -145,21 +131,10 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "b139556d", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Preprocessing transactions: 100%|██████████| 14/14 [00:02<00:00, 6.24it/s] \n", - " Loading price data: 100%|██████████| 1/1 [00:00<00:00, 1.98it/s]\n", - " Calculating returns: 100%|██████████| 1/1 [00:00<00:00, 51.80it/s]\n", - " Loading benchmark: 100%|██████████| 4/4 [00:04<00:00, 1.21s/it]\n" - ] - } - ], + "outputs": [], "source": [ "try:\n", " P = openbb.portfolio.load(transactions_path)\n", @@ -177,21 +152,10 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "af24ed22", "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:09:58.445267\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(11, 5), dpi=150)\n", "openbb.portfolio.rbeta(P, chart=True, external_axes=[ax])\n", @@ -204,21 +168,10 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "636c743d", "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:09:59.229112\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(11, 5), dpi=150)\n", "openbb.portfolio.rsharpe(P, chart=True, external_axes=[ax])\n", @@ -231,21 +184,10 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "id": "ae0d9381", "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:09:59.406325\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(11, 5), dpi=150)\n", "openbb.portfolio.rvol(P, chart=True, external_axes=[ax])\n", @@ -258,21 +200,10 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "id": "7e5e6fff", "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:10:00.720201\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(11, 5), dpi=150)\n", "openbb.portfolio.rsort(P, chart=True, external_axes=[ax])\n", @@ -285,21 +216,10 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "id": "3567b0ca", "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:10:00.974412\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "fig, ax = plt.subplots(nrows=2, ncols=1, figsize=(11, 5), dpi=150)\n", "openbb.portfolio.maxdd(P, chart=True, external_axes=ax)\n", @@ -312,305 +232,54 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "id": "5dbcc1eb", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Loading country/region data: 100%|██████████| 3/3 [00:00<00:00, 362.76it/s]" - ] - }, - { - "data": { - "text/html": [ - "
\n",
-       "\n",
-       "
\n" - ], - "text/plain": [ - "\n", - "\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
PortfolioBenchmark
Netherlands42.6%0.12%
United States32.3%99.0%
Taiwan12.5%---%
China7.55%---%
Germany5.05%---%
United Kingdom---%0.53%
Switzerland---%0.37%
Singapore---%0.03%
\n", - "
" - ], - "text/plain": [ - " Portfolio Benchmark\n", - "Netherlands 42.6% 0.12%\n", - "United States 32.3% 99.0%\n", - "Taiwan 12.5% ---%\n", - "China 7.55% ---%\n", - "Germany 5.05% ---%\n", - "United Kingdom ---% 0.53%\n", - "Switzerland ---% 0.37%\n", - "Singapore ---% 0.03%" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "P.calculate_allocations(\"country\")\n", + "country_allocation = openbb.portfolio.alloc.countries(P)\n", "\n", - "country_allocation = pd.DataFrame(\n", - " [P.portfolio_country_allocation, P.benchmark_country_allocation]\n", - ").T\n", - "country_allocation.columns = [\"Portfolio\", \"Benchmark\"]\n", - "country_allocation.fillna(\"-\", inplace=True)\n", "country_allocation[\"Portfolio\"] = (country_allocation[\"Portfolio\"] * 100).map(\n", " \"{:.3}%\".format\n", ")\n", "country_allocation[\"Benchmark\"] = (country_allocation[\"Benchmark\"] * 100).map(\n", " \"{:.3}%\".format\n", ")\n", + "country_allocation[\"Difference\"] = (country_allocation[\"Difference\"] * 100).map(\n", + " \"{:.3}pp\".format\n", + ")\n", "\n", "country_allocation" ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "id": "8e1a67a6", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Loading sector data: 100%|██████████| 3/3 [00:00<00:00, 514.74it/s]" - ] - }, - { - "data": { - "text/html": [ - "
\n",
-       "\n",
-       "
\n" - ], - "text/plain": [ - "\n", - "\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
PortfolioBenchmark
Technology62.2%23.6%
Consumer Cyclical25.4%10.6%
Healthcare11.2%15.4%
Communication Services1.27%7.35%
Financial Services---%13.7%
Industrials---%8.68%
Consumer Defensive---%7.38%
Energy---%5.36%
Realestate---%2.74%
Utilities---%2.45%
Basic Materials---%2.27%
\n", - "
" - ], - "text/plain": [ - " Portfolio Benchmark\n", - "Technology 62.2% 23.6%\n", - "Consumer Cyclical 25.4% 10.6%\n", - "Healthcare 11.2% 15.4%\n", - "Communication Services 1.27% 7.35%\n", - "Financial Services ---% 13.7%\n", - "Industrials ---% 8.68%\n", - "Consumer Defensive ---% 7.38%\n", - "Energy ---% 5.36%\n", - "Realestate ---% 2.74%\n", - "Utilities ---% 2.45%\n", - "Basic Materials ---% 2.27%" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "P.calculate_allocations(\"sector\")\n", + "sector_allocation = openbb.portfolio.alloc.sectors(P)\n", "\n", - "sector_allocation = pd.DataFrame(\n", - " [P.portfolio_sectors_allocation, P.benchmark_sectors_allocation]\n", - ").T\n", - "sector_allocation.columns = [\"Portfolio\", \"Benchmark\"]\n", - "sector_allocation.fillna(\"-\", inplace=True)\n", "sector_allocation[\"Portfolio\"] = (sector_allocation[\"Portfolio\"] * 100).map(\n", " \"{:.3}%\".format\n", ")\n", "sector_allocation[\"Benchmark\"] = (sector_allocation[\"Benchmark\"] * 100).map(\n", " \"{:.3}%\".format\n", ")\n", + "sector_allocation[\"Difference\"] = (sector_allocation[\"Difference\"] * 100).map(\n", + " \"{:.3}pp\".format\n", + ")\n", "\n", "sector_allocation" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "id": "6e1260b4", "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:10:02.580188\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(10, 4), dpi=150)\n", "openbb.portfolio.distr(P, chart=True, external_axes=[ax])\n", @@ -623,21 +292,10 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "id": "a668a58b", "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:10:02.837335\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(10, 4), dpi=150)\n", "openbb.portfolio.dret(P, chart=True, external_axes=[ax1, ax2])\n", @@ -650,21 +308,10 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "id": "1ea71ca6", "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": "\n\n\n \n \n \n \n 2022-11-12T22:10:03.060634\n image/svg+xml\n \n \n Matplotlib v3.5.3, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(10, 4), dpi=150)\n", "openbb.portfolio.yret(P, chart=True, external_axes=[ax])\n", @@ -685,7 +332,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "id": "ebe0799e", "metadata": {}, "outputs": [], From 630568e22daa074d6d72c5261dfea1c0195ccd6a Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Mon, 14 Nov 2022 11:33:17 +0000 Subject: [PATCH 26/30] forgot this exception --- openbb_terminal/portfolio/portfolio_view.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/openbb_terminal/portfolio/portfolio_view.py b/openbb_terminal/portfolio/portfolio_view.py index fd1d42da9e07..c5350d5d65b9 100644 --- a/openbb_terminal/portfolio/portfolio_view.py +++ b/openbb_terminal/portfolio/portfolio_view.py @@ -290,6 +290,14 @@ def display_category(**kwargs): tables = kwargs["tables"] limit = kwargs["limit"] + if benchmark_allocation.empty: + console.print(f"[red]Benchmark data for {category} is empty.\n[/red]") + return + + if portfolio_allocation.empty: + console.print(f"[red]Portfolio data for {category} is empty.\n[/red]") + return + if tables: print_rich_table( combined.replace(0, "-"), From 9b6a74197a44049722635b0d7481e9c98d01b1a8 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Mon, 14 Nov 2022 12:06:55 +0000 Subject: [PATCH 27/30] some refactor on portfolio alloc country region --- openbb_terminal/portfolio/allocation_model.py | 133 ++++++++---------- openbb_terminal/portfolio/portfolio_model.py | 5 +- 2 files changed, 58 insertions(+), 80 deletions(-) diff --git a/openbb_terminal/portfolio/allocation_model.py b/openbb_terminal/portfolio/allocation_model.py index 9299efa9ec5f..6c0c349c03f4 100644 --- a/openbb_terminal/portfolio/allocation_model.py +++ b/openbb_terminal/portfolio/allocation_model.py @@ -110,8 +110,6 @@ def get_sectors_allocation( DataFrame with country allocations """ - p_bar = tqdm(range(3), desc="Loading sector data") - benchmark_sectors_allocation = ( pd.DataFrame.from_dict( data={ @@ -143,8 +141,6 @@ def get_sectors_allocation( .groupby(by="Sector") .agg({"Portfolio Value": "sum"}) ) - p_bar.n += 1 - p_bar.refresh() # Aggregate sector value for ETFs # Start by getting value by isin/symbol @@ -155,48 +151,45 @@ def get_sectors_allocation( ) etf_global_sector_alloc = pd.DataFrame() - # Loop through each etf and multiply sector weights by current value - for item in etf_ticker_value.index.values: - - # TODO: This can be improved by caching this info similar to what is done in stocks - etf_info = yf.Ticker(item).info - - try: - etf_sector_weight = pd.DataFrame.from_dict( - data={ - sector_name: allocation - for sector in etf_info["sectorWeightings"] - for sector_name, allocation in sector.items() - }, - orient="index", - columns=["Portfolio Value"], - ) - - except Exception: - # If ETF has no sectors like VIX for example or it was not found, add to Other - etf_sector_weight = pd.DataFrame.from_dict( - data={"Other": 1}, orient="index", columns=["Portfolio Value"] + if not etf_ticker_value.empty: + # Loop through each etf and multiply sector weights by current value + for item in tqdm(etf_ticker_value.index.values, desc="Loading ETF data"): + + # TODO: This can be improved by caching this info similar to what is done in stocks + etf_info = yf.Ticker(item).info + + try: + etf_sector_weight = pd.DataFrame.from_dict( + data={ + sector_name: allocation + for sector in etf_info["sectorWeightings"] + for sector_name, allocation in sector.items() + }, + orient="index", + columns=["Portfolio Value"], + ) + + except Exception: + # If ETF has no sectors like VIX for example or it was not found, add to Other + etf_sector_weight = pd.DataFrame.from_dict( + data={"Other": 1}, orient="index", columns=["Portfolio Value"] + ) + + etf_value = etf_ticker_value["Portfolio Value"][item] + + etf_ticker_sector_alloc = etf_sector_weight * etf_value + + # Aggregate etf sector allocation by value + etf_global_sector_alloc = pd.concat( + [etf_global_sector_alloc, etf_ticker_sector_alloc], axis=1 ) + etf_global_sector_alloc.fillna(0, inplace=True) + etf_global_sector_alloc = etf_global_sector_alloc.sum(axis=1) - etf_value = etf_ticker_value["Portfolio Value"][item] - - etf_ticker_sector_alloc = etf_sector_weight * etf_value - - # Aggregate etf sector allocation by value - etf_global_sector_alloc = pd.concat( - [etf_global_sector_alloc, etf_ticker_sector_alloc], axis=1 + etf_global_sector_alloc = pd.DataFrame( + etf_global_sector_alloc, columns=["Portfolio Value"] ) - - etf_global_sector_alloc.fillna(0, inplace=True) - - etf_global_sector_alloc = etf_global_sector_alloc.sum(axis=1) - - p_bar.n += 1 - p_bar.refresh() - - etf_global_sector_alloc = pd.DataFrame( - etf_global_sector_alloc, columns=["Portfolio Value"] - ) + console.print("\n") # Rename columns to match stock and crypto classification etf_global_sector_alloc.index.name = "Sector" @@ -228,11 +221,6 @@ def get_sectors_allocation( portfolio_sectors_allocation.reset_index(inplace=True) portfolio_sectors_allocation.columns = ["Sector", "Portfolio"] - p_bar.n += 1 - p_bar.refresh() - p_bar.disable = True - console.print("\n") - return benchmark_sectors_allocation, portfolio_sectors_allocation @@ -381,8 +369,6 @@ def get_portfolio_allocation( Dictionary with country allocations """ - p_bar = tqdm(range(3), desc=f"Loading {category.lower()} data") - # Define portfolio allocation if not portfolio_trades[category].isnull().any(): allocation = ( @@ -393,9 +379,6 @@ def get_portfolio_allocation( else: allocation = pd.DataFrame() - p_bar.n += 1 - p_bar.refresh() - # Aggregate sector value for ETFs # Start by getting value by symbol etf_ticker_value = ( @@ -403,32 +386,31 @@ def get_portfolio_allocation( .groupby(by="Ticker") .agg({"Portfolio Value": "sum"}) ) - etf_global_alloc = pd.DataFrame() - - # Loop through each etf and multiply sector weights by current value - for item in etf_ticker_value.index.values: + etf_global_alloc = pd.DataFrame(columns=[category, "Portfolio Value"]) - etf_weight = get_symbol_allocation(symbol=item, category=category) - etf_weight.set_index(category, inplace=True) + if not etf_ticker_value.empty: + # Loop through each etf and multiply sector weights by current value + for item in tqdm(etf_ticker_value.index.values, desc="Loading ETF data"): - if etf_weight.empty: - etf_weight = pd.DataFrame.from_dict( - data={"Other": 1}, orient="index", columns=["Portfolio Value"] - ) + etf_weight = get_symbol_allocation(symbol=item, category=category) + etf_weight.set_index(category, inplace=True) - etf_value = etf_ticker_value["Portfolio Value"][item] + if etf_weight.empty: + etf_weight = pd.DataFrame.from_dict( + data={"Other": 1}, orient="index", columns=["Portfolio Value"] + ) - # Aggregate etf allocation by value - etf_ticker_alloc = etf_weight - etf_ticker_alloc["Benchmark"] = etf_ticker_alloc["Benchmark"] * etf_value - etf_global_alloc = pd.concat([etf_global_alloc, etf_ticker_alloc], axis=1) - etf_global_alloc.fillna(0, inplace=True) - etf_global_alloc = etf_global_alloc.sum(axis=1) + etf_value = etf_ticker_value["Portfolio Value"][item] - p_bar.n += 1 - p_bar.refresh() + # Aggregate etf allocation by value + etf_ticker_alloc = etf_weight + etf_ticker_alloc["Benchmark"] = etf_ticker_alloc["Benchmark"] * etf_value + etf_global_alloc = pd.concat([etf_global_alloc, etf_ticker_alloc], axis=1) + etf_global_alloc.fillna(0, inplace=True) + etf_global_alloc = etf_global_alloc.sum(axis=1) - etf_global_alloc = pd.DataFrame(etf_global_alloc, columns=["Portfolio Value"]) + etf_global_alloc = pd.DataFrame(etf_global_alloc, columns=["Portfolio Value"]) + console.print("\n") # Aggregate allocation for stocks and crypto with ETFs allocation = pd.merge( @@ -447,11 +429,6 @@ def get_portfolio_allocation( allocation.fillna(0, inplace=True) - p_bar.n += 1 - p_bar.refresh() - p_bar.disable = True - console.print("\n") - allocation.reset_index(inplace=True) allocation.columns = [category, "Portfolio"] diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index b24cc232ef1c..e08a33a7402f 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -349,15 +349,16 @@ def __preprocess_transactions(self): p_bar.n += 1 p_bar.refresh() + p_bar.disable = True # Warn user of removed ISINs if removed_tickers: console.print( - f"\n\n[red]The following tickers are not supported and were removed: {removed_tickers}." + f"\n[red]The following tickers are not supported and were removed: {removed_tickers}." f"\nManually edit the 'Ticker' field with the proper Yahoo Finance suffix or provide a valid ISIN." f"\nSuffix info on 'Yahoo Finance market coverage':" " https://help.yahoo.com/kb/exchanges-data-providers-yahoo-finance-sln2310.html" - f"\nE.g. IWDA -> IWDA.AS[/red]" + f"\nE.g. IWDA -> IWDA.AS[/red]\n" ) except Exception: console.print("\nCould not preprocess transactions.") From 0a45a2a3ea5245988e0ef69840e270cb8e88f471 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Mon, 14 Nov 2022 12:56:20 +0000 Subject: [PATCH 28/30] fix some allocation bugs --- openbb_terminal/portfolio/allocation_model.py | 44 +++++++++++++------ openbb_terminal/portfolio/portfolio_model.py | 2 +- openbb_terminal/portfolio/portfolio_view.py | 4 +- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/openbb_terminal/portfolio/allocation_model.py b/openbb_terminal/portfolio/allocation_model.py index 6c0c349c03f4..15e0a000d85f 100644 --- a/openbb_terminal/portfolio/allocation_model.py +++ b/openbb_terminal/portfolio/allocation_model.py @@ -175,9 +175,9 @@ def get_sectors_allocation( data={"Other": 1}, orient="index", columns=["Portfolio Value"] ) - etf_value = etf_ticker_value["Portfolio Value"][item] - - etf_ticker_sector_alloc = etf_sector_weight * etf_value + etf_ticker_sector_alloc = ( + etf_sector_weight * etf_ticker_value["Portfolio Value"][item] + ) # Aggregate etf sector allocation by value etf_global_sector_alloc = pd.concat( @@ -246,7 +246,7 @@ def get_countries_allocation( """ benchmark_allocation = get_symbol_allocation( - symbol=benchmark_info["symbol"], category="Country" + symbol=benchmark_info["symbol"], category="Country", col_name="Benchmark" ) portfolio_allocation = get_portfolio_allocation( @@ -277,7 +277,7 @@ def get_regions_allocation( DataFrame with country allocations """ benchmark_allocation = get_symbol_allocation( - symbol=benchmark_info["symbol"], category="Region" + symbol=benchmark_info["symbol"], category="Region", col_name="Benchmark" ) portfolio_allocation = get_portfolio_allocation( @@ -287,7 +287,9 @@ def get_regions_allocation( return benchmark_allocation, portfolio_allocation -def get_symbol_allocation(symbol: str, category: str) -> pd.DataFrame: +def get_symbol_allocation( + symbol: str, category: str, col_name: str = "Weight" +) -> pd.DataFrame: """Get benchmark allocation [Source: Fidelity] Parameters @@ -343,9 +345,9 @@ def get_symbol_allocation(symbol: str, category: str) -> pd.DataFrame: } allocation_df = pd.DataFrame.from_dict(allocation, orient="index") allocation_df.reset_index(inplace=True) - allocation_df.columns = [category, "Benchmark"] + allocation_df.columns = [category, col_name] else: - allocation_df = pd.DataFrame() + allocation_df = pd.DataFrame(columns=[category, col_name]) return allocation_df @@ -389,28 +391,42 @@ def get_portfolio_allocation( etf_global_alloc = pd.DataFrame(columns=[category, "Portfolio Value"]) if not etf_ticker_value.empty: + + no_info = [] # Loop through each etf and multiply sector weights by current value for item in tqdm(etf_ticker_value.index.values, desc="Loading ETF data"): - etf_weight = get_symbol_allocation(symbol=item, category=category) - etf_weight.set_index(category, inplace=True) + etf_weight = get_symbol_allocation( + symbol=item, category=category, col_name="Portfolio Value" + ) if etf_weight.empty: etf_weight = pd.DataFrame.from_dict( data={"Other": 1}, orient="index", columns=["Portfolio Value"] ) - - etf_value = etf_ticker_value["Portfolio Value"][item] + etf_weight.index.name = category + no_info.append(item) + else: + etf_weight.set_index(category, inplace=True) # Aggregate etf allocation by value etf_ticker_alloc = etf_weight - etf_ticker_alloc["Benchmark"] = etf_ticker_alloc["Benchmark"] * etf_value + etf_ticker_alloc["Portfolio Value"] = ( + etf_ticker_alloc["Portfolio Value"] + * etf_ticker_value["Portfolio Value"][item] + ) etf_global_alloc = pd.concat([etf_global_alloc, etf_ticker_alloc], axis=1) etf_global_alloc.fillna(0, inplace=True) etf_global_alloc = etf_global_alloc.sum(axis=1) etf_global_alloc = pd.DataFrame(etf_global_alloc, columns=["Portfolio Value"]) - console.print("\n") + + console.print("") + + if no_info: + console.print( + f"[red]No data found for: {', '.join(no_info)}. Included in 'Other'.[/red]\n" + ) # Aggregate allocation for stocks and crypto with ETFs allocation = pd.merge( diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index e08a33a7402f..c574e290a25e 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -349,10 +349,10 @@ def __preprocess_transactions(self): p_bar.n += 1 p_bar.refresh() - p_bar.disable = True # Warn user of removed ISINs if removed_tickers: + p_bar.disable = True console.print( f"\n[red]The following tickers are not supported and were removed: {removed_tickers}." f"\nManually edit the 'Ticker' field with the proper Yahoo Finance suffix or provide a valid ISIN." diff --git a/openbb_terminal/portfolio/portfolio_view.py b/openbb_terminal/portfolio/portfolio_view.py index c5350d5d65b9..7880a2945d9a 100644 --- a/openbb_terminal/portfolio/portfolio_view.py +++ b/openbb_terminal/portfolio/portfolio_view.py @@ -291,11 +291,11 @@ def display_category(**kwargs): limit = kwargs["limit"] if benchmark_allocation.empty: - console.print(f"[red]Benchmark data for {category} is empty.\n[/red]") + console.print(f"[red]Benchmark data for {category} is empty.[/red]") return if portfolio_allocation.empty: - console.print(f"[red]Portfolio data for {category} is empty.\n[/red]") + console.print(f"[red]Portfolio data for {category} is empty.[/red]") return if tables: From fb0281c09ec361dd8da8b56a808beeadb48c4218 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Mon, 14 Nov 2022 14:24:07 +0000 Subject: [PATCH 29/30] add examples --- openbb_terminal/portfolio/portfolio_model.py | 272 +++++++++++++++++- .../reports/templates/portfolio.ipynb | 5 - .../content/SDK/crypto/dd/active/_index.rst | 4 +- .../content/SDK/crypto/dd/change/_index.rst | 4 +- .../content/SDK/crypto/dd/close/_index.rst | 2 +- website/content/SDK/crypto/dd/eb/_index.rst | 4 +- website/content/SDK/crypto/dd/gh/_index.rst | 8 +- .../content/SDK/crypto/dd/mcapdom/_index.rst | 8 +- website/content/SDK/crypto/dd/mt/_index.rst | 8 +- .../content/SDK/crypto/dd/nonzero/_index.rst | 4 +- website/content/SDK/crypto/dd/oi/_index.rst | 2 +- website/content/SDK/crypto/load/_index.rst | 6 +- .../SDK/crypto/onchain/btc_supply/_index.rst | 2 +- .../SDK/crypto/onchain/btc_transac/_index.rst | 2 +- .../content/SDK/crypto/onchain/hr/_index.rst | 4 +- .../content/SDK/crypto/ov/altindex/_index.rst | 4 +- .../content/SDK/crypto/ov/btcrb/_index.rst | 4 +- website/content/SDK/economy/events/_index.rst | 4 +- website/content/SDK/economy/macro/_index.rst | 4 +- .../content/SDK/economy/treasury/_index.rst | 4 +- website/content/SDK/etf/candle/_index.rst | 4 +- website/content/SDK/etf/load/_index.rst | 4 +- website/content/SDK/etf/news/_index.rst | 4 +- .../SDK/forex/get_currency_list/_index.rst | 2 +- website/content/SDK/forex/load/_index.rst | 2 +- .../content/SDK/futures/historical/_index.rst | 2 +- website/content/SDK/portfolio/alloc/_index.md | 6 + .../SDK/portfolio/alloc/assets/_index.rst | 11 +- .../SDK/portfolio/alloc/countries/_index.rst | 11 +- .../SDK/portfolio/alloc/regions/_index.rst | 11 +- .../SDK/portfolio/alloc/sectors/_index.rst | 11 +- .../content/SDK/portfolio/bench/_index.rst | 8 + .../content/SDK/portfolio/distr/_index.rst | 8 + website/content/SDK/portfolio/dret/_index.rst | 9 + website/content/SDK/portfolio/es/_index.rst | 9 + .../content/SDK/portfolio/holdp/_index.rst | 8 + .../content/SDK/portfolio/holdv/_index.rst | 8 + website/content/SDK/portfolio/load/_index.rst | 7 + .../portfolio/max_drawdown_ratio/_index.rst | 78 ----- .../content/SDK/portfolio/maxdd/_index.rst | 8 + .../SDK/portfolio/metric/calmar/_index.rst | 8 + .../portfolio/metric/commonsense/_index.rst | 8 + .../portfolio/metric/gaintopain/_index.rst | 8 + .../portfolio/metric/information/_index.rst | 8 + .../SDK/portfolio/metric/jensens/_index.rst | 8 + .../SDK/portfolio/metric/kelly/_index.rst | 8 + .../SDK/portfolio/metric/kurtosis/_index.rst | 8 + .../portfolio/metric/maxdrawdown/_index.rst | 8 + .../SDK/portfolio/metric/payoff/_index.rst | 14 + .../portfolio/metric/profitfactor/_index.rst | 8 + .../SDK/portfolio/metric/rsquare/_index.rst | 8 + .../SDK/portfolio/metric/sharpe/_index.rst | 8 + .../SDK/portfolio/metric/skew/_index.rst | 14 + .../SDK/portfolio/metric/sortino/_index.rst | 8 + .../SDK/portfolio/metric/tail/_index.rst | 8 + .../SDK/portfolio/metric/trackerr/_index.rst | 8 + .../portfolio/metric/volatility/_index.rst | 8 + website/content/SDK/portfolio/mret/_index.rst | 9 + website/content/SDK/portfolio/om/_index.rst | 9 + website/content/SDK/portfolio/perf/_index.rst | 9 + .../content/SDK/portfolio/rbeta/_index.rst | 8 + .../content/SDK/portfolio/rsharpe/_index.rst | 8 + .../content/SDK/portfolio/rsort/_index.rst | 8 + website/content/SDK/portfolio/rvol/_index.rst | 8 + website/content/SDK/portfolio/show/_index.rst | 8 + .../content/SDK/portfolio/summary/_index.rst | 11 +- website/content/SDK/portfolio/var/_index.rst | 9 + website/content/SDK/portfolio/yret/_index.rst | 15 +- .../content/SDK/stocks/ba/cnews/_index.rst | 4 +- website/content/SDK/stocks/ba/hist/_index.rst | 8 +- .../content/SDK/stocks/ba/trend/_index.rst | 4 +- .../content/SDK/stocks/ca/hcorr/_index.rst | 4 +- website/content/SDK/stocks/ca/hist/_index.rst | 4 +- .../content/SDK/stocks/ca/volume/_index.rst | 4 +- website/content/SDK/stocks/candle/_index.rst | 4 +- website/content/SDK/stocks/dd/pt/_index.rst | 2 +- .../SDK/stocks/disc/dividends/_index.rst | 2 +- .../content/SDK/stocks/disc/ipo/_index.rst | 4 +- website/content/SDK/stocks/dps/ftd/_index.rst | 8 +- .../content/SDK/stocks/fa/mktcap/_index.rst | 4 +- website/content/SDK/stocks/ins/act/_index.rst | 2 +- website/content/SDK/stocks/load/_index.rst | 4 +- .../content/SDK/stocks/options/pcr/_index.rst | 4 +- .../SDK/stocks/screener/historical/_index.rst | 4 +- website/data/menu/main.yml | 13 +- website/generate.py | 30 +- 86 files changed, 742 insertions(+), 183 deletions(-) create mode 100644 website/content/SDK/portfolio/alloc/_index.md delete mode 100644 website/content/SDK/portfolio/max_drawdown_ratio/_index.rst diff --git a/openbb_terminal/portfolio/portfolio_model.py b/openbb_terminal/portfolio/portfolio_model.py index c574e290a25e..f61c9c9a6999 100644 --- a/openbb_terminal/portfolio/portfolio_model.py +++ b/openbb_terminal/portfolio/portfolio_model.py @@ -834,6 +834,12 @@ def get_r2_score(portfolio_engine: PortfolioEngine) -> pd.DataFrame: ------- pd.DataFrame DataFrame with R2 Score between portfolio and benchmark for different periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.rsquare(P) """ vals = list() @@ -866,6 +872,12 @@ def get_skewness(portfolio_engine: PortfolioEngine) -> pd.DataFrame: ------- pd.DataFrame DataFrame with skewness for portfolio and benchmark for different periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.skew(P) """ vals = list() @@ -909,6 +921,12 @@ def get_kurtosis(portfolio_engine: PortfolioEngine) -> pd.DataFrame: ------- pd.DataFrame DataFrame with kurtosis for portfolio and benchmark for different periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.kurtosis(P) """ vals = list() @@ -954,6 +972,12 @@ def get_stats(portfolio_engine: PortfolioEngine, window: str = "all") -> pd.Data ------- pd.DataFrame DataFrame with overall stats for portfolio and benchmark for a certain period + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.stats(P) """ df = ( @@ -984,6 +1008,12 @@ def get_volatility(portfolio_engine: PortfolioEngine) -> pd.DataFrame: ------- pd.DataFrame DataFrame with volatility for portfolio and benchmark for different periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.volatility(P) """ vals = list() @@ -1031,6 +1061,12 @@ def get_sharpe_ratio( ------- pd.DataFrame DataFrame with sharpe ratio for portfolio and benchmark for different periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.sharpe(P) """ vals = list() @@ -1080,6 +1116,12 @@ def get_sortino_ratio( ------- pd.DataFrame DataFrame with sortino ratio for portfolio and benchmark for different periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.sortino(P) """ vals = list() @@ -1125,6 +1167,12 @@ def get_maximum_drawdown_ratio(portfolio_engine: PortfolioEngine) -> pd.DataFram ------- pd.DataFrame DataFrame with maximum drawdown for portfolio and benchmark for different periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.maxdrawdown(P) """ vals = list() @@ -1168,6 +1216,12 @@ def get_gaintopain_ratio(portfolio_engine: PortfolioEngine): ------- pd.DataFrame DataFrame of the portfolio's gain-to-pain ratio + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.gaintopain(P) """ gtp_period_df = portfolio_helper.get_gaintopain_ratio( @@ -1197,6 +1251,12 @@ def get_tracking_error(portfolio_engine: PortfolioEngine, window: int = 252): DataFrame of tracking errors during different time windows pd.Series Series of rolling tracking error + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.trackerr(P) """ trackr_period_df, trackr_rolling = portfolio_helper.get_tracking_error( @@ -1220,6 +1280,12 @@ def get_information_ratio(portfolio_engine: PortfolioEngine): ------- pd.DataFrame DataFrame of the information ratio during different time periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.information(P) """ ir_period_df = portfolio_helper.get_information_ratio( @@ -1252,6 +1318,12 @@ def get_tail_ratio(portfolio_engine: PortfolioEngine, window: int = 252): Series of the portfolios rolling tail ratio pd.Series Series of the benchmarks rolling tail ratio + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.tail(P) """ tailr_period_df, portfolio_tr, benchmark_tr = portfolio_helper.get_tail_ratio( @@ -1275,6 +1347,12 @@ def get_common_sense_ratio(portfolio_engine: PortfolioEngine): ------- pd.DataFrame DataFrame of the portfolios and the benchmarks common sense ratio during different time periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.commonsense(P) """ csr_period_df = portfolio_helper.get_common_sense_ratio( @@ -1309,6 +1387,12 @@ def get_jensens_alpha( DataFrame of jensens's alpha during different time windows pd.Series Series of jensens's alpha data + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.jensens(P) """ ja_period_df, ja_rolling = portfolio_helper.jensens_alpha( @@ -1341,6 +1425,12 @@ def get_calmar_ratio(portfolio_engine: PortfolioEngine, window: int = 756): DataFrame of calmar ratio of the benchmark and portfolio during different time periods pd.Series Series of calmar ratio data + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.calmar(P) """ cr_period_df, cr_rolling = portfolio_helper.get_calmar_ratio( @@ -1368,6 +1458,12 @@ def get_kelly_criterion(portfolio_engine: PortfolioEngine): ------- pd.DataFrame DataFrame of kelly criterion of the portfolio during different time periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.kelly(P) """ kc_period_df = portfolio_helper.get_kelly_criterion( @@ -1385,6 +1481,12 @@ def get_payoff_ratio(portfolio_engine: PortfolioEngine): ------- pd.DataFrame DataFrame of payoff ratio of the portfolio during different time periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.payoff(P) """ pr_period_ratio = portfolio_helper.get_payoff_ratio( @@ -1408,6 +1510,12 @@ def get_profit_factor(portfolio_engine: PortfolioEngine): ------- pd.DataFrame DataFrame of profit factor of the portfolio during different time periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.profitfactor(P) """ pf_period_df = portfolio_helper.get_profit_factor(portfolio_engine.portfolio_trades) @@ -1428,6 +1536,12 @@ def get_holdings_value(portfolio_engine: PortfolioEngine) -> pd.DataFrame: ------- pd.DataFrame DataFrame of holdings + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.holdv(P) """ all_holdings = portfolio_engine.historical_trade_data["End Value"][ @@ -1451,6 +1565,12 @@ def get_holdings_percentage( portfolio_engine: PortfolioEngine PortfolioEngine class instance, this will hold transactions and perform calculations. Use `portfolio.load` to create a PortfolioEngine. + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.holdp(P) """ all_holdings = portfolio_engine.historical_trade_data["End Value"][ @@ -1487,6 +1607,12 @@ def get_maximum_drawdown( Holdings series pd.Series Drawdown series + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.maxdd(P) """ holdings: pd.Series = portfolio_engine.portfolio_value @@ -1512,6 +1638,12 @@ def get_distribution_returns( Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.distr(P) """ portfolio_returns = portfolio_helper.filter_df_by_period( @@ -1541,6 +1673,12 @@ def get_rolling_volatility( window : str Rolling window size to use Possible options: mtd, qtd, ytd, 1d, 5d, 10d, 1m, 3m, 6m, 1y, 3y, 5y, 10y + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.rvol(P) """ portfolio_rvol = portfolio_helper.rolling_volatility( @@ -1581,6 +1719,12 @@ def get_rolling_sharpe( ------- pd.DataFrame Rolling sharpe ratio DataFrame + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.rsharpe(P) """ portfolio_rsharpe = portfolio_helper.rolling_sharpe( @@ -1623,6 +1767,12 @@ def get_rolling_sortino( ------- pd.DataFrame Rolling sortino ratio DataFrame + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.rsortino(P) """ portfolio_rsortino = portfolio_helper.rolling_sortino( @@ -1663,6 +1813,12 @@ def get_rolling_beta( ------- pd.DataFrame DataFrame of the portfolio's rolling beta + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.rbeta(P) """ df = portfolio_helper.rolling_beta( @@ -1691,6 +1847,13 @@ def get_performance_vs_benchmark( Returns ------- pd.DataFrame + DataFrame with portfolio performance vs the benchmark + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.perf(P) """ portfolio_trades = portfolio_engine.portfolio_trades @@ -1805,6 +1968,13 @@ def get_var( Returns ------- pd.DataFrame + DataFrame with portfolio VaR + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.var(P) """ return qa_model.get_var( @@ -1841,6 +2011,13 @@ def get_es( Returns ------- pd.DataFrame + DataFrame with portfolio expected shortfall + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.es(P) """ return qa_model.get_es( @@ -1873,6 +2050,13 @@ def get_omega( Returns ------- pd.DataFrame + DataFrame with portfolio omega ratio + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.om(P) """ return qa_model.get_omega( @@ -1887,7 +2071,7 @@ def get_summary( window: str = "all", risk_free_rate: float = 0, ) -> pd.DataFrame: - """Get summary portfolio and benchmark returns + """Get portfolio and benchmark returns summary Parameters ---------- @@ -1902,7 +2086,13 @@ def get_summary( Returns ------- pd.DataFrame + DataFrame with portfolio and benchmark returns summary + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.summary(P) """ portfolio_returns = portfolio_helper.filter_df_by_period( @@ -1957,7 +2147,7 @@ def get_summary( def get_yearly_returns( portfolio_engine: PortfolioEngine, window: str = "all", -): +) -> pd.DataFrame: """Get yearly returns Parameters @@ -1967,6 +2157,17 @@ def get_yearly_returns( Use `portfolio.load` to create a PortfolioEngine. window : str interval to compare cumulative returns and benchmark + + Returns + ------- + pd.DataFrame + DataFrame with yearly returns + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.yret(P) """ portfolio_returns = portfolio_helper.filter_df_by_period( @@ -2024,6 +2225,13 @@ def get_monthly_returns( Returns ------- pd.DataFrame + DataFrame with monthly returns + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.mret(P) """ portfolio_returns = portfolio_helper.filter_df_by_period( @@ -2123,6 +2331,13 @@ def get_daily_returns( Returns ------- pd.DataFrame + DataFrame with daily returns + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.dret(P) """ portfolio_returns = portfolio_helper.filter_df_by_period( @@ -2165,6 +2380,11 @@ def generate_portfolio( ------- PortfolioEngine PortfolioEngine class instance, this will hold transactions and perform calculations + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") """ transactions = PortfolioEngine.read_transactions(transactions_file_path) @@ -2189,6 +2409,12 @@ def get_transactions(portfolio_engine: PortfolioEngine) -> pd.DataFrame: ------- pd.DataFrame Portfolio transactions + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.show(P) """ return portfolio_engine.get_transactions() @@ -2209,6 +2435,12 @@ def set_benchmark( full_shares: bool Whether to mimic the portfolio trades exactly (partial shares) or round down the quantity to the nearest number + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.bench(P, symbol="SPY") """ portfolio_engine.set_benchmark(symbol=symbol, full_shares=full_shares) @@ -2268,7 +2500,8 @@ def get_assets_allocation( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. tables: bool Whether to include separate allocation tables limit: int @@ -2280,6 +2513,12 @@ def get_assets_allocation( ------- Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] DataFrame with combined allocation plus individual allocation if tables is `True`. + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.alloc.assets(P) """ portfolio_engine.calculate_allocation(category="Asset", recalculate=recalculate) @@ -2305,7 +2544,8 @@ def get_sectors_allocation( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. tables: bool Whether to include separate allocation tables limit: int @@ -2317,6 +2557,12 @@ def get_sectors_allocation( ------- Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] DataFrame with combined allocation plus individual allocation if tables is `True`. + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.alloc.sectors(P) """ portfolio_engine.calculate_allocation(category="Sector", recalculate=recalculate) @@ -2342,7 +2588,8 @@ def get_countries_allocation( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. tables: bool Whether to include separate allocation tables limit: int @@ -2354,6 +2601,12 @@ def get_countries_allocation( ------- Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] DataFrame with combined allocation plus individual allocation if tables is `True`. + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.alloc.countries(P) """ portfolio_engine.calculate_allocation(category="Country", recalculate=recalculate) @@ -2379,7 +2632,8 @@ def get_regions_allocation( Parameters ---------- portfolio_engine: PortfolioEngine - PortfolioEngine object + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. tables: bool Whether to include separate allocation tables limit: int @@ -2391,6 +2645,12 @@ def get_regions_allocation( ------- Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] DataFrame with combined allocation plus individual allocation if tables is `True`. + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.alloc.regions(P) """ portfolio_engine.calculate_allocation(category="Region", recalculate=recalculate) diff --git a/openbb_terminal/reports/templates/portfolio.ipynb b/openbb_terminal/reports/templates/portfolio.ipynb index 23496c41b663..ce12b934970c 100644 --- a/openbb_terminal/reports/templates/portfolio.ipynb +++ b/openbb_terminal/reports/templates/portfolio.ipynb @@ -139,11 +139,6 @@ "try:\n", " P = openbb.portfolio.load(transactions_path)\n", " openbb.portfolio.show(P)\n", - " # transactions = Portfolio.read_transactions(transactions_path)\n", - " # P = Portfolio(transactions)\n", - " # P.generate_portfolio_data()\n", - " # P.set_benchmark()\n", - " # P.get_transactions()\n", "except ValueError:\n", " raise ValueError(\n", " \"Failed to load the transactions. Is this file inside the 'holdings' folder?\"\n", diff --git a/website/content/SDK/crypto/dd/active/_index.rst b/website/content/SDK/crypto/dd/active/_index.rst index 1d5b9292644e..2088b5531917 100644 --- a/website/content/SDK/crypto/dd/active/_index.rst +++ b/website/content/SDK/crypto/dd/active/_index.rst @@ -17,7 +17,7 @@ crypto.dd.active( symbol: str, interval: str = '24h', start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -60,7 +60,7 @@ crypto.dd.active( crypto.dd.active( symbol: str, start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', interval: str = '24h', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/change/_index.rst b/website/content/SDK/crypto/dd/change/_index.rst index 627aecf0ccf1..191a3c983be6 100644 --- a/website/content/SDK/crypto/dd/change/_index.rst +++ b/website/content/SDK/crypto/dd/change/_index.rst @@ -17,7 +17,7 @@ crypto.dd.change( symbol: str, exchange: str = 'binance', start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -61,7 +61,7 @@ crypto.dd.change( symbol: str, exchange: str = 'binance', start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/dd/close/_index.rst b/website/content/SDK/crypto/dd/close/_index.rst index 8a07bec6cc27..8d5f7cf75146 100644 --- a/website/content/SDK/crypto/dd/close/_index.rst +++ b/website/content/SDK/crypto/dd/close/_index.rst @@ -14,7 +14,7 @@ crypto.dd.close( symbol: str, start_date: str = '2010-01-01', - end_date: str = '2022-11-13', + end_date: str = '2022-11-14', print_errors: bool = True, chart: bool = False, ) -> pandas.core.frame.DataFrame diff --git a/website/content/SDK/crypto/dd/eb/_index.rst b/website/content/SDK/crypto/dd/eb/_index.rst index d11de6ae2c8e..89bd4fd7d345 100644 --- a/website/content/SDK/crypto/dd/eb/_index.rst +++ b/website/content/SDK/crypto/dd/eb/_index.rst @@ -17,7 +17,7 @@ crypto.dd.eb( symbol: str, exchange: str = 'binance', start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -61,7 +61,7 @@ crypto.dd.eb( symbol: str, exchange: str = 'binance', start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', percentage: bool = False, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/gh/_index.rst b/website/content/SDK/crypto/dd/gh/_index.rst index d360c1105d4a..97c24e41c60e 100644 --- a/website/content/SDK/crypto/dd/gh/_index.rst +++ b/website/content/SDK/crypto/dd/gh/_index.rst @@ -17,8 +17,8 @@ crypto.dd.gh( symbol: str, dev_activity: bool = False, interval: str = '1d', - start_date: str = '2021-11-10T20:12:25Z', - end_date: str = '2022-11-10T20:12:25Z', + start_date: str = '2021-11-14T14:22:49Z', + end_date: str = '2022-11-14T14:22:49Z', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -63,9 +63,9 @@ crypto.dd.gh( {{< highlight python >}} crypto.dd.gh( symbol: str, - start_date: str = '2021-11-10T20:12:25Z', + start_date: str = '2021-11-14T14:22:49Z', dev_activity: bool = False, - end_date: str = '2022-11-10T20:12:25Z', + end_date: str = '2022-11-14T14:22:49Z', interval: str = '1d', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/mcapdom/_index.rst b/website/content/SDK/crypto/dd/mcapdom/_index.rst index 020cb24bb496..82285526b749 100644 --- a/website/content/SDK/crypto/dd/mcapdom/_index.rst +++ b/website/content/SDK/crypto/dd/mcapdom/_index.rst @@ -16,8 +16,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.dd.mcapdom( symbol: str, interval: str = '1d', - start_date: str = '2021-11-13', - end_date: str = '2022-11-13', + start_date: str = '2021-11-14', + end_date: str = '2022-11-14', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -59,8 +59,8 @@ crypto.dd.mcapdom( {{< highlight python >}} crypto.dd.mcapdom( symbol: str, - start_date: str = '2021-11-13', - end_date: str = '2022-11-13', + start_date: str = '2021-11-14', + end_date: str = '2022-11-14', interval: str = '1d', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/mt/_index.rst b/website/content/SDK/crypto/dd/mt/_index.rst index e4b7b2924638..6d4c129e4360 100644 --- a/website/content/SDK/crypto/dd/mt/_index.rst +++ b/website/content/SDK/crypto/dd/mt/_index.rst @@ -17,8 +17,8 @@ crypto.dd.mt( symbol: str, timeseries_id: str, interval: str = '1d', - start_date: str = '2021-11-13', - end_date: str = '2022-11-13', + start_date: str = '2021-11-14', + end_date: str = '2022-11-14', chart: bool = False, ) -> Tuple[pandas.core.frame.DataFrame, str] {{< /highlight >}} @@ -65,8 +65,8 @@ crypto.dd.mt( crypto.dd.mt( symbol: str, timeseries_id: str, - start_date: str = '2021-11-13', - end_date: str = '2022-11-13', + start_date: str = '2021-11-14', + end_date: str = '2022-11-14', interval: str = '1d', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/dd/nonzero/_index.rst b/website/content/SDK/crypto/dd/nonzero/_index.rst index 940847ef3a7b..deed90bb61a4 100644 --- a/website/content/SDK/crypto/dd/nonzero/_index.rst +++ b/website/content/SDK/crypto/dd/nonzero/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.dd.nonzero( symbol: str, start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -57,7 +57,7 @@ crypto.dd.nonzero( crypto.dd.nonzero( symbol: str, start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/dd/oi/_index.rst b/website/content/SDK/crypto/dd/oi/_index.rst index 7c2ddbdd4510..1d0b0fdb8bae 100644 --- a/website/content/SDK/crypto/dd/oi/_index.rst +++ b/website/content/SDK/crypto/dd/oi/_index.rst @@ -73,7 +73,7 @@ crypto.dd.oi( interval : int Frequency (possible values are: 0 for ALL, 2 for 1H, 1 for 4H, 4 for 12H), by default 0 export : str - Export dataframe data to csv,json,xlsx fil + Export dataframe data to csv,json,xlsx file chart: bool Flag to display chart diff --git a/website/content/SDK/crypto/load/_index.rst b/website/content/SDK/crypto/load/_index.rst index c1784c7a945e..be774c025355 100644 --- a/website/content/SDK/crypto/load/_index.rst +++ b/website/content/SDK/crypto/load/_index.rst @@ -13,12 +13,10 @@ {{< highlight python >}} crypto.load( symbol: 'str', - start_date: 'Optional[Union[datetime, str]]' = None, - interval: 'str' = '1440', + start_date: 'datetime | str | None' = None, interval: 'str' = '1440', exchange: 'str' = 'binance', vs_currency: 'str' = 'usdt', - end_date: 'Optional[Union[datetime, str]]' = None, - source: 'str' = 'CCXT', + end_date: 'datetime | str | None' = None, source: 'str' = 'CCXT', chart: bool = False, ) -> 'pd.DataFrame' {{< /highlight >}} diff --git a/website/content/SDK/crypto/onchain/btc_supply/_index.rst b/website/content/SDK/crypto/onchain/btc_supply/_index.rst index 709447b6fa09..9efd666b7300 100644 --- a/website/content/SDK/crypto/onchain/btc_supply/_index.rst +++ b/website/content/SDK/crypto/onchain/btc_supply/_index.rst @@ -38,7 +38,7 @@ crypto.onchain.btc_supply() -> pandas.core.frame.DataFrame {{< highlight python >}} crypto.onchain.btc_supply( start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/onchain/btc_transac/_index.rst b/website/content/SDK/crypto/onchain/btc_transac/_index.rst index 558642af7c18..fa025f933550 100644 --- a/website/content/SDK/crypto/onchain/btc_transac/_index.rst +++ b/website/content/SDK/crypto/onchain/btc_transac/_index.rst @@ -38,7 +38,7 @@ crypto.onchain.btc_transac() -> pandas.core.frame.DataFrame {{< highlight python >}} crypto.onchain.btc_transac( start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/onchain/hr/_index.rst b/website/content/SDK/crypto/onchain/hr/_index.rst index b071a0485e37..329ab74d7977 100644 --- a/website/content/SDK/crypto/onchain/hr/_index.rst +++ b/website/content/SDK/crypto/onchain/hr/_index.rst @@ -17,7 +17,7 @@ crypto.onchain.hr( symbol: str, interval: str = '24h', start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -60,7 +60,7 @@ crypto.onchain.hr( crypto.onchain.hr( symbol: str, start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', interval: str = '24h', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/crypto/ov/altindex/_index.rst b/website/content/SDK/crypto/ov/altindex/_index.rst index f3043fc27aec..f298ca86adba 100644 --- a/website/content/SDK/crypto/ov/altindex/_index.rst +++ b/website/content/SDK/crypto/ov/altindex/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. crypto.ov.altindex( period: int = 30, start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -59,7 +59,7 @@ crypto.ov.altindex( crypto.ov.altindex( period: int = 365, start_date: str = '2010-01-01', - end_date: str = '2022-11-10', + end_date: str = '2022-11-14', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/crypto/ov/btcrb/_index.rst b/website/content/SDK/crypto/ov/btcrb/_index.rst index ad0bfd9122ac..b5528de7637d 100644 --- a/website/content/SDK/crypto/ov/btcrb/_index.rst +++ b/website/content/SDK/crypto/ov/btcrb/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} crypto.ov.btcrb( start_date: str = '2010-01-01', - end_date: str = '2022-11-13', + end_date: str = '2022-11-14', chart: bool = False, ) {{< /highlight >}} @@ -49,7 +49,7 @@ crypto.ov.btcrb( {{< highlight python >}} crypto.ov.btcrb( start_date: str = '2010-01-01', - end_date: str = '2022-11-13', + end_date: str = '2022-11-14', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/economy/events/_index.rst b/website/content/SDK/economy/events/_index.rst index 2bef62f0958e..1080059ba6e0 100644 --- a/website/content/SDK/economy/events/_index.rst +++ b/website/content/SDK/economy/events/_index.rst @@ -13,8 +13,8 @@ {{< highlight python >}} economy.events( countries: Union[List[str], str] = '', - start_date: str = '2022-11-13', - end_date: str = '2022-11-13', + start_date: str = '2022-11-14', + end_date: str = '2022-11-14', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/economy/macro/_index.rst b/website/content/SDK/economy/macro/_index.rst index 068338f41e46..4d8d2bbba38b 100644 --- a/website/content/SDK/economy/macro/_index.rst +++ b/website/content/SDK/economy/macro/_index.rst @@ -19,7 +19,7 @@ economy.macro( transform: str = '', start_date: str = '1900-01-01', end_date=datetime.date( - 2022, 11, 13, chart: bool = False, + 2022, 11, 14, chart: bool = False, ), symbol: str = '', chart: bool = False, ) -> Tuple[Any, Dict[Any, Dict[Any, Any]], str] @@ -72,7 +72,7 @@ economy.macro( countries: list = None, transform: str = '', start_date: str = '1900-01-01', - end_date: str = '2022-11-13', + end_date: str = '2022-11-14', symbol: str = '', raw: bool = False, external_axes: Optional[List[axes]] = None, diff --git a/website/content/SDK/economy/treasury/_index.rst b/website/content/SDK/economy/treasury/_index.rst index 5b6d66900d03..f67d86a82a28 100644 --- a/website/content/SDK/economy/treasury/_index.rst +++ b/website/content/SDK/economy/treasury/_index.rst @@ -18,7 +18,7 @@ economy.treasury( maturities: list = None, frequency: str = 'monthly', start_date: str = '1900-01-01', - end_date: str = '2022-11-13', + end_date: str = '2022-11-14', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -65,7 +65,7 @@ economy.treasury( maturities: list = None, frequency: str = 'monthly', start_date: str = '1900-01-01', - end_date: str = '2022-11-13', + end_date: str = '2022-11-14', raw: bool = False, external_axes: Optional[List[axes]] = None, export: str = '', diff --git a/website/content/SDK/etf/candle/_index.rst b/website/content/SDK/etf/candle/_index.rst index fbd1746d544a..56ad7059297c 100644 --- a/website/content/SDK/etf/candle/_index.rst +++ b/website/content/SDK/etf/candle/_index.rst @@ -19,9 +19,9 @@ etf.candle( add_trend: bool = False, ma: Optional[Iterable[int]] = None, asset_type: str = '', - start_date: Union[datetime.datetime, str, NoneType] = '2019-11-06', + start_date: Union[datetime.datetime, str, NoneType] = '2019-11-10', interval: int = 1440, - end_date: Union[datetime.datetime, str, NoneType] = '2022-11-10', + end_date: Union[datetime.datetime, str, NoneType] = '2022-11-14', prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/etf/load/_index.rst b/website/content/SDK/etf/load/_index.rst index 971dd3eff1ff..724970c7f1b2 100644 --- a/website/content/SDK/etf/load/_index.rst +++ b/website/content/SDK/etf/load/_index.rst @@ -13,9 +13,9 @@ {{< highlight python >}} etf.load( symbol: str, - start_date: Union[datetime.datetime, str, NoneType] = '2019-11-06', + start_date: Union[datetime.datetime, str, NoneType] = '2019-11-10', interval: int = 1440, - end_date: Union[datetime.datetime, str, NoneType] = '2022-11-10', + end_date: Union[datetime.datetime, str, NoneType] = '2022-11-14', prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/etf/news/_index.rst b/website/content/SDK/etf/news/_index.rst index dfd66dea5b6d..12f1dfb226f2 100644 --- a/website/content/SDK/etf/news/_index.rst +++ b/website/content/SDK/etf/news/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. etf.news( query: str, limit: int = 10, - start_date: str = '2022-11-06', + start_date: str = '2022-11-07', show_newest: bool = True, sources: str = '', chart: bool = False, @@ -60,7 +60,7 @@ etf.news( etf.news( query: str, limit: int = 3, - start_date: str = '2022-11-06', + start_date: str = '2022-11-07', show_newest: bool = True, sources: str = '', export: str = '', diff --git a/website/content/SDK/forex/get_currency_list/_index.rst b/website/content/SDK/forex/get_currency_list/_index.rst index d3900f6c25f8..52f4987530e8 100644 --- a/website/content/SDK/forex/get_currency_list/_index.rst +++ b/website/content/SDK/forex/get_currency_list/_index.rst @@ -17,5 +17,5 @@ forex.get_currency_list() -> List .. raw:: html

- Load AV currency codes from a local file + Load AV currency codes from a local file.

diff --git a/website/content/SDK/forex/load/_index.rst b/website/content/SDK/forex/load/_index.rst index b0d82217caff..f5ed31f71996 100644 --- a/website/content/SDK/forex/load/_index.rst +++ b/website/content/SDK/forex/load/_index.rst @@ -16,7 +16,7 @@ forex.load( from_symbol: str, resolution: str = 'd', interval: str = '1day', - start_date: str = '2021-11-13', + start_date: str = '2021-11-14', source: str = 'YahooFinance', verbose: bool = False, chart: bool = False, diff --git a/website/content/SDK/futures/historical/_index.rst b/website/content/SDK/futures/historical/_index.rst index 3dec8d1bc884..1aaf400620a9 100644 --- a/website/content/SDK/futures/historical/_index.rst +++ b/website/content/SDK/futures/historical/_index.rst @@ -53,7 +53,7 @@ futures.historical( futures.historical( symbols: List[str], expiry: str = '', - start_date: str = '2019-11-14', + start_date: str = '2019-11-15', raw: bool = False, export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/portfolio/alloc/_index.md b/website/content/SDK/portfolio/alloc/_index.md new file mode 100644 index 000000000000..754aa89dd96f --- /dev/null +++ b/website/content/SDK/portfolio/alloc/_index.md @@ -0,0 +1,6 @@ +--- +title: alloc +keywords: "" +excerpt: "" +geekdocCollapseSection: true +--- diff --git a/website/content/SDK/portfolio/alloc/assets/_index.rst b/website/content/SDK/portfolio/alloc/assets/_index.rst index a4b5f7320d6e..bb1faf243cda 100644 --- a/website/content/SDK/portfolio/alloc/assets/_index.rst +++ b/website/content/SDK/portfolio/alloc/assets/_index.rst @@ -29,7 +29,8 @@ portfolio.alloc.assets( * **Parameters** portfolio_engine: PortfolioEngine - PortfolioEngine object + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. tables: bool Whether to include separate allocation tables limit: int @@ -41,3 +42,11 @@ portfolio.alloc.assets( Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] DataFrame with combined allocation plus individual allocation if tables is `True`. + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.alloc.assets(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/alloc/countries/_index.rst b/website/content/SDK/portfolio/alloc/countries/_index.rst index fccb0aa0df1e..51140335748a 100644 --- a/website/content/SDK/portfolio/alloc/countries/_index.rst +++ b/website/content/SDK/portfolio/alloc/countries/_index.rst @@ -28,7 +28,8 @@ portfolio.alloc.countries( * **Parameters** portfolio_engine: PortfolioEngine - PortfolioEngine object + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. tables: bool Whether to include separate allocation tables limit: int @@ -40,3 +41,11 @@ portfolio.alloc.countries( Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] DataFrame with combined allocation plus individual allocation if tables is `True`. + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.alloc.countries(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/alloc/regions/_index.rst b/website/content/SDK/portfolio/alloc/regions/_index.rst index b1a05723e078..77dd8e32c8d6 100644 --- a/website/content/SDK/portfolio/alloc/regions/_index.rst +++ b/website/content/SDK/portfolio/alloc/regions/_index.rst @@ -28,7 +28,8 @@ portfolio.alloc.regions( * **Parameters** portfolio_engine: PortfolioEngine - PortfolioEngine object + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. tables: bool Whether to include separate allocation tables limit: int @@ -40,3 +41,11 @@ portfolio.alloc.regions( Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] DataFrame with combined allocation plus individual allocation if tables is `True`. + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.alloc.regions(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/alloc/sectors/_index.rst b/website/content/SDK/portfolio/alloc/sectors/_index.rst index f4ce09a0ceb1..cb28354fd26a 100644 --- a/website/content/SDK/portfolio/alloc/sectors/_index.rst +++ b/website/content/SDK/portfolio/alloc/sectors/_index.rst @@ -28,7 +28,8 @@ portfolio.alloc.sectors( * **Parameters** portfolio_engine: PortfolioEngine - PortfolioEngine object + PortfolioEngine class instance, this will hold transactions and perform calculations. + Use `portfolio.load` to create a PortfolioEngine. tables: bool Whether to include separate allocation tables limit: int @@ -40,3 +41,11 @@ portfolio.alloc.sectors( Union[pd.DataFrame, Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]] DataFrame with combined allocation plus individual allocation if tables is `True`. + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.alloc.sectors(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/bench/_index.rst b/website/content/SDK/portfolio/bench/_index.rst index a4a38c71b9fb..7a943ff85072 100644 --- a/website/content/SDK/portfolio/bench/_index.rst +++ b/website/content/SDK/portfolio/bench/_index.rst @@ -34,3 +34,11 @@ portfolio.bench( full_shares: bool Whether to mimic the portfolio trades exactly (partial shares) or round down the quantity to the nearest number + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.bench(P, symbol="SPY") + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/distr/_index.rst b/website/content/SDK/portfolio/distr/_index.rst index 347b2a1fe538..8ec59d03f3ae 100644 --- a/website/content/SDK/portfolio/distr/_index.rst +++ b/website/content/SDK/portfolio/distr/_index.rst @@ -37,6 +37,14 @@ portfolio.distr( Flag to display chart +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.distr(P) + {{< /highlight >}} + | .. raw:: html diff --git a/website/content/SDK/portfolio/dret/_index.rst b/website/content/SDK/portfolio/dret/_index.rst index 8e162b9974fd..52cbb0a25246 100644 --- a/website/content/SDK/portfolio/dret/_index.rst +++ b/website/content/SDK/portfolio/dret/_index.rst @@ -40,6 +40,15 @@ portfolio.dret( * **Returns** pd.DataFrame + DataFrame with daily returns + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.dret(P) + {{< /highlight >}} | diff --git a/website/content/SDK/portfolio/es/_index.rst b/website/content/SDK/portfolio/es/_index.rst index dd6d8c2148d2..c952b8684d39 100644 --- a/website/content/SDK/portfolio/es/_index.rst +++ b/website/content/SDK/portfolio/es/_index.rst @@ -41,3 +41,12 @@ portfolio.es( * **Returns** pd.DataFrame + DataFrame with portfolio expected shortfall + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.es(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/holdp/_index.rst b/website/content/SDK/portfolio/holdp/_index.rst index 4c0b949bed58..d3ca3a64736f 100644 --- a/website/content/SDK/portfolio/holdp/_index.rst +++ b/website/content/SDK/portfolio/holdp/_index.rst @@ -34,6 +34,14 @@ portfolio.holdp( Flag to display chart +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.holdp(P) + {{< /highlight >}} + | .. raw:: html diff --git a/website/content/SDK/portfolio/holdv/_index.rst b/website/content/SDK/portfolio/holdv/_index.rst index 82d1377006a8..b7abd742b057 100644 --- a/website/content/SDK/portfolio/holdv/_index.rst +++ b/website/content/SDK/portfolio/holdv/_index.rst @@ -39,6 +39,14 @@ portfolio.holdv( pd.DataFrame DataFrame of holdings +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.holdv(P) + {{< /highlight >}} + | .. raw:: html diff --git a/website/content/SDK/portfolio/load/_index.rst b/website/content/SDK/portfolio/load/_index.rst index b5246b99fc90..1f6afb11403a 100644 --- a/website/content/SDK/portfolio/load/_index.rst +++ b/website/content/SDK/portfolio/load/_index.rst @@ -42,3 +42,10 @@ portfolio.load( PortfolioEngine PortfolioEngine class instance, this will hold transactions and perform calculations + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/max_drawdown_ratio/_index.rst b/website/content/SDK/portfolio/max_drawdown_ratio/_index.rst deleted file mode 100644 index 0a698bc25ba3..000000000000 --- a/website/content/SDK/portfolio/max_drawdown_ratio/_index.rst +++ /dev/null @@ -1,78 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -To obtain charts, make sure to add :python:`chart = True` as the last parameter. - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.max_drawdown_ratio( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - is_returns: bool = False, - chart: bool = False, -) -> pandas.core.series.Series -{{< /highlight >}} - -.. raw:: html - -

- Calculate the drawdown (MDD) of historical series. Note that the calculation is done - on cumulative returns (or prices). The definition of drawdown is - - DD = (current value - rolling maximum) / rolling maximum -

- -* **Parameters** - - data: pd.Series - Series of input values - is_returns: bool - Flag to indicate inputs are returns - chart: bool - Flag to display chart - - -* **Returns** - - pd.Series - Holdings series - pd.Series - Drawdown series - -| - -.. raw:: html - -

- > Getting charts -

- -{{< highlight python >}} -portfolio.max_drawdown_ratio( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - export: str = '', - chart: bool = False, -) -{{< /highlight >}} - -.. raw:: html - -

- Display maximum drawdown for multiple intervals -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - export : str - Export data format - chart: bool - Flag to display chart diff --git a/website/content/SDK/portfolio/maxdd/_index.rst b/website/content/SDK/portfolio/maxdd/_index.rst index ecebf137cd92..5d8d61ffb7ed 100644 --- a/website/content/SDK/portfolio/maxdd/_index.rst +++ b/website/content/SDK/portfolio/maxdd/_index.rst @@ -46,6 +46,14 @@ portfolio.maxdd( pd.Series Drawdown series +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.maxdd(P) + {{< /highlight >}} + | .. raw:: html diff --git a/website/content/SDK/portfolio/metric/calmar/_index.rst b/website/content/SDK/portfolio/metric/calmar/_index.rst index a351bf066943..60511e2ef835 100644 --- a/website/content/SDK/portfolio/metric/calmar/_index.rst +++ b/website/content/SDK/portfolio/metric/calmar/_index.rst @@ -38,3 +38,11 @@ portfolio.metric.calmar( DataFrame of calmar ratio of the benchmark and portfolio during different time periods pd.Series Series of calmar ratio data + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.calmar(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/commonsense/_index.rst b/website/content/SDK/portfolio/metric/commonsense/_index.rst index 61b2d3fe2c03..bd33934e741e 100644 --- a/website/content/SDK/portfolio/metric/commonsense/_index.rst +++ b/website/content/SDK/portfolio/metric/commonsense/_index.rst @@ -33,3 +33,11 @@ portfolio.metric.commonsense( pd.DataFrame DataFrame of the portfolios and the benchmarks common sense ratio during different time periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.commonsense(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/gaintopain/_index.rst b/website/content/SDK/portfolio/metric/gaintopain/_index.rst index ddbb5129a3b5..1cfa9afda0f6 100644 --- a/website/content/SDK/portfolio/metric/gaintopain/_index.rst +++ b/website/content/SDK/portfolio/metric/gaintopain/_index.rst @@ -33,3 +33,11 @@ portfolio.metric.gaintopain( pd.DataFrame DataFrame of the portfolio's gain-to-pain ratio + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.gaintopain(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/information/_index.rst b/website/content/SDK/portfolio/metric/information/_index.rst index ad5af2ce67da..9f8f7a315c94 100644 --- a/website/content/SDK/portfolio/metric/information/_index.rst +++ b/website/content/SDK/portfolio/metric/information/_index.rst @@ -33,3 +33,11 @@ portfolio.metric.information( pd.DataFrame DataFrame of the information ratio during different time periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.information(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/jensens/_index.rst b/website/content/SDK/portfolio/metric/jensens/_index.rst index 5d11bc657c31..3661be76ef24 100644 --- a/website/content/SDK/portfolio/metric/jensens/_index.rst +++ b/website/content/SDK/portfolio/metric/jensens/_index.rst @@ -41,3 +41,11 @@ portfolio.metric.jensens( DataFrame of jensens's alpha during different time windows pd.Series Series of jensens's alpha data + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.jensens(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/kelly/_index.rst b/website/content/SDK/portfolio/metric/kelly/_index.rst index 94be15e87605..b108eba6f384 100644 --- a/website/content/SDK/portfolio/metric/kelly/_index.rst +++ b/website/content/SDK/portfolio/metric/kelly/_index.rst @@ -33,3 +33,11 @@ portfolio.metric.kelly( pd.DataFrame DataFrame of kelly criterion of the portfolio during different time periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.kelly(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/kurtosis/_index.rst b/website/content/SDK/portfolio/metric/kurtosis/_index.rst index 6334d42d1be4..30243cfbf069 100644 --- a/website/content/SDK/portfolio/metric/kurtosis/_index.rst +++ b/website/content/SDK/portfolio/metric/kurtosis/_index.rst @@ -33,3 +33,11 @@ portfolio.metric.kurtosis( pd.DataFrame DataFrame with kurtosis for portfolio and benchmark for different periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.kurtosis(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/maxdrawdown/_index.rst b/website/content/SDK/portfolio/metric/maxdrawdown/_index.rst index 29f22c33bdad..62ae7bed3171 100644 --- a/website/content/SDK/portfolio/metric/maxdrawdown/_index.rst +++ b/website/content/SDK/portfolio/metric/maxdrawdown/_index.rst @@ -33,3 +33,11 @@ portfolio.metric.maxdrawdown( pd.DataFrame DataFrame with maximum drawdown for portfolio and benchmark for different periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.maxdrawdown(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/payoff/_index.rst b/website/content/SDK/portfolio/metric/payoff/_index.rst index 152562416b86..c11008305ec7 100644 --- a/website/content/SDK/portfolio/metric/payoff/_index.rst +++ b/website/content/SDK/portfolio/metric/payoff/_index.rst @@ -26,9 +26,23 @@ portfolio.metric.payoff( ------- pd.DataFrame DataFrame of payoff ratio of the portfolio during different time periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.payoff(P)

* **Returns** pd.DataFrame DataFrame of payoff ratio of the portfolio during different time periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.payoff(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/profitfactor/_index.rst b/website/content/SDK/portfolio/metric/profitfactor/_index.rst index 42b8581a1181..2858e21ee5e5 100644 --- a/website/content/SDK/portfolio/metric/profitfactor/_index.rst +++ b/website/content/SDK/portfolio/metric/profitfactor/_index.rst @@ -33,3 +33,11 @@ portfolio.metric.profitfactor( pd.DataFrame DataFrame of profit factor of the portfolio during different time periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.profitfactor(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/rsquare/_index.rst b/website/content/SDK/portfolio/metric/rsquare/_index.rst index 7d1985ad3375..6156e6e90d85 100644 --- a/website/content/SDK/portfolio/metric/rsquare/_index.rst +++ b/website/content/SDK/portfolio/metric/rsquare/_index.rst @@ -33,3 +33,11 @@ portfolio.metric.rsquare( pd.DataFrame DataFrame with R2 Score between portfolio and benchmark for different periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.rsquare(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/sharpe/_index.rst b/website/content/SDK/portfolio/metric/sharpe/_index.rst index ca761c6464a4..1e7891848389 100644 --- a/website/content/SDK/portfolio/metric/sharpe/_index.rst +++ b/website/content/SDK/portfolio/metric/sharpe/_index.rst @@ -36,3 +36,11 @@ portfolio.metric.sharpe( pd.DataFrame DataFrame with sharpe ratio for portfolio and benchmark for different periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.sharpe(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/skew/_index.rst b/website/content/SDK/portfolio/metric/skew/_index.rst index 875adc59df24..8d76238904cd 100644 --- a/website/content/SDK/portfolio/metric/skew/_index.rst +++ b/website/content/SDK/portfolio/metric/skew/_index.rst @@ -30,9 +30,23 @@ portfolio.metric.skew( ------- pd.DataFrame DataFrame with skewness for portfolio and benchmark for different periods + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.skew(P)

* **Returns** pd.DataFrame DataFrame with skewness for portfolio and benchmark for different periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.skew(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/sortino/_index.rst b/website/content/SDK/portfolio/metric/sortino/_index.rst index 334054bf9104..134d422c4df2 100644 --- a/website/content/SDK/portfolio/metric/sortino/_index.rst +++ b/website/content/SDK/portfolio/metric/sortino/_index.rst @@ -36,3 +36,11 @@ portfolio.metric.sortino( pd.DataFrame DataFrame with sortino ratio for portfolio and benchmark for different periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.sortino(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/tail/_index.rst b/website/content/SDK/portfolio/metric/tail/_index.rst index da1e16c158b6..1aebf1363cf5 100644 --- a/website/content/SDK/portfolio/metric/tail/_index.rst +++ b/website/content/SDK/portfolio/metric/tail/_index.rst @@ -40,3 +40,11 @@ portfolio.metric.tail( Series of the portfolios rolling tail ratio pd.Series Series of the benchmarks rolling tail ratio + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.tail(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/trackerr/_index.rst b/website/content/SDK/portfolio/metric/trackerr/_index.rst index 3a09a70a6080..24205227e680 100644 --- a/website/content/SDK/portfolio/metric/trackerr/_index.rst +++ b/website/content/SDK/portfolio/metric/trackerr/_index.rst @@ -38,3 +38,11 @@ portfolio.metric.trackerr( DataFrame of tracking errors during different time windows pd.Series Series of rolling tracking error + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.trackerr(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/metric/volatility/_index.rst b/website/content/SDK/portfolio/metric/volatility/_index.rst index f0e7d01905d3..3f64a79e54e6 100644 --- a/website/content/SDK/portfolio/metric/volatility/_index.rst +++ b/website/content/SDK/portfolio/metric/volatility/_index.rst @@ -33,3 +33,11 @@ portfolio.metric.volatility( pd.DataFrame DataFrame with volatility for portfolio and benchmark for different periods + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.metric.volatility(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/mret/_index.rst b/website/content/SDK/portfolio/mret/_index.rst index 43ee27aa5b6f..6004058aff7a 100644 --- a/website/content/SDK/portfolio/mret/_index.rst +++ b/website/content/SDK/portfolio/mret/_index.rst @@ -40,6 +40,15 @@ portfolio.mret( * **Returns** pd.DataFrame + DataFrame with monthly returns + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.mret(P) + {{< /highlight >}} | diff --git a/website/content/SDK/portfolio/om/_index.rst b/website/content/SDK/portfolio/om/_index.rst index 9dae23cd07cd..e69bb74cbf7a 100644 --- a/website/content/SDK/portfolio/om/_index.rst +++ b/website/content/SDK/portfolio/om/_index.rst @@ -43,6 +43,15 @@ portfolio.om( * **Returns** pd.DataFrame + DataFrame with portfolio omega ratio + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.om(P) + {{< /highlight >}} | diff --git a/website/content/SDK/portfolio/perf/_index.rst b/website/content/SDK/portfolio/perf/_index.rst index a514d97be180..2ef96c7701b4 100644 --- a/website/content/SDK/portfolio/perf/_index.rst +++ b/website/content/SDK/portfolio/perf/_index.rst @@ -35,3 +35,12 @@ portfolio.perf( * **Returns** pd.DataFrame + DataFrame with portfolio performance vs the benchmark + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.perf(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/rbeta/_index.rst b/website/content/SDK/portfolio/rbeta/_index.rst index 638bc5ec3857..f86fed92b35e 100644 --- a/website/content/SDK/portfolio/rbeta/_index.rst +++ b/website/content/SDK/portfolio/rbeta/_index.rst @@ -42,6 +42,14 @@ portfolio.rbeta( pd.DataFrame DataFrame of the portfolio's rolling beta +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.rbeta(P) + {{< /highlight >}} + | .. raw:: html diff --git a/website/content/SDK/portfolio/rsharpe/_index.rst b/website/content/SDK/portfolio/rsharpe/_index.rst index 9af51bbc5e6d..72338e388658 100644 --- a/website/content/SDK/portfolio/rsharpe/_index.rst +++ b/website/content/SDK/portfolio/rsharpe/_index.rst @@ -45,6 +45,14 @@ portfolio.rsharpe( pd.DataFrame Rolling sharpe ratio DataFrame +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.rsharpe(P) + {{< /highlight >}} + | .. raw:: html diff --git a/website/content/SDK/portfolio/rsort/_index.rst b/website/content/SDK/portfolio/rsort/_index.rst index a0d39ab2c79b..1d767bbb7f0d 100644 --- a/website/content/SDK/portfolio/rsort/_index.rst +++ b/website/content/SDK/portfolio/rsort/_index.rst @@ -45,6 +45,14 @@ portfolio.rsort( pd.DataFrame Rolling sortino ratio DataFrame +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.rsortino(P) + {{< /highlight >}} + | .. raw:: html diff --git a/website/content/SDK/portfolio/rvol/_index.rst b/website/content/SDK/portfolio/rvol/_index.rst index 4cf42ae0d230..417289547b20 100644 --- a/website/content/SDK/portfolio/rvol/_index.rst +++ b/website/content/SDK/portfolio/rvol/_index.rst @@ -38,6 +38,14 @@ portfolio.rvol( Flag to display chart +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.rvol(P) + {{< /highlight >}} + | .. raw:: html diff --git a/website/content/SDK/portfolio/show/_index.rst b/website/content/SDK/portfolio/show/_index.rst index 53133d3e0fa6..7cd8c86593b5 100644 --- a/website/content/SDK/portfolio/show/_index.rst +++ b/website/content/SDK/portfolio/show/_index.rst @@ -32,3 +32,11 @@ portfolio.show( pd.DataFrame Portfolio transactions + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.show(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/summary/_index.rst b/website/content/SDK/portfolio/summary/_index.rst index 2a0ed9feb17e..a13cf58c1989 100644 --- a/website/content/SDK/portfolio/summary/_index.rst +++ b/website/content/SDK/portfolio/summary/_index.rst @@ -22,7 +22,7 @@ portfolio.summary( .. raw:: html

- Get summary portfolio and benchmark returns + Get portfolio and benchmark returns summary

* **Parameters** @@ -38,3 +38,12 @@ portfolio.summary( * **Returns** pd.DataFrame + DataFrame with portfolio and benchmark returns summary + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.summary(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/var/_index.rst b/website/content/SDK/portfolio/var/_index.rst index 0e2d971efc24..b22b147ffe18 100644 --- a/website/content/SDK/portfolio/var/_index.rst +++ b/website/content/SDK/portfolio/var/_index.rst @@ -44,3 +44,12 @@ portfolio.var( * **Returns** pd.DataFrame + DataFrame with portfolio VaR + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.var(P) + {{< /highlight >}} diff --git a/website/content/SDK/portfolio/yret/_index.rst b/website/content/SDK/portfolio/yret/_index.rst index 2e09073ba4a4..c42e2b84a6ea 100644 --- a/website/content/SDK/portfolio/yret/_index.rst +++ b/website/content/SDK/portfolio/yret/_index.rst @@ -17,7 +17,7 @@ portfolio.yret( portfolio_engine: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, window: str = 'all', chart: bool = False, -) +) -> pandas.core.frame.DataFrame {{< /highlight >}} .. raw:: html @@ -37,6 +37,19 @@ portfolio.yret( Flag to display chart +* **Returns** + + pd.DataFrame + DataFrame with yearly returns + +* **Examples** + + {{< highlight python >}} + >>> from openbb_terminal.sdk import openbb + >>> P = openbb.portfolio.load("openbb_terminal/miscellaneous/portfolio_examples/holdings/example.csv") + >>> openbb.portfolio.yret(P) + {{< /highlight >}} + | .. raw:: html diff --git a/website/content/SDK/stocks/ba/cnews/_index.rst b/website/content/SDK/stocks/ba/cnews/_index.rst index f96209f5ed1f..9ee3fb2200b0 100644 --- a/website/content/SDK/stocks/ba/cnews/_index.rst +++ b/website/content/SDK/stocks/ba/cnews/_index.rst @@ -13,8 +13,8 @@ {{< highlight python >}} stocks.ba.cnews( symbol: str, - start_date: str = '2022-10-14', - end_date: str = '2022-11-13', + start_date: str = '2022-10-15', + end_date: str = '2022-11-14', chart: bool = False, ) -> List[Dict] {{< /highlight >}} diff --git a/website/content/SDK/stocks/ba/hist/_index.rst b/website/content/SDK/stocks/ba/hist/_index.rst index 4114342795fc..0213c933325f 100644 --- a/website/content/SDK/stocks/ba/hist/_index.rst +++ b/website/content/SDK/stocks/ba/hist/_index.rst @@ -15,8 +15,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ba.hist( symbol: str, - start_date: str = '2022-11-06', - end_date: str = '2022-11-13', + start_date: str = '2022-11-07', + end_date: str = '2022-11-14', number: int = 100, chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -61,8 +61,8 @@ stocks.ba.hist( {{< highlight python >}} stocks.ba.hist( symbol: str, - start_date: str = '2022-11-06', - end_date: str = '2022-11-13', + start_date: str = '2022-11-07', + end_date: str = '2022-11-14', number: int = 100, raw: bool = False, limit: int = 10, diff --git a/website/content/SDK/stocks/ba/trend/_index.rst b/website/content/SDK/stocks/ba/trend/_index.rst index 9a87c9b81e87..ecd8834d51d1 100644 --- a/website/content/SDK/stocks/ba/trend/_index.rst +++ b/website/content/SDK/stocks/ba/trend/_index.rst @@ -14,7 +14,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ba.trend( - start_date: str = '2022-11-10', + start_date: str = '2022-11-14', hour: int = 0, number: int = 10, chart: bool = False, @@ -58,7 +58,7 @@ stocks.ba.trend( {{< highlight python >}} stocks.ba.trend( - start_date: str = '2022-11-10', + start_date: str = '2022-11-14', hour: int = 0, number: int = 10, limit: int = 10, diff --git a/website/content/SDK/stocks/ca/hcorr/_index.rst b/website/content/SDK/stocks/ca/hcorr/_index.rst index 8e7ea202b7c0..e8080cd9f22f 100644 --- a/website/content/SDK/stocks/ca/hcorr/_index.rst +++ b/website/content/SDK/stocks/ca/hcorr/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ca.hcorr( similar: List[str], - start_date: str = '2021-11-12', + start_date: str = '2021-11-13', candle_type: str = 'a', chart: bool = False, ) @@ -52,7 +52,7 @@ stocks.ca.hcorr( {{< highlight python >}} stocks.ca.hcorr( similar: List[str], - start_date: str = '2021-11-12', + start_date: str = '2021-11-13', candle_type: str = 'a', display_full_matrix: bool = False, raw: bool = False, diff --git a/website/content/SDK/stocks/ca/hist/_index.rst b/website/content/SDK/stocks/ca/hist/_index.rst index 7fa86fe5fbd0..97fe03576ca3 100644 --- a/website/content/SDK/stocks/ca/hist/_index.rst +++ b/website/content/SDK/stocks/ca/hist/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ca.hist( similar: List[str], - start_date: str = '2021-11-12', + start_date: str = '2021-11-13', candle_type: str = 'a', chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -57,7 +57,7 @@ stocks.ca.hist( {{< highlight python >}} stocks.ca.hist( similar: List[str], - start_date: str = '2021-11-12', + start_date: str = '2021-11-13', candle_type: str = 'a', normalize: bool = True, export: str = '', diff --git a/website/content/SDK/stocks/ca/volume/_index.rst b/website/content/SDK/stocks/ca/volume/_index.rst index 2f8672761bd6..88c013fcc749 100644 --- a/website/content/SDK/stocks/ca/volume/_index.rst +++ b/website/content/SDK/stocks/ca/volume/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.ca.volume( similar: List[str], - start_date: str = '2021-11-12', + start_date: str = '2021-11-13', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -49,7 +49,7 @@ stocks.ca.volume( {{< highlight python >}} stocks.ca.volume( similar: List[str], - start_date: str = '2021-11-12', + start_date: str = '2021-11-13', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/stocks/candle/_index.rst b/website/content/SDK/stocks/candle/_index.rst index 59901a1afa40..d40fe8a60ad0 100644 --- a/website/content/SDK/stocks/candle/_index.rst +++ b/website/content/SDK/stocks/candle/_index.rst @@ -19,9 +19,9 @@ stocks.candle( add_trend: bool = False, ma: Optional[Iterable[int]] = None, asset_type: str = '', - start_date: Union[datetime.datetime, str, NoneType] = '2019-11-06', + start_date: Union[datetime.datetime, str, NoneType] = '2019-11-10', interval: int = 1440, - end_date: Union[datetime.datetime, str, NoneType] = '2022-11-10', + end_date: Union[datetime.datetime, str, NoneType] = '2022-11-14', prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/stocks/dd/pt/_index.rst b/website/content/SDK/stocks/dd/pt/_index.rst index 424a9d911fcc..09360df65521 100644 --- a/website/content/SDK/stocks/dd/pt/_index.rst +++ b/website/content/SDK/stocks/dd/pt/_index.rst @@ -50,7 +50,7 @@ stocks.dd.pt( stocks.dd.pt( symbol: str, data: pandas.core.frame.DataFrame, - start_date: str = '2022-11-13', + start_date: str = '2022-11-14', limit: int = 10, raw: bool = False, export: str = '', diff --git a/website/content/SDK/stocks/disc/dividends/_index.rst b/website/content/SDK/stocks/disc/dividends/_index.rst index d77d33fa0e3a..50e8bfd2b20d 100644 --- a/website/content/SDK/stocks/disc/dividends/_index.rst +++ b/website/content/SDK/stocks/disc/dividends/_index.rst @@ -12,7 +12,7 @@ {{< highlight python >}} stocks.disc.dividends( - date: str = '2022-11-13', + date: str = '2022-11-14', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/stocks/disc/ipo/_index.rst b/website/content/SDK/stocks/disc/ipo/_index.rst index 2cf51709f705..f45dc14802be 100644 --- a/website/content/SDK/stocks/disc/ipo/_index.rst +++ b/website/content/SDK/stocks/disc/ipo/_index.rst @@ -12,8 +12,8 @@ {{< highlight python >}} stocks.disc.ipo( - start_date: str = '2022-11-08', - end_date: str = '2022-11-13', + start_date: str = '2022-11-09', + end_date: str = '2022-11-14', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} diff --git a/website/content/SDK/stocks/dps/ftd/_index.rst b/website/content/SDK/stocks/dps/ftd/_index.rst index 821afcfb3b74..72516c9fdd45 100644 --- a/website/content/SDK/stocks/dps/ftd/_index.rst +++ b/website/content/SDK/stocks/dps/ftd/_index.rst @@ -15,8 +15,8 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.dps.ftd( symbol: str, - start_date: str = '2022-09-14', - end_date: str = '2022-11-13', + start_date: str = '2022-09-15', + end_date: str = '2022-11-14', limit: int = 0, chart: bool = False, ) -> pandas.core.frame.DataFrame @@ -59,8 +59,8 @@ stocks.dps.ftd( stocks.dps.ftd( symbol: str, data: pandas.core.frame.DataFrame, - start_date: str = '2022-09-14', - end_date: str = '2022-11-13', + start_date: str = '2022-09-15', + end_date: str = '2022-11-14', limit: int = 0, raw: bool = False, export: str = '', diff --git a/website/content/SDK/stocks/fa/mktcap/_index.rst b/website/content/SDK/stocks/fa/mktcap/_index.rst index 1c1416f7d229..ac33ebb82e51 100644 --- a/website/content/SDK/stocks/fa/mktcap/_index.rst +++ b/website/content/SDK/stocks/fa/mktcap/_index.rst @@ -15,7 +15,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. {{< highlight python >}} stocks.fa.mktcap( symbol: str, - start_date: str = '2019-11-11', + start_date: str = '2019-11-12', chart: bool = False, ) -> Tuple[pandas.core.frame.DataFrame, str] {{< /highlight >}} @@ -54,7 +54,7 @@ stocks.fa.mktcap( {{< highlight python >}} stocks.fa.mktcap( symbol: str, - start_date: str = '2019-11-11', + start_date: str = '2019-11-12', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/stocks/ins/act/_index.rst b/website/content/SDK/stocks/ins/act/_index.rst index 2d1352c16371..f32f0de270c6 100644 --- a/website/content/SDK/stocks/ins/act/_index.rst +++ b/website/content/SDK/stocks/ins/act/_index.rst @@ -50,7 +50,7 @@ stocks.ins.act( stocks.ins.act( data: pandas.core.frame.DataFrame, symbol: str, - start_date: str = '2019-11-09', + start_date: str = '2019-11-10', interval: str = '1440min', limit: int = 10, raw: bool = False, diff --git a/website/content/SDK/stocks/load/_index.rst b/website/content/SDK/stocks/load/_index.rst index 3b8e9fe73e56..93a3f6319cec 100644 --- a/website/content/SDK/stocks/load/_index.rst +++ b/website/content/SDK/stocks/load/_index.rst @@ -13,9 +13,9 @@ {{< highlight python >}} stocks.load( symbol: str, - start_date: Union[datetime.datetime, str, NoneType] = '2019-11-06', + start_date: Union[datetime.datetime, str, NoneType] = '2019-11-10', interval: int = 1440, - end_date: Union[datetime.datetime, str, NoneType] = '2022-11-10', + end_date: Union[datetime.datetime, str, NoneType] = '2022-11-14', prepost: bool = False, source: str = 'YahooFinance', iexrange: str = 'ytd', diff --git a/website/content/SDK/stocks/options/pcr/_index.rst b/website/content/SDK/stocks/options/pcr/_index.rst index 560e8d08b521..e6fc4a5dc965 100644 --- a/website/content/SDK/stocks/options/pcr/_index.rst +++ b/website/content/SDK/stocks/options/pcr/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. stocks.options.pcr( symbol: str, window: int = 30, - start_date: str = '2021-11-12', + start_date: str = '2021-11-13', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -51,7 +51,7 @@ stocks.options.pcr( stocks.options.pcr( symbol: str, window: int = 30, - start_date: str = '2021-11-12', + start_date: str = '2021-11-13', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, chart: bool = False, diff --git a/website/content/SDK/stocks/screener/historical/_index.rst b/website/content/SDK/stocks/screener/historical/_index.rst index b532798b4fdc..bd2c8c1b332d 100644 --- a/website/content/SDK/stocks/screener/historical/_index.rst +++ b/website/content/SDK/stocks/screener/historical/_index.rst @@ -16,7 +16,7 @@ To obtain charts, make sure to add :python:`chart = True` as the last parameter. stocks.screener.historical( preset_loaded: str = 'top_gainers', limit: int = 10, - start_date: str = '2022-05-17', + start_date: str = '2022-05-18', type_candle: str = 'a', normalize: bool = True, chart: bool = False, @@ -66,7 +66,7 @@ stocks.screener.historical( stocks.screener.historical( preset_loaded: str = 'top_gainers', limit: int = 10, - start_date: str = '2022-05-17', + start_date: str = '2022-05-18', type_candle: str = 'a', normalize: bool = True, export: str = '', diff --git a/website/data/menu/main.yml b/website/data/menu/main.yml index 70c5636bb5dc..0a7bd3ef8d7f 100644 --- a/website/data/menu/main.yml +++ b/website/data/menu/main.yml @@ -2487,6 +2487,17 @@ main: - name: portfolio ref: /SDK/portfolio sub: + - name: alloc + ref: /SDK/portfolio/alloc + sub: + - name: assets + ref: /SDK/portfolio/alloc/assets + - name: countries + ref: /SDK/portfolio/alloc/countries + - name: regions + ref: /SDK/portfolio/alloc/regions + - name: sectors + ref: /SDK/portfolio/alloc/sectors - name: bench ref: /SDK/portfolio/bench - name: calmar @@ -2515,8 +2526,6 @@ main: ref: /SDK/portfolio/kurtosis - name: load ref: /SDK/portfolio/load - - name: max_drawdown_ratio - ref: /SDK/portfolio/max_drawdown_ratio - name: maxdd ref: /SDK/portfolio/maxdd - name: maxdrawdown diff --git a/website/generate.py b/website/generate.py index 738f6817a074..e0cb67df070c 100644 --- a/website/generate.py +++ b/website/generate.py @@ -86,8 +86,8 @@ def write_section( if code_snippet: file.write(" {{< highlight python >}}\n") - file.write(" " + text) - file.write("{{< /highlight >}}") + file.write(" " + text + "\n") + file.write(" {{< /highlight >}}") else: file.write(" " + text) @@ -218,13 +218,19 @@ def write_docstring(name: str, func, file, chart: bool): title="Parameters\n ----------\n", docstring=formatted_docstring ) + has_returns = False returns_title_start, returns_title_end = locate_section( title="Returns\n -------\n", docstring=formatted_docstring ) + if returns_title_start > -1: + has_returns = True + has_examples = False examples_title_start, examples_title_end = locate_section( title="Examples\n --------\n", docstring=formatted_docstring ) + if examples_title_start > -1: + has_examples = True has_parameters = False if signature(func[2]).parameters: @@ -244,8 +250,10 @@ def write_docstring(name: str, func, file, chart: bool): # Summary if has_parameters: bottom = parameters_title_start - else: + elif has_returns: bottom = returns_title_start + else: + bottom = len(formatted_docstring) write_summary( bottom=bottom, @@ -255,10 +263,18 @@ def write_docstring(name: str, func, file, chart: bool): # Parameters if parameters_title_start > 0: + + if has_returns: + end = returns_title_start + elif has_examples: + end = examples_title_start + else: + end = len(formatted_docstring) + write_section( title="Parameters", start=parameters_title_end, - end=returns_title_start, + end=end, docstring=formatted_docstring.replace("_:", r"\_:"), file=file, ) @@ -270,6 +286,12 @@ def write_docstring(name: str, func, file, chart: bool): # Returns if returns_title_start > 0: + + if has_examples: + end = examples_title_start + else: + end = len(formatted_docstring) + write_section( title="Returns", start=returns_title_end, From 7a4c153b30b2f6c3fad69a4cd3e12ea4c39b6668 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Mon, 14 Nov 2022 14:33:14 +0000 Subject: [PATCH 30/30] regenerate website --- website/content/SDK/crypto/dd/gh/_index.rst | 8 ++-- .../content/SDK/portfolio/calmar/_index.rst | 39 ----------------- .../SDK/portfolio/commonsense/_index.rst | 34 --------------- .../SDK/portfolio/gaintopain/_index.rst | 34 --------------- .../SDK/portfolio/information/_index.rst | 34 --------------- .../content/SDK/portfolio/jensens/_index.rst | 42 ------------------- .../content/SDK/portfolio/kelly/_index.rst | 34 --------------- .../content/SDK/portfolio/kurtosis/_index.rst | 34 --------------- .../SDK/portfolio/maxdrawdown/_index.rst | 34 --------------- .../content/SDK/portfolio/payoff/_index.rst | 34 --------------- .../SDK/portfolio/profitfactor/_index.rst | 34 --------------- .../content/SDK/portfolio/sharpe/_index.rst | 37 ---------------- website/content/SDK/portfolio/skew/_index.rst | 37 ---------------- .../content/SDK/portfolio/sortino/_index.rst | 37 ---------------- website/content/SDK/portfolio/tail/_index.rst | 42 ------------------- .../content/SDK/portfolio/trackerr/_index.rst | 39 ----------------- .../SDK/portfolio/volatility/_index.rst | 34 --------------- website/data/menu/main.yml | 32 -------------- 18 files changed, 4 insertions(+), 615 deletions(-) delete mode 100644 website/content/SDK/portfolio/calmar/_index.rst delete mode 100644 website/content/SDK/portfolio/commonsense/_index.rst delete mode 100644 website/content/SDK/portfolio/gaintopain/_index.rst delete mode 100644 website/content/SDK/portfolio/information/_index.rst delete mode 100644 website/content/SDK/portfolio/jensens/_index.rst delete mode 100644 website/content/SDK/portfolio/kelly/_index.rst delete mode 100644 website/content/SDK/portfolio/kurtosis/_index.rst delete mode 100644 website/content/SDK/portfolio/maxdrawdown/_index.rst delete mode 100644 website/content/SDK/portfolio/payoff/_index.rst delete mode 100644 website/content/SDK/portfolio/profitfactor/_index.rst delete mode 100644 website/content/SDK/portfolio/sharpe/_index.rst delete mode 100644 website/content/SDK/portfolio/skew/_index.rst delete mode 100644 website/content/SDK/portfolio/sortino/_index.rst delete mode 100644 website/content/SDK/portfolio/tail/_index.rst delete mode 100644 website/content/SDK/portfolio/trackerr/_index.rst delete mode 100644 website/content/SDK/portfolio/volatility/_index.rst diff --git a/website/content/SDK/crypto/dd/gh/_index.rst b/website/content/SDK/crypto/dd/gh/_index.rst index 97c24e41c60e..3bcc379f76b5 100644 --- a/website/content/SDK/crypto/dd/gh/_index.rst +++ b/website/content/SDK/crypto/dd/gh/_index.rst @@ -17,8 +17,8 @@ crypto.dd.gh( symbol: str, dev_activity: bool = False, interval: str = '1d', - start_date: str = '2021-11-14T14:22:49Z', - end_date: str = '2022-11-14T14:22:49Z', + start_date: str = '2021-11-14T14:32:50Z', + end_date: str = '2022-11-14T14:32:50Z', chart: bool = False, ) -> pandas.core.frame.DataFrame {{< /highlight >}} @@ -63,9 +63,9 @@ crypto.dd.gh( {{< highlight python >}} crypto.dd.gh( symbol: str, - start_date: str = '2021-11-14T14:22:49Z', + start_date: str = '2021-11-14T14:32:50Z', dev_activity: bool = False, - end_date: str = '2022-11-14T14:22:49Z', + end_date: str = '2022-11-14T14:32:50Z', interval: str = '1d', export: str = '', external_axes: Optional[List[matplotlib.axes._axes.Axes]] = None, diff --git a/website/content/SDK/portfolio/calmar/_index.rst b/website/content/SDK/portfolio/calmar/_index.rst deleted file mode 100644 index f8deb1c26d95..000000000000 --- a/website/content/SDK/portfolio/calmar/_index.rst +++ /dev/null @@ -1,39 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.calmar( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - window: int = 756, - chart: bool = False, -) -{{< /highlight >}} - -.. raw:: html - -

- Get calmar ratio -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - window: int - Interval used for rolling values - -* **Returns** - - pd.DataFrame - DataFrame of calmar ratio of the benchmark and portfolio during different time periods - pd.Series - Series of calmar ratio data diff --git a/website/content/SDK/portfolio/commonsense/_index.rst b/website/content/SDK/portfolio/commonsense/_index.rst deleted file mode 100644 index 85009730666f..000000000000 --- a/website/content/SDK/portfolio/commonsense/_index.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.commonsense( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - chart: bool = False, -) -{{< /highlight >}} - -.. raw:: html - -

- Get common sense ratio -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - -* **Returns** - - pd.DataFrame - DataFrame of the portfolios and the benchmarks common sense ratio during different time periods diff --git a/website/content/SDK/portfolio/gaintopain/_index.rst b/website/content/SDK/portfolio/gaintopain/_index.rst deleted file mode 100644 index 408633cf70ee..000000000000 --- a/website/content/SDK/portfolio/gaintopain/_index.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.gaintopain( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - chart: bool = False, -) -{{< /highlight >}} - -.. raw:: html - -

- Get Pain-to-Gain ratio based on historical data -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - -* **Returns** - - pd.DataFrame - DataFrame of the portfolio's gain-to-pain ratio diff --git a/website/content/SDK/portfolio/information/_index.rst b/website/content/SDK/portfolio/information/_index.rst deleted file mode 100644 index 71d898b07db1..000000000000 --- a/website/content/SDK/portfolio/information/_index.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.information( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - chart: bool = False, -) -{{< /highlight >}} - -.. raw:: html - -

- Get information ratio -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - -* **Returns** - - pd.DataFrame - DataFrame of the information ratio during different time periods diff --git a/website/content/SDK/portfolio/jensens/_index.rst b/website/content/SDK/portfolio/jensens/_index.rst deleted file mode 100644 index 8a9027aa08b4..000000000000 --- a/website/content/SDK/portfolio/jensens/_index.rst +++ /dev/null @@ -1,42 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.jensens( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - risk_free_rate: float = 0, - window: str = '1y', - chart: bool = False, -) -{{< /highlight >}} - -.. raw:: html - -

- Get jensen's alpha -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - window: str - Interval used for rolling values - risk_free_rate: float - Risk free rate - -* **Returns** - - pd.DataFrame - DataFrame of jensens's alpha during different time windows - pd.Series - Series of jensens's alpha data diff --git a/website/content/SDK/portfolio/kelly/_index.rst b/website/content/SDK/portfolio/kelly/_index.rst deleted file mode 100644 index c401f2cd69ac..000000000000 --- a/website/content/SDK/portfolio/kelly/_index.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.kelly( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - chart: bool = False, -) -{{< /highlight >}} - -.. raw:: html - -

- Gets kelly criterion -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - -* **Returns** - - pd.DataFrame - DataFrame of kelly criterion of the portfolio during different time periods diff --git a/website/content/SDK/portfolio/kurtosis/_index.rst b/website/content/SDK/portfolio/kurtosis/_index.rst deleted file mode 100644 index b1743c23e65e..000000000000 --- a/website/content/SDK/portfolio/kurtosis/_index.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.kurtosis( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - chart: bool = False, -) -> pandas.core.frame.DataFrame -{{< /highlight >}} - -.. raw:: html - -

- Class method that retrieves kurtosis for portfolio and benchmark selected -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - -* **Returns** - - pd.DataFrame - DataFrame with kurtosis for portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/maxdrawdown/_index.rst b/website/content/SDK/portfolio/maxdrawdown/_index.rst deleted file mode 100644 index 502bbc9d4c88..000000000000 --- a/website/content/SDK/portfolio/maxdrawdown/_index.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.maxdrawdown( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - chart: bool = False, -) -> pandas.core.frame.DataFrame -{{< /highlight >}} - -.. raw:: html - -

- Class method that retrieves maximum drawdown ratio for portfolio and benchmark selected -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - -* **Returns** - - pd.DataFrame - DataFrame with maximum drawdown for portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/payoff/_index.rst b/website/content/SDK/portfolio/payoff/_index.rst deleted file mode 100644 index a7c2cb29a320..000000000000 --- a/website/content/SDK/portfolio/payoff/_index.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.payoff( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - chart: bool = False, -) -{{< /highlight >}} - -.. raw:: html - -

- Gets payoff ratio - - Returns - ------- - pd.DataFrame - DataFrame of payoff ratio of the portfolio during different time periods -

- -* **Returns** - - pd.DataFrame - DataFrame of payoff ratio of the portfolio during different time periods diff --git a/website/content/SDK/portfolio/profitfactor/_index.rst b/website/content/SDK/portfolio/profitfactor/_index.rst deleted file mode 100644 index c50c0d0ce9be..000000000000 --- a/website/content/SDK/portfolio/profitfactor/_index.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.profitfactor( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - chart: bool = False, -) -{{< /highlight >}} - -.. raw:: html - -

- Gets profit factor -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - -* **Returns** - - pd.DataFrame - DataFrame of profit factor of the portfolio during different time periods diff --git a/website/content/SDK/portfolio/sharpe/_index.rst b/website/content/SDK/portfolio/sharpe/_index.rst deleted file mode 100644 index cd22f1fef5c3..000000000000 --- a/website/content/SDK/portfolio/sharpe/_index.rst +++ /dev/null @@ -1,37 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.sharpe( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - risk_free_rate: float = 0, - chart: bool = False, -) -> pandas.core.frame.DataFrame -{{< /highlight >}} - -.. raw:: html - -

- Class method that retrieves sharpe ratio for portfolio and benchmark selected -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - risk_free_rate: float - Risk free rate value - -* **Returns** - - pd.DataFrame - DataFrame with sharpe ratio for portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/skew/_index.rst b/website/content/SDK/portfolio/skew/_index.rst deleted file mode 100644 index 9600bce4d23e..000000000000 --- a/website/content/SDK/portfolio/skew/_index.rst +++ /dev/null @@ -1,37 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.skew( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - chart: bool = False, -) -> pandas.core.frame.DataFrame -{{< /highlight >}} - -.. raw:: html - -

- Class method that retrieves skewness for portfolio and benchmark selected - - portfolio: Portfolio - Portfolio object with trades loaded - - Returns - ------- - pd.DataFrame - DataFrame with skewness for portfolio and benchmark for different periods -

- -* **Returns** - - pd.DataFrame - DataFrame with skewness for portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/sortino/_index.rst b/website/content/SDK/portfolio/sortino/_index.rst deleted file mode 100644 index f23f4491153a..000000000000 --- a/website/content/SDK/portfolio/sortino/_index.rst +++ /dev/null @@ -1,37 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.sortino( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - risk_free_rate: float = 0, - chart: bool = False, -) -> pandas.core.frame.DataFrame -{{< /highlight >}} - -.. raw:: html - -

- Class method that retrieves sortino ratio for portfolio and benchmark selected -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - risk_free_rate: float - Risk free rate value - -* **Returns** - - pd.DataFrame - DataFrame with sortino ratio for portfolio and benchmark for different periods diff --git a/website/content/SDK/portfolio/tail/_index.rst b/website/content/SDK/portfolio/tail/_index.rst deleted file mode 100644 index 390e5e988797..000000000000 --- a/website/content/SDK/portfolio/tail/_index.rst +++ /dev/null @@ -1,42 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.tail( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - window: int = 252, - chart: bool = False, -) -{{< /highlight >}} - -.. raw:: html - -

- Get tail ratio -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - - window: int - Interval used for rolling values - -* **Returns** - - pd.DataFrame - DataFrame of the portfolios and the benchmarks tail ratio during different time windows - pd.Series - Series of the portfolios rolling tail ratio - pd.Series - Series of the benchmarks rolling tail ratio diff --git a/website/content/SDK/portfolio/trackerr/_index.rst b/website/content/SDK/portfolio/trackerr/_index.rst deleted file mode 100644 index 2d32e45d1f16..000000000000 --- a/website/content/SDK/portfolio/trackerr/_index.rst +++ /dev/null @@ -1,39 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.trackerr( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - window: int = 252, - chart: bool = False, -) -{{< /highlight >}} - -.. raw:: html - -

- Get tracking error -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - window: int - Interval used for rolling values - -* **Returns** - - pd.DataFrame - DataFrame of tracking errors during different time windows - pd.Series - Series of rolling tracking error diff --git a/website/content/SDK/portfolio/volatility/_index.rst b/website/content/SDK/portfolio/volatility/_index.rst deleted file mode 100644 index 08a6ed859326..000000000000 --- a/website/content/SDK/portfolio/volatility/_index.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. role:: python(code) - :language: python - :class: highlight - -| - -.. raw:: html - -

- > Getting data -

- -{{< highlight python >}} -portfolio.volatility( - portfolio: openbb_terminal.portfolio.portfolio_model.PortfolioEngine, - chart: bool = False, -) -> pandas.core.frame.DataFrame -{{< /highlight >}} - -.. raw:: html - -

- Class method that retrieves volatility for portfolio and benchmark selected -

- -* **Parameters** - - portfolio: Portfolio - Portfolio object with trades loaded - -* **Returns** - - pd.DataFrame - DataFrame with volatility for portfolio and benchmark for different periods diff --git a/website/data/menu/main.yml b/website/data/menu/main.yml index 0a7bd3ef8d7f..fdd58d94f899 100644 --- a/website/data/menu/main.yml +++ b/website/data/menu/main.yml @@ -2500,36 +2500,20 @@ main: ref: /SDK/portfolio/alloc/sectors - name: bench ref: /SDK/portfolio/bench - - name: calmar - ref: /SDK/portfolio/calmar - - name: commonsense - ref: /SDK/portfolio/commonsense - name: distr ref: /SDK/portfolio/distr - name: dret ref: /SDK/portfolio/dret - name: es ref: /SDK/portfolio/es - - name: gaintopain - ref: /SDK/portfolio/gaintopain - name: holdp ref: /SDK/portfolio/holdp - name: holdv ref: /SDK/portfolio/holdv - - name: information - ref: /SDK/portfolio/information - - name: jensens - ref: /SDK/portfolio/jensens - - name: kelly - ref: /SDK/portfolio/kelly - - name: kurtosis - ref: /SDK/portfolio/kurtosis - name: load ref: /SDK/portfolio/load - name: maxdd ref: /SDK/portfolio/maxdd - - name: maxdrawdown - ref: /SDK/portfolio/maxdrawdown - name: metric ref: /SDK/portfolio/metric sub: @@ -2571,8 +2555,6 @@ main: ref: /SDK/portfolio/mret - name: om ref: /SDK/portfolio/om - - name: payoff - ref: /SDK/portfolio/payoff - name: perf ref: /SDK/portfolio/perf - name: po @@ -2620,8 +2602,6 @@ main: ref: /SDK/portfolio/po/relriskparity - name: riskparity ref: /SDK/portfolio/po/riskparity - - name: profitfactor - ref: /SDK/portfolio/profitfactor - name: rbeta ref: /SDK/portfolio/rbeta - name: rsharpe @@ -2634,24 +2614,12 @@ main: ref: /SDK/portfolio/rsquare - name: rvol ref: /SDK/portfolio/rvol - - name: sharpe - ref: /SDK/portfolio/sharpe - name: show ref: /SDK/portfolio/show - - name: skew - ref: /SDK/portfolio/skew - - name: sortino - ref: /SDK/portfolio/sortino - name: summary ref: /SDK/portfolio/summary - - name: tail - ref: /SDK/portfolio/tail - - name: trackerr - ref: /SDK/portfolio/trackerr - name: var ref: /SDK/portfolio/var - - name: volatility - ref: /SDK/portfolio/volatility - name: yret ref: /SDK/portfolio/yret - name: stocks