mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 22:11:55 +00:00
Add alpha vantage economy endpoints to Econ menu (#918)
* Add alpha vantage gdp * Add gdp per capita * Add av inflation * AV treasury yield * AV unemployment * Hugo doc * forgot to commit a hugo page Co-authored-by: James Maslek <james@macbook-pro.myfiosgateway.com>
This commit is contained in:
@@ -3,8 +3,10 @@ __docformat__ = "numpy"
|
||||
|
||||
import pandas as pd
|
||||
from alpha_vantage.sectorperformance import SectorPerformances
|
||||
import requests
|
||||
|
||||
from gamestonk_terminal import config_terminal as cfg
|
||||
from gamestonk_terminal.helper_funcs import get_user_agent
|
||||
|
||||
|
||||
def get_sector_data() -> pd.DataFrame:
|
||||
@@ -21,3 +23,147 @@ def get_sector_data() -> pd.DataFrame:
|
||||
# pylint: disable=unbalanced-tuple-unpacking
|
||||
df_sectors, _ = sector_perf.get_sector()
|
||||
return df_sectors
|
||||
|
||||
|
||||
def get_real_gdp(interval: str = "a") -> pd.DataFrame:
|
||||
"""Get annual or quarterly Real GDP for US
|
||||
|
||||
Parameters
|
||||
----------
|
||||
interval : str, optional
|
||||
Interval for GDP, by default "a" for annual
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Dataframe of GDP
|
||||
"""
|
||||
s_interval = "quarterly" if interval == "q" else "annual"
|
||||
url = f"https://www.alphavantage.co/query?function=REAL_GDP&interval={s_interval}&apikey={cfg.API_KEY_ALPHAVANTAGE}"
|
||||
r = requests.get(url, headers={"User-Agent": get_user_agent()})
|
||||
|
||||
if r.status_code != 200:
|
||||
return pd.DataFrame()
|
||||
|
||||
data = pd.DataFrame(r.json()["data"])
|
||||
data["date"] = pd.to_datetime(data["date"])
|
||||
data["GDP"] = data["value"].astype(float)
|
||||
data = data.drop(columns=["value"])
|
||||
return data
|
||||
|
||||
|
||||
def get_gdp_capita() -> pd.DataFrame:
|
||||
"""Real GDP per Capita for United States
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
DataFrame of GDP per Capita
|
||||
"""
|
||||
url = f"https://www.alphavantage.co/query?function=REAL_GDP_PER_CAPITA&apikey={cfg.API_KEY_ALPHAVANTAGE}"
|
||||
r = requests.get(url, headers={"User-Agent": get_user_agent()})
|
||||
if r.status_code != 200:
|
||||
return pd.DataFrame()
|
||||
data = pd.DataFrame(r.json()["data"])
|
||||
data["date"] = pd.to_datetime(data["date"])
|
||||
data["GDP"] = data["value"].astype(float)
|
||||
data = data.drop(columns=["value"])
|
||||
return data
|
||||
|
||||
|
||||
def get_inflation() -> pd.DataFrame:
|
||||
"""Get historical Inflation for United States from AlphaVantage
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
DataFrame of inflation rates
|
||||
"""
|
||||
url = f"https://www.alphavantage.co/query?function=INFLATION&apikey={cfg.API_KEY_ALPHAVANTAGE}"
|
||||
r = requests.get(url, headers={"User-Agent": get_user_agent()})
|
||||
if r.status_code != 200:
|
||||
return pd.DataFrame()
|
||||
data = pd.DataFrame(r.json()["data"])
|
||||
data["date"] = pd.to_datetime(data["date"])
|
||||
data["Inflation"] = data["value"].astype(float)
|
||||
data = data.drop(columns=["value"])
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def get_cpi(interval: str) -> pd.DataFrame:
|
||||
"""Get Consumer Price Index from Alpha Vantage
|
||||
|
||||
Parameters
|
||||
----------
|
||||
interval : str
|
||||
Interval for data. Either "m" or "s" for monthly or semiannual
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Dataframe of CPI
|
||||
"""
|
||||
s_interval = "semiannual" if interval == "s" else "monthly"
|
||||
url = f"https://www.alphavantage.co/query?function=CPI&interval={s_interval}&apikey={cfg.API_KEY_ALPHAVANTAGE}"
|
||||
r = requests.get(url, headers={"User-Agent": get_user_agent()})
|
||||
|
||||
if r.status_code != 200:
|
||||
return pd.DataFrame()
|
||||
|
||||
data = pd.DataFrame(r.json()["data"])
|
||||
data["date"] = pd.to_datetime(data["date"])
|
||||
data["CPI"] = data["value"].astype(float)
|
||||
data = data.drop(columns=["value"])
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def get_treasury_yield(interval: str, maturity: str) -> pd.DataFrame:
|
||||
"""Get historical yield for a given maturity
|
||||
|
||||
Parameters
|
||||
----------
|
||||
interval : str
|
||||
Interval for data. Can be "d","w","m" for daily, weekly or monthly
|
||||
maturity : str
|
||||
Maturity timeline. Can be "3mo","5y","10y" or "30y"
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Dataframe of historical yields
|
||||
"""
|
||||
d_interval = {"d": "daily", "w": "weekly", "m": "monthly"}
|
||||
d_maturity = {"3m": "3month", "5y": "5year", "10y": "10year", "30y": "30year"}
|
||||
|
||||
url = f"https://www.alphavantage.co/query?function=TREASURY_YIELD&interval={d_interval[interval]}&ma"
|
||||
url += f"turity={d_maturity[maturity]}&apikey={cfg.API_KEY_ALPHAVANTAGE}"
|
||||
r = requests.get(url, headers={"User-Agent": get_user_agent()})
|
||||
if r.status_code != 200:
|
||||
return pd.DataFrame()
|
||||
|
||||
data = pd.DataFrame(r.json()["data"])
|
||||
data["date"] = pd.to_datetime(data["date"])
|
||||
data["Yield"] = data["value"].astype(float)
|
||||
data = data.drop(columns=["value"])
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def get_unemployment() -> pd.DataFrame:
|
||||
"""Get historical unemployment for United States
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Dataframe of historical yields
|
||||
"""
|
||||
url = f"https://www.alphavantage.co/query?function=UNEMPLOYMENT&apikey={cfg.API_KEY_ALPHAVANTAGE}"
|
||||
r = requests.get(url, headers={"User-Agent": get_user_agent()})
|
||||
if r.status_code != 200:
|
||||
return pd.DataFrame()
|
||||
data = pd.DataFrame(r.json()["data"])
|
||||
data["date"] = pd.to_datetime(data["date"])
|
||||
data["unemp"] = data["value"].astype(float)
|
||||
data = data.drop(columns=["value"])
|
||||
return data
|
||||
|
||||
@@ -8,7 +8,8 @@ from tabulate import tabulate
|
||||
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.economy import alphavantage_model
|
||||
from gamestonk_terminal.helper_funcs import export_data
|
||||
from gamestonk_terminal.helper_funcs import export_data, plot_autoscale
|
||||
from gamestonk_terminal import config_plot as cfp
|
||||
|
||||
|
||||
def realtime_performance_sector(raw: bool, export: str):
|
||||
@@ -59,3 +60,316 @@ def realtime_performance_sector(raw: bool, export: str):
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
plt.show()
|
||||
|
||||
|
||||
def display_real_gdp(
|
||||
interval: str, start_year: int = 2010, raw: bool = False, export: str = ""
|
||||
):
|
||||
"""Display US GDP from AlphaVantage
|
||||
|
||||
Parameters
|
||||
----------
|
||||
interval : str
|
||||
Interval for GDP. Either "a" or "q"
|
||||
start_year : int, optional
|
||||
Start year for plot, by default 2010
|
||||
raw : bool, optional
|
||||
Flag to show raw data, by default False
|
||||
export : str, optional
|
||||
Format to export data, by default ""
|
||||
"""
|
||||
gdp_full = alphavantage_model.get_real_gdp(interval)
|
||||
if gdp_full.empty:
|
||||
print("Error getting data. Check API Key")
|
||||
return
|
||||
gdp = gdp_full[gdp_full.date >= f"{start_year}-01-01"]
|
||||
int_string = "Annual" if interval == "a" else "Quarterly"
|
||||
year_str = str(start_year) if interval == "a" else str(list(gdp.date)[-1].year)
|
||||
fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=cfp.PLOT_DPI)
|
||||
ax.plot(gdp.date, gdp.GDP, marker="o", c="dodgerblue")
|
||||
ax.set_xlabel("Date")
|
||||
ax.set_title(f"{int_string} US GDP ($B) from {year_str}")
|
||||
ax.set_ylabel("US GDP ($B) ")
|
||||
ax.grid("on")
|
||||
fig.tight_layout()
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
plt.show()
|
||||
|
||||
export_data(
|
||||
export,
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"gdp",
|
||||
gdp_full,
|
||||
)
|
||||
if raw:
|
||||
if gtff.USE_TABULATE_DF:
|
||||
print(
|
||||
tabulate(
|
||||
gdp.head(20),
|
||||
headers=["Date", "GDP"],
|
||||
tablefmt="fancy_grid",
|
||||
showindex=False,
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(gdp.head(20).to_string())
|
||||
print("")
|
||||
|
||||
|
||||
def display_gdp_capita(start_year: int = 2010, raw: bool = False, export: str = ""):
|
||||
"""Display US GDP per Capita from AlphaVantage
|
||||
|
||||
Parameters
|
||||
----------
|
||||
start_year : int, optional
|
||||
Start year for plot, by default 2010
|
||||
raw : bool, optional
|
||||
Flag to show raw data, by default False
|
||||
export : str, optional
|
||||
Format to export data, by default ""
|
||||
"""
|
||||
gdp_capita = alphavantage_model.get_gdp_capita()
|
||||
if gdp_capita.empty:
|
||||
print("Error getting data. Check API Key")
|
||||
return
|
||||
gdp = gdp_capita[gdp_capita.date >= f"{start_year}-01-01"]
|
||||
fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=cfp.PLOT_DPI)
|
||||
ax.plot(gdp.date, gdp.GDP, marker="o", c="dodgerblue")
|
||||
ax.set_xlabel("Date")
|
||||
ax.set_title(f"US GDP per Capita (Chained 2012 USD) from {start_year}")
|
||||
ax.set_ylabel("US GDP (Chained 2012 USD) ")
|
||||
ax.grid("on")
|
||||
fig.tight_layout()
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
plt.show()
|
||||
|
||||
export_data(
|
||||
export,
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"gdpc",
|
||||
gdp_capita,
|
||||
)
|
||||
if raw:
|
||||
if gtff.USE_TABULATE_DF:
|
||||
print(
|
||||
tabulate(
|
||||
gdp.head(20),
|
||||
headers=["Date", "GDP"],
|
||||
tablefmt="fancy_grid",
|
||||
showindex=False,
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(gdp.head(20).to_string())
|
||||
print("")
|
||||
|
||||
|
||||
def display_inflation(start_year: int = 2010, raw: bool = False, export: str = ""):
|
||||
"""Display US Inflation from AlphaVantage
|
||||
|
||||
Parameters
|
||||
----------
|
||||
start_year : int, optional
|
||||
Start year for plot, by default 2010
|
||||
raw : bool, optional
|
||||
Flag to show raw data, by default False
|
||||
export : str, optional
|
||||
Format to export data, by default ""
|
||||
"""
|
||||
inflation = alphavantage_model.get_inflation()
|
||||
if inflation.empty:
|
||||
print("Error getting data. Check API Key")
|
||||
return
|
||||
inf = inflation[inflation.date >= f"{start_year}-01-01"]
|
||||
fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=cfp.PLOT_DPI)
|
||||
ax.plot(inf.date, inf.Inflation, marker="o", c="dodgerblue")
|
||||
ax.set_xlabel("Date")
|
||||
ax.set_title(f"US Inflation from {list(inf.date)[-1].year}")
|
||||
ax.set_ylabel("Inflation (%)")
|
||||
ax.grid("on")
|
||||
fig.tight_layout()
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
plt.show()
|
||||
|
||||
export_data(
|
||||
export,
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"inf",
|
||||
inflation,
|
||||
)
|
||||
if raw:
|
||||
if gtff.USE_TABULATE_DF:
|
||||
print(
|
||||
tabulate(
|
||||
inf.head(20),
|
||||
headers=["Date", "Inflation"],
|
||||
tablefmt="fancy_grid",
|
||||
showindex=False,
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(inf.head(20).to_string())
|
||||
print("")
|
||||
|
||||
|
||||
def display_cpi(
|
||||
interval: str, start_year: int = 2010, raw: bool = False, export: str = ""
|
||||
):
|
||||
"""Display US consumer price index (CPI) from AlphaVantage
|
||||
|
||||
Parameters
|
||||
----------
|
||||
interval : str
|
||||
Interval for GDP. Either "m" or "s"
|
||||
start_year : int, optional
|
||||
Start year for plot, by default 2010
|
||||
raw : bool, optional
|
||||
Flag to show raw data, by default False
|
||||
export : str, optional
|
||||
Format to export data, by default ""
|
||||
"""
|
||||
cpi_full = alphavantage_model.get_cpi(interval)
|
||||
if cpi_full.empty:
|
||||
print("Error getting data. Check API Key")
|
||||
return
|
||||
cpi = cpi_full[cpi_full.date >= f"{start_year}-01-01"]
|
||||
int_string = "Semi-Annual" if interval == "s" else "Monthly"
|
||||
year_str = str(list(cpi.date)[-1].year)
|
||||
fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=cfp.PLOT_DPI)
|
||||
ax.plot(cpi.date, cpi.CPI, marker="o", c="dodgerblue")
|
||||
ax.set_xlabel("Date")
|
||||
ax.set_title(f"{int_string} CPI from {year_str}")
|
||||
ax.set_ylabel("CPI ")
|
||||
ax.grid("on")
|
||||
fig.tight_layout()
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
plt.show()
|
||||
|
||||
export_data(
|
||||
export,
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"cpi",
|
||||
cpi_full,
|
||||
)
|
||||
if raw:
|
||||
if gtff.USE_TABULATE_DF:
|
||||
print(
|
||||
tabulate(
|
||||
cpi.head(20),
|
||||
headers=["Date", "CPI"],
|
||||
tablefmt="fancy_grid",
|
||||
showindex=False,
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(cpi.head(20).to_string())
|
||||
print("")
|
||||
|
||||
|
||||
def display_treasury_yield(
|
||||
interval: str, maturity: str, start_date: str, raw: bool = False, export: str = ""
|
||||
):
|
||||
"""Display historical treasury yield for given maturity
|
||||
|
||||
Parameters
|
||||
----------
|
||||
interval : str
|
||||
Interval for data. Can be "d","w","m" for daily, weekly or monthly
|
||||
maturity : str
|
||||
Maturity timeline. Can be "3mo","5y","10y" or "30y"
|
||||
start_date: str
|
||||
Start date for data. Should be in YYYY-MM-DD format
|
||||
raw : bool, optional
|
||||
Flag to display raw data, by default False
|
||||
export : str, optional
|
||||
Format to export data, by default ""
|
||||
"""
|
||||
d_maturity = {"3m": "3month", "5y": "5year", "10y": "10year", "30y": "30year"}
|
||||
yields = alphavantage_model.get_treasury_yield(interval, maturity)
|
||||
if yields.empty:
|
||||
print("Error getting data. Check API Key")
|
||||
return
|
||||
yld = yields[yields.date >= start_date]
|
||||
fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=cfp.PLOT_DPI)
|
||||
ax.plot(yld.date, yld.Yield, marker="o", c="dodgerblue")
|
||||
ax.set_xlabel("Date")
|
||||
ax.set_title(f"{d_maturity[maturity]} Treasury Yield")
|
||||
ax.set_ylabel("Yield")
|
||||
ax.grid("on")
|
||||
fig.tight_layout()
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
plt.show()
|
||||
|
||||
export_data(
|
||||
export,
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"tyld",
|
||||
yields,
|
||||
)
|
||||
if raw:
|
||||
if gtff.USE_TABULATE_DF:
|
||||
print(
|
||||
tabulate(
|
||||
yld.head(20),
|
||||
headers=["Date", "Yield"],
|
||||
tablefmt="fancy_grid",
|
||||
showindex=False,
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(yld.head(20).to_string())
|
||||
print("")
|
||||
|
||||
|
||||
def display_unemployment(start_year: int = 2015, raw: bool = False, export: str = ""):
|
||||
"""Display US unemployment AlphaVantage
|
||||
|
||||
Parameters
|
||||
----------
|
||||
start_year : int, optional
|
||||
Start year for plot, by default 2010
|
||||
raw : bool, optional
|
||||
Flag to show raw data, by default False
|
||||
export : str, optional
|
||||
Format to export data, by default ""
|
||||
"""
|
||||
unemp = alphavantage_model.get_unemployment()
|
||||
if unemp.empty:
|
||||
print("Error getting data. Check API Key")
|
||||
return
|
||||
un = unemp[unemp.date >= f"{start_year}-01-01"]
|
||||
fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=cfp.PLOT_DPI)
|
||||
ax.plot(un.date, un.unemp, marker="o", c="dodgerblue")
|
||||
ax.set_xlabel("Date")
|
||||
ax.set_title(f"US Unemployment from {start_year}")
|
||||
ax.set_ylabel("US Unemployment ")
|
||||
ax.grid("on")
|
||||
fig.tight_layout()
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
plt.show()
|
||||
|
||||
export_data(
|
||||
export,
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"unemp",
|
||||
unemp,
|
||||
)
|
||||
if raw:
|
||||
if gtff.USE_TABULATE_DF:
|
||||
print(
|
||||
tabulate(
|
||||
un.head(20),
|
||||
headers=["Date", "GDP"],
|
||||
tablefmt="fancy_grid",
|
||||
showindex=False,
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(un.head(20).to_string())
|
||||
print("")
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
""" Econ Controller """
|
||||
__docformat__ = "numpy"
|
||||
|
||||
# pylint:disable=too-many-lines
|
||||
import argparse
|
||||
from datetime import datetime, timedelta
|
||||
import os
|
||||
from typing import List
|
||||
|
||||
@@ -17,6 +18,7 @@ from gamestonk_terminal.economy import (
|
||||
wsj_view,
|
||||
)
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
EXPORT_BOTH_RAW_DATA_AND_FIGURES,
|
||||
check_positive,
|
||||
get_flair,
|
||||
parse_known_args_and_warn,
|
||||
@@ -29,7 +31,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
)
|
||||
from gamestonk_terminal.menu import session
|
||||
|
||||
# pylint: disable=R1710
|
||||
# pylint: disable=R1710,R0904
|
||||
|
||||
|
||||
class EconomyController:
|
||||
@@ -84,6 +86,12 @@ class EconomyController:
|
||||
"spectrum",
|
||||
"map",
|
||||
"rtps",
|
||||
"gdp",
|
||||
"gdpc",
|
||||
"inf",
|
||||
"cpi",
|
||||
"tyld",
|
||||
"unemp",
|
||||
"industry",
|
||||
]
|
||||
|
||||
@@ -131,6 +139,12 @@ Finviz:
|
||||
spectrum spectrum of sectors, industry, country
|
||||
Alpha Vantage:
|
||||
rtps real-time performance sectors
|
||||
gdp real GDP for United States
|
||||
gdpc quarterly real GDP per Capita data of the United States
|
||||
inf infation rates for United States
|
||||
cpi consumer price index for United States
|
||||
tyld treasury yields for United States
|
||||
unemp United States unemployment rates
|
||||
FRED:
|
||||
search search FRED series notes
|
||||
series plot series from https://fred.stlouisfed.org
|
||||
@@ -782,6 +796,284 @@ FRED:
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_gdp(self, other_args: List[str]):
|
||||
"""Process gdp command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="gdp",
|
||||
description="""
|
||||
Get real GDP for US on either annual or quarterly interval [Source: Alpha Vantage]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--interval",
|
||||
help="Interval for GDP data",
|
||||
dest="interval",
|
||||
choices=["a", "q"],
|
||||
default="a",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--start",
|
||||
help="Start year. Quarterly only goes back to 2002.",
|
||||
dest="start",
|
||||
type=int,
|
||||
default=2010,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--raw",
|
||||
help="Display raw data",
|
||||
action="store_true",
|
||||
dest="raw",
|
||||
default=False,
|
||||
)
|
||||
if other_args and "-" not in other_args[0]:
|
||||
other_args.insert(0, "-i")
|
||||
|
||||
ns_parser = parse_known_args_and_warn(
|
||||
parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES
|
||||
)
|
||||
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
alphavantage_view.display_real_gdp(
|
||||
interval=ns_parser.interval,
|
||||
start_year=ns_parser.start,
|
||||
raw=ns_parser.raw,
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_gdpc(self, other_args: List[str]):
|
||||
"""Process gdpc command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="gdpc",
|
||||
description="""
|
||||
Get real GDP per capita for United States[Source: Alpha Vantage]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--start",
|
||||
help="Start year.",
|
||||
dest="start",
|
||||
type=int,
|
||||
default=2010,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--raw",
|
||||
help="Display raw data",
|
||||
action="store_true",
|
||||
dest="raw",
|
||||
default=False,
|
||||
)
|
||||
|
||||
ns_parser = parse_known_args_and_warn(
|
||||
parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES
|
||||
)
|
||||
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
alphavantage_view.display_gdp_capita(
|
||||
start_year=ns_parser.start,
|
||||
raw=ns_parser.raw,
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_inf(self, other_args: List[str]):
|
||||
"""Process inf command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="inf",
|
||||
description="""
|
||||
Get historical Inflation for United States[Source: Alpha Vantage]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--start",
|
||||
help="Start year.",
|
||||
dest="start",
|
||||
type=int,
|
||||
default=2010,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--raw",
|
||||
help="Display raw data",
|
||||
action="store_true",
|
||||
dest="raw",
|
||||
default=False,
|
||||
)
|
||||
|
||||
ns_parser = parse_known_args_and_warn(
|
||||
parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES
|
||||
)
|
||||
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
alphavantage_view.display_inflation(
|
||||
start_year=ns_parser.start,
|
||||
raw=ns_parser.raw,
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_cpi(self, other_args: List[str]):
|
||||
"""Process cpi command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="inf",
|
||||
description="""
|
||||
Get historical CPI for United States [Source: Alpha Vantage]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--interval",
|
||||
help="Interval for GDP data",
|
||||
dest="interval",
|
||||
choices=["s", "m"],
|
||||
default="s",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--start",
|
||||
help="Start year.",
|
||||
dest="start",
|
||||
type=int,
|
||||
default=2010,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--raw",
|
||||
help="Display raw data",
|
||||
action="store_true",
|
||||
dest="raw",
|
||||
default=False,
|
||||
)
|
||||
|
||||
ns_parser = parse_known_args_and_warn(
|
||||
parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES
|
||||
)
|
||||
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
alphavantage_view.display_cpi(
|
||||
interval=ns_parser.interval,
|
||||
start_year=ns_parser.start,
|
||||
raw=ns_parser.raw,
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_tyld(self, other_args: List[str]):
|
||||
"""Process tyld command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="tyld",
|
||||
description="""
|
||||
Get historical Treasury Yield [Source: Alpha Vantage]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--interval",
|
||||
help="Interval for treasury data",
|
||||
dest="interval",
|
||||
choices=["d", "w", "m"],
|
||||
default="w",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-m",
|
||||
"--maturity",
|
||||
help="Maturity timeline for treasury",
|
||||
dest="maturity",
|
||||
choices=["3m", "5y", "10y", "30y"],
|
||||
default="5y",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--start",
|
||||
help="Start date.",
|
||||
dest="start",
|
||||
type=valid_date,
|
||||
default=datetime.now() - timedelta(days=366),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--raw",
|
||||
help="Display raw data",
|
||||
action="store_true",
|
||||
dest="raw",
|
||||
default=False,
|
||||
)
|
||||
|
||||
ns_parser = parse_known_args_and_warn(
|
||||
parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES
|
||||
)
|
||||
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
alphavantage_view.display_treasury_yield(
|
||||
interval=ns_parser.interval,
|
||||
maturity=ns_parser.maturity,
|
||||
start_date=ns_parser.start,
|
||||
raw=ns_parser.raw,
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_unemp(self, other_args: List[str]):
|
||||
"""Process unemp command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="unemp",
|
||||
description="""
|
||||
Get United States Unemployment data [Source: Alpha Vantage]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--start",
|
||||
help="Start year.",
|
||||
dest="start",
|
||||
type=int,
|
||||
default=2015,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--raw",
|
||||
help="Display raw data",
|
||||
action="store_true",
|
||||
dest="raw",
|
||||
default=False,
|
||||
)
|
||||
|
||||
ns_parser = parse_known_args_and_warn(
|
||||
parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES
|
||||
)
|
||||
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
alphavantage_view.display_unemployment(
|
||||
start_year=ns_parser.start,
|
||||
raw=ns_parser.raw,
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
@try_except
|
||||
def call_series(self, other_args: List[str]):
|
||||
"""Process series command"""
|
||||
|
||||
17
website/content/economy/cpi/_index.md
vendored
Normal file
17
website/content/economy/cpi/_index.md
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
```
|
||||
usage: inf [-i {s,m}] [-s START] [--raw] [-h] [--export {png,jpg,pdf,svg}]
|
||||
```
|
||||
|
||||
Get historical CPI for United States [Source: Alpha Vantage]
|
||||
|
||||
```
|
||||
optional arguments:
|
||||
-i {s,m}, --interval {s,m}
|
||||
Interval for GDP data (default: s)
|
||||
-s START, --start START
|
||||
Start year. (default: 2010)
|
||||
--raw Display raw data (default: False)
|
||||
-h, --help show this help message (default: False)
|
||||
--export {png,jpg,pdf,svg}
|
||||
Export or figure into png, jpg, pdf, svg (default: )
|
||||
```
|
||||
17
website/content/economy/gdp/_index.md
vendored
Normal file
17
website/content/economy/gdp/_index.md
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
```
|
||||
usage: gdp [-i {a,q}] [-s START] [--raw] [-h] [--export {png,jpg,pdf,svg}]
|
||||
```
|
||||
|
||||
Get real GDP for US on either annual or quarterly interval [Source: Alpha Vantage]
|
||||
|
||||
```
|
||||
optional arguments:
|
||||
-i {a,q}, --interval {a,q}
|
||||
Interval for GDP data (default: a)
|
||||
-s START, --start START
|
||||
Start year. Quarterly only goes back to 2002. (default: 2010)
|
||||
--raw Display raw data (default: False)
|
||||
-h, --help show this help message (default: False)
|
||||
--export {png,jpg,pdf,svg}
|
||||
Export or figure into png, jpg, pdf, svg (default: )
|
||||
```
|
||||
15
website/content/economy/gdpc/_index.md
vendored
Normal file
15
website/content/economy/gdpc/_index.md
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
```
|
||||
usage: gdpc [-s START] [--raw] [-h] [--export {png,jpg,pdf,svg}]
|
||||
```
|
||||
|
||||
Get real GDP per capita for United States [Source: Alpha Vantage]
|
||||
|
||||
```
|
||||
optional arguments:
|
||||
-s START, --start START
|
||||
Start year. (default: 2010)
|
||||
--raw Display raw data (default: False)
|
||||
-h, --help show this help message (default: False)
|
||||
--export {png,jpg,pdf,svg}
|
||||
Export or figure into png, jpg, pdf, svg (default: )
|
||||
```
|
||||
15
website/content/economy/inf/_index.md
vendored
Normal file
15
website/content/economy/inf/_index.md
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
```
|
||||
usage: inf [-s START] [--raw] [-h] [--export {png,jpg,pdf,svg}]
|
||||
```
|
||||
|
||||
Get historical Inflation for United States[Source: Alpha Vantage]
|
||||
|
||||
```
|
||||
optional arguments:
|
||||
-s START, --start START
|
||||
Start year. (default: 2010)
|
||||
--raw Display raw data (default: False)
|
||||
-h, --help show this help message (default: False)
|
||||
--export {png,jpg,pdf,svg}
|
||||
Export or figure into png, jpg, pdf, svg (default: )
|
||||
```
|
||||
17
website/content/economy/tyld/_index.md
vendored
Normal file
17
website/content/economy/tyld/_index.md
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
```
|
||||
usage: tyld [-i {d,w,m}] [-m {3m,5y,10y,30y}] [-s START] [--raw] [-h] [--export {png,jpg,pdf,svg}]
|
||||
|
||||
Get historical Treasury Yield [Source: Alpha Vantage]
|
||||
|
||||
optional arguments:
|
||||
-i {d,w,m}, --interval {d,w,m}
|
||||
Interval for treasury data (default: w)
|
||||
-m {3m,5y,10y,30y}, --maturity {3m,5y,10y,30y}
|
||||
Maturity timeline for treasury (default: 5y)
|
||||
-s START, --start START
|
||||
Start date. (default: 2020-11-04 14:03:29.757932)
|
||||
--raw Display raw data (default: False)
|
||||
-h, --help show this help message (default: False)
|
||||
--export {png,jpg,pdf,svg}
|
||||
Export or figure into png, jpg, pdf, svg (default: )
|
||||
```
|
||||
15
website/content/economy/unemp/_index.md
vendored
Normal file
15
website/content/economy/unemp/_index.md
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
```
|
||||
usage: unemp [-s START] [--raw] [-h] [--export {png,jpg,pdf,svg}]
|
||||
```
|
||||
|
||||
Get United States Unemployment data [Source: Alpha Vantage]
|
||||
|
||||
```
|
||||
optional arguments:
|
||||
-s START, --start START
|
||||
Start year. (default: 2015)
|
||||
--raw Display raw data (default: False)
|
||||
-h, --help show this help message (default: False)
|
||||
--export {png,jpg,pdf,svg}
|
||||
Export or figure into png, jpg, pdf, svg (default: )
|
||||
```
|
||||
12
website/data/menu/main.yml
vendored
12
website/data/menu/main.yml
vendored
@@ -799,6 +799,18 @@ main:
|
||||
ref: "/economy/spectrum"
|
||||
- name: rtps
|
||||
ref: "/economy/rtps"
|
||||
- name: gdp
|
||||
ref: "/economy/gdp"
|
||||
- name: gdpc
|
||||
ref: "/economy/gdpc"
|
||||
- name: inf
|
||||
ref: "/economy/inf"
|
||||
- name: cpi
|
||||
ref: "/economy/cpi"
|
||||
- name: tyld
|
||||
ref: "/economy/tyld"
|
||||
- name: unemp
|
||||
ref: "/economy/unemp"
|
||||
- name: search
|
||||
ref: "/economy/search"
|
||||
- name: series
|
||||
|
||||
Reference in New Issue
Block a user