From a07e4e44c371e7eaf128dd7ef4c04f461227f9bc Mon Sep 17 00:00:00 2001 From: jeroen Date: Fri, 24 Feb 2023 10:30:59 +0100 Subject: [PATCH] Fix some missing docstrings --- openbb_terminal/fixedincome/fred_model.py | 90 +++++++++++++++++++++-- openbb_terminal/fixedincome/oecd_model.py | 30 +++++++- openbb_terminal/fixedincome/oecd_view.py | 8 +- 3 files changed, 117 insertions(+), 11 deletions(-) diff --git a/openbb_terminal/fixedincome/fred_model.py b/openbb_terminal/fixedincome/fred_model.py index 61289f36b23..5a2b0810496 100644 --- a/openbb_terminal/fixedincome/fred_model.py +++ b/openbb_terminal/fixedincome/fred_model.py @@ -21,6 +21,10 @@ from openbb_terminal.rich_config import console logger = logging.getLogger(__name__) +ice_bofa_path = pathlib.Path(__file__).parent / "ice_bofa_indices.xlsx" +commercial_paper_path = pathlib.Path(__file__).parent / "commercial_paper.xlsx" +spot_rates_path = pathlib.Path(__file__).parent / "corporate_spot_rates.xlsx" + YIELD_CURVE_SERIES_NOMINAL = { "1Month": "DGS1MO", "3Month": "DGS3MO", @@ -655,7 +659,12 @@ def get_sofr( Parameters ---------- parameter: str - The parameter to get data for. + The parameter to get data for. Choose from: + "overnight" + "30_day_average" + "90_day_average" + "180_day_average" + "index" start_date: Optional[str] Start date, formatted YYYY-MM-DD end_date: Optional[str] @@ -705,7 +714,18 @@ def get_ameribor( Parameters ---------- parameter: str - The parameter to get data for. + The parameter to get data for. Choose from: + "overnight": "AMERIBOR", + "term_30": "AMBOR30T", + "term_90": "AMBOR90T", + "1_week_term_structure": "AMBOR1W", + "1_month_term_structure": "AMBOR1M", + "3_month_term_structure": "AMBOR3M", + "6_month_term_structure": "AMBOR6M", + "1_year_term_structure": "AMBOR1Y", + "2_year_term_structure": "AMBOR2Y", + "30_day_ma": "AMBOR30", + "90_day_ma": "AMBOR90", start_date: Optional[str] Start date, formatted YYYY-MM-DD end_date: Optional[str] @@ -730,7 +750,14 @@ def get_fed( Parameters ---------- parameter: str - The parameter to get data for. + The parameter to get data for. Choose from: + "monthly" + "daily" + "weekly" + "daily_excl_weekend" + "annual" + "biweekly" + "volume" start_date: Optional[str] Start date, formatted YYYY-MM-DD end_date: Optional[str] @@ -830,7 +857,12 @@ def get_dwpcr( Parameters ---------- parameter: str - The parameter to get data for. + The parameter to get data for. Choose from: + "daily_excl_weekend" + "monthly" + "weekly" + "daily" + "annual" start_date: Optional[str] Start date, formatted YYYY-MM-DD end_date: Optional[str] @@ -859,7 +891,10 @@ def get_ecb( Parameters ---------- interest_type: Optional[str] - The ability to decide what interest rate to plot + The ability to decide what interest rate to plot. Choose from: + "deposit" + "lending" + "refinancing" start_date: Optional[str] Start date, formatted YYYY-MM-DD end_date: Optional[str] @@ -919,6 +954,18 @@ def get_usrates( Either "tbills", "cmn", or "tips". maturity: str Depending on the chosen parameter, a set of maturities is available. + "4_week": {"tbill": "DTB4WK"}, + "1_month": {"cmn": "DGS1MO"}, + "3_month": {"tbill": "TB3MS", "cmn": "DGS3MO"}, + "6_month": {"tbill": "DTB6", "cmn": "DGS6MO"}, + "1_year": {"tbill": "DTB1YR", "cmn": "DGS1"}, + "2_year": {"cmn": "DGS2"}, + "3_year": {"cmn": "DGS3"}, + "5_year": {"tips": "DFII5", "cmn": "DGS5"}, + "7_year": {"tips": "DFII7", "cmn": "DGS7"}, + "10_year": {"tips": "DFII10", "cmn": "DGS10"}, + "20_year": {"tips": "DFII20", "cmn": "DGS20"}, + "30_year": {"tips": "DFII30", "cmn": "DGS30"}, start_date: Optional[str] Start date, formatted YYYY-MM-DD end_date: Optional[str] @@ -935,11 +982,14 @@ def get_icebofa( category: str = "all", area: str = "us", grade: str = "non_sovereign", + options: bool = False, start_date: Optional[str] = None, end_date: Optional[str] = None, ) -> pd.DataFrame: """Get data for ICE BofA US Corporate Bond Indices. + Find the available options by using the options parameter. + Parameters ---------- data_type: str @@ -951,15 +1001,37 @@ def get_icebofa( grade: str The type of grade you want to see, either "a", "aa", "aaa", "b", "bb", "bbb", "ccc", "crossover", "high_grade", "high_yield", "non_financial", "non_sovereign", "private_sector", "public_sector" + options: bool + Set to True to obtain the available options. start_date: Optional[str] Start date, formatted YYYY-MM-DD end_date: Optional[str] End date, formatted YYYY-MM-DD """ + series = pd.read_excel(ice_bofa_path) + + if options: + return series.drop( + ["Frequency", "Units", "Asset Class", "FRED Series ID", "Description"], + axis=1, + )[ + series["Type"].isin( + ["yield", "yield_to_worst", "total_return"] + if data_type != "spread" + else ["spread"] + ) + ] + if data_type == "total_return": units = "index" elif data_type in ["yield", "yield_to_worst", "spread"]: units = "percent" + else: + console.print( + "Please choose either 'yield', 'yield_to_worst', " + "'total_return' or 'spread'." + ) + return pd.DataFrame() series = pd.read_excel(ice_bofa_path) series = series[ @@ -1025,7 +1097,7 @@ def get_cp( start_date: Optional[str] = None, end_date: Optional[str] = None, ): - """Plot Commercial Paper + """Obtain Commercial Paper data Parameters ---------- @@ -1082,7 +1154,7 @@ def get_spot( Parameters ---------- maturity: str - The maturity you want to see (ranging from '1y' to '100y') + The maturity you want to see (ranging from '1y' to '100y' in interval of 0.5, e.g. '50.5y') category: list The category you want to see ('par_yield' and/or 'spot_rate') description: bool @@ -1113,7 +1185,7 @@ def get_spot( df = pd.DataFrame.from_dict(series_dictionary) df.index = pd.to_datetime(df.index).date - return df + return df[0] def get_hqm( @@ -1178,6 +1250,7 @@ def get_icespread( category: str = "all", area: str = "us", grade: str = "non_sovereign", + options: bool = False, start_date: Optional[str] = None, end_date: Optional[str] = None, ) -> pd.DataFrame: @@ -1198,6 +1271,7 @@ def get_icespread( category=category, area=area, grade=grade, + options=options, start_date=start_date, end_date=end_date, ) diff --git a/openbb_terminal/fixedincome/oecd_model.py b/openbb_terminal/fixedincome/oecd_model.py index ea3f85c192f..77d7aa9b5b4 100644 --- a/openbb_terminal/fixedincome/oecd_model.py +++ b/openbb_terminal/fixedincome/oecd_model.py @@ -193,8 +193,36 @@ def get_treasury( start_date: Optional[str] = None, end_date: Optional[str] = None, ) -> pd.DataFrame: - df_short, df_long = pd.DataFrame(), pd.DataFrame() + """Gets interest rates data from selected countries (3 month and 10 year) + Short-term interest rates are the rates at which short-term borrowings are effected between financial + institutions or the rate at which short-term government paper is issued or traded in the market. Short-term + interest rates are generally averages of daily rates, measured as a percentage. Short-term interest rates are + based on three-month money market rates where available. Typical standardised names are "money market rate" and + "treasury bill rate". + + Long-term interest rates refer to government bonds maturing in ten years. Rates are mainly determined by the + price charged by the lender, the risk from the borrower and the fall in the capital value. Long-term interest + rates are generally averages of daily rates, measured as a percentage. These interest rates are implied by the + prices at which the government bonds are traded on financial markets, not the interest rates at which the loans + were issued. In all cases, they refer to bonds whose capital repayment is guaranteed by governments. Long-term + interest rates are one of the determinants of business investment. Low long-term interest rates encourage + investment in new equipment and high interest rates discourage it. Investment is, in turn, a major source of + economic growth. + + Parameters + ---------- + short_term: list + Countries you wish to plot the 3-month interest rate for + long_term: list + Countries you wish to plot the 10-year interest rate for + forecast: bool + If True, plot forecasts for short term interest rates + start_date: str + Start date of data, in YYYY-MM-DD format + end_date: str + End date of data, in YYYY-MM-DD format + """ if short_term: df_short = get_interest_rate_data( f"short{'_forecast' if forecast else ''}", diff --git a/openbb_terminal/fixedincome/oecd_view.py b/openbb_terminal/fixedincome/oecd_view.py index 20548b31da4..2a8445a4191 100644 --- a/openbb_terminal/fixedincome/oecd_view.py +++ b/openbb_terminal/fixedincome/oecd_view.py @@ -54,14 +54,18 @@ def plot_treasuries( Parameters ---------- - countries: list - List of countries to get data for + short_term: list + Countries you wish to plot the 3-month interest rate for + long_term: list + Countries you wish to plot the 10-year interest rate for forecast: bool If True, plot forecasts for short term interest rates start_date: str Start date of data, in YYYY-MM-DD format end_date: str End date of data, in YYYY-MM-DD format + raw: bool + If True, print raw data export: str Export data to csv or excel file external_axes: Optional[List[plt.Axes]]