mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
Added function to allow for custom fred data.
This commit is contained in:
@@ -4,7 +4,9 @@ The purpose of fred is to have the ability to look at economic data.
|
||||
|
||||
* [GDP](#GDP)
|
||||
* Get GDP data
|
||||
|
||||
* [cust](#cust)
|
||||
* Get custom fred data
|
||||
|
||||
## GDP <a name="GDP"></a>
|
||||
```text
|
||||
usage: GDP [-n N_TO_GET] [-s START_DATE] [-p PLOT]]
|
||||
@@ -21,4 +23,24 @@ GDP -n 20
|
||||
To plot all GDP data since 1/1/2010:
|
||||
````
|
||||
GDP -s 1/1/2010 -p True
|
||||
````
|
||||
````
|
||||
|
||||
|
||||
## cust <a name="cust"></a>
|
||||
|
||||
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]
|
||||
````
|
||||
* -id : Series ID for FRED data. Required argument
|
||||
* -s : Start data to acquire data. Defaults to 1/1/2020
|
||||
* -p : Option to plot. Defaults to False
|
||||
* -disp : Option to print data to console. Defaults to True.
|
||||
|
||||
The GDP is specifically defined in this menu, but to reproduce it with the custom function, it would be
|
||||
````
|
||||
cust -id GDP -s 1/1/2020 -p True -disp False
|
||||
````
|
||||
|
||||
The plot flag allows for plotting and the disp flag tells whether or not to print data to the console.
|
||||
@@ -63,4 +63,67 @@ def get_GDP(l_args):
|
||||
print("")
|
||||
return
|
||||
|
||||
def custom_data(l_args):
|
||||
fred = Fred(api_key=FRED_API_KEY)
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="Custom",
|
||||
description="""
|
||||
Custom Data
|
||||
""",
|
||||
)
|
||||
parser.add_argument('-id',
|
||||
dest = 'series_id',
|
||||
required = True,
|
||||
type=str,
|
||||
help = 'FRED Series ID')
|
||||
parser.add_argument("-s",
|
||||
dest="start_date",
|
||||
type=str,
|
||||
default='1/1/2020',
|
||||
required=False,
|
||||
help='Date to Start')
|
||||
parser.add_argument("-p",
|
||||
dest="plot_",
|
||||
type=bool,
|
||||
default=False,
|
||||
required=False,
|
||||
help='Plot data')
|
||||
parser.add_argument("-disp",
|
||||
dest="disp_",
|
||||
type=bool,
|
||||
default=True,
|
||||
required=False,
|
||||
help='Printdata')
|
||||
|
||||
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, l_args)
|
||||
|
||||
if not ns_parser:
|
||||
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)
|
||||
print("")
|
||||
return
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("")
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ def print_fred():
|
||||
print(" quit quit to abandon program")
|
||||
print(" ")
|
||||
print(" GDP get GDP")
|
||||
print(" cust User Specified FRED Data")
|
||||
return
|
||||
|
||||
def fred_menu():
|
||||
@@ -24,7 +25,8 @@ def fred_menu():
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
"GDP"]
|
||||
"GDP",
|
||||
"cust"]
|
||||
fred_parser.add_argument("cmd", choices=choices)
|
||||
completer = NestedCompleter.from_nested_dict({c: None for c in choices})
|
||||
|
||||
@@ -62,3 +64,6 @@ def fred_menu():
|
||||
|
||||
elif ns_known_args.cmd == "GDP":
|
||||
fred_api.get_GDP(l_args)
|
||||
|
||||
elif ns_known_args.cmd == "cust":
|
||||
fred_api.custom_data(l_args)
|
||||
|
||||
@@ -25,6 +25,7 @@ decorator==4.4.2; python_full_version >= "3.6.1" and python_version >= "3.6" and
|
||||
defusedxml==0.7.1; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
|
||||
entrypoints==0.3; python_version >= "3.6"
|
||||
finviz==1.3.4
|
||||
fredapi==0.4.3
|
||||
fundamentalanalysis==0.2.6
|
||||
hijri-converter==2.1.1; python_version >= "3.6"
|
||||
holidays==0.10.5.2
|
||||
|
||||
Reference in New Issue
Block a user