mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 05:21:48 +00:00
1
.github/workflows/Mac.yml
vendored
1
.github/workflows/Mac.yml
vendored
@@ -45,6 +45,7 @@ jobs:
|
||||
- name: Install gensim with conda
|
||||
shell: bash -l {0}
|
||||
run: |
|
||||
conda install numpy=1.19.5
|
||||
conda install gensim=3.8.3
|
||||
|
||||
- name: Install dependencies (Bash)
|
||||
|
||||
1
.github/workflows/windows.yml
vendored
1
.github/workflows/windows.yml
vendored
@@ -51,6 +51,7 @@ jobs:
|
||||
- name: Install fbprophet with conda
|
||||
shell: bash -l {0}
|
||||
run: |
|
||||
conda install numpy=1.19.5
|
||||
conda install -c conda-forge fbprophet=0.6
|
||||
conda install spyder
|
||||
conda install gensim=3.8.3
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from . import fred_controller # noqa: F401
|
||||
|
||||
151
gamestonk_terminal/fred/fred_controller.py
Normal file
151
gamestonk_terminal/fred/fred_controller.py
Normal file
@@ -0,0 +1,151 @@
|
||||
""" Fred Controller """
|
||||
__docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
from typing import List
|
||||
from matplotlib import pyplot as plt
|
||||
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 gamestonk_terminal.fred import fred_view
|
||||
|
||||
|
||||
class FredController:
|
||||
""" Fred Controller """
|
||||
|
||||
# Command choices
|
||||
CHOICES = [
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
"gdp",
|
||||
"unemp",
|
||||
"t1",
|
||||
"t5",
|
||||
"t10",
|
||||
"t30",
|
||||
"mort30",
|
||||
"fedrate",
|
||||
"moodAAA",
|
||||
"usdcad",
|
||||
"cust",
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
"""Constructor"""
|
||||
self.disc_parser = argparse.ArgumentParser(add_help=False, prog="fred")
|
||||
self.disc_parser.add_argument(
|
||||
"cmd",
|
||||
choices=self.CHOICES,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def print_help():
|
||||
""" Print help """
|
||||
|
||||
print("\nFred Economic Data:")
|
||||
print(" help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
print(" quit quit to abandon program")
|
||||
print(" ")
|
||||
print(" gdp GDP")
|
||||
print(" unemp Unemployment Rate")
|
||||
print(" t1 1-Year Treasury Constant Maturity Rate")
|
||||
print(" t5 5-Year Treasury Constant Maturity Rate")
|
||||
print(" t10 10-Year Treasury Constant Maturity Rate")
|
||||
print(" t30 30-Year Treasury Constant Maturity Rate")
|
||||
print(" mort30 30-Year Fixed Rate Mortgage Average")
|
||||
print(" fedrate Effective Federal Funds Rate")
|
||||
print(" moodAAA Moody's Seasoned AAA Corporate Bond Yield")
|
||||
print(" usdcad Canada / U.S. Foreign Exchange Rate (CAD per 1 USD)")
|
||||
print("")
|
||||
print(" cust User Specified FRED Data - Please Specify --id")
|
||||
print("")
|
||||
return
|
||||
|
||||
def switch(self, an_input: str):
|
||||
"""Process and dispatch input
|
||||
|
||||
Returns
|
||||
-------
|
||||
True, False or None
|
||||
False - quit the menu
|
||||
True - quit the program
|
||||
None - continue in the menu
|
||||
"""
|
||||
(known_args, other_args) = self.disc_parser.parse_known_args(an_input.split())
|
||||
|
||||
fred_data_list = [
|
||||
"gdp",
|
||||
"unemp",
|
||||
"t1",
|
||||
"t5",
|
||||
"t10",
|
||||
"t30",
|
||||
"mort30",
|
||||
"fedrate",
|
||||
"moodAAA",
|
||||
"usdcad",
|
||||
]
|
||||
|
||||
if known_args.cmd in fred_data_list:
|
||||
return getattr(self, "call_fred_api")(other_args, known_args.cmd)
|
||||
|
||||
return getattr(
|
||||
self, "call_" + known_args.cmd, lambda: "Command not recognized!"
|
||||
)(other_args)
|
||||
|
||||
def call_help(self, _):
|
||||
"""Process Help command"""
|
||||
self.print_help()
|
||||
|
||||
def call_q(self, _):
|
||||
"""Process Q command - quit the menu"""
|
||||
return False
|
||||
|
||||
def call_quit(self, _):
|
||||
"""Process Quit command - quit the program"""
|
||||
return True
|
||||
|
||||
def call_fred_api(self, other_args: List[str], cmd: str):
|
||||
"""Process Fred Data call"""
|
||||
fred_view.get_fred_data(other_args, cmd)
|
||||
|
||||
def call_cust(self, other_args: List[str]):
|
||||
"""Process cust call"""
|
||||
fred_view.custom_data(other_args)
|
||||
|
||||
|
||||
def menu():
|
||||
"""Fred Menu"""
|
||||
|
||||
fred_controller = FredController()
|
||||
|
||||
plt.close("all")
|
||||
|
||||
fred_controller.print_help()
|
||||
|
||||
# Loop forever and ever
|
||||
while True:
|
||||
# Get input command from user
|
||||
if session and gtff.USE_PROMPT_TOOLKIT:
|
||||
completer = NestedCompleter.from_nested_dict(
|
||||
{c: None for c in fred_controller.CHOICES}
|
||||
)
|
||||
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (fred)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (fred)> ")
|
||||
try:
|
||||
process_input = fred_controller.switch(an_input)
|
||||
|
||||
if process_input is not None:
|
||||
return process_input
|
||||
|
||||
except SystemExit:
|
||||
print("The command selected doesn't exist\n")
|
||||
continue
|
||||
@@ -1,90 +0,0 @@
|
||||
import argparse
|
||||
from matplotlib import pyplot as plt
|
||||
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 gamestonk_terminal.fred import fred_api
|
||||
|
||||
|
||||
def print_fred():
|
||||
""" Print help """
|
||||
|
||||
print("\nFred Economic Data:")
|
||||
print(" help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
print(" quit quit to abandon program")
|
||||
print(" ")
|
||||
print(" gdp GDP")
|
||||
print(" unemp Unemployment Rate")
|
||||
print(" t1 1-Year Treasury Constant Maturity Rate")
|
||||
print(" t5 5-Year Treasury Constant Maturity Rate")
|
||||
print(" t10 10-Year Treasury Constant Maturity Rate")
|
||||
print(" t30 30-Year Treasury Constant Maturity Rate")
|
||||
print(" mort30 30-Year Fixed Rate Mortgage Average")
|
||||
print(" fedrate Effective Federal Funds Rate")
|
||||
print(" moodAAA Moody's Seasoned AAA Corporate Bond Yield")
|
||||
print(" usdcad Canada / U.S. Foreign Exchange Rate (CAD per 1 USD)")
|
||||
print("")
|
||||
print(" cust User Specified FRED Data - Please Specify --id")
|
||||
print("")
|
||||
return
|
||||
|
||||
|
||||
def fred_menu():
|
||||
plt.close("all")
|
||||
fred_parser = argparse.ArgumentParser(prog="fred", add_help=False)
|
||||
defined_choices = [
|
||||
"gdp",
|
||||
"unemp",
|
||||
"t1",
|
||||
"t5",
|
||||
"t10",
|
||||
"t30",
|
||||
"mort30",
|
||||
"fedrate",
|
||||
"moodAAA",
|
||||
"usdcad",
|
||||
]
|
||||
choices = ["help", "q", "quit", "cust"] + defined_choices
|
||||
|
||||
fred_parser.add_argument("cmd", choices=choices)
|
||||
completer = NestedCompleter.from_nested_dict({c: None for c in choices})
|
||||
|
||||
should_print_help = True
|
||||
while True:
|
||||
if should_print_help:
|
||||
print_fred()
|
||||
should_print_help = False
|
||||
|
||||
# Get input command from user
|
||||
if session and gtff.USE_PROMPT_TOOLKIT:
|
||||
as_input = session.prompt(
|
||||
f"{get_flair()} (fred)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
as_input = input(f"{get_flair()} (fred)> ")
|
||||
try:
|
||||
(ns_known_args, l_args) = fred_parser.parse_known_args(as_input.split())
|
||||
|
||||
except SystemExit:
|
||||
print("The command selected doesn't exist\n")
|
||||
continue
|
||||
|
||||
if ns_known_args.cmd == "help":
|
||||
should_print_help = True
|
||||
|
||||
elif ns_known_args.cmd == "q":
|
||||
# Leave the fred menu
|
||||
return False
|
||||
|
||||
elif ns_known_args.cmd == "quit":
|
||||
# Abandon the program
|
||||
return True
|
||||
|
||||
elif ns_known_args.cmd in defined_choices:
|
||||
fred_api.get_fred_data(l_args, ns_known_args.cmd)
|
||||
|
||||
elif ns_known_args.cmd == "cust":
|
||||
fred_api.custom_data(l_args)
|
||||
@@ -1,4 +1,8 @@
|
||||
""" Fred View """
|
||||
__docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
from typing import List
|
||||
import pandas as pd
|
||||
from pandas.plotting import register_matplotlib_converters
|
||||
import matplotlib.pyplot as plt
|
||||
@@ -26,6 +30,7 @@ api_map = {
|
||||
"usdcad": "DEXCAUS",
|
||||
"unemp": "UNRATE",
|
||||
}
|
||||
|
||||
title_map = {
|
||||
"gdp": "Gross Domestic Product",
|
||||
"t10": "10-Year Treasury Constant Maturity Rate",
|
||||
@@ -40,15 +45,26 @@ title_map = {
|
||||
}
|
||||
|
||||
|
||||
def get_fred_data(l_args, choice):
|
||||
def get_fred_data(other_args: List[str], choice: str):
|
||||
"""Displace Fred data and graph for a selected chosen data series
|
||||
|
||||
Parameters
|
||||
----------
|
||||
other_args : List[str]
|
||||
argparse other args
|
||||
choice : str
|
||||
Fred data series: "gdp","unemp", "t1", "t5", "t10", "t30", "mort30",
|
||||
"fedrate", "moodAAA", "usdcad",
|
||||
"""
|
||||
|
||||
fred = Fred(api_key=API_FRED_KEY)
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="Custom",
|
||||
description="""
|
||||
Custom Data
|
||||
""",
|
||||
Custom Data
|
||||
""",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
@@ -77,7 +93,7 @@ def get_fred_data(l_args, choice):
|
||||
)
|
||||
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, l_args)
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
|
||||
if not ns_parser:
|
||||
return
|
||||
@@ -115,7 +131,14 @@ def get_fred_data(l_args, choice):
|
||||
return
|
||||
|
||||
|
||||
def custom_data(l_args):
|
||||
def custom_data(other_args: List[str]):
|
||||
"""Displace Fred data for a custom series request
|
||||
|
||||
Parameters
|
||||
----------
|
||||
other_args : List[str]
|
||||
argparse other args
|
||||
"""
|
||||
fred = Fred(api_key=API_FRED_KEY)
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
@@ -155,7 +178,7 @@ def custom_data(l_args):
|
||||
)
|
||||
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, l_args)
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
|
||||
if not ns_parser:
|
||||
return
|
||||
@@ -26,7 +26,7 @@ from gamestonk_terminal.technical_analysis import ta_controller
|
||||
from gamestonk_terminal.comparison_analysis import ca_controller
|
||||
from gamestonk_terminal.exploratory_data_analysis import eda_controller
|
||||
from gamestonk_terminal.options import op_controller
|
||||
from gamestonk_terminal.fred import fred_menu as fm
|
||||
from gamestonk_terminal.fred import fred_controller
|
||||
from gamestonk_terminal.residuals_analysis import ra_controller
|
||||
from gamestonk_terminal.portfolio import port_controller
|
||||
from gamestonk_terminal.cryptocurrency import crypto_controller
|
||||
@@ -231,7 +231,7 @@ def main():
|
||||
b_quit = op_controller.menu(s_ticker)
|
||||
|
||||
elif ns_known_args.opt == "fred":
|
||||
b_quit = fm.fred_menu()
|
||||
b_quit = fred_controller.menu()
|
||||
|
||||
elif ns_known_args.opt == "pa":
|
||||
b_quit = port_controller.menu()
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
""" sentiment/twitter_api.py """
|
||||
# flake8: noqa: F401
|
||||
import unittest
|
||||
|
||||
# pylint: disable=unused-import
|
||||
try:
|
||||
from gamestonk_terminal.behavioural_analysis.twitter_view import (
|
||||
inference,
|
||||
sentiment,
|
||||
)
|
||||
except ModuleNotFoundError as e:
|
||||
print("One of the optional packages seems to be missing")
|
||||
print(e)
|
||||
print("Skipping the test")
|
||||
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
|
||||
|
||||
class TestSentimentTwitterApi(unittest.TestCase):
|
||||
def test_inference(self):
|
||||
if not gtff.ENABLE_PREDICT:
|
||||
return
|
||||
# Fix: implement a better twitter client
|
||||
# inference([], "PLTR")
|
||||
return
|
||||
|
||||
def test_sentiment(self):
|
||||
if not gtff.ENABLE_PREDICT:
|
||||
return
|
||||
# Fix: implement a better twitter client
|
||||
# sentiment([], "PLTR")
|
||||
return
|
||||
Reference in New Issue
Block a user