mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
Big Code Refactoring with contexts vs category division (#644)
* big-refactoring * add terminal_helper * fix tests * remove init modules Co-authored-by: jmaslek <jmaslek11@gmail.com>
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
# flake8: noqa
|
||||
from . import discovery
|
||||
from . import due_diligence
|
||||
from . import fundamental_analysis
|
||||
from . import papermill
|
||||
from . import prediction_techniques
|
||||
from . import behavioural_analysis
|
||||
from . import technical_analysis
|
||||
|
||||
@@ -19,7 +19,7 @@ load MSFT -s 2014-01-01
|
||||
Anyone reading this, note this is quite a discussion between the devs. Since this is a time series, there is an inherent
|
||||
ordering of the data. However, since returns are random, it is hard to predict, and ordering data may not have any meaning.
|
||||
|
||||
To this end, we allow users to specify how much validation data to use and if it should be shuffled. By default, we will split
|
||||
To this end, we allow users to specify how much validation data to use and if it should be shuffled. By default, we will split
|
||||
into 10% validation data with a random shuffle. This will allow the user to see how the model performs at various times in your sequence.
|
||||
|
||||
```
|
||||
@@ -108,7 +108,7 @@ This tells your model how "fast" to train by adjusting the factor that gets mult
|
||||
|
||||
Select the number of epochs to train your model. The bigger number of epochs, the longer the training will take, and also increase chances of overfitting.
|
||||
|
||||
An early stopping has been implemented that will (if desired) stop training once the validation loss has plateaued. the patience (number of
|
||||
An early stopping has been implemented that will (if desired) stop training once the validation loss has plateaued. the patience (number of
|
||||
epochs with no improvement) can be found in the config file.
|
||||
```
|
||||
--epochs : number of training epochs. Default 200.
|
||||
@@ -244,7 +244,7 @@ Long_Short_Term_Memory \
|
||||
|
||||
## conv1d <a name="conv1d"></a>
|
||||
```
|
||||
usage: lstm [-d N_DAYS] [-i N_INPUTS] [--epochs N_EPOCHS] [-e S_END_DATE] [--loops N_LOOPS] [-v VALID]
|
||||
usage: lstm [-d N_DAYS] [-i N_INPUTS] [--epochs N_EPOCHS] [-e S_END_DATE] [--loops N_LOOPS] [-v VALID]
|
||||
[--lr LEARNING_RATE] [--no_shuffle]
|
||||
```
|
||||
1D Convolutional Neural Net:
|
||||
@@ -259,4 +259,4 @@ usage: lstm [-d N_DAYS] [-i N_INPUTS] [--epochs N_EPOCHS] [-e S_END_DATE] [--loo
|
||||
* --batch_size: batch size for model training, should not be used unless advanced user. Default None.
|
||||
* --loops: number of loops to iterate and train models. Default 1.
|
||||
* --lr : learning rate for optimizer
|
||||
* --no_shuffle : split validation data in time_ordered way instead of random.
|
||||
* --no_shuffle : split validation data in time_ordered way instead of random.
|
||||
@@ -17,7 +17,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
get_next_stock_market_days,
|
||||
plot_autoscale,
|
||||
)
|
||||
from gamestonk_terminal.prediction_techniques.pred_helper import (
|
||||
from gamestonk_terminal.common.prediction_techniques.pred_helper import (
|
||||
print_pretty_prediction,
|
||||
price_prediction_backtesting_color,
|
||||
print_prediction_kpis,
|
||||
@@ -18,7 +18,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
get_next_stock_market_days,
|
||||
plot_autoscale,
|
||||
)
|
||||
from gamestonk_terminal.prediction_techniques.pred_helper import (
|
||||
from gamestonk_terminal.common.prediction_techniques.pred_helper import (
|
||||
print_pretty_prediction,
|
||||
price_prediction_backtesting_color,
|
||||
print_prediction_kpis,
|
||||
@@ -12,7 +12,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
valid_date,
|
||||
get_next_stock_market_days,
|
||||
)
|
||||
from gamestonk_terminal.prediction_techniques.pred_helper import (
|
||||
from gamestonk_terminal.common.prediction_techniques.pred_helper import (
|
||||
print_pretty_prediction,
|
||||
prepare_scale_train_valid_test,
|
||||
plot_data_predictions,
|
||||
@@ -28,7 +28,7 @@ from tensorflow.keras.optimizers import (
|
||||
SGD,
|
||||
)
|
||||
from gamestonk_terminal.helper_funcs import get_next_stock_market_days
|
||||
from gamestonk_terminal.prediction_techniques.pred_helper import (
|
||||
from gamestonk_terminal.common.prediction_techniques.pred_helper import (
|
||||
prepare_scale_train_valid_test,
|
||||
forecast,
|
||||
plot_data_predictions,
|
||||
@@ -21,7 +21,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
plot_autoscale,
|
||||
)
|
||||
|
||||
from gamestonk_terminal.prediction_techniques.pred_helper import (
|
||||
from gamestonk_terminal.common.prediction_techniques.pred_helper import (
|
||||
print_pretty_prediction,
|
||||
price_prediction_backtesting_color,
|
||||
print_prediction_kpis,
|
||||
@@ -3,13 +3,13 @@ __docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
from typing import List
|
||||
from collections import OrderedDict
|
||||
from matplotlib import pyplot as plt
|
||||
import pandas as pd
|
||||
from pandas.plotting import register_matplotlib_converters
|
||||
import seaborn as sns
|
||||
import scipy.stats as stats
|
||||
import statsmodels.api as sm
|
||||
from collections import OrderedDict
|
||||
import matplotlib.gridspec as gridspec
|
||||
from statsmodels.graphics.gofplots import qqplot
|
||||
from statsmodels.tsa.stattools import adfuller, kpss, bds
|
||||
@@ -42,13 +42,12 @@ def naive(
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
return "", None, list()
|
||||
|
||||
naive = pd.Series(stock.values[:-1], index=stock[1:].index)
|
||||
model = pd.Series(stock.values[:-1], index=stock[1:].index)
|
||||
|
||||
model_name = "Naive"
|
||||
model = naive
|
||||
residuals = stock[1:].values - naive.values
|
||||
residuals = stock[1:].values - model.values
|
||||
|
||||
return model_name, model, residuals
|
||||
|
||||
@@ -116,7 +115,7 @@ def arima(
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
return "", None, list()
|
||||
|
||||
if ns_parser.s_order:
|
||||
t_order = tuple(int(ord) for ord in list(ns_parser.s_order))
|
||||
@@ -5,6 +5,9 @@ env_files = [f for f in os.listdir() if f.endswith(".env")]
|
||||
if env_files:
|
||||
load_dotenv(env_files[0])
|
||||
|
||||
# Choose one of: stocks, options, crypto, economy, etf, portfolio, forex
|
||||
DEFAULT_CONTEXT = ""
|
||||
|
||||
# By default the jupyter notebook will be run on port 8888
|
||||
PAPERMILL_NOTEBOOK_REPORT_PORT = "8888"
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ 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.cryptocurrency.binance import binance_model
|
||||
from gamestonk_terminal.technical_analysis import ta_controller
|
||||
from gamestonk_terminal.cryptocurrency.technical_analysis import ta_controller
|
||||
|
||||
|
||||
class BinanceController:
|
||||
@@ -53,7 +53,7 @@ class BinanceController:
|
||||
print(" book show order book")
|
||||
print(" candle show candles")
|
||||
print(" balance show coin balance")
|
||||
print(" ta open technical analysis menu")
|
||||
print("> ta open technical analysis menu")
|
||||
print("")
|
||||
|
||||
def switch(self, an_input: str):
|
||||
@@ -162,7 +162,6 @@ class BinanceController:
|
||||
ticker=self.current_coin,
|
||||
start=self.current_df.index[0],
|
||||
interval="",
|
||||
context="(crypto)>(bin)",
|
||||
)
|
||||
print("")
|
||||
if quit is not None:
|
||||
|
||||
@@ -10,7 +10,7 @@ from binance.client import Client
|
||||
from binance.exceptions import BinanceAPIException
|
||||
from tabulate import tabulate
|
||||
from gamestonk_terminal.helper_funcs import check_positive
|
||||
from gamestonk_terminal.main_helper import parse_known_args_and_warn
|
||||
from gamestonk_terminal.helper_funcs import parse_known_args_and_warn
|
||||
import gamestonk_terminal.config_terminal as cfg
|
||||
from gamestonk_terminal.cryptocurrency.binance.binance_view import (
|
||||
plot_order_book,
|
||||
|
||||
@@ -5,7 +5,7 @@ import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import mplfinance as mpf
|
||||
import pandas as pd
|
||||
from gamestonk_terminal.main_helper import plot_autoscale
|
||||
from gamestonk_terminal.helper_funcs import plot_autoscale
|
||||
from gamestonk_terminal.config_plot import PLOT_DPI
|
||||
from gamestonk_terminal.feature_flags import USE_ION as ion
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ 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.cryptocurrency.coingecko import pycoingecko_view
|
||||
from gamestonk_terminal.technical_analysis import ta_controller
|
||||
from gamestonk_terminal.cryptocurrency.technical_analysis import ta_controller
|
||||
|
||||
|
||||
class GeckoController:
|
||||
@@ -90,7 +90,7 @@ class GeckoController:
|
||||
print(f"Loaded coin: {self.current_coin}")
|
||||
print("")
|
||||
print(" chart price chart for loaded coin")
|
||||
print(" ta yechnical analysis menu for loaded coin")
|
||||
print("> ta technical analysis menu for loaded coin")
|
||||
print(" info nasic information about loaded coin")
|
||||
print(" market market stats about loaded coin")
|
||||
print(" ath all time high related stats for loaded coin")
|
||||
@@ -301,7 +301,6 @@ class GeckoController:
|
||||
ticker=self.current_coin.coin_symbol,
|
||||
start=self.current_df.index[0],
|
||||
interval="",
|
||||
context="(crypto)>(cg)",
|
||||
)
|
||||
print("")
|
||||
if quit is not None:
|
||||
|
||||
@@ -11,7 +11,7 @@ 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.cryptocurrency.coinpaprika import coinpaprika_view
|
||||
from gamestonk_terminal.technical_analysis import ta_controller
|
||||
from gamestonk_terminal.cryptocurrency.technical_analysis import ta_controller
|
||||
|
||||
|
||||
class PaprikaController:
|
||||
@@ -232,7 +232,6 @@ class PaprikaController:
|
||||
ticker=self.current_coin,
|
||||
start=self.current_df.index[0],
|
||||
interval="",
|
||||
context="(crypto)>(cp)",
|
||||
)
|
||||
print("")
|
||||
if quit is not None:
|
||||
|
||||
@@ -3,8 +3,6 @@ __docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
from typing import List
|
||||
from json.decoder import JSONDecodeError
|
||||
|
||||
import difflib
|
||||
from tabulate import tabulate
|
||||
from pandas.plotting import register_matplotlib_converters
|
||||
@@ -13,7 +11,7 @@ import mplfinance as mpf
|
||||
import pandas as pd
|
||||
|
||||
from gamestonk_terminal.helper_funcs import parse_known_args_and_warn, check_positive
|
||||
from gamestonk_terminal.main_helper import plot_autoscale
|
||||
from gamestonk_terminal.helper_funcs import plot_autoscale
|
||||
from gamestonk_terminal.feature_flags import USE_ION as ion
|
||||
import gamestonk_terminal.cryptocurrency.coinpaprika.coinpaprika_model as paprika
|
||||
from gamestonk_terminal.cryptocurrency.cryptocurrency_helpers import (
|
||||
@@ -70,14 +68,9 @@ CURRENCIES = [
|
||||
"ARS",
|
||||
"ISK",
|
||||
]
|
||||
try:
|
||||
PLATFORMS = paprika.get_all_contract_platforms()["platform_id"].tolist()
|
||||
COINS = paprika.get_list_of_coins()
|
||||
COINS_DCT = dict(zip(COINS.id, COINS.symbol))
|
||||
# see https://github.com/GamestonkTerminal/GamestonkTerminal/pull/562#issuecomment-887842888
|
||||
# EXCHANGES = paprika.get_list_of_exchanges()
|
||||
except JSONDecodeError:
|
||||
print("JSON Error loading from coinpaprika")
|
||||
|
||||
# see https://github.com/GamestonkTerminal/GamestonkTerminal/pull/562#issuecomment-887842888
|
||||
# EXCHANGES = paprika.get_list_of_exchanges()
|
||||
|
||||
|
||||
def global_market(other_args: List[str]):
|
||||
@@ -774,7 +767,7 @@ def contracts(other_args: List[str]):
|
||||
dest="platform",
|
||||
default="eth-ethereum",
|
||||
type=str,
|
||||
choices=PLATFORMS,
|
||||
choices=paprika.get_all_contract_platforms()["platform_id"].tolist(),
|
||||
)
|
||||
parser.add_argument(
|
||||
"-t",
|
||||
@@ -1449,6 +1442,8 @@ def load(other_args: List[str]):
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
COINS = paprika.get_list_of_coins()
|
||||
COINS_DCT = dict(zip(COINS.id, COINS.symbol))
|
||||
coin_id, _ = paprika.validate_coin(ns_parser.coin, COINS_DCT)
|
||||
|
||||
if coin_id:
|
||||
|
||||
@@ -13,6 +13,7 @@ from gamestonk_terminal.cryptocurrency.binance import binance_controller
|
||||
from gamestonk_terminal.cryptocurrency.coingecko import pycoingecko_controller
|
||||
from gamestonk_terminal.cryptocurrency import finbrain_crypto_view
|
||||
from gamestonk_terminal.cryptocurrency.coinpaprika import coinpaprika_controller
|
||||
from gamestonk_terminal.cryptocurrency.report import report_controller
|
||||
|
||||
|
||||
class CryptoController:
|
||||
@@ -23,13 +24,23 @@ class CryptoController:
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
]
|
||||
|
||||
CHOICES_COMMAND = [
|
||||
"finbrain",
|
||||
]
|
||||
|
||||
CHOICES_MENUS = [
|
||||
"cg",
|
||||
"bin",
|
||||
"cmc",
|
||||
"finbrain",
|
||||
"cp",
|
||||
"report",
|
||||
]
|
||||
|
||||
CHOICES += CHOICES_COMMAND
|
||||
CHOICES += CHOICES_MENUS
|
||||
|
||||
def __init__(self):
|
||||
"""CONSTRUCTOR"""
|
||||
|
||||
@@ -41,7 +52,10 @@ class CryptoController:
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/cryptocurrency"
|
||||
)
|
||||
print("\nCryptocurrency:")
|
||||
print("")
|
||||
print(">> CRYPTO <<")
|
||||
print("")
|
||||
print("What do you want to do?")
|
||||
print(" cls clear screen")
|
||||
print(" ?/help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
@@ -53,6 +67,7 @@ class CryptoController:
|
||||
print("> cmc Coinmarketcap menu")
|
||||
print("> bin Binance menu with order book, candles, ta.. ")
|
||||
print("> cp CoinPaprika menu")
|
||||
print("> report generate automatic report")
|
||||
print("")
|
||||
|
||||
def switch(self, an_input: str):
|
||||
@@ -126,6 +141,15 @@ class CryptoController:
|
||||
return True
|
||||
print("")
|
||||
|
||||
def call_report(self, _):
|
||||
"""Process report command"""
|
||||
ret = report_controller.menu()
|
||||
|
||||
if ret is False:
|
||||
self.print_help()
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def menu():
|
||||
crypto_controller = CryptoController()
|
||||
|
||||
@@ -8,7 +8,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
parse_known_args_and_warn,
|
||||
)
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.behavioural_analysis.finbrain_view import (
|
||||
from gamestonk_terminal.common.behavioural_analysis.finbrain_view import (
|
||||
get_sentiment,
|
||||
plot_sentiment,
|
||||
sentiment_coloring,
|
||||
|
||||
@@ -11,7 +11,7 @@ Command | Template | Example
|
||||
`dp` | [Dark Pool](/notebooks/templates/dark_pool.ipynb) | [Dark Pool](/notebooks/examples/amc_dark_pool_20210728_235316.html)
|
||||
`cm` | [Crypto Market](/notebooks/templates/crypto_market.ipynb) | [Crypto Market](/notebooks/examples/crypto_market_20210729_001530.html)
|
||||
|
||||
|
||||
|
||||
## How to run the report
|
||||
|
||||
1. In [config_terminal](/gamestonk_terminal/config_terminal.py) you may need to change your `PAPERMILL_NOTEBOOK_REPORT_PORT` from `8888`. If the notebook generation fails, it is likely that the port selected is not the correct one.
|
||||
@@ -36,11 +36,10 @@ extension = ".ipynb"
|
||||
* You're now ready to write your own notes
|
||||
|
||||
6. Once you're happy with your report, you can either:
|
||||
* Re-run the last cell (potentially changing output from `.html` with:
|
||||
* Re-run the last cell (potentially changing output from `.html` with:
|
||||
```
|
||||
folder = "notebooks/reports/"
|
||||
extension = ".ipynb"
|
||||
!jupyter nbconvert {folder + report_name + extension} --to html --no-input
|
||||
```
|
||||
* Or, on the toolbar click on "File" -> "Download as" -> Select your preferred option (e.g. HTML)
|
||||
|
||||
151
gamestonk_terminal/cryptocurrency/report/report_controller.py
Normal file
151
gamestonk_terminal/cryptocurrency/report/report_controller.py
Normal file
@@ -0,0 +1,151 @@
|
||||
"""Papermill Controller Module"""
|
||||
__docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from typing import List
|
||||
import subprocess
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
from gamestonk_terminal.cryptocurrency.report import crypto_market_view
|
||||
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.menu import session
|
||||
from gamestonk_terminal.helper_funcs import get_flair
|
||||
from gamestonk_terminal import config_terminal
|
||||
|
||||
# pylint: disable=R1732
|
||||
|
||||
|
||||
class ReportController:
|
||||
"""Report Controller class"""
|
||||
|
||||
CHOICES = [
|
||||
"cls",
|
||||
"?",
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
]
|
||||
|
||||
CHOICES_COMMANDS = [
|
||||
"ov",
|
||||
]
|
||||
|
||||
CHOICES += CHOICES_COMMANDS
|
||||
|
||||
def __init__(self):
|
||||
"""Constructor"""
|
||||
self.report_parser = argparse.ArgumentParser(add_help=False, prog="report")
|
||||
self.report_parser.add_argument(
|
||||
"cmd",
|
||||
choices=self.CHOICES,
|
||||
)
|
||||
|
||||
def switch(self, an_input: str, proc: subprocess.Popen):
|
||||
"""Process and dispatch input
|
||||
|
||||
Parameters
|
||||
-------
|
||||
an_input : str
|
||||
string with input arguments
|
||||
proc : subprocess.Popen
|
||||
subprocess that calls jupyter notebook for report generation
|
||||
|
||||
Returns
|
||||
-------
|
||||
True, False or None
|
||||
False - quit the menu
|
||||
True - quit the program
|
||||
None - continue in the menu
|
||||
"""
|
||||
|
||||
# Empty command
|
||||
if not an_input:
|
||||
print("")
|
||||
return None
|
||||
|
||||
(known_args, other_args) = self.report_parser.parse_known_args(an_input.split())
|
||||
|
||||
# Help menu again
|
||||
if known_args.cmd == "?":
|
||||
print_help()
|
||||
return None
|
||||
|
||||
# Clear screen
|
||||
if known_args.cmd == "cls":
|
||||
os.system("cls||clear")
|
||||
return None
|
||||
|
||||
return getattr(
|
||||
self, "call_" + known_args.cmd, lambda: "Command not recognized!"
|
||||
)(other_args, proc)
|
||||
|
||||
def call_help(self, *_):
|
||||
"""Process Help command"""
|
||||
print_help()
|
||||
|
||||
def call_q(self, _, proc):
|
||||
"""Process Q command - quit the menu"""
|
||||
proc.kill()
|
||||
return False
|
||||
|
||||
def call_quit(self, _, proc):
|
||||
"""Process Quit command - quit the program"""
|
||||
proc.kill()
|
||||
return True
|
||||
|
||||
def call_ov(self, other_args: List[str], _):
|
||||
"""Process ov command"""
|
||||
crypto_market_view.crypto_market_report(other_args)
|
||||
|
||||
|
||||
def print_help():
|
||||
"""Print help"""
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/cryptocurrency/report"
|
||||
)
|
||||
print("\nReports:")
|
||||
print(" cls clear screen")
|
||||
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(" ov generate crypto overview report")
|
||||
print("")
|
||||
|
||||
|
||||
def menu():
|
||||
"""Report Menu"""
|
||||
report_controller = ReportController()
|
||||
report_controller.call_help(None)
|
||||
|
||||
# Initialize jupyter notebook
|
||||
cmd = f"jupyter notebook --port={config_terminal.PAPERMILL_NOTEBOOK_REPORT_PORT}"
|
||||
proc = subprocess.Popen(
|
||||
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
||||
)
|
||||
|
||||
while True:
|
||||
# Get input command from user
|
||||
if session and gtff.USE_PROMPT_TOOLKIT:
|
||||
completer = NestedCompleter.from_nested_dict(
|
||||
{c: None for c in report_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (crypto)>(report)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (crypto)>(report)> ")
|
||||
|
||||
try:
|
||||
process_input = report_controller.switch(an_input, proc)
|
||||
except SystemExit:
|
||||
print("The command selected doesn't exist\n")
|
||||
continue
|
||||
|
||||
if process_input is False:
|
||||
return False
|
||||
|
||||
if process_input is True:
|
||||
return True
|
||||
@@ -0,0 +1,239 @@
|
||||
"""Technical Analysis Controller Module"""
|
||||
__docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
import pandas as pd
|
||||
import matplotlib.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.common.technical_analysis import (
|
||||
custom_indicators_view,
|
||||
momentum,
|
||||
overlap,
|
||||
trend_indicators,
|
||||
volatility,
|
||||
volume,
|
||||
)
|
||||
|
||||
|
||||
class TechnicalAnalysisController:
|
||||
"""Technical Analysis Controller class"""
|
||||
|
||||
# Command choices
|
||||
CHOICES = [
|
||||
"cls",
|
||||
"?",
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
"ema",
|
||||
"sma",
|
||||
"vwap",
|
||||
"cci",
|
||||
"macd",
|
||||
"rsi",
|
||||
"stoch",
|
||||
"adx",
|
||||
"aroon",
|
||||
"bbands",
|
||||
"ad",
|
||||
"obv",
|
||||
"fib",
|
||||
]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
ticker: str,
|
||||
start: datetime,
|
||||
interval: str,
|
||||
stock: pd.DataFrame,
|
||||
):
|
||||
"""Constructor"""
|
||||
self.ticker = ticker
|
||||
self.start = start
|
||||
self.interval = interval
|
||||
self.stock = stock
|
||||
|
||||
self.ta_parser = argparse.ArgumentParser(add_help=False, prog="ta")
|
||||
self.ta_parser.add_argument(
|
||||
"cmd",
|
||||
choices=self.CHOICES,
|
||||
)
|
||||
|
||||
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:
|
||||
print(
|
||||
f"\n{s_intraday} Stock: {self.ticker} (from {self.start.strftime('%Y-%m-%d')})"
|
||||
)
|
||||
else:
|
||||
print(f"\n{s_intraday} Stock: {self.ticker}")
|
||||
|
||||
print("\nTechnical Analysis:")
|
||||
print(" cls clear screen")
|
||||
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("overlap:")
|
||||
print(" ema exponential moving average")
|
||||
print(" sma simple moving average")
|
||||
print(" vwap volume weighted average price")
|
||||
print("momentum:")
|
||||
print(" cci commodity channel index")
|
||||
print(" macd moving average convergence/divergence")
|
||||
print(" rsi relative strength index")
|
||||
print(" stoch stochastic oscillator")
|
||||
print("trend:")
|
||||
print(" adx average directional movement index")
|
||||
print(" aroon aroon indicator")
|
||||
print("volatility:")
|
||||
print(" bbands bollinger bands")
|
||||
print("volume:")
|
||||
print(" ad accumulation/distribution line values")
|
||||
print(" obv on balance volume")
|
||||
print("custom:")
|
||||
print(" fib fibonocci retracement")
|
||||
print("")
|
||||
|
||||
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
|
||||
"""
|
||||
|
||||
# Empty command
|
||||
if not an_input:
|
||||
print("")
|
||||
return None
|
||||
|
||||
(known_args, other_args) = self.ta_parser.parse_known_args(an_input.split())
|
||||
|
||||
# Help menu again
|
||||
if known_args.cmd == "?":
|
||||
self.print_help()
|
||||
return None
|
||||
|
||||
# Clear screen
|
||||
if known_args.cmd == "cls":
|
||||
os.system("cls||clear")
|
||||
return None
|
||||
|
||||
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_ema(self, other_args: List[str]):
|
||||
"""Process ema command"""
|
||||
overlap.ema(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_sma(self, other_args: List[str]):
|
||||
"""Process sma command"""
|
||||
overlap.sma(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_vwap(self, other_args: List[str]):
|
||||
"""Process vwap command"""
|
||||
overlap.vwap(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_cci(self, other_args: List[str]):
|
||||
"""Process cci command"""
|
||||
momentum.cci(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_macd(self, other_args: List[str]):
|
||||
"""Process macd command"""
|
||||
momentum.macd(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_rsi(self, other_args: List[str]):
|
||||
"""Process rsi command"""
|
||||
momentum.rsi(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_stoch(self, other_args: List[str]):
|
||||
"""Process stoch command"""
|
||||
momentum.stoch(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_adx(self, other_args: List[str]):
|
||||
"""Process adx command"""
|
||||
trend_indicators.adx(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_aroon(self, other_args: List[str]):
|
||||
"""Process aroon command"""
|
||||
trend_indicators.aroon(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_bbands(self, other_args: List[str]):
|
||||
"""Process bbands command"""
|
||||
volatility.bbands(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_ad(self, other_args: List[str]):
|
||||
"""Process ad command"""
|
||||
volume.ad(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_obv(self, other_args: List[str]):
|
||||
"""Process obv command"""
|
||||
volume.obv(other_args, self.ticker, self.interval, self.stock)
|
||||
|
||||
def call_fib(self, other_args: List[str]):
|
||||
"""Process fib command"""
|
||||
custom_indicators_view.fibinocci_retracement(
|
||||
other_args, self.stock, self.ticker
|
||||
)
|
||||
|
||||
|
||||
def menu(ticker: str, start: datetime, interval: str, stock: pd.DataFrame):
|
||||
"""Technical Analysis Menu"""
|
||||
|
||||
ta_controller = TechnicalAnalysisController(ticker, start, interval, stock)
|
||||
ta_controller.call_help(None)
|
||||
|
||||
while True:
|
||||
# Get input command from user
|
||||
if session and gtff.USE_PROMPT_TOOLKIT:
|
||||
completer = NestedCompleter.from_nested_dict(
|
||||
{c: None for c in ta_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (crypto)>(ta)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (crypto)>(ta)> ")
|
||||
|
||||
try:
|
||||
plt.close("all")
|
||||
|
||||
process_input = ta_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 +1 @@
|
||||
from . import econ_controller # noqa: F401
|
||||
from . import economy_controller # noqa: F401
|
||||
|
||||
@@ -12,6 +12,9 @@ from gamestonk_terminal.economy import fred_view
|
||||
from gamestonk_terminal.economy import finnhub_view
|
||||
from gamestonk_terminal.economy import cnn_view
|
||||
from gamestonk_terminal.economy import wsj_view
|
||||
from gamestonk_terminal.economy.report import report_controller
|
||||
|
||||
# pylint: disable=R1710
|
||||
|
||||
|
||||
class EconomyController:
|
||||
@@ -19,11 +22,14 @@ class EconomyController:
|
||||
|
||||
# Command choices
|
||||
CHOICES = [
|
||||
"?",
|
||||
"cls",
|
||||
"?",
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
]
|
||||
|
||||
CHOICES_COMMANDS = [
|
||||
"events",
|
||||
"fred",
|
||||
"vixcls",
|
||||
@@ -47,9 +53,16 @@ class EconomyController:
|
||||
"currencies",
|
||||
]
|
||||
|
||||
CHOICES_MENUS = [
|
||||
"report",
|
||||
]
|
||||
|
||||
CHOICES += CHOICES_COMMANDS
|
||||
CHOICES += CHOICES_MENUS
|
||||
|
||||
def __init__(self):
|
||||
"""Constructor"""
|
||||
self.econ_parser = argparse.ArgumentParser(add_help=False, prog="econ")
|
||||
self.econ_parser = argparse.ArgumentParser(add_help=False, prog="economy")
|
||||
self.econ_parser.add_argument(
|
||||
"cmd",
|
||||
choices=self.CHOICES,
|
||||
@@ -61,7 +74,10 @@ class EconomyController:
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/economy"
|
||||
)
|
||||
print("\nEconomic Data:")
|
||||
print("")
|
||||
print(">> ECONOMY <<")
|
||||
print("")
|
||||
print("What do you want to do?")
|
||||
print(" cls clear screen")
|
||||
print(" ?/help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
@@ -92,7 +108,8 @@ class EconomyController:
|
||||
print(" glbonds global bonds overview")
|
||||
print(" currencies currency overview")
|
||||
print("")
|
||||
return
|
||||
print("> report generate automatic report")
|
||||
print("")
|
||||
|
||||
def switch(self, an_input: str):
|
||||
"""Process and dispatch input
|
||||
@@ -218,6 +235,15 @@ class EconomyController:
|
||||
"""Process curremcies command"""
|
||||
wsj_view.display_currencies(other_args)
|
||||
|
||||
def call_report(self, _):
|
||||
"""Process report command"""
|
||||
ret = report_controller.menu()
|
||||
|
||||
if ret is False:
|
||||
self.print_help()
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def menu():
|
||||
"""Econ Menu"""
|
||||
@@ -234,11 +260,11 @@ def menu():
|
||||
)
|
||||
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (econ)> ",
|
||||
f"{get_flair()} (economy)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (econ)> ")
|
||||
an_input = input(f"{get_flair()} (economy)> ")
|
||||
try:
|
||||
process_input = econ_controller.switch(an_input)
|
||||
|
||||
@@ -185,6 +185,7 @@ def display_fred(other_args: List[str], choice: str):
|
||||
if gtff.USE_ION:
|
||||
plt.ion()
|
||||
plt.show()
|
||||
print("")
|
||||
|
||||
except SystemExit:
|
||||
print("")
|
||||
|
||||
45
gamestonk_terminal/economy/report/README.md
vendored
Normal file
45
gamestonk_terminal/economy/report/README.md
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
# PAPERMILL
|
||||
|
||||
This menu has a different concept from remaining menus. It has 2 main goals:
|
||||
- Generate a personalised report.
|
||||
- Allow the user to write notes on that notebook (report), as if it was his personal investment diary.
|
||||
|
||||
Command | Template | Example
|
||||
------ | --------|----
|
||||
`dd` | [Due Diligence Template](/notebooks/templates/due_diligence.ipynb) | [Due Diligence Example](/notebooks/examples/aapl_due_diligence_20210729_001048.html)
|
||||
`econ` | [Economy Template](/notebooks/templates/econ_data.ipynb) | [Economy Example](/notebooks/examples/econ_data_20210729_001227.html)
|
||||
`dp` | [Dark Pool](/notebooks/templates/dark_pool.ipynb) | [Dark Pool](/notebooks/examples/amc_dark_pool_20210728_235316.html)
|
||||
`cm` | [Crypto Market](/notebooks/templates/crypto_market.ipynb) | [Crypto Market](/notebooks/examples/crypto_market_20210729_001530.html)
|
||||
|
||||
|
||||
## How to run the report
|
||||
|
||||
1. In [config_terminal](/gamestonk_terminal/config_terminal.py) you may need to change your `PAPERMILL_NOTEBOOK_REPORT_PORT` from `8888`. If the notebook generation fails, it is likely that the port selected is not the correct one.
|
||||
|
||||
2. Start the terminal with `python terminal.py`
|
||||
|
||||
3. Select `mill` and select one of the available reports generation, e.g. `econ`
|
||||
|
||||
4. This should prompt you with a filled notebok with name: `report_name_date_time.ipynb`. E.g. `econ_data_20210725_193517.ipynb`
|
||||
|
||||
5. Due to the last cell of the notebook, the report is saved by default as `.html`. E.g. `econ_data_20210725_193517.html`
|
||||
```
|
||||
folder = "notebooks/reports/"
|
||||
extension = ".ipynb"
|
||||
!jupyter nbconvert {folder + report_name + extension} --to html --no-input
|
||||
```
|
||||
|
||||
6. You can now write your own personal notes on the notebook. By doing:
|
||||
* Click on the notebook cell that you are interested in writing your notes
|
||||
* On the toolbar click on "+" to add a new cell
|
||||
* On the tooblar click on "Cell" -> "Cell Type" -> "Markdown"
|
||||
* You're now ready to write your own notes
|
||||
|
||||
6. Once you're happy with your report, you can either:
|
||||
* Re-run the last cell (potentially changing output from `.html` with:
|
||||
```
|
||||
folder = "notebooks/reports/"
|
||||
extension = ".ipynb"
|
||||
!jupyter nbconvert {folder + report_name + extension} --to html --no-input
|
||||
```
|
||||
* Or, on the toolbar click on "File" -> "Download as" -> Select your preferred option (e.g. HTML)
|
||||
@@ -7,7 +7,7 @@ from datetime import datetime, timedelta
|
||||
import pandas as pd
|
||||
import mplfinance as mpf
|
||||
|
||||
from gamestonk_terminal.technical_analysis import trendline_api as trend
|
||||
from gamestonk_terminal.common.technical_analysis import trendline_api as trend
|
||||
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
151
gamestonk_terminal/economy/report/report_controller.py
Normal file
151
gamestonk_terminal/economy/report/report_controller.py
Normal file
@@ -0,0 +1,151 @@
|
||||
"""Papermill Controller Module"""
|
||||
__docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from typing import List
|
||||
import subprocess
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
from gamestonk_terminal.economy.report import econ_data_view
|
||||
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.menu import session
|
||||
from gamestonk_terminal.helper_funcs import get_flair
|
||||
from gamestonk_terminal import config_terminal
|
||||
|
||||
# pylint: disable=R1732
|
||||
|
||||
|
||||
class ReportController:
|
||||
"""Report Controller class"""
|
||||
|
||||
CHOICES = [
|
||||
"cls",
|
||||
"?",
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
]
|
||||
|
||||
CHOICES_COMMANDS = [
|
||||
"ov",
|
||||
]
|
||||
|
||||
CHOICES += CHOICES_COMMANDS
|
||||
|
||||
def __init__(self):
|
||||
"""Constructor"""
|
||||
self.report_parser = argparse.ArgumentParser(add_help=False, prog="report")
|
||||
self.report_parser.add_argument(
|
||||
"cmd",
|
||||
choices=self.CHOICES,
|
||||
)
|
||||
|
||||
def switch(self, an_input: str, proc: subprocess.Popen):
|
||||
"""Process and dispatch input
|
||||
|
||||
Parameters
|
||||
-------
|
||||
an_input : str
|
||||
string with input arguments
|
||||
proc : subprocess.Popen
|
||||
subprocess that calls jupyter notebook for report generation
|
||||
|
||||
Returns
|
||||
-------
|
||||
True, False or None
|
||||
False - quit the menu
|
||||
True - quit the program
|
||||
None - continue in the menu
|
||||
"""
|
||||
|
||||
# Empty command
|
||||
if not an_input:
|
||||
print("")
|
||||
return None
|
||||
|
||||
(known_args, other_args) = self.report_parser.parse_known_args(an_input.split())
|
||||
|
||||
# Help menu again
|
||||
if known_args.cmd == "?":
|
||||
print_help()
|
||||
return None
|
||||
|
||||
# Clear screen
|
||||
if known_args.cmd == "cls":
|
||||
os.system("cls||clear")
|
||||
return None
|
||||
|
||||
return getattr(
|
||||
self, "call_" + known_args.cmd, lambda: "Command not recognized!"
|
||||
)(other_args, proc)
|
||||
|
||||
def call_help(self, *_):
|
||||
"""Process Help command"""
|
||||
print_help()
|
||||
|
||||
def call_q(self, _, proc):
|
||||
"""Process Q command - quit the menu"""
|
||||
proc.kill()
|
||||
return False
|
||||
|
||||
def call_quit(self, _, proc):
|
||||
"""Process Quit command - quit the program"""
|
||||
proc.kill()
|
||||
return True
|
||||
|
||||
def call_ov(self, other_args: List[str], _):
|
||||
"""Process ov command"""
|
||||
econ_data_view.economy_data_report(other_args)
|
||||
|
||||
|
||||
def print_help():
|
||||
"""Print help"""
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/economy/report"
|
||||
)
|
||||
print("\nReports:")
|
||||
print(" cls clear screen")
|
||||
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(" ov generate economy overview report")
|
||||
print("")
|
||||
|
||||
|
||||
def menu():
|
||||
"""Report Menu"""
|
||||
report_controller = ReportController()
|
||||
report_controller.call_help(None)
|
||||
|
||||
# Initialize jupyter notebook
|
||||
cmd = f"jupyter notebook --port={config_terminal.PAPERMILL_NOTEBOOK_REPORT_PORT}"
|
||||
proc = subprocess.Popen(
|
||||
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
||||
)
|
||||
|
||||
while True:
|
||||
# Get input command from user
|
||||
if session and gtff.USE_PROMPT_TOOLKIT:
|
||||
completer = NestedCompleter.from_nested_dict(
|
||||
{c: None for c in report_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (economy)>(report)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (economy)>(report)> ")
|
||||
|
||||
try:
|
||||
process_input = report_controller.switch(an_input, proc)
|
||||
except SystemExit:
|
||||
print("The command selected doesn't exist\n")
|
||||
continue
|
||||
|
||||
if process_input is False:
|
||||
return False
|
||||
|
||||
if process_input is True:
|
||||
return True
|
||||
@@ -21,12 +21,17 @@ from gamestonk_terminal.etf import wsj_view
|
||||
|
||||
|
||||
class ETFController:
|
||||
"""ETF Controller class"""
|
||||
|
||||
CHOICES = [
|
||||
"cls",
|
||||
"?",
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
]
|
||||
|
||||
CHOICES_COMMANDS = [
|
||||
"web",
|
||||
"search",
|
||||
"overview",
|
||||
@@ -38,9 +43,10 @@ class ETFController:
|
||||
"active",
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
"""CONSTRUCTOR"""
|
||||
CHOICES += CHOICES_COMMANDS
|
||||
|
||||
def __init__(self):
|
||||
"""Constructor"""
|
||||
self.etf_parser = argparse.ArgumentParser(add_help=False, prog="etf")
|
||||
self.etf_parser.add_argument("cmd", choices=self.CHOICES)
|
||||
|
||||
@@ -49,7 +55,10 @@ class ETFController:
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/etf"
|
||||
)
|
||||
print("\nETF:")
|
||||
print("")
|
||||
print(">> ETF <<")
|
||||
print("")
|
||||
print("What do you want to do?")
|
||||
print(" cls clear screen")
|
||||
print(" ?/help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
@@ -61,7 +70,7 @@ class ETFController:
|
||||
print(" holdings get top holdings for ETF")
|
||||
print(" compare compare overview of multiple ETF")
|
||||
print(" screener screen etfs based on overview data")
|
||||
print("\n Wall St. Journal")
|
||||
print("\nWall St. Journal")
|
||||
print(" gainers show top gainers")
|
||||
print(" decliners show top decliners")
|
||||
print(" active show most active")
|
||||
|
||||
201
gamestonk_terminal/forex/behavioural_analysis/ba_controller.py
Normal file
201
gamestonk_terminal/forex/behavioural_analysis/ba_controller.py
Normal file
@@ -0,0 +1,201 @@
|
||||
"""Behavioural Analysis Controller Module"""
|
||||
__docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
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.common.behavioural_analysis import (
|
||||
google_view,
|
||||
)
|
||||
|
||||
|
||||
class BehaviouralAnalysisController:
|
||||
"""Behavioural Analysis Controller class"""
|
||||
|
||||
# Command choices
|
||||
CHOICES = [
|
||||
"?",
|
||||
"cls",
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
]
|
||||
|
||||
CHOICES_COMMANDS = [
|
||||
"infer",
|
||||
"sentiment",
|
||||
"mentions",
|
||||
"regions",
|
||||
"queries",
|
||||
"rise",
|
||||
]
|
||||
|
||||
CHOICES += CHOICES_COMMANDS
|
||||
|
||||
def __init__(self, ticker: str, start: datetime):
|
||||
"""Constructor"""
|
||||
self.ticker = ticker
|
||||
self.start = start
|
||||
self.ba_parser = argparse.ArgumentParser(add_help=False, prog="ba")
|
||||
self.ba_parser.add_argument(
|
||||
"cmd",
|
||||
choices=self.CHOICES,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def print_help():
|
||||
"""Print help"""
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/behavioural_analysis"
|
||||
)
|
||||
print("\nBehavioural Analysis:")
|
||||
print(" cls clear screen")
|
||||
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("Twitter:")
|
||||
print(" infer infer about stock's sentiment from latest tweets")
|
||||
print(" sentiment in-depth sentiment prediction from tweets over time")
|
||||
print("")
|
||||
print("Google:")
|
||||
print(" mentions interest over time based on stock's mentions")
|
||||
print(" regions regions that show highest interest in stock")
|
||||
print(" queries top related queries with this stock")
|
||||
print(" rise top rising related queries with stock")
|
||||
print("")
|
||||
|
||||
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
|
||||
"""
|
||||
# Empty command
|
||||
if not an_input:
|
||||
print("")
|
||||
return None
|
||||
|
||||
(known_args, other_args) = self.ba_parser.parse_known_args(an_input.split())
|
||||
|
||||
# Help menu again
|
||||
if known_args.cmd == "?":
|
||||
self.print_help()
|
||||
return None
|
||||
|
||||
# Clear screen
|
||||
if known_args.cmd == "cls":
|
||||
os.system("cls||clear")
|
||||
return None
|
||||
|
||||
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_mentions(self, other_args: List[str]):
|
||||
"""Process mentions command"""
|
||||
google_view.mentions(other_args, self.ticker, self.start)
|
||||
|
||||
def call_regions(self, other_args: List[str]):
|
||||
"""Process regions command"""
|
||||
google_view.regions(other_args, self.ticker)
|
||||
|
||||
def call_queries(self, other_args: List[str]):
|
||||
"""Process queries command"""
|
||||
google_view.queries(other_args, self.ticker)
|
||||
|
||||
def call_rise(self, other_args: List[str]):
|
||||
"""Process rise command"""
|
||||
google_view.rise(other_args, self.ticker)
|
||||
|
||||
def call_infer(self, other_args: List[str]):
|
||||
"""Process infer command"""
|
||||
if not gtff.ENABLE_PREDICT:
|
||||
print("Predict is not enabled in feature_flags.py")
|
||||
print("Twitter inference menu is disabled", "\n")
|
||||
return
|
||||
|
||||
try:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from gamestonk_terminal.common.behavioural_analysis import twitter_view
|
||||
except ModuleNotFoundError as e:
|
||||
print("Optional packages need to be installed")
|
||||
print(e, "\n")
|
||||
return
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
return
|
||||
|
||||
twitter_view.inference(other_args, self.ticker)
|
||||
|
||||
def call_sentiment(self, other_args: List[str]):
|
||||
"""Process sentiment command"""
|
||||
if not gtff.ENABLE_PREDICT:
|
||||
print("Predict is not enabled in feature_flags.py")
|
||||
print("Twitter inference menu is disabled", "\n")
|
||||
return
|
||||
|
||||
try:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from gamestonk_terminal.common.behavioural_analysis import twitter_view
|
||||
except ModuleNotFoundError as e:
|
||||
print("Optional packages need to be installed")
|
||||
print(e, "\n")
|
||||
return
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
return
|
||||
|
||||
twitter_view.sentiment(other_args, self.ticker)
|
||||
|
||||
|
||||
def menu(ticker: str, start: datetime):
|
||||
"""Behavioural Analysis Menu"""
|
||||
|
||||
ba_controller = BehaviouralAnalysisController(ticker, start)
|
||||
ba_controller.call_help(None)
|
||||
|
||||
while True:
|
||||
# Get input command from user
|
||||
if session and gtff.USE_PROMPT_TOOLKIT:
|
||||
completer = NestedCompleter.from_nested_dict(
|
||||
{c: None for c in ba_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (forex)>(ba)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (forex)>(ba)> ")
|
||||
|
||||
try:
|
||||
process_input = ba_controller.switch(an_input)
|
||||
|
||||
if process_input is not None:
|
||||
return process_input
|
||||
|
||||
except SystemExit:
|
||||
print("The command selected doesn't exist\n")
|
||||
continue
|
||||
@@ -8,7 +8,7 @@ from datetime import datetime
|
||||
import pandas as pd
|
||||
from matplotlib import pyplot as plt
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
from gamestonk_terminal.exploratory_data_analysis import eda_api
|
||||
from gamestonk_terminal.common.exploratory_data_analysis import eda_api
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.helper_funcs import get_flair
|
||||
from gamestonk_terminal.menu import session
|
||||
@@ -182,11 +182,11 @@ def menu(ticker: str, start: datetime, interval: str, stock: pd.DataFrame):
|
||||
{c: None for c in eda_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (eda)> ",
|
||||
f"{get_flair()} (forex)>(eda)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (eda)> ")
|
||||
an_input = input(f"{get_flair()} (forex)>(eda)> ")
|
||||
|
||||
try:
|
||||
plt.close("all")
|
||||
@@ -8,16 +8,17 @@ from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.menu import session
|
||||
from gamestonk_terminal.forex import fx_view
|
||||
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
|
||||
|
||||
# from gamestonk_terminal.stocks.due_diligence import news_view, reddit_view
|
||||
|
||||
from gamestonk_terminal.forex.exploratory_data_analysis import eda_controller
|
||||
from gamestonk_terminal.forex.behavioural_analysis import ba_controller
|
||||
|
||||
account = cfg.OANDA_ACCOUNT
|
||||
|
||||
|
||||
class ForexController:
|
||||
"""Oanda Controller class"""
|
||||
"""Forex Controller class"""
|
||||
|
||||
CHOICES = [
|
||||
"cls",
|
||||
@@ -25,6 +26,9 @@ class ForexController:
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
]
|
||||
|
||||
CHOICES_COMMANDS = [
|
||||
"price",
|
||||
"summary",
|
||||
"list",
|
||||
@@ -39,15 +43,21 @@ class ForexController:
|
||||
"candles",
|
||||
"pending",
|
||||
"calendar",
|
||||
"news",
|
||||
"reddit",
|
||||
# "news",
|
||||
# "reddit",
|
||||
]
|
||||
|
||||
CHOICES_MENUS = [
|
||||
"eda",
|
||||
"ba",
|
||||
]
|
||||
|
||||
CHOICES += CHOICES_COMMANDS
|
||||
CHOICES += CHOICES_MENUS
|
||||
|
||||
def __init__(self):
|
||||
"""Construct Data"""
|
||||
self.fx_parser = argparse.ArgumentParser(add_help=False, prog="fx")
|
||||
self.fx_parser = argparse.ArgumentParser(add_help=False, prog="forex")
|
||||
self.fx_parser.add_argument(
|
||||
"cmd",
|
||||
choices=self.CHOICES,
|
||||
@@ -76,7 +86,7 @@ class ForexController:
|
||||
print("")
|
||||
print(f"Loaded instrument: {self.instrument if self.instrument else ''}")
|
||||
print("")
|
||||
print(" load load an instrument to use")
|
||||
print(" load load an instrument to use")
|
||||
if self.instrument:
|
||||
print(" candles show candles")
|
||||
print(" price shows price for selected instrument")
|
||||
@@ -87,6 +97,7 @@ class ForexController:
|
||||
print(
|
||||
" reddit search reddit for posts about the loaded instrument"
|
||||
)
|
||||
print("")
|
||||
print(
|
||||
"> eda exploratory data analysis, e.g.: decompose, cusum, residuals analysis"
|
||||
)
|
||||
@@ -193,13 +204,7 @@ class ForexController:
|
||||
"""Call calendar"""
|
||||
fx_view.calendar(self.instrument, other_args)
|
||||
|
||||
def call_news(self, other_args: List[str]):
|
||||
"""Call news [News API]"""
|
||||
news_view.news(other_args, self.instrument)
|
||||
|
||||
def call_reddit(self, other_args: List[str]):
|
||||
instrument = fx_view.format_instrument(self.instrument, " ")
|
||||
reddit_view.due_diligence(other_args, instrument)
|
||||
# TODO: Add news and reddit commands back
|
||||
|
||||
def call_eda(self, _):
|
||||
try:
|
||||
@@ -223,7 +228,7 @@ class ForexController:
|
||||
|
||||
|
||||
def menu():
|
||||
"""Oanda Menu"""
|
||||
"""Forex Menu"""
|
||||
fx_controller = ForexController()
|
||||
fx_controller.call_help(None)
|
||||
while True:
|
||||
@@ -233,11 +238,11 @@ def menu():
|
||||
)
|
||||
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (fx)> ",
|
||||
f"{get_flair()} (forex)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (fx)> ")
|
||||
an_input = input(f"{get_flair()} (forex)> ")
|
||||
|
||||
try:
|
||||
process_input = fx_controller.switch(an_input)
|
||||
@@ -28,13 +28,15 @@ from gamestonk_terminal.menu import session
|
||||
class OptionsController:
|
||||
"""Options Controller class."""
|
||||
|
||||
# Command choices
|
||||
CHOICES = [
|
||||
"cls",
|
||||
"?",
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
]
|
||||
|
||||
CHOICES_COMMANDS = [
|
||||
"disp",
|
||||
"scr",
|
||||
"calc",
|
||||
@@ -52,19 +54,15 @@ class OptionsController:
|
||||
"unu",
|
||||
]
|
||||
|
||||
def __init__(self, ticker: str):
|
||||
"""Construct data."""
|
||||
self.ticker = ticker
|
||||
if self.ticker:
|
||||
if TRADIER_TOKEN == "REPLACE_ME":
|
||||
self.expiry_dates = yfinance_model.option_expirations(self.ticker)
|
||||
else:
|
||||
self.expiry_dates = tradier_model.option_expirations(self.ticker)
|
||||
else:
|
||||
self.expiry_dates = []
|
||||
CHOICES += CHOICES_COMMANDS
|
||||
|
||||
def __init__(self):
|
||||
"""Construct data."""
|
||||
self.ticker = ""
|
||||
self.expiry_dates = []
|
||||
self.selected_date = ""
|
||||
self.op_parser = argparse.ArgumentParser(add_help=False, prog="op")
|
||||
|
||||
self.op_parser = argparse.ArgumentParser(add_help=False, prog="options")
|
||||
self.op_parser.add_argument(
|
||||
"cmd",
|
||||
choices=self.CHOICES,
|
||||
@@ -308,18 +306,10 @@ class OptionsController:
|
||||
syncretism_view.historical_greeks(self.ticker, self.selected_date, other_args)
|
||||
|
||||
|
||||
def menu(ticker: str):
|
||||
def menu():
|
||||
"""Options Menu."""
|
||||
|
||||
try:
|
||||
op_controller = OptionsController(ticker)
|
||||
op_controller.call_help(None)
|
||||
except IndexError:
|
||||
print("No options found for " + ticker)
|
||||
print("")
|
||||
process_input = False
|
||||
return process_input
|
||||
|
||||
op_controller = OptionsController()
|
||||
op_controller.call_help(None)
|
||||
while True:
|
||||
# Get input command from user
|
||||
if session and gtff.USE_PROMPT_TOOLKIT:
|
||||
@@ -327,11 +317,11 @@ def menu(ticker: str):
|
||||
{c: None for c in op_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (op)> ",
|
||||
f"{get_flair()} (options)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (op)> ")
|
||||
an_input = input(f"{get_flair()} (options)> ")
|
||||
|
||||
try:
|
||||
plt.close("all")
|
||||
@@ -1 +0,0 @@
|
||||
from . import papermill_controller # noqa: F401
|
||||
@@ -122,7 +122,7 @@ usage: alphist [-p --period] [-t --timeframe]
|
||||
* -p/--period The duration of the data in \<number> + \<unit>, such as 1D, where <unit> can be D for day, W for week, M for month and A for year. Defaults to 1M
|
||||
* -t/--timeframe The resolution of time window. 1Min, 5Min, 15Min, 1H, or 1D. If omitted, 1Min for less than 7 days period, 15Min for less than 30 days, or otherwise 1D.
|
||||
|
||||
|
||||
|
||||
## ALLY <a name="ALLY"></a>
|
||||
|
||||
In order to access your Ally Invest account through the API, you must first acquire a key from
|
||||
@@ -3,7 +3,7 @@ import numpy as np
|
||||
import ally
|
||||
import yfinance as yf
|
||||
from termcolor import colored
|
||||
from gamestonk_terminal.brokers.brokers_helpers import ally_positions_to_df
|
||||
from gamestonk_terminal.portfolio.brokers.brokers_helpers import ally_positions_to_df
|
||||
|
||||
# pylint: disable=no-member
|
||||
|
||||
@@ -12,7 +12,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
plot_autoscale,
|
||||
)
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.brokers.brokers_helpers import (
|
||||
from gamestonk_terminal.portfolio.brokers.brokers_helpers import (
|
||||
alpaca_positions_to_df,
|
||||
)
|
||||
|
||||
@@ -11,13 +11,13 @@ 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.brokers import (
|
||||
from gamestonk_terminal.portfolio.brokers import (
|
||||
rh_api,
|
||||
alp_api,
|
||||
ally_api,
|
||||
)
|
||||
from gamestonk_terminal.brokers.degiro import degiro_controller
|
||||
from gamestonk_terminal.brokers.brokers_helpers import (
|
||||
from gamestonk_terminal.portfolio.brokers.degiro import degiro_controller
|
||||
from gamestonk_terminal.portfolio.brokers.brokers_helpers import (
|
||||
merge_brokers_holdings,
|
||||
print_brokers_holdings,
|
||||
)
|
||||
@@ -240,11 +240,11 @@ def menu():
|
||||
{c: None for c in bro_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (bro)> ",
|
||||
f"{get_flair()} (portfolio)>(bro)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (bro)> ")
|
||||
an_input = input(f"{get_flair()} (portfolio)>(bro)> ")
|
||||
|
||||
try:
|
||||
process_input = bro_controller.switch(an_input)
|
||||
@@ -14,7 +14,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
parse_known_args_and_warn,
|
||||
)
|
||||
from gamestonk_terminal.menu import session
|
||||
from gamestonk_terminal.brokers.degiro.degiro_view import DegiroView
|
||||
from gamestonk_terminal.portfolio.brokers.degiro.degiro_view import DegiroView
|
||||
|
||||
|
||||
class DegiroController:
|
||||
@@ -14,7 +14,7 @@ from degiro_connector.trading.pb.trading_pb2 import (
|
||||
)
|
||||
|
||||
# IMPORTATION INTERNAL
|
||||
from gamestonk_terminal.brokers.degiro.degiro_model import DegiroModel
|
||||
from gamestonk_terminal.portfolio.brokers.degiro.degiro_model import DegiroModel
|
||||
|
||||
# pylint: disable=no-member
|
||||
|
||||
@@ -16,7 +16,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
)
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.config_terminal import RH_USERNAME as user, RH_PASSWORD as pw
|
||||
from gamestonk_terminal.brokers.brokers_helpers import rh_positions_to_df
|
||||
from gamestonk_terminal.portfolio.brokers.brokers_helpers import rh_positions_to_df
|
||||
|
||||
register_matplotlib_converters()
|
||||
|
||||
@@ -9,7 +9,7 @@ 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.portfolio_analysis import portfolio_parser
|
||||
from gamestonk_terminal.portfolio.portfolio_analysis import portfolio_parser
|
||||
|
||||
|
||||
class PortfolioController:
|
||||
@@ -123,11 +123,11 @@ def menu():
|
||||
{c: None for c in pa_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (pa)> ",
|
||||
f"{get_flair()} (portfolio)>(pa)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (pa)> ")
|
||||
an_input = input(f"{get_flair()} (portfolio)>(pa)> ")
|
||||
|
||||
try:
|
||||
process_input = pa_controller.switch(an_input)
|
||||
167
gamestonk_terminal/portfolio/portfolio_controller.py
Normal file
167
gamestonk_terminal/portfolio/portfolio_controller.py
Normal file
@@ -0,0 +1,167 @@
|
||||
import argparse
|
||||
import os
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
|
||||
from gamestonk_terminal.helper_funcs import get_flair
|
||||
|
||||
from gamestonk_terminal.menu import session
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
|
||||
from gamestonk_terminal.portfolio.brokers import bro_controller
|
||||
from gamestonk_terminal.portfolio.portfolio_analysis import pa_controller
|
||||
from gamestonk_terminal.portfolio.portfolio_optimization import po_controller
|
||||
|
||||
# pylint: disable=R1710
|
||||
|
||||
|
||||
class PortfolioController:
|
||||
"""Portfolio Controller class"""
|
||||
|
||||
CHOICES = [
|
||||
"cls",
|
||||
"?",
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
]
|
||||
|
||||
CHOICES_MENUS = [
|
||||
"load",
|
||||
"quote",
|
||||
"candle",
|
||||
"view",
|
||||
]
|
||||
|
||||
CHOICES_MENUS = [
|
||||
"bro",
|
||||
"pa",
|
||||
"po",
|
||||
]
|
||||
|
||||
CHOICES += CHOICES_MENUS
|
||||
|
||||
def __init__(self):
|
||||
"""Constructor"""
|
||||
self.port_parser = argparse.ArgumentParser(add_help=False, prog="portfolio")
|
||||
self.port_parser.add_argument(
|
||||
"cmd",
|
||||
choices=self.CHOICES,
|
||||
)
|
||||
self.completer = NestedCompleter.from_nested_dict(
|
||||
{c: None for c in self.CHOICES}
|
||||
)
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
help_text = """https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/portfolio
|
||||
|
||||
>> PORTFOLIO <<
|
||||
|
||||
What do you want to do?
|
||||
cls clear screen
|
||||
?/help show this menu again
|
||||
q quit this menu, and shows back to main menu
|
||||
quit quit to abandon the program
|
||||
|
||||
> bro brokers holdings, \t\t supports: robinhood, alpaca, ally
|
||||
> pa portfolio analysis, \t\t analyses your custom portfolio
|
||||
> po portfolio optimization, \t optimal portfolio weights from pyportfolioopt
|
||||
"""
|
||||
print(help_text)
|
||||
|
||||
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
|
||||
"""
|
||||
|
||||
# Empty command
|
||||
if not an_input:
|
||||
print("")
|
||||
return None
|
||||
|
||||
(known_args, other_args) = self.port_parser.parse_known_args(an_input.split())
|
||||
|
||||
# Help menu again
|
||||
if known_args.cmd == "?":
|
||||
self.print_help()
|
||||
return None
|
||||
|
||||
# Clear screen
|
||||
if known_args.cmd == "cls":
|
||||
os.system("cls||clear")
|
||||
return None
|
||||
|
||||
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 - exit the program"""
|
||||
return True
|
||||
|
||||
# MENUS
|
||||
def call_bro(self, _):
|
||||
"""Process bro command"""
|
||||
ret = bro_controller.menu()
|
||||
if ret is False:
|
||||
self.print_help()
|
||||
else:
|
||||
return True
|
||||
|
||||
def call_pa(self, _):
|
||||
"""Process pa command"""
|
||||
ret = pa_controller.menu()
|
||||
if ret is False:
|
||||
self.print_help()
|
||||
else:
|
||||
return True
|
||||
|
||||
def call_po(self, _):
|
||||
"""Process po command"""
|
||||
ret = po_controller.menu()
|
||||
if ret is False:
|
||||
self.print_help()
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def menu():
|
||||
"""Portfolio Menu"""
|
||||
portfolio_controller = PortfolioController()
|
||||
portfolio_controller.call_help(None)
|
||||
while True:
|
||||
if session and gtff.USE_PROMPT_TOOLKIT:
|
||||
completer = NestedCompleter.from_nested_dict(
|
||||
{c: None for c in portfolio_controller.CHOICES}
|
||||
)
|
||||
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (portfolio)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (portfolio)> ")
|
||||
|
||||
try:
|
||||
process_input = portfolio_controller.switch(an_input)
|
||||
|
||||
if process_input is not None:
|
||||
return process_input
|
||||
|
||||
except SystemExit:
|
||||
print("The command selected doesn't exit\n")
|
||||
continue
|
||||
@@ -15,7 +15,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
plot_autoscale,
|
||||
check_non_negative,
|
||||
)
|
||||
from gamestonk_terminal.portfolio_optimization.optimizer_helper import (
|
||||
from gamestonk_terminal.portfolio.portfolio_optimization.optimizer_helper import (
|
||||
process_stocks,
|
||||
prepare_efficient_frontier,
|
||||
pie_chart_weights,
|
||||
@@ -9,7 +9,7 @@ from prompt_toolkit.completion import NestedCompleter
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal.helper_funcs import get_flair, parse_known_args_and_warn
|
||||
from gamestonk_terminal.menu import session
|
||||
from gamestonk_terminal.portfolio_optimization import optimizer_view
|
||||
from gamestonk_terminal.portfolio.portfolio_optimization import optimizer_view
|
||||
|
||||
|
||||
class PortfolioOptimization:
|
||||
@@ -37,17 +37,12 @@ class PortfolioOptimization:
|
||||
]
|
||||
|
||||
# pylint: disable=dangerous-default-value
|
||||
def __init__(
|
||||
self,
|
||||
tickers: List[str],
|
||||
):
|
||||
"""
|
||||
Construct Portfolio Optimization
|
||||
"""
|
||||
def __init__(self):
|
||||
"""Construct Portfolio Optimization"""
|
||||
|
||||
self.po_parser = argparse.ArgumentParser(add_help=False, prog="po")
|
||||
self.po_parser.add_argument("cmd", choices=self.CHOICES)
|
||||
self.tickers = list(set(tickers))
|
||||
self.tickers = list()
|
||||
|
||||
@staticmethod
|
||||
def print_help(tickers: List[str]):
|
||||
@@ -273,13 +268,11 @@ class PortfolioOptimization:
|
||||
print(e, "\n")
|
||||
|
||||
|
||||
def menu(tickers: List[str]):
|
||||
def menu():
|
||||
"""Portfolio Optimization Menu"""
|
||||
if tickers == [""]:
|
||||
tickers = []
|
||||
plt.close("all")
|
||||
po_controller = PortfolioOptimization(tickers)
|
||||
po_controller.call_help(tickers)
|
||||
po_controller = PortfolioOptimization()
|
||||
po_controller.call_help([])
|
||||
|
||||
while True:
|
||||
# Get input command from user
|
||||
@@ -288,11 +281,11 @@ def menu(tickers: List[str]):
|
||||
{c: None for c in po_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (po)> ",
|
||||
f"{get_flair()} (portfolio)>(po)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (po)> ")
|
||||
an_input = input(f"{get_flair()} (portfolio)>(po)> ")
|
||||
|
||||
try:
|
||||
plt.close("all")
|
||||
@@ -69,4 +69,3 @@ usage: learn
|
||||
```
|
||||
|
||||
<img width="1231" alt="Captura de ecrã 2021-05-01, às 21 16 07" src="https://user-images.githubusercontent.com/25267873/116794091-79df8080-aac2-11eb-902c-0d165ee3563b.png">
|
||||
|
||||
@@ -20,6 +20,9 @@ class ResourceCollectionController:
|
||||
"help",
|
||||
"q",
|
||||
"quit",
|
||||
]
|
||||
|
||||
CHOICES_COMMANDS = [
|
||||
"hfletters",
|
||||
"arxiv",
|
||||
"finra",
|
||||
@@ -28,9 +31,11 @@ class ResourceCollectionController:
|
||||
"learn",
|
||||
]
|
||||
|
||||
CHOICES += CHOICES_COMMANDS
|
||||
|
||||
def __init__(self):
|
||||
"""Constructor"""
|
||||
self.rc_parser = argparse.ArgumentParser(add_help=False, prog="rc")
|
||||
self.rc_parser = argparse.ArgumentParser(add_help=False, prog="resources")
|
||||
self.rc_parser.add_argument(
|
||||
"cmd",
|
||||
choices=self.CHOICES,
|
||||
@@ -40,9 +45,12 @@ class ResourceCollectionController:
|
||||
def print_help():
|
||||
"""Print help"""
|
||||
print(
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/resource_collection"
|
||||
"https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/resources"
|
||||
)
|
||||
print("\nResources:")
|
||||
print("")
|
||||
print(">> RESOURCES <<")
|
||||
print("")
|
||||
print("What do you want to do?")
|
||||
print(" cls clear screen")
|
||||
print(" ?/help show this menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
@@ -147,11 +155,11 @@ def menu():
|
||||
{c: None for c in rc_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (rc)> ",
|
||||
f"{get_flair()} (resources)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (rc)> ")
|
||||
an_input = input(f"{get_flair()} (resources)> ")
|
||||
|
||||
try:
|
||||
process_input = rc_controller.switch(an_input)
|
||||
@@ -1,11 +1,11 @@
|
||||
# Backtesting
|
||||
|
||||
This menu aims to apply backtesting strategies regarding a pre-loaded ticker, and the usage of the following commands along with an example will be exploited below. Note that this is currently just a simple logic (i.e price comparisons). These strategies should not be used immediately and should be researched, improved and further tested on your own.
|
||||
This menu aims to apply backtesting strategies regarding a pre-loaded ticker, and the usage of the following commands along with an example will be exploited below. Note that this is currently just a simple logic (i.e price comparisons). These strategies should not be used immediately and should be researched, improved and further tested on your own.
|
||||
|
||||
* [ema](#ema)
|
||||
* buy when price exceeds EMA(l)
|
||||
* [ema_cross](#ema_cross)
|
||||
* buy when EMA(short) > EMA(long)
|
||||
* [ema_cross](#ema_cross)
|
||||
* buy when EMA(short) > EMA(long)
|
||||
* [rsi](#rsi)
|
||||
* buy when RSI < low and sell when RSI > high
|
||||
|
||||
@@ -27,7 +27,7 @@ This strategy buys when price > EMA(l).
|
||||
|
||||
### ema_cross <a name="ema_cross"></a>
|
||||
````
|
||||
usage: ema_cross [-l] [-s] [--spy] [--no_bench] [--no_short]
|
||||
usage: ema_cross [-l] [-s] [--spy] [--no_bench] [--no_short]
|
||||
````
|
||||
|
||||
This strategy goes long when EMA(short) > EMA(long) and goes short when EMA(short) < EMA(long). It provides the option to go long only through the --no_short flag.
|
||||
@@ -43,7 +43,7 @@ This strategy goes long when EMA(short) > EMA(long) and goes short when EMA(shor
|
||||
|
||||
### rsi <a name="rsi"></a>
|
||||
````
|
||||
usage: rsi [-u] [-l] [-p] [--spy] [--no_bench] [--no_short]
|
||||
usage: rsi [-u] [-l] [-p] [--spy] [--no_bench] [--no_short]
|
||||
````
|
||||
|
||||
This strategy goes long when the RSI is "oversold" - defined as the low parameter. It goes short when the RSI is "overbought" - defined as the high (upper) parameter
|
||||
@@ -17,7 +17,7 @@ from gamestonk_terminal.menu import session
|
||||
# Save current matplotlib backend
|
||||
default_backend = mpl.get_backend()
|
||||
# pylint: disable=wrong-import-position
|
||||
from gamestonk_terminal.backtesting import bt_view # noqa: E402
|
||||
from gamestonk_terminal.stocks.backtesting import bt_view # noqa: E402
|
||||
|
||||
# Restore backend matplotlib used
|
||||
mpl.use(default_backend)
|
||||
@@ -127,11 +127,11 @@ def menu(ticker: str, start: Union[str, datetime]):
|
||||
{c: None for c in bt_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (bt)> ",
|
||||
f"{get_flair()} (stocks)>(bt)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (bt)> ")
|
||||
an_input = input(f"{get_flair()} (stocks)>(bt)> ")
|
||||
|
||||
try:
|
||||
plt.close("all")
|
||||
@@ -8,7 +8,11 @@ import pandas as pd
|
||||
import bt
|
||||
import pandas_ta as ta
|
||||
from gamestonk_terminal.helper_funcs import check_positive, parse_known_args_and_warn
|
||||
from gamestonk_terminal.backtesting.bt_helper import buy_and_hold, plot_bt, get_data
|
||||
from gamestonk_terminal.stocks.backtesting.bt_helper import (
|
||||
buy_and_hold,
|
||||
plot_bt,
|
||||
get_data,
|
||||
)
|
||||
|
||||
np.seterr(divide="ignore")
|
||||
|
||||
363
gamestonk_terminal/stocks/behavioural_analysis/README.md
vendored
Normal file
363
gamestonk_terminal/stocks/behavioural_analysis/README.md
vendored
Normal file
@@ -0,0 +1,363 @@
|
||||
# BEHAVIOURAL ANALYSIS
|
||||
|
||||
This menu aims to extrapolate behavioural analysis regarding a pre-loaded ticker, and the usage of the following commands along with an example will be exploited below.
|
||||
|
||||
* [finbrain](#finbrain)
|
||||
- sentiment from 15+ major news headlines
|
||||
* [stats](#stats)
|
||||
- sentiment stats including comparison with sector
|
||||
|
||||
[REDDIT](#REDDIT)
|
||||
* [wsb](#wsb)
|
||||
- show what WSB gang is up to in subreddit wallstreetbets
|
||||
* [watchlist](#watchlist)
|
||||
- show other users watchlist
|
||||
* [popular](#popular)
|
||||
- show popular tickers
|
||||
* [spac_c](#spac_c)
|
||||
- show other users spacs announcements from subreddit SPACs community
|
||||
* [spac](#spac)
|
||||
- show other users spacs announcements from other subs
|
||||
|
||||
[STOCKTWITS](#STOCKTWITS)
|
||||
* [bullbear](#bullbear)
|
||||
- estimate quick sentiment from last 30 messages on board
|
||||
* [messages](#messages)
|
||||
- output up to the 30 last messages on the board
|
||||
* [trending](#trending)
|
||||
- trending stocks
|
||||
* [stalker](#stalker)
|
||||
- stalk stocktwits user's last messages
|
||||
|
||||
[TWITTER](#TWITTER)
|
||||
* [infer](#infer)
|
||||
- infer about stock's sentiment from latest tweets
|
||||
* [sentiment](#sentiment)
|
||||
- in-depth sentiment prediction from tweets over time
|
||||
|
||||
[GOOGLE](#GOOGLE)
|
||||
* [mentions](#mentions)
|
||||
- interest over time based on stock's mentions
|
||||
* [regions](#regions)
|
||||
- regions that show highest interest in stock
|
||||
* [queries](#queries)
|
||||
- top related queries with this stock
|
||||
* [rise](#rise)
|
||||
- top rising related queries with stock
|
||||
|
||||
[SENTIMENT INVESTOR](#SENTIMENTINVESTOR)
|
||||
* [metrics](#metrics)
|
||||
- core social sentiment metrics for this stock
|
||||
* [social](#social)
|
||||
- social media figures for stock popularity
|
||||
* [historical](#historical)
|
||||
- plot the past week of data for a selected metric
|
||||
|
||||
## finbrain <a name="finbrain"></a>
|
||||
```
|
||||
usage: finbrain
|
||||
```
|
||||
FinBrain collects the news headlines from 15+ major financial news sources on a daily basis and analyzes them to generate sentiment scores for more than 4500 US stocks. FinBrain Technologies develops deep learning algorithms for financial analysis and prediction, which currently serves traders from more than 150 countries all around the world. [Source: See https://finbrain.tech]
|
||||
|
||||

|
||||
|
||||
<img width="986" alt="Captura de ecrã 2021-03-18, às 12 53 31" src="https://user-images.githubusercontent.com/25267873/111629542-4fbf5100-87e9-11eb-8d5d-96faa8d3fca4.png">
|
||||
|
||||
|
||||
## stats <a name="stats"></a>
|
||||
```
|
||||
usage: stats
|
||||
```
|
||||
Sentiment stats which displays buzz, news score, articles last week, articles weekly average, bullish vs bearish percentages, sector average bullish percentage, and sector average news score. [Source: https://finnhub.io]
|
||||
|
||||
<img width="1003" alt="Captura de ecrã 2021-05-03, às 15 26 09" src="https://user-images.githubusercontent.com/25267873/116888922-e9b94c80-ac23-11eb-959e-be24c79488a3.png">
|
||||
|
||||
|
||||
# REDDIT <a name="REDDIT"></a>
|
||||
|
||||
## wsb <a name="wsb"></a>
|
||||
```
|
||||
usage: wsb [-l N_LIMIT] [-n]
|
||||
```
|
||||
Print what WSB gang are up to in subreddit wallstreetbets. [Source: Reddit]
|
||||
* -l : limit of posts to print. Default 10.
|
||||
* -n : new flag, if true the posts retrieved are based on being more recent rather than their score. Default False.
|
||||
|
||||
<img width="947" alt="wsb" src="https://user-images.githubusercontent.com/25267873/108612074-d5afce00-73dc-11eb-80ca-8ecfad12020c.png">
|
||||
|
||||
|
||||
## watchlist <a name="watchlist"></a>
|
||||
```
|
||||
usage: watchlist [-l N_LIMIT]
|
||||
```
|
||||
Print other users watchlist. [Source: Reddit]
|
||||
* -l : limit of posts to print. Default 5.
|
||||
|
||||
<img width="941" alt="watchlist" src="https://user-images.githubusercontent.com/25267873/108920576-caeb7800-762c-11eb-937c-94ecbb65d119.png">
|
||||
|
||||
|
||||
## popular <a name="popular"></a>
|
||||
```
|
||||
usage: popular [-l N_LIMIT] [-s S_SUBREDDIT] [-d N_DAYS]
|
||||
```
|
||||
Print latest popular tickers. [Source: Reddit]
|
||||
* -l : limit of posts retrieved per sub reddit. Default 50.
|
||||
* -s : subreddits to look for tickers, e.g. pennystocks,stocks. Default: pennystocks, RobinHoodPennyStocks, Daytrading, StockMarket, stocks, investing, wallstreetbets.
|
||||
|
||||
<img width="948" alt="popular" src="https://user-images.githubusercontent.com/25267873/108917846-4dbe0400-7628-11eb-821e-9fda97a6d9cd.png">
|
||||
|
||||
|
||||
## spac_c <a name="spac_c"></a>
|
||||
```
|
||||
usage: spac_c [-l N_LIMIT] [-p]
|
||||
```
|
||||
Print other users SPACs announcement under subreddit 'SPACs'. [Source: Reddit]
|
||||
* -l : limit of posts with SPACs retrieved. Default 10.
|
||||
* -p : popular flag, if true the posts retrieved are based on score rather than time. Default False.
|
||||
|
||||
<img width="936" alt="spac_c" src="https://user-images.githubusercontent.com/25267873/108920571-c8891e00-762c-11eb-8da8-e2b775bc7109.png">
|
||||
|
||||
|
||||
## spac <a name="spac"></a>
|
||||
```
|
||||
usage: spac [-h] [-l N_LIMIT] [-d N_DAYS]
|
||||
```
|
||||
Print other users SPACs announcement under subreddit 'SPACs'. [Source: Reddit]
|
||||
* -l : limit of posts with SPACs retrieved. Default 5.
|
||||
|
||||
<img width="939" alt="spac" src="https://user-images.githubusercontent.com/25267873/108920696-04bc7e80-762d-11eb-896b-1b1c19903584.png">
|
||||
|
||||
|
||||
# STOCKTWITS <a name="STOCKTWITS"></a>
|
||||
|
||||
## bullbear <a name="bullbear"></a>
|
||||
```
|
||||
usage: bullbear [-t S_TICKER]
|
||||
```
|
||||
Print bullbear sentiment based on last 30 messages on the board. Also prints the watchlist_count. [Source: Stocktwits]
|
||||
* -t : ticker to gather sentiment from.
|
||||
|
||||
<img width="934" alt="sentiment" src="https://user-images.githubusercontent.com/25267873/108612307-42c46300-73df-11eb-9cec-253c8fb6d62f.png">
|
||||
|
||||
|
||||
## messages <a name="messages"></a>
|
||||
```
|
||||
usage: messages [-t S_TICKER] [-l N_LIM]
|
||||
```
|
||||
Print up to 30 of the last messages on the board. [Source: Stocktwits]
|
||||
* -t : get board messages from this ticker. Default pre-loaded.
|
||||
* -l : limit messages shown. Default 30.
|
||||
|
||||
<img width="958" alt="messages" src="https://user-images.githubusercontent.com/25267873/108612310-448e2680-73df-11eb-8fa8-b619c6269742.png">
|
||||
|
||||
|
||||
## trending <a name="trending"></a>
|
||||
```
|
||||
usage: trending
|
||||
```
|
||||
Stocks trending. [Source: Stocktwits]
|
||||
|
||||
<img width="956" alt="trending" src="https://user-images.githubusercontent.com/25267873/108612311-4526bd00-73df-11eb-840b-18829fcecdd3.png">
|
||||
|
||||
|
||||
## stalker <a name="stalker"></a>
|
||||
```
|
||||
usage: stalker [-u S_USER] [-l N_LIM]
|
||||
```
|
||||
Print up to the last 30 messages of a user. [Source: Stocktwits]
|
||||
* -u : username. Default newsfilter.
|
||||
* -l : limit messages shown. Default 30.
|
||||
|
||||
<img width="943" alt="stalker" src="https://user-images.githubusercontent.com/25267873/108612309-435cf980-73df-11eb-92c9-e9f15f966d8e.png">
|
||||
|
||||
|
||||
# TWITTER <a name="TWITTER"></a>
|
||||
Uses VADER sentiment. VADER (Valence Aware Dictionary and sEntiment Reasoner) is a lexicon and rule-based sentiment analysis
|
||||
tool that is specifically attuned to sentiments expressed in social media.
|
||||
|
||||
The output of VADER analysis :
|
||||
```
|
||||
The compound score is computed by summing the valence scores of each word in the lexicon, adjusted according to the
|
||||
rules, and then normalized to be between -1 (most extreme negative) and +1 (most extreme positive). This is the most
|
||||
useful metric if you want a single unidimensional measure of sentiment for a given sentence. Calling it a 'normalized,
|
||||
weighted composite score' is accurate.
|
||||
```
|
||||
A sample tweet is shown below along with what the VADER polarity scores are.
|
||||
|
||||
```'
|
||||
Have some $SENS 🚀🏆\n👉FDA approval coming very soon, 👉News is out, amazing test results. \n👉Very high short
|
||||
interest rate. \n👉Major short squeeze coming. \n\n$amc $gme $nakd $ctrm $tsla $aapl $oeg $aht $bbby $bb $fsr $spce
|
||||
https://t.co/B0cPhufpA2'
|
||||
```
|
||||
|
||||
This gives the following scores:
|
||||
```python
|
||||
created_at Thu Jun 03 20:37:54
|
||||
text Have some $SENS 🚀🏆\n👉FDA approval coming very...
|
||||
sentiment 0.872
|
||||
positive 0.177
|
||||
negative 0
|
||||
neutral 0.823
|
||||
```
|
||||
|
||||
Note that both functions use twitters v2 endpoint, which only gives 7 days of historical data. It also requires at least 10 tweets be pulled.
|
||||
|
||||
## infer <a name="infer"></a>
|
||||
```
|
||||
usage: infer [-n N_NUM]
|
||||
```
|
||||
Print quick sentiment inference from last tweets that contain the ticker. This model splits the text into character-level tokens and uses theVADER model to make predictions.
|
||||
* -n : num of latest tweets to infer from. Default 100.
|
||||
|
||||
|
||||
## sentiment <a name="sentiment"></a>
|
||||
```
|
||||
usage: sentiment [-n N_NUM] [-d N_DAYS_PAST]
|
||||
```
|
||||
Plot in-depth sentiment extracted from tweets from last days that contain pre-defined ticker. This model splits the text into character-level tokens and uses the VADER model to make predictions.
|
||||
* -n : num of tweets to extract per hour. Default 15.
|
||||
* -d : num of days in the past to extract tweets. Default 6. Max 6
|
||||
|
||||
# GOOGLE
|
||||
|
||||
## mentions <a name="mentions"></a>
|
||||
```
|
||||
usage: mentions [-s S_START]
|
||||
```
|
||||
Plot weekly bars of stock's interest over time. other users watchlist. [Source: Google]
|
||||
* -s : starting date (format YYYY-MM-DD) from when we are interested in stock's mentions. Default: the one provided in main menu.
|
||||
|
||||

|
||||
|
||||
|
||||
## regions <a name="regions"></a>
|
||||
```
|
||||
usage: regions [-n N_NUM]
|
||||
```
|
||||
Plot bars of regions based on stock's interest. [Source: Google]
|
||||
* -n : number of regions to plot that show highest interest. Default 10.
|
||||
|
||||

|
||||
|
||||
|
||||
## queries <a name="queries"></a>
|
||||
```
|
||||
usage: queries [-n N_NUM]
|
||||
```
|
||||
Print top related queries with this stock's query. [Source: Google]
|
||||
* -n : number of top related queries to print. Default 10.
|
||||
|
||||
<img width="937" alt="Captura de ecrã 2021-02-22, às 22 15 16" src="https://user-images.githubusercontent.com/25267873/108777341-91970780-755b-11eb-985e-819285688eea.png">
|
||||
|
||||
|
||||
## rise <a name="rise"></a>
|
||||
```
|
||||
usage: rise [-n N_NUM]
|
||||
```
|
||||
Print top rising related queries with this stock's query. [Source: Google]
|
||||
* -n : number of top rising related queries to print. Default 10.
|
||||
|
||||
<img width="934" alt="Captura de ecrã 2021-02-22, às 22 21 21" src="https://user-images.githubusercontent.com/25267873/108777814-4f21fa80-755c-11eb-96da-0327c9a0da57.png">
|
||||
|
||||
# SENTIMENTINVESTOR
|
||||
|
||||
> **[Sentiment Investor](https://sentimentinvestor.com)** analyzes data from four major social media platforms to
|
||||
> generate hourly metrics on over 2,000 stocks. Sentiment provides volume and
|
||||
> sentiment metrics powered by proprietary NLP models.
|
||||
|
||||
## Metric definitions
|
||||
|
||||
### AHI (Absolute Hype Index) <a name="AHI"></a>
|
||||
|
||||
AHI is a measure of how much people are talking about a stock on social media.
|
||||
It is calculated by dividing the total number of mentions for the chosen stock
|
||||
on a social network by the mean number of mentions any stock receives on that
|
||||
social medium.
|
||||
|
||||
### RHI (Relative Hype Index) <a name="RHI"></a>
|
||||
|
||||
RHI is a measure of whether people are talking about a stock more or less than
|
||||
usual, calculated by dividing the mean AHI for the past day by the mean AHI for
|
||||
for the past week for that stock.
|
||||
|
||||
### Sentiment Score <a name="sentiment"></a>
|
||||
|
||||
Sentiment score is the percentage of people talking positively about the stock.
|
||||
For each social network the number of positive posts/comments is divided by the
|
||||
total number of both positive and negative posts/comments.
|
||||
|
||||
### SGP (Standard General Perception) <a name="SGP"></a>
|
||||
|
||||
SGP is a measure of whether people are more or less positive about a stock than
|
||||
usual. It is calculated by averaging the past day of sentiment values and then
|
||||
dividing it by the average of the past week of sentiment values.
|
||||
|
||||
## metrics <a name="metrics"></a>
|
||||
|
||||
```
|
||||
usage: metrics [-h] [ticker]
|
||||
```
|
||||
|
||||
The `metrics` command presents the four core metrics provided by Sentiment Investor,
|
||||
including AHI, RHI, sentiment and SGP, as described above.
|
||||
|
||||
Optional arguments:
|
||||
- [optional, positional] ticker
|
||||
ticker to use instead of the loaded one
|
||||
- `-h`, `--help`
|
||||
show this help message
|
||||
|
||||
Example output:
|
||||
|
||||

|
||||
|
||||
## social <a name="social"></a>
|
||||
|
||||
```
|
||||
usage: social [-h] [ticker]
|
||||
```
|
||||
|
||||
The `social` command prints the raw data for a given stock, including the number
|
||||
of mentions it has received on social media in the last hour and the sentiment
|
||||
score of those comments.
|
||||
|
||||
Optional arguments:
|
||||
- [optional, positional] ticker
|
||||
ticker to use instead of the loaded one
|
||||
- `-h`, `--help`
|
||||
show this help message
|
||||
|
||||
Example output:
|
||||
|
||||

|
||||
|
||||
## historical <a name="historical"></a>
|
||||
|
||||
```
|
||||
usage: historical [-t TICKER] [-s [{date,value}]] [-d [{asc,desc}]] [-h] [{sentiment,AHI,RHI,SGP}]
|
||||
```
|
||||
|
||||
The `historical` command plots the past week of data for a selected
|
||||
SentimentInvestor core metric, one of:
|
||||
[AHI](#ahi), [RHI](#ahi), [sentiment](#sentiment) or [SGP](#SGP).
|
||||
It also outputs a sorted table of the mean value for that metric for each day.
|
||||
|
||||
Positional arguments:
|
||||
- one of `sentiment`, `AHI`, `RHI` or `SGP`
|
||||
(optional) the metric to plot (default: `sentiment`)
|
||||
|
||||
Optional arguments:
|
||||
- `-t`, `--ticker TICKER`
|
||||
ticker for which to fetch data
|
||||
- `-s`, `--sort [{date,value}]`
|
||||
the parameter to sort output table by
|
||||
- `-d`, `--direction [{asc,desc}]`
|
||||
the direction to sort the output table
|
||||
- `-h`, `--help`
|
||||
show this help message
|
||||
|
||||
Example output:
|
||||
|
||||

|
||||
|
||||

|
||||
@@ -10,7 +10,7 @@ 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.behavioural_analysis import (
|
||||
from gamestonk_terminal.common.behavioural_analysis import (
|
||||
google_view,
|
||||
reddit_view,
|
||||
stocktwits_view,
|
||||
@@ -216,7 +216,7 @@ class BehaviouralAnalysisController:
|
||||
|
||||
try:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from gamestonk_terminal.behavioural_analysis import twitter_view
|
||||
from gamestonk_terminal.common.behavioural_analysis import twitter_view
|
||||
except ModuleNotFoundError as e:
|
||||
print("Optional packages need to be installed")
|
||||
print(e, "\n")
|
||||
@@ -236,7 +236,7 @@ class BehaviouralAnalysisController:
|
||||
|
||||
try:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from gamestonk_terminal.behavioural_analysis import twitter_view
|
||||
from gamestonk_terminal.common.behavioural_analysis import twitter_view
|
||||
except ModuleNotFoundError as e:
|
||||
print("Optional packages need to be installed")
|
||||
print(e, "\n")
|
||||
@@ -268,15 +268,12 @@ class BehaviouralAnalysisController:
|
||||
sentimentinvestor_view.historical(self.ticker, other_args)
|
||||
|
||||
|
||||
def menu(ticker: str, start: datetime, context: str = ""):
|
||||
def menu(ticker: str, start: datetime):
|
||||
"""Behavioural Analysis Menu"""
|
||||
|
||||
ba_controller = BehaviouralAnalysisController(ticker, start)
|
||||
ba_controller.call_help(None)
|
||||
|
||||
if context:
|
||||
context = f"({context})>"
|
||||
|
||||
while True:
|
||||
# Get input command from user
|
||||
if session and gtff.USE_PROMPT_TOOLKIT:
|
||||
@@ -284,11 +281,11 @@ def menu(ticker: str, start: datetime, context: str = ""):
|
||||
{c: None for c in ba_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} {context}(ba)> ",
|
||||
f"{get_flair()} (stocks)>(ba)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} {context}(ba)> ")
|
||||
an_input = input(f"{get_flair()} (stocks)>(ba)> ")
|
||||
|
||||
try:
|
||||
process_input = ba_controller.switch(an_input)
|
||||
@@ -15,13 +15,15 @@ from prompt_toolkit.completion import NestedCompleter
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from gamestonk_terminal import config_terminal as cfg
|
||||
from gamestonk_terminal.helper_funcs import get_flair, parse_known_args_and_warn
|
||||
from gamestonk_terminal.comparison_analysis import yahoo_finance_view
|
||||
from gamestonk_terminal.comparison_analysis import market_watch_view
|
||||
from gamestonk_terminal.comparison_analysis import finbrain_view
|
||||
from gamestonk_terminal.comparison_analysis import finviz_compare_view
|
||||
from gamestonk_terminal.portfolio_optimization import po_controller
|
||||
from gamestonk_terminal.stocks.comparison_analysis import yahoo_finance_view
|
||||
from gamestonk_terminal.stocks.comparison_analysis import market_watch_view
|
||||
from gamestonk_terminal.stocks.comparison_analysis import finbrain_view
|
||||
from gamestonk_terminal.stocks.comparison_analysis import finviz_compare_view
|
||||
from gamestonk_terminal.portfolio.portfolio_optimization import po_controller
|
||||
from gamestonk_terminal.menu import session
|
||||
|
||||
# pylint: disable=E1121
|
||||
|
||||
|
||||
class ComparisonAnalysisController:
|
||||
"""Comparison Analysis Controller class"""
|
||||
@@ -413,11 +415,11 @@ def menu(ticker: str, start: datetime, interval: str, stock: pd.DataFrame):
|
||||
{c: None for c in ca_controller.CHOICES}
|
||||
)
|
||||
an_input = session.prompt(
|
||||
f"{get_flair()} (ca)> ",
|
||||
f"{get_flair()} (stocks)>(ca)> ",
|
||||
completer=completer,
|
||||
)
|
||||
else:
|
||||
an_input = input(f"{get_flair()} (ca)> ")
|
||||
an_input = input(f"{get_flair()} (stocks)>(ca)> ")
|
||||
|
||||
try:
|
||||
plt.close("all")
|
||||
@@ -13,7 +13,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
)
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
|
||||
from gamestonk_terminal.discovery import ark_model
|
||||
from gamestonk_terminal.stocks.discovery import ark_model
|
||||
|
||||
|
||||
def direction_color_red_green(val: str) -> str:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user