Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3882 Fixed #3885

Merged
merged 11 commits into from
Jan 12, 2023
34 changes: 24 additions & 10 deletions openbb_terminal/economy/economy_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,19 @@ def call_macro(self, other_args: List[str]):
)

if not df.empty:

df.columns = ["_".join(column) for column in df.columns]

if ns_parser.transform:
df.columns = [df.columns[0] + f"_{ns_parser.transform}"]

self.DATASETS["macro"] = pd.concat([self.DATASETS["macro"], df])
for column in df.columns:
if column in self.DATASETS["macro"].columns:
self.DATASETS["macro"].drop(column, axis=1, inplace=True)

self.DATASETS["macro"] = pd.concat(
[self.DATASETS["macro"], df], axis=1
)

# update units dict
for country, data in units.items():
Expand Down Expand Up @@ -851,6 +858,7 @@ def call_index(self, other_args: List[str]):
)

if not df.empty:

self.DATASETS["index"][index] = df

self.stored_datasets = (
Expand Down Expand Up @@ -961,20 +969,26 @@ def call_treasury(self, other_args: List[str]):
)

if not df.empty:
self.DATASETS["treasury"] = pd.concat(
[
self.DATASETS["treasury"],
df,
]
)

cols = []
for column in self.DATASETS["treasury"].columns:
for column in df.columns:
if isinstance(column, tuple):
cols.append("_".join(column))
else:
cols.append(column)
self.DATASETS["treasury"].columns = cols
df.columns = cols

for column in df.columns:
if column in self.DATASETS["treasury"].columns:
self.DATASETS["treasury"].drop(column, axis=1, inplace=True)

self.DATASETS["treasury"] = pd.concat(
[
self.DATASETS["treasury"],
df,
],
axis=1,
)

