diff --git a/ROADMAP.md b/ROADMAP.md index 37c69ea2cb1..e2ddc7cf15d 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -172,6 +172,7 @@ ___ ## Economy * [x] Implement Economic data (gpd, unemployment rate, ...) (@jmaslek) - [PR #167](https://github.com/DidierRLopes/GamestonkTerminal/pull/167) * [x] Refactor FRED to ECON menu and add VIX view (@jmaslek) - [PR #405](https://github.com/DidierRLopes/GamestonkTerminal/pull/405) +* [x] Output economic impact events calendar (@didier) - [PR #430](https://github.com/DidierRLopes/GamestonkTerminal/pull/430) **NEXT** diff --git a/gamestonk_terminal/README.md b/gamestonk_terminal/README.md index e314b341ba2..5ac456b0be8 100644 --- a/gamestonk_terminal/README.md +++ b/gamestonk_terminal/README.md @@ -329,19 +329,21 @@ Command|Description|Source   ## Economy [»](econ/README.md) -Command|Description ------- | -------- -`vixcls` | Volatility Index -`gdp` | Gross Domestic Product -`unrate` | Unemployment Rate -`dgs1` | 1-Year Treasury Constant Maturity Rate -`dgs5` | 5-Year Treasury Constant Maturity Rate -`dgs10` | 10-Year Treasury Constant Maturity Rate -`dgs30` | 30-Year Treasury Constant Maturity Rate -`mortgage30us` | 30-Year Fixed Rate Mortgage Average -`fedfunds` | Effective Federal Funds Rate -`aaa` | Moody's Seasoned AAA Corporate Bond Yield -`dexcaus` | Canada / U.S. Foreign Exchange Rate (CAD per 1 USD) +Command|Description|Source +------ | -------- | -------- +`events` | economic impact events | https://finnhub.io +`fred` | display customized FRED data | https://fred.stlouisfed.org +`vixcls` | Volatility Index | https://fred.stlouisfed.org +`gdp` | Gross Domestic Product | https://fred.stlouisfed.org +`unrate` | Unemployment Rate | https://fred.stlouisfed.org +`dgs1` | 1-Year Treasury Constant Maturity Rate | https://fred.stlouisfed.org +`dgs5` | 5-Year Treasury Constant Maturity Rate | https://fred.stlouisfed.org +`dgs10` | 10-Year Treasury Constant Maturity Rate | https://fred.stlouisfed.org +`dgs30` | 30-Year Treasury Constant Maturity Rate | https://fred.stlouisfed.org +`mortgage30us` | 30-Year Fixed Rate Mortgage Average | https://fred.stlouisfed.org +`fedfunds` | Effective Federal Funds Rate | https://fred.stlouisfed.org +`aaa` | Moody's Seasoned AAA Corporate Bond Yield | https://fred.stlouisfed.org +`dexcaus` | Canada / U.S. Foreign Exchange Rate (CAD per 1 USD) | https://fred.stlouisfed.org   diff --git a/gamestonk_terminal/econ/README.md b/gamestonk_terminal/econ/README.md index 1e6bb26f4b9..8bd5054abed 100644 --- a/gamestonk_terminal/econ/README.md +++ b/gamestonk_terminal/econ/README.md @@ -1,7 +1,9 @@ -# ECONONMY +# ECONOMY This menu aims to assess economy data, and the usage of the following commands along with an example will be exploited below. +* [events](#events) + * economic impact events [Finnhub] * [fred](#fred) * display customized FRED from https://fred.stlouisfed.org * [vixcls](#vixcls) @@ -28,6 +30,20 @@ This menu aims to assess economy data, and the usage of the following commands a * Canada / U.S. Foreign Exchange Rate (CAD per 1 USD) +## events +```text +usage: events [-c {NZ,AU,ERL,CA,EU,US,JP,CN,GB,CH}] [-i {low,medium,high,all}] [-n NUM] +``` + +Output economy impact calendar impact events. [Source: https://finnhub.io] + +* -c : Country from where to get economy calendar impact events, between NZ,AU,ERL,CA,EU,US,JP,CN,GB,CH. Default: US. +* -i : Impact of the economy event, between low,medium,high,all. Default: all. +* -n : Number economy calendar impact events to display. Default: 10. + +Captura de ecrã 2021-05-02, às 19 51 47 + + ## fred ```text usage: fred [-i SERIES_ID] [-s START_DATE] [-t] diff --git a/gamestonk_terminal/econ/econ_controller.py b/gamestonk_terminal/econ/econ_controller.py index 2bdaf1e8727..1b47f16d6b1 100644 --- a/gamestonk_terminal/econ/econ_controller.py +++ b/gamestonk_terminal/econ/econ_controller.py @@ -9,6 +9,7 @@ from gamestonk_terminal import feature_flags as gtff from gamestonk_terminal.helper_funcs import get_flair from gamestonk_terminal.menu import session from gamestonk_terminal.econ import fred_view +from gamestonk_terminal.econ import finnhub_view class EconController: @@ -19,6 +20,7 @@ class EconController: "help", "q", "quit", + "events", "fred", "vixcls", "gdp", @@ -50,6 +52,7 @@ class EconController: print(" q quit this menu, and shows back to main menu") print(" quit quit to abandon program") print(" ") + print(" events economic impact events [Finnhub]") print( " fred display customized FRED data from https://fred.stlouisfed.org" ) @@ -95,6 +98,10 @@ class EconController: """Process Quit command - quit the program""" return True + def call_events(self, other_args: List[str]): + """Process events command""" + finnhub_view.economy_calendar_events(other_args) + def call_fred(self, other_args: List[str]): """Process fred command""" fred_view.display_fred(other_args, "") diff --git a/gamestonk_terminal/econ/finnhub_view.py b/gamestonk_terminal/econ/finnhub_view.py new file mode 100644 index 00000000000..2f4d45d6c32 --- /dev/null +++ b/gamestonk_terminal/econ/finnhub_view.py @@ -0,0 +1,131 @@ +import argparse +from typing import List +import requests +import pandas as pd +from gamestonk_terminal import config_terminal as cfg +from gamestonk_terminal.helper_funcs import ( + parse_known_args_and_warn, + check_positive, +) + + +def get_economy_calendar_events() -> pd.DataFrame: + """Get economic calendar events + + Returns + ------- + pd.DataFrame + Get dataframe with economic calendar events + """ + response = requests.get( + f"https://finnhub.io/api/v1/calendar/economic?token={cfg.API_FINNHUB_KEY}" + ) + if response.status_code == 200: + d_data = response.json() + if "economicCalendar" in d_data: + return pd.DataFrame(d_data["economicCalendar"]) + + return pd.DataFrame() + + +def economy_calendar_events(other_args: List[str]): + """Output economy calendar impact events + + Parameters + ---------- + other_args : List[str] + Command line arguments to be processed with argparse + """ + parser = argparse.ArgumentParser( + add_help=False, + prog="events", + description=""" + Output economy impact calendar impact events. [Source: https://finnhub.io] + """, + ) + parser.add_argument( + "-c", + "--country", + action="store", + dest="country", + type=str, + default="US", + choices=["NZ", "AU", "ERL", "CA", "EU", "US", "JP", "CN", "GB", "CH"], + help="Country from where to get economy calendar impact events", + ) + parser.add_argument( + "-n", + "--num", + action="store", + dest="num", + type=check_positive, + default=10, + help="Number economy calendar impact events to display", + ) + parser.add_argument( + "-i", + "--impact", + action="store", + dest="impact", + type=str, + default="all", + choices=["low", "medium", "high", "all"], + help="Impact of the economy event", + ) + + try: + if other_args: + if "-" not in other_args[0]: + other_args.insert(0, "-c") + + ns_parser = parse_known_args_and_warn(parser, other_args) + if not ns_parser: + return + + df_events = get_economy_calendar_events() + + if df_events.empty: + print("No latest economy calendar events found\n") + return + + df_econ_calendar = df_events[ + df_events["country"] == ns_parser.country + ].sort_values("time", ascending=False) + + if df_econ_calendar.empty: + print("No latet economy calendar events found in the specified country\n") + return + + if ns_parser.impact != "all": + df_econ_calendar = df_econ_calendar[ + df_econ_calendar["impact"] == ns_parser.impact + ] + + if df_econ_calendar.empty: + print( + "No latet economy calendar events found in the specified country with this impact\n" + ) + return + + df_econ_calendar = df_econ_calendar.fillna("---").head(n=ns_parser.num) + + d_econ_calendar_map = { + "actual": "Actual release", + "prev": "Previous release", + "country": "Country", + "unit": "Unit", + "estimate": "Estimate", + "event": "Event", + "impact": "Impact Level", + "time": "Release time", + } + + df_econ_calendar = df_econ_calendar[ + ["time", "event", "impact", "prev", "estimate", "actual", "unit"] + ].rename(columns=d_econ_calendar_map) + + print(df_econ_calendar.to_string(index=False)) + print("") + + except Exception as e: + print(e, "\n") diff --git a/gamestonk_terminal/main_helper.py b/gamestonk_terminal/main_helper.py index 824e14918b2..5723f7b3460 100644 --- a/gamestonk_terminal/main_helper.py +++ b/gamestonk_terminal/main_helper.py @@ -55,7 +55,7 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open): " > scr screener stocks, \t\t e.g. overview/performance, using preset filters" ) print(" > mill papermill menu, \t\t menu to generate notebook reports") - print(" > econ economic data, \t\t from: FRED, VIX") + print(" > econ economic data, \t\t e.g.: FRED, events") print( " > pa portfolio analysis, \t\t supports: robinhood, alpaca, ally " )