mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
Bug fixes and code improvements (#519)
* Add README link to each menu * Retrieve good error when #517 happens * Fix column names with numbers in dataframes * Update README.md * ignore false positive
This commit is contained in:
@@ -313,7 +313,9 @@ Example:
|
||||
<!-- CONTRIBUTING -->
|
||||
## Contributing
|
||||
|
||||
There are 3 main ways of contributing to this project.
|
||||
There are 3 main ways of contributing to this project.
|
||||
|
||||
For a 1h coding session where the architecture of the repo is explained while a new feature is added, check https://www.youtube.com/watch?v=9BMI9cleTTg.
|
||||
|
||||
**Become a Contributor 🦍**
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ class BacktestingController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/backtesting"
|
||||
)
|
||||
print("\nBacktesting:")
|
||||
print(" help show this backtesting menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
|
||||
@@ -58,7 +58,9 @@ class BehaviouralAnalysisController:
|
||||
@staticmethod
|
||||
def print_help():
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/behavioural_analysis"
|
||||
)
|
||||
print("\nBehavioural Analysis:")
|
||||
print(" help show this behavioural analysis menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
|
||||
@@ -53,9 +53,11 @@ class BrokersController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"Brokers Supported:\n"
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/brokers"
|
||||
)
|
||||
print(
|
||||
"\nBrokers Supported:\n"
|
||||
" ally - Ally Invest\n"
|
||||
" alp - Alpaca\n"
|
||||
" rh - Robinhood\n"
|
||||
|
||||
@@ -31,6 +31,7 @@ class DegiroController:
|
||||
"quit",
|
||||
"topnews",
|
||||
"update",
|
||||
"help",
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
@@ -153,9 +154,8 @@ class DegiroController:
|
||||
|
||||
self.__degiro_view.create(ns_parser=ns_parser)
|
||||
|
||||
def help(self):
|
||||
def help(self, _):
|
||||
"""Show the help menu."""
|
||||
|
||||
DegiroView.help_display()
|
||||
|
||||
def hold(self, l_args):
|
||||
@@ -362,7 +362,7 @@ def menu():
|
||||
|
||||
# SETUP CONTROLLER
|
||||
degiro_controller = DegiroController()
|
||||
degiro_controller.help()
|
||||
degiro_controller.help(None)
|
||||
|
||||
while True:
|
||||
# Get input command from user
|
||||
|
||||
@@ -43,9 +43,14 @@ class DegiroView:
|
||||
@staticmethod
|
||||
def help_display():
|
||||
print(
|
||||
"Degiro:\n"
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/brokers/degiro"
|
||||
)
|
||||
print(
|
||||
"\nDegiro:\n"
|
||||
" help show this help menu again\n"
|
||||
" q quit degiro standalone menu\n"
|
||||
" quit quit the app\n"
|
||||
"\n"
|
||||
" login connect to degiro's api\n"
|
||||
" logout disconnect from degiro's api\n"
|
||||
"\n"
|
||||
|
||||
@@ -84,6 +84,9 @@ class ComparisonAnalysisController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/comparison_analysis"
|
||||
)
|
||||
|
||||
s_intraday = (f"Intraday {self.interval}", "Daily")[self.interval == "1440min"]
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ def historical(
|
||||
plt.plot(
|
||||
df_stock.index, df_stock[d_candle_types[ns_parser.type_candle]].values
|
||||
)
|
||||
# plt.plot(df_stock.index, df_stock["5. adjusted close"].values, lw=2)
|
||||
# plt.plot(df_stock.index, df_stock["Adj Close"].values, lw=2)
|
||||
l_min = [df_stock.index[0]]
|
||||
l_leg = [ticker]
|
||||
|
||||
|
||||
@@ -46,6 +46,9 @@ class CryptoController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/cryptocurrency"
|
||||
)
|
||||
print("\nCryptocurrency:")
|
||||
print(" help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
@@ -148,31 +151,19 @@ class CryptoController:
|
||||
"""Process ta command"""
|
||||
if not self.current_coin:
|
||||
print("Please load a coin through either load or select", "\n")
|
||||
|
||||
elif self.current_df.empty:
|
||||
print("Price dataframe is empty")
|
||||
else:
|
||||
# Need to make the columns in df be compatible. Also since there are no splits or dividends, there is no
|
||||
# adj close. To tell ta to use Close, we can just set the interval to anything but 1440.
|
||||
# Binance provides candles so we just need to rename:
|
||||
if self.source == "BIN":
|
||||
self.current_df = self.current_df.rename(
|
||||
columns={
|
||||
"Open": "1. open",
|
||||
"High": "2. high",
|
||||
"Low": "3. low",
|
||||
"Close": "4. close",
|
||||
"Volume": "6. volume",
|
||||
}
|
||||
)
|
||||
self.current_df.index.name = "date"
|
||||
|
||||
else:
|
||||
# Coingecko does not provide candles so we can only provide close data.
|
||||
elif self.source == "CG":
|
||||
if self.source == "CG":
|
||||
|
||||
self.current_df = self.current_df[["Price"]].rename(
|
||||
columns={"Price": "4. close"}
|
||||
columns={"Price": "Close"}
|
||||
)
|
||||
self.current_df.index.name = "date"
|
||||
|
||||
self.current_df.index.name = "date"
|
||||
|
||||
ta_controller.menu(
|
||||
self.current_coin,
|
||||
|
||||
@@ -71,7 +71,9 @@ class DiscoveryController:
|
||||
@staticmethod
|
||||
def print_help():
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/discovery"
|
||||
)
|
||||
print("\nDiscovery Mode:")
|
||||
print(" help show this discovery menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
|
||||
@@ -100,10 +100,10 @@ def price_target_from_analysts(
|
||||
df_analyst_data = df_analyst_data[start:] # type: ignore
|
||||
|
||||
if interval == "1440min":
|
||||
plt.plot(stock.index, stock["5. adjusted close"].values, lw=3)
|
||||
plt.plot(stock.index, stock["Adj Close"].values, lw=3)
|
||||
# Intraday
|
||||
else:
|
||||
plt.plot(stock.index, stock["4. close"].values, lw=3)
|
||||
plt.plot(stock.index, stock["Close"].values, lw=3)
|
||||
|
||||
if start:
|
||||
plt.plot(df_analyst_data.groupby(by=["Date"]).mean()[start:]) # type: ignore
|
||||
@@ -394,9 +394,9 @@ def insider_activity(
|
||||
_, ax = plt.subplots()
|
||||
|
||||
if interval == "1440min":
|
||||
plt.plot(stock.index, stock["5. adjusted close"].values, lw=3)
|
||||
plt.plot(stock.index, stock["Adj Close"].values, lw=3)
|
||||
else: # Intraday
|
||||
plt.plot(stock.index, stock["4. close"].values, lw=3)
|
||||
plt.plot(stock.index, stock["Close"].values, lw=3)
|
||||
|
||||
plt.title(f"{ticker.upper()} (Time Series) and Price Target")
|
||||
|
||||
@@ -434,9 +434,9 @@ def insider_activity(
|
||||
|
||||
n_stock_price = 0
|
||||
if interval == "1440min":
|
||||
n_stock_price = stock["5. adjusted close"][ind_dt]
|
||||
n_stock_price = stock["Adj Close"][ind_dt]
|
||||
else:
|
||||
n_stock_price = stock["4. close"][ind_dt]
|
||||
n_stock_price = stock["Close"][ind_dt]
|
||||
|
||||
plt.vlines(
|
||||
x=ind_dt,
|
||||
@@ -463,9 +463,9 @@ def insider_activity(
|
||||
|
||||
n_stock_price = 0
|
||||
if interval == "1440min":
|
||||
n_stock_price = stock["5. adjusted close"][ind_dt]
|
||||
n_stock_price = stock["Adj Close"][ind_dt]
|
||||
else:
|
||||
n_stock_price = stock["4. close"][ind_dt]
|
||||
n_stock_price = stock["Close"][ind_dt]
|
||||
|
||||
plt.vlines(
|
||||
x=ind_dt,
|
||||
|
||||
@@ -75,7 +75,9 @@ class DueDiligenceController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/due_diligence"
|
||||
)
|
||||
intraday = (f"Intraday {self.interval}", "Daily")[self.interval == "1440min"]
|
||||
|
||||
if self.start:
|
||||
|
||||
@@ -16,6 +16,8 @@ from gamestonk_terminal.helper_funcs import (
|
||||
parse_known_args_and_warn,
|
||||
)
|
||||
|
||||
# pylint: disable=too-many-branches
|
||||
|
||||
|
||||
def sec_fillings(other_args: List[str], ticker: str):
|
||||
"""Display SEC filings for a given stock ticker
|
||||
@@ -189,12 +191,17 @@ def sean_seah_warnings(other_args: List[str], ticker: str):
|
||||
df_financials.loc[len(df_financials.index)] = l_financials
|
||||
break
|
||||
|
||||
l_fin = ["EPS (Basic)", "Net Income", "Interest Expense", "EBITDA"]
|
||||
|
||||
if not all(elem in df_financials["Item"].values for elem in l_fin):
|
||||
print("The source doesn't contain all necessary financial data")
|
||||
print(url_financials, "\n")
|
||||
return
|
||||
|
||||
# Set item name as index
|
||||
df_financials = df_financials.set_index("Item")
|
||||
|
||||
df_sean_seah = df_financials.loc[
|
||||
["EPS (Basic)", "Net Income", "Interest Expense", "EBITDA"]
|
||||
]
|
||||
df_sean_seah = df_financials.loc[l_fin]
|
||||
|
||||
# From BALANCE SHEET, get: 'Liabilities & Shareholders\' Equity', 'Long-Term Debt'
|
||||
url_financials = f"https://www.marketwatch.com/investing/stock/{ticker}/financials/balance-sheet"
|
||||
|
||||
@@ -47,7 +47,9 @@ class EconomyController:
|
||||
@staticmethod
|
||||
def print_help():
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/economy"
|
||||
)
|
||||
print("\nEconomic Data:")
|
||||
print(" help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
|
||||
@@ -28,6 +28,9 @@ class ETFController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/etf"
|
||||
)
|
||||
print("\nETF:")
|
||||
print(" help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
|
||||
@@ -3,9 +3,9 @@ __docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
from detecta import detect_cusum
|
||||
from matplotlib import pyplot as plt
|
||||
from datetime import datetime
|
||||
import pandas as pd
|
||||
from pandas.plotting import register_matplotlib_converters
|
||||
import numpy as np
|
||||
@@ -88,7 +88,7 @@ def hist(other_args: List[str], ticker: str, stock: pd.DataFrame, start: datetim
|
||||
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
|
||||
stock = stock["5. adjusted close"]
|
||||
stock = stock["Adj Close"]
|
||||
|
||||
sns.distplot(
|
||||
stock,
|
||||
@@ -119,7 +119,9 @@ def hist(other_args: List[str], ticker: str, stock: pd.DataFrame, start: datetim
|
||||
return
|
||||
|
||||
|
||||
def cdf(other_args: List[str], ticker: str, stock: pd.DataFrame, start: datetime):
|
||||
def cumulative_distribution_function(
|
||||
other_args: List[str], ticker: str, stock: pd.DataFrame, start: datetime
|
||||
):
|
||||
"""Plot cumulative distribution function
|
||||
|
||||
Parameters
|
||||
@@ -146,7 +148,7 @@ def cdf(other_args: List[str], ticker: str, stock: pd.DataFrame, start: datetime
|
||||
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
|
||||
stock = stock["5. adjusted close"]
|
||||
stock = stock["Adj Close"]
|
||||
|
||||
cdf = stock.value_counts().sort_index().div(len(stock)).cumsum()
|
||||
cdf.plot(lw=2)
|
||||
@@ -230,7 +232,7 @@ def bwy(other_args: List[str], ticker: str, stock: pd.DataFrame, start: datetime
|
||||
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
|
||||
stock = stock["5. adjusted close"]
|
||||
stock = stock["Adj Close"]
|
||||
|
||||
sns.set(style="whitegrid")
|
||||
box_plot = sns.boxplot(x=stock.index.year, y=stock)
|
||||
@@ -278,7 +280,7 @@ def bwm(other_args: List[str], ticker: str, stock: pd.DataFrame, start: datetime
|
||||
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
|
||||
stock = stock["5. adjusted close"]
|
||||
stock = stock["Adj Close"]
|
||||
|
||||
sns.set(style="whitegrid")
|
||||
box_plot = sns.boxplot(x=stock.index.month, y=stock)
|
||||
@@ -341,7 +343,7 @@ def rolling(other_args: List[str], ticker: str, stock: pd.DataFrame):
|
||||
"--window",
|
||||
dest="rolling_window",
|
||||
type=check_positive,
|
||||
default=100,
|
||||
default=10,
|
||||
help="rolling window",
|
||||
)
|
||||
|
||||
@@ -350,7 +352,7 @@ def rolling(other_args: List[str], ticker: str, stock: pd.DataFrame):
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
stock = stock["5. adjusted close"]
|
||||
stock = stock["Adj Close"]
|
||||
|
||||
rolling_mean = stock.rolling(
|
||||
ns_parser.rolling_window, center=True, min_periods=1
|
||||
@@ -359,7 +361,7 @@ def rolling(other_args: List[str], ticker: str, stock: pd.DataFrame):
|
||||
ns_parser.rolling_window, center=True, min_periods=1
|
||||
).std()
|
||||
|
||||
fig, axMean = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
_, axMean = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
|
||||
axMean.plot(stock.index, stock.values, label=ticker, linewidth=2, color="black")
|
||||
axMean.plot(rolling_mean, linestyle="--", linewidth=3, color="blue")
|
||||
@@ -434,7 +436,7 @@ def decompose(other_args: List[str], ticker: str, stock: pd.DataFrame):
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
stock = stock["5. adjusted close"]
|
||||
stock = stock["Adj Close"]
|
||||
|
||||
seasonal_periods = 5
|
||||
# Hodrick-Prescott filter
|
||||
@@ -562,7 +564,7 @@ def decompose(other_args: List[str], ticker: str, stock: pd.DataFrame):
|
||||
return
|
||||
|
||||
|
||||
def cusum(other_args: List[str], ticker: str, stock: pd.DataFrame):
|
||||
def cusum(other_args: List[str], stock: pd.DataFrame):
|
||||
"""Cumulative sum algorithm (CUSUM) to detect abrupt changes in data
|
||||
|
||||
Parameters
|
||||
@@ -586,11 +588,7 @@ def cusum(other_args: List[str], ticker: str, stock: pd.DataFrame):
|
||||
"--threshold",
|
||||
dest="threshold",
|
||||
type=float,
|
||||
default=(
|
||||
max(stock["5. adjusted close"].values)
|
||||
- min(stock["5. adjusted close"].values)
|
||||
)
|
||||
/ 40,
|
||||
default=(max(stock["Adj Close"].values) - min(stock["Adj Close"].values)) / 40,
|
||||
help="threshold",
|
||||
)
|
||||
parser.add_argument(
|
||||
@@ -598,11 +596,7 @@ def cusum(other_args: List[str], ticker: str, stock: pd.DataFrame):
|
||||
"--drift",
|
||||
dest="drift",
|
||||
type=float,
|
||||
default=(
|
||||
max(stock["5. adjusted close"].values)
|
||||
- min(stock["5. adjusted close"].values)
|
||||
)
|
||||
/ 80,
|
||||
default=(max(stock["Adj Close"].values) - min(stock["Adj Close"].values)) / 80,
|
||||
help="drift",
|
||||
)
|
||||
|
||||
@@ -611,7 +605,7 @@ def cusum(other_args: List[str], ticker: str, stock: pd.DataFrame):
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
stock = stock["5. adjusted close"]
|
||||
stock = stock["Adj Close"]
|
||||
|
||||
detect_cusum(stock.values, ns_parser.threshold, ns_parser.drift, True, True)
|
||||
|
||||
@@ -650,7 +644,7 @@ def acf(other_args: List[str], ticker: str, stock: pd.DataFrame, start: datetime
|
||||
"--lags",
|
||||
dest="lags",
|
||||
type=check_positive,
|
||||
default=40,
|
||||
default=15,
|
||||
help="maximum lags to display in plots",
|
||||
)
|
||||
|
||||
@@ -659,7 +653,8 @@ def acf(other_args: List[str], ticker: str, stock: pd.DataFrame, start: datetime
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
stock = stock["5. adjusted close"]
|
||||
print(stock.head())
|
||||
stock = stock["Adj Close"]
|
||||
|
||||
fig = plt.figure(
|
||||
figsize=plot_autoscale(), dpi=PLOT_DPI, constrained_layout=True
|
||||
|
||||
@@ -52,7 +52,10 @@ class EdaController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/"
|
||||
"GamestonkTerminal/tree/main/gamestonk_terminal/exploratory_data_analysis"
|
||||
)
|
||||
s_intraday = (f"Intraday {self.interval}", "Daily")[self.interval == "1440min"]
|
||||
|
||||
if self.start:
|
||||
@@ -117,7 +120,9 @@ class EdaController:
|
||||
|
||||
def call_cdf(self, other_args: List[str]):
|
||||
"""Process cdf command"""
|
||||
eda_api.cdf(other_args, self.ticker, self.stock, self.start)
|
||||
eda_api.cumulative_distribution_function(
|
||||
other_args, self.ticker, self.stock, self.start
|
||||
)
|
||||
|
||||
def call_bwy(self, other_args: List[str]):
|
||||
"""Process bwy command"""
|
||||
@@ -137,7 +142,7 @@ class EdaController:
|
||||
|
||||
def call_cusum(self, other_args: List[str]):
|
||||
"""Process cusum command"""
|
||||
eda_api.cusum(other_args, self.ticker, self.stock)
|
||||
eda_api.cusum(other_args, self.stock)
|
||||
|
||||
def call_acf(self, other_args: List[str]):
|
||||
"""Process acf command"""
|
||||
|
||||
@@ -17,7 +17,7 @@ USE_ION = strtobool(os.getenv("GTFF_USE_ION", "False"))
|
||||
USE_PROMPT_TOOLKIT = strtobool(os.getenv("GTFF_USE_PROMPT_TOOLKIT", "False"))
|
||||
|
||||
# Enable Prediction features
|
||||
ENABLE_PREDICT = strtobool(os.getenv("GTFF_ENABLE_PREDICT", "False"))
|
||||
ENABLE_PREDICT = strtobool(os.getenv("GTFF_ENABLE_PREDICT", "True"))
|
||||
|
||||
# Enable plot autoscaling
|
||||
USE_PLOT_AUTOSCALING = strtobool(os.getenv("GTFF_USE_PLOT_AUTOSCALING", "False"))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import argparse
|
||||
from typing import List
|
||||
import pandas as pd
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
from gamestonk_terminal.helper_funcs import get_flair
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
@@ -9,7 +10,6 @@ from gamestonk_terminal import config_terminal as cfg
|
||||
from gamestonk_terminal.due_diligence import news_view, reddit_view
|
||||
from gamestonk_terminal.behavioural_analysis import ba_controller
|
||||
from gamestonk_terminal.exploratory_data_analysis import eda_controller
|
||||
import pandas as pd
|
||||
|
||||
|
||||
account = cfg.OANDA_ACCOUNT
|
||||
@@ -51,10 +51,11 @@ class ForexController:
|
||||
)
|
||||
self.instrument = None
|
||||
|
||||
@staticmethod
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/forex"
|
||||
)
|
||||
print("\nForex Mode:")
|
||||
print(" help show this menu again")
|
||||
print(" q quit this menu and goes back to main menu")
|
||||
@@ -108,7 +109,7 @@ class ForexController:
|
||||
|
||||
def call_help(self, _):
|
||||
"""Process Help Command"""
|
||||
self.print_help(self)
|
||||
self.print_help()
|
||||
|
||||
def call_q(self, _):
|
||||
"""Process Q command - quit the menu"""
|
||||
@@ -180,10 +181,10 @@ class ForexController:
|
||||
instrument = fx_view.format_instrument(self.instrument, " ")
|
||||
reddit_view.due_diligence(other_args, instrument)
|
||||
|
||||
def call_eda(self, other_args):
|
||||
def call_eda(self, _):
|
||||
try:
|
||||
df = fx_view.get_candles_dataframe(account, self.instrument, None)
|
||||
df = df.rename(columns={"Close": "5. adjusted close"})
|
||||
df = df.rename(columns={"Close": "Adj Close"})
|
||||
instrument = self.instrument
|
||||
s_start = pd.to_datetime(df.index.values[0])
|
||||
s_interval = "1440min"
|
||||
@@ -191,7 +192,7 @@ class ForexController:
|
||||
except AttributeError:
|
||||
print("No data found, do you have your oanda API keys set?")
|
||||
|
||||
def call_ba(self, other_args: List[str]):
|
||||
def call_ba(self, _):
|
||||
instrument = fx_view.format_instrument(self.instrument, " ")
|
||||
try:
|
||||
df = fx_view.get_candles_dataframe(account, self.instrument, None)
|
||||
|
||||
@@ -51,7 +51,10 @@ class AlphaVantageController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/"
|
||||
"tree/main/gamestonk_terminal/fundamental_analysis/alpha_vantage"
|
||||
)
|
||||
intraday = (f"Intraday {self.interval}", "Daily")[self.interval == "1440min"]
|
||||
|
||||
if self.start:
|
||||
|
||||
@@ -66,7 +66,9 @@ class FundamentalAnalysisController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/fundamental_analysis"
|
||||
)
|
||||
intraday = (f"Intraday {self.interval}", "Daily")[self.interval == "1440min"]
|
||||
|
||||
if self.start:
|
||||
|
||||
@@ -57,7 +57,10 @@ class FinancialModelingPrepController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/"
|
||||
"tree/main/gamestonk_terminal/fundamental_analysis/financial_modeling_prep"
|
||||
)
|
||||
intraday = (f"Intraday {self.interval}", "Daily")[self.interval == "1440min"]
|
||||
|
||||
if self.start:
|
||||
|
||||
@@ -58,7 +58,9 @@ class GovController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/government"
|
||||
)
|
||||
print("\nExploratory Data Analysis:")
|
||||
print(" help show this comparison analysis menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
|
||||
@@ -19,6 +19,7 @@ import pytz
|
||||
from tabulate import tabulate
|
||||
import git
|
||||
|
||||
# pylint: disable=no-member
|
||||
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
valid_date,
|
||||
@@ -156,6 +157,17 @@ def load(other_args: List[str], s_ticker, s_start, s_interval, df_stock):
|
||||
symbol=ns_parser.s_ticker, outputsize="full"
|
||||
)
|
||||
|
||||
df_stock_candidate.columns = [
|
||||
val.split(". ")[1].capitalize()
|
||||
for val in df_stock_candidate.columns
|
||||
]
|
||||
|
||||
df_stock_candidate = df_stock_candidate.rename(
|
||||
columns={
|
||||
"Adjusted close": "Adj Close",
|
||||
}
|
||||
)
|
||||
|
||||
# Check that loading a stock was not successful
|
||||
# pylint: disable=no-member
|
||||
if df_stock_candidate.empty:
|
||||
@@ -179,16 +191,6 @@ def load(other_args: List[str], s_ticker, s_start, s_interval, df_stock):
|
||||
print("")
|
||||
return [s_ticker, s_start, s_interval, df_stock]
|
||||
|
||||
df_stock_candidate = df_stock_candidate.rename(
|
||||
columns={
|
||||
"Open": "1. open",
|
||||
"High": "2. high",
|
||||
"Low": "3. low",
|
||||
"Close": "4. close",
|
||||
"Adj Close": "5. adjusted close",
|
||||
"Volume": "6. volume",
|
||||
}
|
||||
)
|
||||
df_stock_candidate.index.name = "date"
|
||||
|
||||
# Check if start time from dataframe is more recent than specified
|
||||
@@ -209,6 +211,18 @@ def load(other_args: List[str], s_ticker, s_start, s_interval, df_stock):
|
||||
outputsize="full",
|
||||
interval=str(ns_parser.n_interval) + "min",
|
||||
)
|
||||
|
||||
df_stock_candidate.columns = [
|
||||
val.split(". ")[1].capitalize()
|
||||
for val in df_stock_candidate.columns
|
||||
]
|
||||
|
||||
df_stock_candidate = df_stock_candidate.rename(
|
||||
columns={
|
||||
"Adjusted close": "Adj Close",
|
||||
}
|
||||
)
|
||||
|
||||
s_interval = str(ns_parser.n_interval) + "min"
|
||||
# Check that loading a stock was not successful
|
||||
# pylint: disable=no-member
|
||||
@@ -267,16 +281,6 @@ def load(other_args: List[str], s_ticker, s_start, s_interval, df_stock):
|
||||
else:
|
||||
s_start = ns_parser.s_start_date
|
||||
|
||||
df_stock_candidate = df_stock_candidate.rename(
|
||||
columns={
|
||||
"Open": "1. open",
|
||||
"High": "2. high",
|
||||
"Low": "3. low",
|
||||
"Close": "4. close",
|
||||
"Adj Close": "5. adjusted close",
|
||||
"Volume": "6. volume",
|
||||
}
|
||||
)
|
||||
df_stock_candidate.index.name = "date"
|
||||
|
||||
s_intraday = (f"Intraday {s_interval}", "Daily")[ns_parser.n_interval == 1440]
|
||||
@@ -570,7 +574,7 @@ def view(other_args: List[str], s_ticker: str, s_start, s_interval, df_stock):
|
||||
if len([i for i in ln_col_idx if i > 4]) > 0:
|
||||
print("An index bigger than 4 was given, which is wrong. Try again")
|
||||
return
|
||||
# Append last column of df to be filtered which corresponds to: 6. Volume
|
||||
# Append last column of df to be filtered which corresponds to: Volume
|
||||
ln_col_idx.append(5)
|
||||
# Slice dataframe from the starting date YYYY-MM-DD selected
|
||||
df_stock = df_stock[ns_parser.s_start_date :]
|
||||
|
||||
@@ -26,7 +26,7 @@ class OptionsController:
|
||||
self.yf_ticker_data = yf.Ticker(self.ticker)
|
||||
self.expiry_date = self.yf_ticker_data.options[0]
|
||||
self.options = self.yf_ticker_data.option_chain(self.expiry_date)
|
||||
self.last_adj_close_price = stock["5. adjusted close"].values[-1]
|
||||
self.last_adj_close_price = stock["Adj Close"].values[-1]
|
||||
|
||||
self.op_parser = argparse.ArgumentParser(add_help=False, prog="op")
|
||||
self.op_parser.add_argument(
|
||||
@@ -82,6 +82,9 @@ class OptionsController:
|
||||
@staticmethod
|
||||
def print_help(expiry_date):
|
||||
"""Print help."""
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/options"
|
||||
)
|
||||
print("\nOptions:")
|
||||
print(" help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
|
||||
@@ -30,6 +30,9 @@ class PortfolioController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/portfolio_analysis"
|
||||
)
|
||||
print("\nPortfolio Analysis:")
|
||||
print(" help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
|
||||
@@ -49,6 +49,9 @@ class PortfolioOptimization:
|
||||
@staticmethod
|
||||
def print_help(tickers: List[str]):
|
||||
"""Print help"""
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/portfolio_optimization"
|
||||
)
|
||||
print("\nPortfolio Optimization:")
|
||||
print(" help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
|
||||
@@ -151,15 +151,15 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
# Machine Learning model
|
||||
if ns_parser.s_order:
|
||||
t_order = tuple(int(ord) for ord in ns_parser.s_order.split(","))
|
||||
model = ARIMA(df_stock["5. adjusted close"].values, order=t_order).fit()
|
||||
model = ARIMA(df_stock["Adj Close"].values, order=t_order).fit()
|
||||
l_predictions = model.predict(
|
||||
start=len(df_stock["5. adjusted close"]) + 1,
|
||||
end=len(df_stock["5. adjusted close"]) + ns_parser.n_days,
|
||||
start=len(df_stock["Adj Close"]) + 1,
|
||||
end=len(df_stock["Adj Close"]) + ns_parser.n_days,
|
||||
)
|
||||
else:
|
||||
if ns_parser.b_seasonal:
|
||||
model = pmdarima.auto_arima(
|
||||
df_stock["5. adjusted close"].values,
|
||||
df_stock["Adj Close"].values,
|
||||
error_action="ignore",
|
||||
seasonal=True,
|
||||
m=5,
|
||||
@@ -167,7 +167,7 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
)
|
||||
else:
|
||||
model = pmdarima.auto_arima(
|
||||
df_stock["5. adjusted close"].values,
|
||||
df_stock["Adj Close"].values,
|
||||
error_action="ignore",
|
||||
seasonal=False,
|
||||
information_criteria=ns_parser.s_ic,
|
||||
@@ -178,7 +178,7 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
|
||||
# Prediction data
|
||||
l_pred_days = get_next_stock_market_days(
|
||||
last_stock_day=df_stock["5. adjusted close"].index[-1],
|
||||
last_stock_day=df_stock["Adj Close"].index[-1],
|
||||
n_next_days=ns_parser.n_days,
|
||||
)
|
||||
df_pred = pd.Series(l_predictions, index=l_pred_days, name="Price")
|
||||
@@ -189,7 +189,7 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
|
||||
# Plotting
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"], lw=2)
|
||||
if ns_parser.s_order:
|
||||
# BACKTESTING
|
||||
if ns_parser.s_end_date:
|
||||
@@ -220,7 +220,7 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2)
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_pred.index[0]],
|
||||
[df_stock["5. adjusted close"].values[-1], df_pred.values[0]],
|
||||
[df_stock["Adj Close"].values[-1], df_pred.values[0]],
|
||||
lw=1,
|
||||
c="tab:green",
|
||||
linestyle="--",
|
||||
@@ -238,7 +238,7 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
if ns_parser.s_end_date:
|
||||
plt.plot(
|
||||
df_future.index,
|
||||
df_future["5. adjusted close"],
|
||||
df_future["Adj Close"],
|
||||
lw=2,
|
||||
c="tab:blue",
|
||||
ls="--",
|
||||
@@ -246,8 +246,8 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_future.index[0]],
|
||||
[
|
||||
df_stock["5. adjusted close"].values[-1],
|
||||
df_future["5. adjusted close"].values[0],
|
||||
df_stock["Adj Close"].values[-1],
|
||||
df_future["Adj Close"].values[0],
|
||||
],
|
||||
lw=1,
|
||||
c="tab:blue",
|
||||
@@ -265,20 +265,18 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
plt.subplot(211)
|
||||
plt.plot(
|
||||
df_future.index,
|
||||
df_future["5. adjusted close"],
|
||||
df_future["Adj Close"],
|
||||
lw=2,
|
||||
c="tab:blue",
|
||||
ls="--",
|
||||
)
|
||||
plt.plot(df_pred.index, df_pred, lw=2, c="green")
|
||||
plt.scatter(
|
||||
df_future.index, df_future["5. adjusted close"], c="tab:blue", lw=3
|
||||
)
|
||||
plt.scatter(df_future.index, df_future["Adj Close"], c="tab:blue", lw=3)
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_future.index[0]],
|
||||
[
|
||||
df_stock["5. adjusted close"].values[-1],
|
||||
df_future["5. adjusted close"].values[0],
|
||||
df_stock["Adj Close"].values[-1],
|
||||
df_future["Adj Close"].values[0],
|
||||
],
|
||||
lw=2,
|
||||
c="tab:blue",
|
||||
@@ -287,7 +285,7 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
plt.scatter(df_pred.index, df_pred, c="green", lw=3)
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_pred.index[0]],
|
||||
[df_stock["5. adjusted close"].values[-1], df_pred.values[0]],
|
||||
[df_stock["Adj Close"].values[-1], df_pred.values[0]],
|
||||
lw=2,
|
||||
c="green",
|
||||
ls="--",
|
||||
@@ -310,16 +308,16 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
plt.plot(
|
||||
df_future.index,
|
||||
100
|
||||
* (df_pred.values - df_future["5. adjusted close"].values)
|
||||
/ df_future["5. adjusted close"].values,
|
||||
* (df_pred.values - df_future["Adj Close"].values)
|
||||
/ df_future["Adj Close"].values,
|
||||
lw=2,
|
||||
c="red",
|
||||
)
|
||||
plt.scatter(
|
||||
df_future.index,
|
||||
100
|
||||
* (df_pred.values - df_future["5. adjusted close"].values)
|
||||
/ df_future["5. adjusted close"].values,
|
||||
* (df_pred.values - df_future["Adj Close"].values)
|
||||
/ df_future["Adj Close"].values,
|
||||
c="red",
|
||||
lw=5,
|
||||
)
|
||||
@@ -329,8 +327,8 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
[
|
||||
0,
|
||||
100
|
||||
* (df_pred.values[0] - df_future["5. adjusted close"].values[0])
|
||||
/ df_future["5. adjusted close"].values[0],
|
||||
* (df_pred.values[0] - df_future["Adj Close"].values[0])
|
||||
/ df_future["Adj Close"].values[0],
|
||||
],
|
||||
lw=2,
|
||||
ls="--",
|
||||
@@ -356,7 +354,7 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
# Refactor prediction dataframe for backtesting print
|
||||
df_pred.name = "Prediction"
|
||||
df_pred = df_pred.to_frame()
|
||||
df_pred["Real"] = df_future["5. adjusted close"]
|
||||
df_pred["Real"] = df_future["Adj Close"]
|
||||
|
||||
if gtff.USE_COLOR:
|
||||
|
||||
@@ -376,7 +374,7 @@ def arima(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
|
||||
else:
|
||||
# Print prediction data
|
||||
print_pretty_prediction(df_pred, df_stock["5. adjusted close"].values[-1])
|
||||
print_pretty_prediction(df_pred, df_stock["Adj Close"].values[-1])
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -168,7 +168,7 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
|
||||
# Get ETS model
|
||||
model, title = get_exponential_smoothing_model(
|
||||
df_stock["5. adjusted close"].values,
|
||||
df_stock["Adj Close"].values,
|
||||
ns_parser.trend,
|
||||
ns_parser.seasonal,
|
||||
ns_parser.seasonal_periods,
|
||||
@@ -178,7 +178,7 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
forecast = [i if i > 0 else 0 for i in model.forecast(ns_parser.n_days)]
|
||||
|
||||
l_pred_days = get_next_stock_market_days(
|
||||
last_stock_day=df_stock["5. adjusted close"].index[-1],
|
||||
last_stock_day=df_stock["Adj Close"].index[-1],
|
||||
n_next_days=ns_parser.n_days,
|
||||
)
|
||||
df_pred = pd.Series(forecast, index=l_pred_days, name="Price")
|
||||
@@ -197,7 +197,7 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
|
||||
# Plotting
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"], lw=2)
|
||||
# BACKTESTING
|
||||
if ns_parser.s_end_date:
|
||||
plt.title(f"BACKTESTING: {title} on {s_ticker}")
|
||||
@@ -217,7 +217,7 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
)
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_pred.index[0]],
|
||||
[df_stock["5. adjusted close"].values[-1], df_pred.values[0]],
|
||||
[df_stock["Adj Close"].values[-1], df_pred.values[0]],
|
||||
lw=1,
|
||||
c="tab:green",
|
||||
linestyle="--",
|
||||
@@ -243,7 +243,7 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
if ns_parser.s_end_date:
|
||||
plt.plot(
|
||||
df_future.index,
|
||||
df_future["5. adjusted close"],
|
||||
df_future["Adj Close"],
|
||||
lw=2,
|
||||
c="tab:blue",
|
||||
ls="--",
|
||||
@@ -251,8 +251,8 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_future.index[0]],
|
||||
[
|
||||
df_stock["5. adjusted close"].values[-1],
|
||||
df_future["5. adjusted close"].values[0],
|
||||
df_stock["Adj Close"].values[-1],
|
||||
df_future["Adj Close"].values[0],
|
||||
],
|
||||
lw=1,
|
||||
c="tab:blue",
|
||||
@@ -270,7 +270,7 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
plt.subplot(211)
|
||||
plt.plot(
|
||||
df_future.index,
|
||||
df_future["5. adjusted close"],
|
||||
df_future["Adj Close"],
|
||||
lw=2,
|
||||
c="tab:blue",
|
||||
ls="--",
|
||||
@@ -278,15 +278,15 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
plt.plot(df_pred.index, df_pred, lw=2, c="green")
|
||||
plt.scatter(
|
||||
df_future.index,
|
||||
df_future["5. adjusted close"],
|
||||
df_future["Adj Close"],
|
||||
c="tab:blue",
|
||||
lw=3,
|
||||
)
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_future.index[0]],
|
||||
[
|
||||
df_stock["5. adjusted close"].values[-1],
|
||||
df_future["5. adjusted close"].values[0],
|
||||
df_stock["Adj Close"].values[-1],
|
||||
df_future["Adj Close"].values[0],
|
||||
],
|
||||
lw=2,
|
||||
c="tab:blue",
|
||||
@@ -295,7 +295,7 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
plt.scatter(df_pred.index, df_pred, c="green", lw=3)
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_pred.index[0]],
|
||||
[df_stock["5. adjusted close"].values[-1], df_pred.values[0]],
|
||||
[df_stock["Adj Close"].values[-1], df_pred.values[0]],
|
||||
lw=2,
|
||||
c="green",
|
||||
ls="--",
|
||||
@@ -319,16 +319,16 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
plt.plot(
|
||||
df_future.index,
|
||||
100
|
||||
* (df_pred.values - df_future["5. adjusted close"].values)
|
||||
/ df_future["5. adjusted close"].values,
|
||||
* (df_pred.values - df_future["Adj Close"].values)
|
||||
/ df_future["Adj Close"].values,
|
||||
lw=2,
|
||||
c="red",
|
||||
)
|
||||
plt.scatter(
|
||||
df_future.index,
|
||||
100
|
||||
* (df_pred.values - df_future["5. adjusted close"].values)
|
||||
/ df_future["5. adjusted close"].values,
|
||||
* (df_pred.values - df_future["Adj Close"].values)
|
||||
/ df_future["Adj Close"].values,
|
||||
c="red",
|
||||
lw=5,
|
||||
)
|
||||
@@ -338,11 +338,8 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
[
|
||||
0,
|
||||
100
|
||||
* (
|
||||
df_pred.values[0]
|
||||
- df_future["5. adjusted close"].values[0]
|
||||
)
|
||||
/ df_future["5. adjusted close"].values[0],
|
||||
* (df_pred.values[0] - df_future["Adj Close"].values[0])
|
||||
/ df_future["Adj Close"].values[0],
|
||||
],
|
||||
lw=2,
|
||||
ls="--",
|
||||
@@ -369,7 +366,7 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
# Refactor prediction dataframe for backtesting print
|
||||
df_pred.name = "Prediction"
|
||||
df_pred = df_pred.to_frame()
|
||||
df_pred["Real"] = df_future["5. adjusted close"]
|
||||
df_pred["Real"] = df_future["Adj Close"]
|
||||
|
||||
if gtff.USE_COLOR:
|
||||
|
||||
@@ -391,9 +388,7 @@ def exponential_smoothing(other_args: List[str], s_ticker: str, df_stock: pd.Dat
|
||||
|
||||
else:
|
||||
# Print prediction data
|
||||
print_pretty_prediction(
|
||||
df_pred, df_stock["5. adjusted close"].values[-1]
|
||||
)
|
||||
print_pretty_prediction(df_pred, df_stock["Adj Close"].values[-1])
|
||||
print("")
|
||||
|
||||
else:
|
||||
|
||||
@@ -136,7 +136,7 @@ def k_nearest_neighbors(other_args: List[str], s_ticker: str, df_stock: pd.DataF
|
||||
dates_forecast_input,
|
||||
scaler,
|
||||
is_error,
|
||||
) = prepare_scale_train_valid_test(df_stock["5. adjusted close"], ns_parser)
|
||||
) = prepare_scale_train_valid_test(df_stock["Adj Close"], ns_parser)
|
||||
if is_error:
|
||||
print("Error preparing data")
|
||||
return
|
||||
@@ -161,9 +161,7 @@ def k_nearest_neighbors(other_args: List[str], s_ticker: str, df_stock: pd.DataF
|
||||
forecast_data_df = pd.DataFrame(
|
||||
[i if i > 0 else 0 for i in forecast_data.T], index=future_dates
|
||||
)
|
||||
print_pretty_prediction(
|
||||
forecast_data_df[0], df_stock["5. adjusted close"].values[-1]
|
||||
)
|
||||
print_pretty_prediction(forecast_data_df[0], df_stock["Adj Close"].values[-1])
|
||||
plot_data_predictions(
|
||||
df_stock,
|
||||
preds,
|
||||
|
||||
@@ -171,7 +171,7 @@ def mlp(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
dates_forecast_input,
|
||||
scaler,
|
||||
is_error,
|
||||
) = prepare_scale_train_valid_test(df_stock["5. adjusted close"], ns_parser)
|
||||
) = prepare_scale_train_valid_test(df_stock["Adj Close"], ns_parser)
|
||||
if is_error:
|
||||
return
|
||||
print(
|
||||
@@ -222,11 +222,11 @@ def mlp(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
if ns_parser.n_loops > 1:
|
||||
forecast_data_df["Median"] = forecast_data_df.median(axis=1)
|
||||
print_pretty_prediction(
|
||||
forecast_data_df["Median"], df_stock["5. adjusted close"].values[-1]
|
||||
forecast_data_df["Median"], df_stock["Adj Close"].values[-1]
|
||||
)
|
||||
else:
|
||||
print_pretty_prediction(
|
||||
forecast_data_df[0], df_stock["5. adjusted close"].values[-1]
|
||||
forecast_data_df[0], df_stock["Adj Close"].values[-1]
|
||||
)
|
||||
plot_data_predictions(
|
||||
df_stock,
|
||||
@@ -283,7 +283,7 @@ def rnn(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
dates_forecast_input,
|
||||
scaler,
|
||||
is_error,
|
||||
) = prepare_scale_train_valid_test(df_stock["5. adjusted close"], ns_parser)
|
||||
) = prepare_scale_train_valid_test(df_stock["Adj Close"], ns_parser)
|
||||
if is_error:
|
||||
return
|
||||
print(
|
||||
@@ -333,11 +333,11 @@ def rnn(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
if ns_parser.n_loops > 1:
|
||||
forecast_data_df["Median"] = forecast_data_df.median(axis=1)
|
||||
print_pretty_prediction(
|
||||
forecast_data_df["Median"], df_stock["5. adjusted close"].values[-1]
|
||||
forecast_data_df["Median"], df_stock["Adj Close"].values[-1]
|
||||
)
|
||||
else:
|
||||
print_pretty_prediction(
|
||||
forecast_data_df[0], df_stock["5. adjusted close"].values[-1]
|
||||
forecast_data_df[0], df_stock["Adj Close"].values[-1]
|
||||
)
|
||||
plot_data_predictions(
|
||||
df_stock,
|
||||
@@ -392,7 +392,7 @@ def lstm(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
dates_forecast_input,
|
||||
scaler,
|
||||
is_error,
|
||||
) = prepare_scale_train_valid_test(df_stock["5. adjusted close"], ns_parser)
|
||||
) = prepare_scale_train_valid_test(df_stock["Adj Close"], ns_parser)
|
||||
if is_error:
|
||||
return
|
||||
print(
|
||||
@@ -444,11 +444,11 @@ def lstm(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
if ns_parser.n_loops > 1:
|
||||
forecast_data_df["Median"] = forecast_data_df.median(axis=1)
|
||||
print_pretty_prediction(
|
||||
forecast_data_df["Median"], df_stock["5. adjusted close"].values[-1]
|
||||
forecast_data_df["Median"], df_stock["Adj Close"].values[-1]
|
||||
)
|
||||
else:
|
||||
print_pretty_prediction(
|
||||
forecast_data_df[0], df_stock["5. adjusted close"].values[-1]
|
||||
forecast_data_df[0], df_stock["Adj Close"].values[-1]
|
||||
)
|
||||
plot_data_predictions(
|
||||
df_stock,
|
||||
@@ -504,7 +504,7 @@ def conv1d(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
dates_forecast_input,
|
||||
scaler,
|
||||
is_error,
|
||||
) = prepare_scale_train_valid_test(df_stock["5. adjusted close"], ns_parser)
|
||||
) = prepare_scale_train_valid_test(df_stock["Adj Close"], ns_parser)
|
||||
if is_error:
|
||||
return
|
||||
print(
|
||||
@@ -556,11 +556,11 @@ def conv1d(other_args: List[str], s_ticker: str, df_stock: pd.DataFrame):
|
||||
if ns_parser.n_loops > 1:
|
||||
forecast_data_df["Median"] = forecast_data_df.median(axis=1)
|
||||
print_pretty_prediction(
|
||||
forecast_data_df["Median"], df_stock["5. adjusted close"].values[-1]
|
||||
forecast_data_df["Median"], df_stock["Adj Close"].values[-1]
|
||||
)
|
||||
else:
|
||||
print_pretty_prediction(
|
||||
forecast_data_df[0], df_stock["5. adjusted close"].values[-1]
|
||||
forecast_data_df[0], df_stock["Adj Close"].values[-1]
|
||||
)
|
||||
plot_data_predictions(
|
||||
df_stock,
|
||||
|
||||
@@ -61,7 +61,9 @@ class PredictionTechniquesController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/prediction_techniques"
|
||||
)
|
||||
s_intraday = (f"Intraday {self.interval}", "Daily")[self.interval == "1440min"]
|
||||
|
||||
if self.start:
|
||||
|
||||
@@ -399,7 +399,7 @@ def plot_data_predictions(
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
plt.plot(
|
||||
df_stock.index,
|
||||
df_stock["5. adjusted close"].values,
|
||||
df_stock["Adj Close"].values,
|
||||
"-ob",
|
||||
lw=1,
|
||||
ms=2,
|
||||
|
||||
@@ -151,7 +151,7 @@ def regression(
|
||||
|
||||
# Split training data
|
||||
stock_x, stock_y = splitTrain.split_train(
|
||||
df_stock["5. adjusted close"].values,
|
||||
df_stock["Adj Close"].values,
|
||||
ns_parser.n_inputs,
|
||||
ns_parser.n_days,
|
||||
ns_parser.n_jumps,
|
||||
@@ -175,22 +175,20 @@ def regression(
|
||||
l_predictions = [
|
||||
i if i > 0 else 0
|
||||
for i in model.predict(
|
||||
df_stock["5. adjusted close"]
|
||||
.values[-ns_parser.n_inputs :]
|
||||
.reshape(1, -1)
|
||||
df_stock["Adj Close"].values[-ns_parser.n_inputs :].reshape(1, -1)
|
||||
)[0]
|
||||
]
|
||||
|
||||
# Prediction data
|
||||
l_pred_days = get_next_stock_market_days(
|
||||
last_stock_day=df_stock["5. adjusted close"].index[-1],
|
||||
last_stock_day=df_stock["Adj Close"].index[-1],
|
||||
n_next_days=ns_parser.n_days,
|
||||
)
|
||||
df_pred = pd.Series(l_predictions, index=l_pred_days, name="Price")
|
||||
|
||||
# Plotting
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"], lw=2)
|
||||
# BACKTESTING
|
||||
if ns_parser.s_end_date:
|
||||
plt.title(
|
||||
@@ -210,7 +208,7 @@ def regression(
|
||||
plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2)
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_pred.index[0]],
|
||||
[df_stock["5. adjusted close"].values[-1], df_pred.values[0]],
|
||||
[df_stock["Adj Close"].values[-1], df_pred.values[0]],
|
||||
lw=1,
|
||||
c="tab:green",
|
||||
linestyle="--",
|
||||
@@ -228,7 +226,7 @@ def regression(
|
||||
if ns_parser.s_end_date:
|
||||
plt.plot(
|
||||
df_future.index,
|
||||
df_future["5. adjusted close"],
|
||||
df_future["Adj Close"],
|
||||
lw=2,
|
||||
c="tab:blue",
|
||||
ls="--",
|
||||
@@ -236,8 +234,8 @@ def regression(
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_future.index[0]],
|
||||
[
|
||||
df_stock["5. adjusted close"].values[-1],
|
||||
df_future["5. adjusted close"].values[0],
|
||||
df_stock["Adj Close"].values[-1],
|
||||
df_future["Adj Close"].values[0],
|
||||
],
|
||||
lw=1,
|
||||
c="tab:blue",
|
||||
@@ -255,20 +253,18 @@ def regression(
|
||||
plt.subplot(211)
|
||||
plt.plot(
|
||||
df_future.index,
|
||||
df_future["5. adjusted close"],
|
||||
df_future["Adj Close"],
|
||||
lw=2,
|
||||
c="tab:blue",
|
||||
ls="--",
|
||||
)
|
||||
plt.plot(df_pred.index, df_pred, lw=2, c="green")
|
||||
plt.scatter(
|
||||
df_future.index, df_future["5. adjusted close"], c="tab:blue", lw=3
|
||||
)
|
||||
plt.scatter(df_future.index, df_future["Adj Close"], c="tab:blue", lw=3)
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_future.index[0]],
|
||||
[
|
||||
df_stock["5. adjusted close"].values[-1],
|
||||
df_future["5. adjusted close"].values[0],
|
||||
df_stock["Adj Close"].values[-1],
|
||||
df_future["Adj Close"].values[0],
|
||||
],
|
||||
lw=2,
|
||||
c="tab:blue",
|
||||
@@ -277,7 +273,7 @@ def regression(
|
||||
plt.scatter(df_pred.index, df_pred, c="green", lw=3)
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_pred.index[0]],
|
||||
[df_stock["5. adjusted close"].values[-1], df_pred.values[0]],
|
||||
[df_stock["Adj Close"].values[-1], df_pred.values[0]],
|
||||
lw=2,
|
||||
c="green",
|
||||
ls="--",
|
||||
@@ -300,16 +296,16 @@ def regression(
|
||||
plt.plot(
|
||||
df_future.index,
|
||||
100
|
||||
* (df_pred.values - df_future["5. adjusted close"].values)
|
||||
/ df_future["5. adjusted close"].values,
|
||||
* (df_pred.values - df_future["Adj Close"].values)
|
||||
/ df_future["Adj Close"].values,
|
||||
lw=2,
|
||||
c="red",
|
||||
)
|
||||
plt.scatter(
|
||||
df_future.index,
|
||||
100
|
||||
* (df_pred.values - df_future["5. adjusted close"].values)
|
||||
/ df_future["5. adjusted close"].values,
|
||||
* (df_pred.values - df_future["Adj Close"].values)
|
||||
/ df_future["Adj Close"].values,
|
||||
c="red",
|
||||
lw=5,
|
||||
)
|
||||
@@ -319,8 +315,8 @@ def regression(
|
||||
[
|
||||
0,
|
||||
100
|
||||
* (df_pred.values[0] - df_future["5. adjusted close"].values[0])
|
||||
/ df_future["5. adjusted close"].values[0],
|
||||
* (df_pred.values[0] - df_future["Adj Close"].values[0])
|
||||
/ df_future["Adj Close"].values[0],
|
||||
],
|
||||
lw=2,
|
||||
ls="--",
|
||||
@@ -346,7 +342,7 @@ def regression(
|
||||
# Refactor prediction dataframe for backtesting print
|
||||
df_pred.name = "Prediction"
|
||||
df_pred = df_pred.to_frame()
|
||||
df_pred["Real"] = df_future["5. adjusted close"]
|
||||
df_pred["Real"] = df_future["Adj Close"]
|
||||
|
||||
if gtff.USE_COLOR:
|
||||
|
||||
@@ -366,7 +362,7 @@ def regression(
|
||||
|
||||
else:
|
||||
# Print prediction data
|
||||
print_pretty_prediction(df_pred, df_stock["5. adjusted close"].values[-1])
|
||||
print_pretty_prediction(df_pred, df_stock["Adj Close"].values[-1])
|
||||
print("")
|
||||
|
||||
except SystemExit:
|
||||
|
||||
@@ -49,10 +49,11 @@ class ResearchController:
|
||||
choices=self.CHOICES,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/research"
|
||||
)
|
||||
s_intraday = (f"Intraday {self.interval}", "Daily")[self.interval == "1440min"]
|
||||
|
||||
if self.start:
|
||||
@@ -107,7 +108,7 @@ class ResearchController:
|
||||
|
||||
def call_help(self, _):
|
||||
"""Process Help command"""
|
||||
self.print_help(self)
|
||||
self.print_help()
|
||||
|
||||
def call_q(self, _):
|
||||
"""Process Q command - quit the menu"""
|
||||
|
||||
@@ -46,7 +46,7 @@ class ResidualsController:
|
||||
self.ticker = ticker
|
||||
self.start = start
|
||||
self.interval = interval
|
||||
self.stock = stock["5. adjusted close"]
|
||||
self.stock = stock["Adj Close"]
|
||||
|
||||
self.model_name: str = "None"
|
||||
self.model: pd.Series = None
|
||||
@@ -60,7 +60,9 @@ class ResidualsController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/residuals_analysis"
|
||||
)
|
||||
s_intraday = (f"Intraday {self.interval}", "Daily")[self.interval == "1440min"]
|
||||
|
||||
if self.start:
|
||||
|
||||
@@ -3,7 +3,6 @@ __docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
import webbrowser
|
||||
from typing import List
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.helper_funcs import get_flair
|
||||
@@ -37,7 +36,9 @@ class ResourceCollectionController:
|
||||
@staticmethod
|
||||
def print_help():
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/resource_collection"
|
||||
)
|
||||
print("\nResources:")
|
||||
print(" help show this behavioural analysis menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
@@ -82,32 +83,32 @@ class ResourceCollectionController:
|
||||
"""Process Quit command - quit the program"""
|
||||
return True
|
||||
|
||||
def call_hfletters(self, other_args: List[str]):
|
||||
def call_hfletters(self, _):
|
||||
"""Process hfletters command"""
|
||||
webbrowser.open("https://miltonfmr.com/hedge-fund-letters/")
|
||||
print("")
|
||||
|
||||
def call_arxiv(self, other_args: List[str]):
|
||||
def call_arxiv(self, _):
|
||||
"""Process arxiv command"""
|
||||
webbrowser.open("https://arxiv.org")
|
||||
print("")
|
||||
|
||||
def call_finra(self, other_args: List[str]):
|
||||
def call_finra(self, _):
|
||||
"""Process finra command"""
|
||||
webbrowser.open("https://www.finra.org/#/")
|
||||
print("")
|
||||
|
||||
def call_edgar(self, other_args: List[str]):
|
||||
def call_edgar(self, _):
|
||||
"""Process edgar command"""
|
||||
webbrowser.open("https://www.sec.gov/edgar.shtml")
|
||||
print("")
|
||||
|
||||
def call_fred(self, other_args: List[str]):
|
||||
def call_fred(self, _):
|
||||
"""Process fred command"""
|
||||
webbrowser.open("https://fred.stlouisfed.org")
|
||||
print("")
|
||||
|
||||
def call_learn(self, other_args: List[str]):
|
||||
def call_learn(self, _):
|
||||
"""Process learn command"""
|
||||
webbrowser.open("https://moongangcapital.com/free-stock-market-resources/")
|
||||
print("")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Author of preset: Traceabl3
|
||||
l# Author of preset: Traceabl3
|
||||
# Description: When the 50 sma crosses below the 200 sma. More information can be found in https://www.investopedia.com/terms/d/deathcross.asp
|
||||
|
||||
[General]
|
||||
|
||||
@@ -53,7 +53,9 @@ class ScreenerController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/screener"
|
||||
)
|
||||
print("\nScreener:")
|
||||
print(" help show this screener menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
|
||||
@@ -62,9 +62,9 @@ def cci(l_args, s_ticker, s_interval, df_stock):
|
||||
# Daily
|
||||
if s_interval == "1440min":
|
||||
df_ta = ta.cci(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["5. adjusted close"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Adj Close"],
|
||||
length=ns_parser.n_length,
|
||||
scalar=ns_parser.n_scalar,
|
||||
offset=ns_parser.n_offset,
|
||||
@@ -73,9 +73,9 @@ def cci(l_args, s_ticker, s_interval, df_stock):
|
||||
# Intraday
|
||||
else:
|
||||
df_ta = ta.cci(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["4. close"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Close"],
|
||||
length=ns_parser.n_length,
|
||||
scalar=ns_parser.n_scalar,
|
||||
offset=ns_parser.n_offset,
|
||||
@@ -85,9 +85,9 @@ def cci(l_args, s_ticker, s_interval, df_stock):
|
||||
plt.subplot(211)
|
||||
plt.title(f"Commodity Channel Index (CCI) on {s_ticker}")
|
||||
if s_interval == "1440min":
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"].values, "k", lw=2)
|
||||
else:
|
||||
plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Close"].values, "k", lw=2)
|
||||
plt.xlim(df_stock.index[0], df_stock.index[-1])
|
||||
plt.ylabel("Share Price ($)")
|
||||
plt.grid(b=True, which="major", color="#666666", linestyle="-")
|
||||
@@ -181,7 +181,7 @@ def macd(l_args, s_ticker, s_interval, df_stock):
|
||||
# Daily
|
||||
if s_interval == "1440min":
|
||||
df_ta = ta.macd(
|
||||
df_stock["5. adjusted close"],
|
||||
df_stock["Adj Close"],
|
||||
fast=ns_parser.n_fast,
|
||||
slow=ns_parser.n_slow,
|
||||
signal=ns_parser.n_signal,
|
||||
@@ -191,7 +191,7 @@ def macd(l_args, s_ticker, s_interval, df_stock):
|
||||
# Intraday
|
||||
else:
|
||||
df_ta = ta.macd(
|
||||
df_stock["4. close"],
|
||||
df_stock["Close"],
|
||||
fast=ns_parser.n_fast,
|
||||
slow=ns_parser.n_slow,
|
||||
signal=ns_parser.n_signal,
|
||||
@@ -202,9 +202,9 @@ def macd(l_args, s_ticker, s_interval, df_stock):
|
||||
plt.subplot(211)
|
||||
plt.title(f"Moving Average Convergence Divergence (MACD) on {s_ticker}")
|
||||
if s_interval == "1440min":
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"].values, "k", lw=2)
|
||||
else:
|
||||
plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Close"].values, "k", lw=2)
|
||||
plt.xlim(df_stock.index[0], df_stock.index[-1])
|
||||
plt.ylabel("Share Price ($)")
|
||||
plt.grid(b=True, which="major", color="#666666", linestyle="-")
|
||||
@@ -296,7 +296,7 @@ def rsi(l_args, s_ticker, s_interval, df_stock):
|
||||
# Daily
|
||||
if s_interval == "1440min":
|
||||
df_ta = ta.rsi(
|
||||
df_stock["5. adjusted close"],
|
||||
df_stock["Adj Close"],
|
||||
length=ns_parser.n_length,
|
||||
scalar=ns_parser.n_scalar,
|
||||
drift=ns_parser.n_drift,
|
||||
@@ -306,7 +306,7 @@ def rsi(l_args, s_ticker, s_interval, df_stock):
|
||||
# Intraday
|
||||
else:
|
||||
df_ta = ta.rsi(
|
||||
df_stock["4. close"],
|
||||
df_stock["Close"],
|
||||
length=ns_parser.n_length,
|
||||
scalar=ns_parser.n_scalar,
|
||||
drift=ns_parser.n_drift,
|
||||
@@ -316,9 +316,9 @@ def rsi(l_args, s_ticker, s_interval, df_stock):
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
plt.subplot(211)
|
||||
if s_interval == "1440min":
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"].values, "k", lw=2)
|
||||
else:
|
||||
plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Close"].values, "k", lw=2)
|
||||
plt.title(f"Relative Strength Index (RSI) on {s_ticker}")
|
||||
plt.xlim(df_stock.index[0], df_stock.index[-1])
|
||||
plt.ylabel("Share Price ($)")
|
||||
@@ -411,9 +411,9 @@ def stoch(l_args, s_ticker, s_interval, df_stock):
|
||||
# Daily
|
||||
if s_interval == "1440min":
|
||||
df_ta = ta.stoch(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["5. adjusted close"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Adj Close"],
|
||||
k=ns_parser.n_fastkperiod,
|
||||
d=ns_parser.n_slowdperiod,
|
||||
smooth_k=ns_parser.n_slowkperiod,
|
||||
@@ -423,9 +423,9 @@ def stoch(l_args, s_ticker, s_interval, df_stock):
|
||||
# Intraday
|
||||
else:
|
||||
df_ta = ta.stoch(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["4. close"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Close"],
|
||||
k=ns_parser.n_fastkperiod,
|
||||
d=ns_parser.n_slowdperiod,
|
||||
smooth_k=ns_parser.n_slowkperiod,
|
||||
@@ -435,9 +435,9 @@ def stoch(l_args, s_ticker, s_interval, df_stock):
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
plt.subplot(211)
|
||||
if s_interval == "1440min":
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"].values, "k", lw=2)
|
||||
else:
|
||||
plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Close"].values, "k", lw=2)
|
||||
plt.title(f"Stochastic Relative Strength Index (STOCH RSI) on {s_ticker}")
|
||||
plt.xlim(df_stock.index[0], df_stock.index[-1])
|
||||
plt.ylabel("Share Price ($)")
|
||||
|
||||
@@ -56,7 +56,7 @@ def ema(l_args, s_ticker, s_interval, df_stock):
|
||||
# Daily
|
||||
if s_interval == "1440min":
|
||||
df_ta = ta.ema(
|
||||
df_stock["5. adjusted close"],
|
||||
df_stock["Adj Close"],
|
||||
length=ns_parser.n_length,
|
||||
offset=ns_parser.n_offset,
|
||||
).dropna()
|
||||
@@ -64,7 +64,7 @@ def ema(l_args, s_ticker, s_interval, df_stock):
|
||||
# Intraday
|
||||
else:
|
||||
df_ta = ta.ema(
|
||||
df_stock["4. close"],
|
||||
df_stock["Close"],
|
||||
length=ns_parser.n_length,
|
||||
offset=ns_parser.n_offset,
|
||||
).dropna()
|
||||
@@ -73,18 +73,18 @@ def ema(l_args, s_ticker, s_interval, df_stock):
|
||||
plt.title(f"{ns_parser.n_length} EMA on {s_ticker}")
|
||||
if s_interval == "1440min":
|
||||
plt.plot(
|
||||
df_stock["5. adjusted close"].index,
|
||||
df_stock["5. adjusted close"].values,
|
||||
df_stock["Adj Close"].index,
|
||||
df_stock["Adj Close"].values,
|
||||
"k",
|
||||
lw=3,
|
||||
)
|
||||
plt.xlim(
|
||||
df_stock["5. adjusted close"].index[0],
|
||||
df_stock["5. adjusted close"].index[-1],
|
||||
df_stock["Adj Close"].index[0],
|
||||
df_stock["Adj Close"].index[-1],
|
||||
)
|
||||
else:
|
||||
plt.plot(df_stock["4. close"].index, df_stock["4. close"].values, "k", lw=3)
|
||||
plt.xlim(df_stock["4. close"].index[0], df_stock["4. close"].index[-1])
|
||||
plt.plot(df_stock["Close"].index, df_stock["Close"].values, "k", lw=3)
|
||||
plt.xlim(df_stock["Close"].index[0], df_stock["Close"].index[-1])
|
||||
plt.xlabel("Time")
|
||||
plt.ylabel(f"Share Price of {s_ticker} ($)")
|
||||
plt.plot(df_ta.index, df_ta.values, c="tab:blue")
|
||||
@@ -152,21 +152,21 @@ def sma(l_args, s_ticker, s_interval, df_stock):
|
||||
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
if s_interval == "1440min":
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"].values, color="k")
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"].values, color="k")
|
||||
else:
|
||||
plt.plot(df_stock.index, df_stock["4. close"].values, color="k")
|
||||
plt.plot(df_stock.index, df_stock["Close"].values, color="k")
|
||||
l_legend = list()
|
||||
l_legend.append(s_ticker)
|
||||
for length in ns_parser.l_length:
|
||||
if s_interval == "1440min":
|
||||
df_ta = ta.sma(
|
||||
df_stock["5. adjusted close"],
|
||||
df_stock["Adj Close"],
|
||||
length=length,
|
||||
offset=ns_parser.n_offset,
|
||||
).dropna()
|
||||
else:
|
||||
df_ta = ta.sma(
|
||||
df_stock["4. close"], length=length, offset=ns_parser.n_offset
|
||||
df_stock["Close"], length=length, offset=ns_parser.n_offset
|
||||
).dropna()
|
||||
plt.plot(df_ta.index, df_ta.values)
|
||||
l_legend.append(f"{length} SMA")
|
||||
@@ -218,28 +218,28 @@ def vwap(l_args, s_ticker, s_interval, df_stock):
|
||||
# Daily
|
||||
if s_interval == "1440min":
|
||||
df_ta = ta.vwap(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["5. adjusted close"],
|
||||
volume=df_stock["6. volume"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Adj Close"],
|
||||
volume=df_stock["Volume"],
|
||||
offset=ns_parser.n_offset,
|
||||
)
|
||||
|
||||
# Intraday
|
||||
else:
|
||||
df_ta = ta.vwap(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["4. close"],
|
||||
volume=df_stock["5. volume"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Close"],
|
||||
volume=df_stock["Volume"],
|
||||
offset=ns_parser.n_offset,
|
||||
)
|
||||
|
||||
_, axPrice = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
if s_interval == "1440min":
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"].values, color="k")
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"].values, color="k")
|
||||
else:
|
||||
plt.plot(df_stock.index, df_stock["4. close"].values, color="k")
|
||||
plt.plot(df_stock.index, df_stock["Close"].values, color="k")
|
||||
plt.plot(df_ta.index, df_ta.values)
|
||||
plt.title(f"VWAP on {s_ticker}")
|
||||
plt.xlim(df_stock.index[0], df_stock.index[-1])
|
||||
@@ -247,10 +247,11 @@ def vwap(l_args, s_ticker, s_interval, df_stock):
|
||||
plt.ylabel("Share Price ($)")
|
||||
plt.legend([s_ticker, "VWAP"])
|
||||
_ = axPrice.twinx()
|
||||
|
||||
if s_interval == "1440min":
|
||||
plt.bar(
|
||||
df_stock.index,
|
||||
df_stock["6. volume"].values,
|
||||
df_stock["Volume"].values,
|
||||
color="k",
|
||||
alpha=0.8,
|
||||
width=0.3,
|
||||
@@ -258,7 +259,7 @@ def vwap(l_args, s_ticker, s_interval, df_stock):
|
||||
else:
|
||||
plt.bar(
|
||||
df_stock.index,
|
||||
df_stock["5. volume"].values,
|
||||
df_stock["Volume"].values,
|
||||
color="k",
|
||||
alpha=0.8,
|
||||
width=0.3,
|
||||
|
||||
@@ -69,7 +69,9 @@ class TechnicalAnalysisController:
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/technical_analysis"
|
||||
)
|
||||
s_intraday = (f"Intraday {self.interval }", "Daily")[self.interval == "1440min"]
|
||||
|
||||
if self.start:
|
||||
|
||||
@@ -69,9 +69,9 @@ def adx(l_args, s_ticker, s_interval, df_stock):
|
||||
# Daily
|
||||
if s_interval == "1440min":
|
||||
df_ta = ta.adx(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["5. adjusted close"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Adj Close"],
|
||||
length=ns_parser.n_length,
|
||||
scalar=ns_parser.n_scalar,
|
||||
drift=ns_parser.n_drift,
|
||||
@@ -81,9 +81,9 @@ def adx(l_args, s_ticker, s_interval, df_stock):
|
||||
# Intraday
|
||||
else:
|
||||
df_ta = ta.adx(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["4. close"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Close"],
|
||||
length=ns_parser.n_length,
|
||||
scalar=ns_parser.n_scalar,
|
||||
drift=ns_parser.n_drift,
|
||||
@@ -102,7 +102,7 @@ def adx(l_args, s_ticker, s_interval, df_stock):
|
||||
def plot_adx(df_stock, s_ticker, df_ta):
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
plt.subplot(211)
|
||||
plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Close"].values, "k", lw=2)
|
||||
plt.title(f"Average Directional Movement Index (ADX) on {s_ticker}")
|
||||
plt.xlim(df_stock.index[0], df_stock.index[-1])
|
||||
plt.ylabel("Share Price ($)")
|
||||
@@ -186,8 +186,8 @@ def aroon(l_args, s_ticker, s_interval, df_stock):
|
||||
return
|
||||
|
||||
df_ta = ta.aroon(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
length=ns_parser.n_length,
|
||||
scalar=ns_parser.n_scalar,
|
||||
offset=ns_parser.n_offset,
|
||||
@@ -197,10 +197,10 @@ def aroon(l_args, s_ticker, s_interval, df_stock):
|
||||
plt.subplot(311)
|
||||
# Daily
|
||||
if s_interval == "1440min":
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"].values, "k", lw=2)
|
||||
# Intraday
|
||||
else:
|
||||
plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Close"].values, "k", lw=2)
|
||||
|
||||
plt.title(f"Aroon on {s_ticker}")
|
||||
plt.xlim(df_stock.index[0], df_stock.index[-1])
|
||||
|
||||
@@ -70,7 +70,7 @@ def bbands(l_args, s_ticker, s_interval, df_stock):
|
||||
# Daily
|
||||
if s_interval == "1440min":
|
||||
df_ta = ta.bbands(
|
||||
close=df_stock["5. adjusted close"],
|
||||
close=df_stock["Adj Close"],
|
||||
length=ns_parser.n_length,
|
||||
std=ns_parser.n_std,
|
||||
mamode=ns_parser.s_mamode,
|
||||
@@ -80,7 +80,7 @@ def bbands(l_args, s_ticker, s_interval, df_stock):
|
||||
# Intraday
|
||||
else:
|
||||
df_ta = ta.bbands(
|
||||
close=df_stock["4. close"],
|
||||
close=df_stock["Close"],
|
||||
length=ns_parser.n_length,
|
||||
std=ns_parser.n_std,
|
||||
mamode=ns_parser.s_mamode,
|
||||
@@ -89,11 +89,9 @@ def bbands(l_args, s_ticker, s_interval, df_stock):
|
||||
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
if s_ticker == "1440min":
|
||||
plt.plot(
|
||||
df_stock.index, df_stock["5. adjusted close"].values, color="k", lw=3
|
||||
)
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"].values, color="k", lw=3)
|
||||
else:
|
||||
plt.plot(df_stock.index, df_stock["4. close"].values, color="k", lw=3)
|
||||
plt.plot(df_stock.index, df_stock["Close"].values, color="k", lw=3)
|
||||
plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "r", lw=2)
|
||||
plt.plot(df_ta.index, df_ta.iloc[:, 1].values, "b", lw=1.5, ls="--")
|
||||
plt.plot(df_ta.index, df_ta.iloc[:, 2].values, "g", lw=2)
|
||||
|
||||
@@ -58,20 +58,20 @@ def ad(l_args, s_ticker, s_interval, df_stock):
|
||||
# Use open stock values
|
||||
if ns_parser.b_use_open:
|
||||
df_ta = ta.ad(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["5. adjusted close"],
|
||||
volume=df_stock["6. volume"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Adj Close"],
|
||||
volume=df_stock["Volume"],
|
||||
offset=ns_parser.n_offset,
|
||||
open_=df_stock["1. open"],
|
||||
open_=df_stock["Open"],
|
||||
).dropna()
|
||||
# Do not use open stock values
|
||||
else:
|
||||
df_ta = ta.ad(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["5. adjusted close"],
|
||||
volume=df_stock["6. volume"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Adj Close"],
|
||||
volume=df_stock["Volume"],
|
||||
offset=ns_parser.n_offset,
|
||||
).dropna()
|
||||
|
||||
@@ -80,29 +80,29 @@ def ad(l_args, s_ticker, s_interval, df_stock):
|
||||
# Use open stock values
|
||||
if ns_parser.b_use_open:
|
||||
df_ta = ta.ad(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["4. close"],
|
||||
volume=df_stock["5. volume"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Close"],
|
||||
volume=df_stock["Volume"],
|
||||
offset=ns_parser.n_offset,
|
||||
open_=df_stock["1. open"],
|
||||
open_=df_stock["Open"],
|
||||
).dropna()
|
||||
# Do not use open stock values
|
||||
else:
|
||||
df_ta = ta.ad(
|
||||
high=df_stock["2. high"],
|
||||
low=df_stock["3. low"],
|
||||
close=df_stock["4. close"],
|
||||
volume=df_stock["5. volume"],
|
||||
high=df_stock["High"],
|
||||
low=df_stock["Low"],
|
||||
close=df_stock["Close"],
|
||||
volume=df_stock["Volume"],
|
||||
offset=ns_parser.n_offset,
|
||||
).dropna()
|
||||
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
axPrice = plt.subplot(211)
|
||||
if s_interval == "1440min":
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"].values, "k", lw=2)
|
||||
else:
|
||||
plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Close"].values, "k", lw=2)
|
||||
plt.title(f"Accumulation/Distribution Line (AD) on {s_ticker}")
|
||||
plt.xlim(df_stock.index[0], df_stock.index[-1])
|
||||
plt.ylabel("Share Price ($)")
|
||||
@@ -113,7 +113,7 @@ def ad(l_args, s_ticker, s_interval, df_stock):
|
||||
if s_interval == "1440min":
|
||||
plt.bar(
|
||||
df_stock.index,
|
||||
df_stock["6. volume"].values,
|
||||
df_stock["Volume"].values,
|
||||
color="k",
|
||||
alpha=0.8,
|
||||
width=0.3,
|
||||
@@ -121,7 +121,7 @@ def ad(l_args, s_ticker, s_interval, df_stock):
|
||||
else:
|
||||
plt.bar(
|
||||
df_stock.index,
|
||||
df_stock["5. volume"].values,
|
||||
df_stock["Volume"].values,
|
||||
color="k",
|
||||
alpha=0.8,
|
||||
width=0.3,
|
||||
@@ -181,25 +181,25 @@ def obv(l_args, s_ticker, s_interval, df_stock):
|
||||
# Daily
|
||||
if s_interval == "1440min":
|
||||
df_ta = ta.obv(
|
||||
close=df_stock["5. adjusted close"],
|
||||
volume=df_stock["6. volume"],
|
||||
close=df_stock["Adj Close"],
|
||||
volume=df_stock["Volume"],
|
||||
offset=ns_parser.n_offset,
|
||||
).dropna()
|
||||
|
||||
# Intraday
|
||||
else:
|
||||
df_ta = ta.obv(
|
||||
close=df_stock["4. close"],
|
||||
volume=df_stock["5. volume"],
|
||||
close=df_stock["Close"],
|
||||
volume=df_stock["Volume"],
|
||||
offset=ns_parser.n_offset,
|
||||
).dropna()
|
||||
|
||||
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
axPrice = plt.subplot(211)
|
||||
if s_interval == "1440min":
|
||||
plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Adj Close"].values, "k", lw=2)
|
||||
else:
|
||||
plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2)
|
||||
plt.plot(df_stock.index, df_stock["Close"].values, "k", lw=2)
|
||||
plt.title(f"On-Balance Volume (OBV) on {s_ticker}")
|
||||
plt.xlim(df_stock.index[0], df_stock.index[-1])
|
||||
plt.ylabel("Share Price ($)")
|
||||
@@ -210,7 +210,7 @@ def obv(l_args, s_ticker, s_interval, df_stock):
|
||||
if s_interval == "1440min":
|
||||
plt.bar(
|
||||
df_stock.index,
|
||||
df_stock["6. volume"].values,
|
||||
df_stock["Volume"].values,
|
||||
color="k",
|
||||
alpha=0.8,
|
||||
width=0.3,
|
||||
@@ -218,7 +218,7 @@ def obv(l_args, s_ticker, s_interval, df_stock):
|
||||
else:
|
||||
plt.bar(
|
||||
df_stock.index,
|
||||
df_stock["5. volume"].values,
|
||||
df_stock["Volume"].values,
|
||||
color="k",
|
||||
alpha=0.8,
|
||||
width=0.3,
|
||||
|
||||
23
terminal.py
23
terminal.py
@@ -390,16 +390,6 @@ Contexts:
|
||||
)
|
||||
|
||||
df_stock = yf.download(self.ticker, start=self.start, progress=False)
|
||||
df_stock = df_stock.rename(
|
||||
columns={
|
||||
"Open": "1. open",
|
||||
"High": "2. high",
|
||||
"Low": "3. low",
|
||||
"Close": "4. close",
|
||||
"Adj Close": "5. adjusted close",
|
||||
"Volume": "6. volume",
|
||||
}
|
||||
)
|
||||
df_stock.index.name = "date"
|
||||
s_interval = "1440min"
|
||||
|
||||
@@ -419,16 +409,6 @@ Contexts:
|
||||
)
|
||||
|
||||
df_stock = yf.download(self.ticker, start=self.start, progress=False)
|
||||
df_stock = df_stock.rename(
|
||||
columns={
|
||||
"Open": "1. open",
|
||||
"High": "2. high",
|
||||
"Low": "3. low",
|
||||
"Close": "4. close",
|
||||
"Adj Close": "5. adjusted close",
|
||||
"Volume": "6. volume",
|
||||
}
|
||||
)
|
||||
|
||||
return op_controller.menu(
|
||||
self.ticker,
|
||||
@@ -448,7 +428,7 @@ Contexts:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from gamestonk_terminal.prediction_techniques import pred_controller
|
||||
except ModuleNotFoundError as e:
|
||||
print("One of the optional packages seems to be missing", "\n", e)
|
||||
print("One of the optional packages seems to be missing: ", e, "\n")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
@@ -472,6 +452,7 @@ Contexts:
|
||||
df_stock_pred, _ = ts.get_daily_adjusted(
|
||||
symbol=self.ticker, outputsize="full"
|
||||
)
|
||||
|
||||
# pylint: disable=no-member
|
||||
df_stock_pred = df_stock_pred.sort_index(ascending=True)
|
||||
df_stock_pred = df_stock_pred[self.start :]
|
||||
|
||||
Reference in New Issue
Block a user