self.stored_datasets = (
economy_helpers.update_stored_datasets_string(self.DATASETS)
Expand Down Expand Up @@ -1562,7 +1576,7 @@ def call_eval(self, other_args):
self.stored_datasets = economy_helpers.update_stored_datasets_string(
self.DATASETS
)
console.print()
self.update_runtime_choices()

@log_start_end(log=logger)
def call_qa(self, _):
Expand Down
2 changes: 2 additions & 0 deletions openbb_terminal/economy/plot_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def show_plot(
ax_2_coloring = -1

dataset_yaxis_1 = dataset_yaxis_1.dropna()
dataset_yaxis_1.index = pd.to_datetime(dataset_yaxis_1.index)

for column in dataset_yaxis_1:
ax1.plot(
Expand All @@ -72,6 +73,7 @@ def show_plot(
ax2 = ax1.twinx()

dataset_yaxis_2 = dataset_yaxis_2.dropna()
dataset_yaxis_2.index = pd.to_datetime(dataset_yaxis_2.index)

for column in dataset_yaxis_2:
ax2.plot(
Expand Down
168 changes: 84 additions & 84 deletions openbb_terminal/miscellaneous/scripts/economy/test_economy.openbb
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
economy
# overview
# overview -t indices
# overview -t usbonds
# overview -t glbonds
# overview -t currencies
# futures
# futures -c energy --source Finviz
# futures -c metals --source Finviz
# futures -c meats --source Finviz
# futures -c grains --source Finviz
# futures -c softs --source Finviz
# futures -c energy
# futures -c metals
# futures -c meats
# futures -c grains
# futures -c softs
# futures -c energy -s ticker --reverse --source Finviz
# map
# map -p 1w -t world
# bigmac
# bigmac -c USA,ESP,LVA,DEU,FRA,FIN
# ycrv
# ycrv --source FRED --date 2022-10-03 --raw
# ycrv -c united_states --source Investing
# events
# events --country united_states -i high --cat employment -s 2022-07-07 -e 2022-07-08
# events -c spain --source Investing
# edebt --limit 10
# spread
# spread --group PIIGS --color binary
# spread --countries portugal,spain,italy,united states --maturity 5Y --change=True --color openbb
# rtps
# valuation
# valuation --group sector --sortby MarketCap --reverse
# performance
# performance -g basic_materials -s Month -a
# spectrum
# spectrum --group consumer_defensive
# macro
# macro -p RGDP,CPI
# macro -p URATE -c Netherlands,Germany
# macro -p URATE -c United_States --start 2008-01-01
# macro -p GDP --countries Portugal,France,United_Kingdom,Spain,Italy,Poland --start 2000-01-10
# treasury
# treasury --maturity 20y --type nominal
# treasury --raw
# treasury --type inflation --start 2020-01-01 --limit 10
# fred T10Y2Y,DFII10 -s 2019-01-01 -e 2022-01-01
# fred -q treasury
# fred -p T10Y2Y,FII10 -s 2005-01-01
# fred T5YIEM,T10YIEM,T20YIEM,T30YIEM
# index -i nasdaq,dowjones,sp500 -s 2005-01-01
# macro -p URATE -c Netherlands,Germany -s 2005-01-01
# index -i sp500 -s 2005-01-01
# plot --y1 T10Y2Y --y2 T5YIEM
# plot --y1 T10Y2Y,T20YIEM
# rtps
# valuation
# performance
# spectrum
# fred DGS2,DGS5
# eval spread = DGS2 - DGS5
# qa
# summary
# normality
# unitroot --fuller_reg c --kps_reg ct
# line
# line --log
# hist
# hist -b 10
# cdf
# bw
# bw --yearly
# acf --lags 5
# qqplot
# rolling
# rolling -w 5
# spread -w 10
# quantile --window 5 --quantile 0.01
# skew --window 5
# kurtosis --window 9
# raw --limit 2 --reverse
# cusum --threshold 10 --drift 10
# decompose
overview
overview -t indices
overview -t usbonds
overview -t glbonds
overview -t currencies
futures
futures -c energy --source Finviz
futures -c metals --source Finviz
futures -c meats --source Finviz
futures -c grains --source Finviz
futures -c softs --source Finviz
futures -c energy
futures -c metals
futures -c meats
futures -c grains
futures -c softs
futures -c energy -s ticker --reverse --source Finviz
map
map -p 1w -t world
bigmac
bigmac -c USA,ESP,LVA,DEU,FRA,FIN
ycrv
ycrv --source FRED --date 2022-10-03 --raw
ycrv -c united_states --source Investing
events
events --country united_states -i high --cat employment -s 2022-07-07 -e 2022-07-08
events -c spain --source Investing
edebt --limit 10
spread
spread --group PIIGS --color binary
spread --countries portugal,spain,italy,united states --maturity 5Y --change=True --color openbb
rtps
valuation
valuation --group sector --sortby MarketCap --reverse
performance
performance -g basic_materials -s Month -a
spectrum
spectrum --group consumer_defensive
macro
macro -p RGDP,CPI
macro -p URATE -c Netherlands,Germany
macro -p URATE -c United_States --start 2008-01-01
macro -p GDP --countries Portugal,France,United_Kingdom,Spain,Italy,Poland --start 2000-01-10
treasury
treasury --maturity 20y --type nominal
treasury --raw
treasury --type inflation --start 2020-01-01 --limit 10
fred T10Y2Y,DFII10 -s 2019-01-01 -e 2022-01-01
fred -q treasury
fred -p T10Y2Y,FII10 -s 2005-01-01
fred T5YIEM,T10YIEM,T20YIEM,T30YIEM
index -i nasdaq,dowjones,sp500 -s 2005-01-01
macro -p URATE -c Netherlands,Germany -s 2005-01-01
index -i sp500 -s 2005-01-01
plot --y1 T10Y2Y --y2 T5YIEM
plot --y1 T10Y2Y,T20YIEM
rtps
valuation
performance
spectrum
fred DGS2,DGS5
eval spread = DGS2 - DGS5
qa
summary
normality
unitroot --fuller_reg c --kps_reg ct
line
line --log
hist
hist -b 10
cdf
bw
bw --yearly
acf --lags 5
qqplot
rolling
rolling -w 5
spread -w 10
quantile --window 5 --quantile 0.01
skew --window 5
kurtosis --window 9
raw --limit 2 --reverse
cusum --threshold 10 --drift 10
decompose
exit
25 changes: 14 additions & 11 deletions openbb_terminal/stocks/stocks_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,16 @@ def load(

start_date = check_datetime(start_date)
end_date = check_datetime(end_date, start=False)
int_string = "Daily"
if weekly:
int_string = "Weekly"
if monthly:
int_string = "Monthly"

# Daily
if int(interval) == 1440:

int_string = "Daily"
if weekly:
int_string = "Weekly"
if monthly:
int_string = "Monthly"

if source == "AlphaVantage":
df_stock_candidate = load_stock_av(symbol, start_date, end_date)
df_stock_candidate = load_stock_av(symbol,int_string, start_date, end_date)

elif source == "YahooFinance":
df_stock_candidate = load_stock_yf(
Expand Down Expand Up @@ -338,11 +336,16 @@ def load(
df_stock_candidate.index.name = "date"
s_start = df_stock_candidate.index[0]
s_interval = f"{interval}min"
int_string = "Daily" if interval == 1440 else "Intraday"

else:

if source == "AlphaVantage":
s_start = start_date
int_string = "Minute"
s_interval = f"{interval}min"
df_stock_candidate = load_stock_av(symbol,int_string, start_date, end_date,s_interval)

if source == "YahooFinance":
elif source == "YahooFinance":
s_int = str(interval) + "m"
s_interval = s_int + "in"
d_granularity = {"1m": 6, "5m": 59, "15m": 59, "30m": 59, "60m": 729}
Expand Down Expand Up @@ -429,7 +432,7 @@ def load(
s_interval = f"{interval}min"
int_string = "Intraday"

s_intraday = (f"Intraday {s_interval}", int_string)[interval == 1440]
s_intraday = (f"Intraday {interval}min", int_string)[interval == 1440]

if verbose:
console.print(
Expand Down
25 changes: 20 additions & 5 deletions openbb_terminal/stocks/stocks_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,32 @@


def load_stock_av(
symbol: str, start_date: datetime, end_date: datetime
symbol: str,interval: str, start_date: datetime, end_date: datetime, interval_min:str = "1min"
) -> pd.DataFrame:
try:
ts = TimeSeries(key=cfg.API_KEY_ALPHAVANTAGE, output_format="pandas")
df_stock_candidate: pd.DataFrame = ts.get_daily_adjusted(
symbol=symbol, outputsize="full"
)[0]
if interval == "Minute":
df_stock_candidate: pd.DataFrame = ts.get_intraday(
symbol=symbol, interval=interval_min
)[0]
elif interval == "Daily":
df_stock_candidate: pd.DataFrame = ts.get_daily_adjusted(
symbol=symbol, outputsize="full"
)[0]
elif interval == "Weekly":
df_stock_candidate: pd.DataFrame = ts.get_weekly_adjusted(
symbol=symbol
)[0]
elif interval == "Monthly":
df_stock_candidate: pd.DataFrame = ts.get_monthly_adjusted(
symbol=symbol
)[0]
else:
console.print("Invalid interval specified")
return pd.DataFrame()
except Exception as e:
console.print(e)
return pd.DataFrame()

df_stock_candidate.columns = [
val.split(". ")[1].capitalize() for val in df_stock_candidate.columns
]
Expand Down