mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-08 18:32:21 +00:00
Plotting changes, flag updates.
This commit is contained in:
@@ -9,12 +9,13 @@ The purpose of fred is to have the ability to look at economic data.
|
||||
|
||||
## gdp <a name="gdp"></a>
|
||||
```text
|
||||
usage: gdp [-n N_TO_GET] [-s START_DATE] [-p PLOT]]
|
||||
usage: gdp [-n N_TO_GET] [-s START_DATE] [--noplot] [--hidedata]
|
||||
```
|
||||
Gets GDP data. Data is released quarterly
|
||||
* -n : Number of points to display. If unspecified, it will display all available.
|
||||
* -s : Start Date. Format YYYY-mm-dd. First point to get. Defaults to Jan 1 2015
|
||||
* -p : Option to plot. Defaults to False
|
||||
* --noplot : Flag to hide plot
|
||||
* --hidedata : Flag to suppress printing output
|
||||
|
||||
To get and plot the last 20 reported GDP values:
|
||||
````
|
||||
@@ -22,34 +23,32 @@ gdp -n 20
|
||||
````
|
||||
To show all GDP data since 1/1/2016, with no plot.
|
||||
````
|
||||
gdp -s 2016-01-01 -p False
|
||||
gdp -s 2016-01-01 --noplot
|
||||
````
|
||||
Outputs:
|
||||
````
|
||||
Date: 01-01-2015, GDP: 18003.399
|
||||
Date: 04-01-2015, GDP: 18223.577
|
||||
Date: 07-01-2015, GDP: 18347.425
|
||||
Date: 10-01-2015, GDP: 18378.803
|
||||
Date: 01-01-2016, GDP: 18470.156
|
||||
Date: 04-01-2016, GDP: 18656.207
|
||||
Date: 07-01-2016, GDP: 18821.359
|
||||
Date: 10-01-2016, GDP: 19032.58
|
||||
Date: 01-01-2017, GDP: 19237.435
|
||||
Date: 04-01-2017, GDP: 19379.232
|
||||
Date: 07-01-2017, GDP: 19617.288
|
||||
Date: 10-01-2017, GDP: 19937.963
|
||||
Date: 01-01-2018, GDP: 20242.215
|
||||
Date: 04-01-2018, GDP: 20552.653
|
||||
Date: 07-01-2018, GDP: 20742.723
|
||||
Date: 10-01-2018, GDP: 20909.853
|
||||
Date: 01-01-2019, GDP: 21115.309
|
||||
Date: 04-01-2019, GDP: 21329.877
|
||||
Date: 07-01-2019, GDP: 21540.325
|
||||
Date: 10-01-2019, GDP: 21747.394
|
||||
Date: 01-01-2020, GDP: 21561.139
|
||||
Date: 04-01-2020, GDP: 19520.114
|
||||
Date: 07-01-2020, GDP: 21170.252
|
||||
Date: 10-01-2020, GDP: 21487.896
|
||||
|
||||
GDP
|
||||
Date
|
||||
2016-01-01 18470.156
|
||||
2016-04-01 18656.207
|
||||
2016-07-01 18821.359
|
||||
2016-10-01 19032.580
|
||||
2017-01-01 19237.435
|
||||
2017-04-01 19379.232
|
||||
2017-07-01 19617.288
|
||||
2017-10-01 19937.963
|
||||
2018-01-01 20242.215
|
||||
2018-04-01 20552.653
|
||||
2018-07-01 20742.723
|
||||
2018-10-01 20909.853
|
||||
2019-01-01 21115.309
|
||||
2019-04-01 21329.877
|
||||
2019-07-01 21540.325
|
||||
2019-10-01 21747.394
|
||||
2020-01-01 21561.139
|
||||
2020-04-01 19520.114
|
||||
2020-07-01 21170.252
|
||||
2020-10-01 21487.896
|
||||
````
|
||||
|
||||
|
||||
@@ -58,46 +57,48 @@ Date: 10-01-2020, GDP: 21487.896
|
||||
The fred database has many different datasets freely available. They each have their own custom SERIES_ID which can be obtained through the website.
|
||||
|
||||
````
|
||||
usage: cust [-id] [-s START_DATE] [-p PLOT] [-disp DISP]
|
||||
usage: cust [-i --id] [-s START_DATE] [--noplot] [--hidedata]
|
||||
````
|
||||
* -id : Series ID for FRED data. Required argument
|
||||
* -i/--id : Series ID for FRED data. Required argument
|
||||
* -s : Start Date. Format YYYY-mm-dd. First point to get. Defaults to Jan 1 2015.
|
||||
* -p : Option to plot. Defaults to True
|
||||
* -disp : Option to print data to console. Defaults to False.
|
||||
* --noplot : Flag to suppress output plot.
|
||||
* --hidedata : Flag to suppress data output
|
||||
|
||||
An example of custom data could be the unemployment rate. According to https://fred.stlouisfed.org/series/UNRATE , the series ID is UNRATE. So to plot this for 2019 to now
|
||||
|
||||
````
|
||||
cust -id UNRATE -s 2019-01-01 -disp True
|
||||
cust --id UNRATE -s 2019-01-01
|
||||
````
|
||||
This will plot and display:
|
||||
|
||||
|
||||
````
|
||||
Date: 01-01-2019, DATA: 4.0
|
||||
Date: 02-01-2019, DATA: 3.8
|
||||
Date: 03-01-2019, DATA: 3.8
|
||||
Date: 04-01-2019, DATA: 3.7
|
||||
Date: 05-01-2019, DATA: 3.7
|
||||
Date: 06-01-2019, DATA: 3.6
|
||||
Date: 07-01-2019, DATA: 3.6
|
||||
Date: 08-01-2019, DATA: 3.7
|
||||
Date: 09-01-2019, DATA: 3.5
|
||||
Date: 10-01-2019, DATA: 3.6
|
||||
Date: 11-01-2019, DATA: 3.6
|
||||
Date: 12-01-2019, DATA: 3.6
|
||||
Date: 01-01-2020, DATA: 3.5
|
||||
Date: 02-01-2020, DATA: 3.5
|
||||
Date: 03-01-2020, DATA: 4.4
|
||||
Date: 04-01-2020, DATA: 14.8
|
||||
Date: 05-01-2020, DATA: 13.3
|
||||
Date: 06-01-2020, DATA: 11.1
|
||||
Date: 07-01-2020, DATA: 10.2
|
||||
Date: 08-01-2020, DATA: 8.4
|
||||
Date: 09-01-2020, DATA: 7.8
|
||||
Date: 10-01-2020, DATA: 6.9
|
||||
Date: 11-01-2020, DATA: 6.7
|
||||
Date: 12-01-2020, DATA: 6.7
|
||||
Date: 01-01-2021, DATA: 6.3
|
||||
Date: 02-01-2021, DATA: 6.2
|
||||
UNRATE
|
||||
Date
|
||||
2019-01-01 4.0
|
||||
2019-02-01 3.8
|
||||
2019-03-01 3.8
|
||||
2019-04-01 3.7
|
||||
2019-05-01 3.7
|
||||
2019-06-01 3.6
|
||||
2019-07-01 3.6
|
||||
2019-08-01 3.7
|
||||
2019-09-01 3.5
|
||||
2019-10-01 3.6
|
||||
2019-11-01 3.6
|
||||
2019-12-01 3.6
|
||||
2020-01-01 3.5
|
||||
2020-02-01 3.5
|
||||
2020-03-01 4.4
|
||||
2020-04-01 14.8
|
||||
2020-05-01 13.3
|
||||
2020-06-01 11.1
|
||||
2020-07-01 10.2
|
||||
2020-08-01 8.4
|
||||
2020-09-01 7.8
|
||||
2020-10-01 6.9
|
||||
2020-11-01 6.7
|
||||
2020-12-01 6.7
|
||||
2021-01-01 6.3
|
||||
2021-02-01 6.2
|
||||
````
|
||||
@@ -1,12 +1,18 @@
|
||||
from fredapi import Fred
|
||||
import argparse
|
||||
import pandas as pd
|
||||
from pandas.plotting import register_matplotlib_converters
|
||||
import matplotlib.pyplot as plt
|
||||
from fredapi import Fred
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
parse_known_args_and_warn,
|
||||
valid_date,
|
||||
str_to_bool,
|
||||
plot_autoscale,
|
||||
)
|
||||
from gamestonk_terminal.config_plot import PLOT_DPI
|
||||
from gamestonk_terminal.config_terminal import API_FRED_KEY
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
|
||||
register_matplotlib_converters()
|
||||
|
||||
|
||||
def get_GDP(l_args):
|
||||
@@ -37,12 +43,19 @@ def get_GDP(l_args):
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
dest="plot",
|
||||
type=str_to_bool,
|
||||
"--noplot",
|
||||
action="store_false",
|
||||
default=True,
|
||||
required=False,
|
||||
help="Plot GDP",
|
||||
dest="noplot",
|
||||
help="Suppress output plot",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--hidedata",
|
||||
action="store_false",
|
||||
default=True,
|
||||
dest="hidedata",
|
||||
help="Suppress data display plot",
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -52,22 +65,30 @@ def get_GDP(l_args):
|
||||
return
|
||||
|
||||
gdp = fred.get_series("GDP", ns_parser.start_date)
|
||||
|
||||
gdp = pd.DataFrame(gdp, columns=["GDP"])
|
||||
gdp.index.name = "Date"
|
||||
if int(ns_parser.n_to_get) > 0:
|
||||
lastn = gdp.tail(int(ns_parser.n_to_get))
|
||||
|
||||
else:
|
||||
lastn = gdp
|
||||
|
||||
for date, val in lastn.iteritems():
|
||||
print(f'Date: {date.strftime("%m-%d-%Y")}, GDP: {val} ')
|
||||
if ns_parser.hidedata:
|
||||
print(lastn)
|
||||
print("")
|
||||
|
||||
if ns_parser.plot:
|
||||
plt.figure()
|
||||
lastn.plot(style="-ok")
|
||||
if ns_parser.noplot:
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
plt.plot(lastn.index, lastn.GDP, "-ok")
|
||||
plt.xlabel("Time")
|
||||
plt.ylabel("GDP")
|
||||
plt.xlim(lastn.index[0], lastn.index[-1])
|
||||
plt.ylabel("GDP (bn $)")
|
||||
plt.title("FRED GDP Data (in Billions of USD)")
|
||||
plt.grid(b=True, which="major", color="#666666", linestyle="-")
|
||||
plt.minorticks_on()
|
||||
plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2)
|
||||
plt.show()
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
@@ -86,7 +107,7 @@ def custom_data(l_args):
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-id", dest="series_id", required=True, type=str, help="FRED Series ID"
|
||||
"-i", "--id", dest="series_id", required=True, type=str, help="FRED Series ID"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
@@ -95,23 +116,23 @@ def custom_data(l_args):
|
||||
type=valid_date,
|
||||
default="2015-01-01",
|
||||
required=False,
|
||||
help="Date to Start",
|
||||
help="Starting date (YYYY-MM-DD) of data",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
dest="plot",
|
||||
type=str_to_bool,
|
||||
"--noplot",
|
||||
action="store_false",
|
||||
default=True,
|
||||
required=False,
|
||||
help="Plot data",
|
||||
dest="noplot",
|
||||
help="Suppress output plot",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-disp",
|
||||
dest="disp",
|
||||
type=str_to_bool,
|
||||
default=False,
|
||||
required=False,
|
||||
help="Print data",
|
||||
"--hidedata",
|
||||
action="store_false",
|
||||
default=True,
|
||||
dest="hidedata",
|
||||
help="Suppress data display plot",
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -121,20 +142,28 @@ def custom_data(l_args):
|
||||
return
|
||||
|
||||
data = fred.get_series(ns_parser.series_id, ns_parser.start_date)
|
||||
if ns_parser.disp:
|
||||
for date, val in data.iteritems():
|
||||
print(f'Date: {date.strftime("%m-%d-%Y")}, DATA: {val} ')
|
||||
try:
|
||||
if ns_parser.plot:
|
||||
plt.figure()
|
||||
data.plot(style="-ok")
|
||||
plt.xlabel("Time")
|
||||
plt.ylabel("DATA")
|
||||
plt.show()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
data = pd.DataFrame(data, columns=[f"{ns_parser.series_id}"])
|
||||
data.index.name = "Date"
|
||||
if ns_parser.hidedata:
|
||||
print(data)
|
||||
print("")
|
||||
return
|
||||
if ns_parser.noplot:
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
plt.plot(data.index, data.iloc[:, 0], "-ok")
|
||||
plt.xlabel("Time")
|
||||
plt.xlim(data.index[0], data.index[-1])
|
||||
plt.ylabel(f"{ns_parser.series_id}")
|
||||
plt.grid(b=True, which="major", color="#666666", linestyle="-")
|
||||
plt.minorticks_on()
|
||||
plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2)
|
||||
plt.title(f"FRED {ns_parser.series_id} Series")
|
||||
plt.show()
|
||||
print("")
|
||||
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
|
||||
except SystemExit:
|
||||
print("")
|
||||
except Exception as e:
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import argparse
|
||||
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.helper_funcs import get_flair
|
||||
from gamestonk_terminal.menu import session
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
from gamestonk_terminal.fred import fred_api
|
||||
|
||||
|
||||
@@ -17,6 +16,7 @@ def print_fred():
|
||||
print(" ")
|
||||
print(" gdp get GDP")
|
||||
print(" cust User Specified FRED Data")
|
||||
print("")
|
||||
return
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user