mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
Fixing pylint errors and warnings
This commit is contained in:
@@ -54,7 +54,7 @@ confidence=
|
||||
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
|
||||
# disable=too-many-instance-attributes,len-as-condition,too-few-public-methods,anomalous-backslash-in-string,no-else-return,simplifiable-if-statement,too-many-arguments,duplicate-code,no-name-in-module,no-member,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,missing-docstring,invalid-name,bad-whitespace,consider-using-enumerate,unexpected-keyword-arg
|
||||
|
||||
disable=useless-return,missing-docstring,invalid-name,import-error,bad-continuation,broad-except,unnecessary-lambda,no-self-use,duplicate-code,consider-using-generator
|
||||
disable=useless-return,missing-docstring,invalid-name,import-error,bad-continuation,broad-except,unnecessary-lambda,no-self-use,duplicate-code,consider-using-generator,unbalanced-tuple-unpacking
|
||||
|
||||
# Enable the message, report, category or checker with the given id(s). You can
|
||||
# either give multiple identifier separated by comma (,) or put this option
|
||||
@@ -397,7 +397,7 @@ valid-metaclass-classmethod-first-arg=mcs
|
||||
[DESIGN]
|
||||
|
||||
# Maximum number of arguments for function / method
|
||||
max-args=5
|
||||
max-args=8
|
||||
|
||||
# Maximum number of attributes for a class (see R0902).
|
||||
# max-attributes=7
|
||||
@@ -416,7 +416,7 @@ max-locals=40
|
||||
max-parents=7
|
||||
|
||||
# Maximum number of public methods for a class (see R0904).
|
||||
max-public-methods=20
|
||||
max-public-methods=30
|
||||
|
||||
# Maximum number of return / yield for function / method body
|
||||
max-returns=9
|
||||
|
||||
@@ -4,6 +4,7 @@ __docformat__ = "numpy"
|
||||
import argparse
|
||||
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
|
||||
@@ -14,7 +15,6 @@ from gamestonk_terminal.behavioural_analysis import (
|
||||
stocktwits_view,
|
||||
finbrain_view,
|
||||
)
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
|
||||
|
||||
class BehaviouralAnalysisController:
|
||||
|
||||
@@ -9,13 +9,14 @@ import matplotlib.dates as mdates
|
||||
import pandas as pd
|
||||
from pandas.plotting import register_matplotlib_converters
|
||||
import numpy as np
|
||||
from colorama import Fore, Style
|
||||
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
parse_known_args_and_warn,
|
||||
plot_autoscale,
|
||||
)
|
||||
from gamestonk_terminal.config_plot import PLOT_DPI
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from colorama import Fore, Style
|
||||
|
||||
|
||||
register_matplotlib_converters()
|
||||
|
||||
@@ -189,17 +189,6 @@ def popular_tickers(l_args):
|
||||
wallstreetbets
|
||||
""",
|
||||
)
|
||||
"""
|
||||
parser.add_argument(
|
||||
"-d",
|
||||
"--days",
|
||||
action="store",
|
||||
dest="n_days",
|
||||
type=check_positive,
|
||||
default=1,
|
||||
help="look for the tickers from those n past days.",
|
||||
)
|
||||
"""
|
||||
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, l_args)
|
||||
@@ -502,17 +491,6 @@ def spac(l_args):
|
||||
default=5,
|
||||
help="limit of posts with SPACs retrieved.",
|
||||
)
|
||||
"""
|
||||
parser.add_argument(
|
||||
"-d",
|
||||
"--days",
|
||||
action="store",
|
||||
dest="n_days",
|
||||
type=check_positive,
|
||||
default=5,
|
||||
help="look for the tickers from those n past days.",
|
||||
)
|
||||
"""
|
||||
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, l_args)
|
||||
|
||||
@@ -44,14 +44,9 @@ def check_one_of_ohlca(type_candles: str) -> str:
|
||||
Unknown candle type
|
||||
"""
|
||||
|
||||
if (
|
||||
type_candles == "o"
|
||||
or type_candles == "h"
|
||||
or type_candles == "l"
|
||||
or type_candles == "c"
|
||||
or type_candles == "a"
|
||||
):
|
||||
if type_candles in ("o", "h", "l", "c", "a"):
|
||||
return type_candles
|
||||
|
||||
raise argparse.ArgumentTypeError("The type of candles specified is not recognized")
|
||||
|
||||
|
||||
|
||||
@@ -4,10 +4,11 @@ __docformat__ = "numpy"
|
||||
import argparse
|
||||
from typing import List
|
||||
import webbrowser
|
||||
from gamestonk_terminal.helper_funcs import parse_known_args_and_warn
|
||||
from finvizfinance.group import valuation, performance, spectrum
|
||||
from PIL import Image
|
||||
|
||||
from gamestonk_terminal.helper_funcs import parse_known_args_and_warn
|
||||
|
||||
l_GROUPS = [
|
||||
"Sector",
|
||||
"Industry",
|
||||
@@ -97,6 +98,7 @@ def get_valuation_performance_data(group: str, data_type: str):
|
||||
pd.DataFrame
|
||||
dataframe with valuation/performance data
|
||||
"""
|
||||
|
||||
if data_type == "valuation":
|
||||
df_group = valuation.Valuation().ScreenerView(group=group)
|
||||
elif data_type == "performance":
|
||||
@@ -117,6 +119,7 @@ def get_spectrum_data(group: str):
|
||||
data_type : str
|
||||
select data type to see data between valuation or performance
|
||||
"""
|
||||
|
||||
spectrum.Spectrum().ScreenerView(group=group)
|
||||
|
||||
|
||||
@@ -130,6 +133,7 @@ def view_group_data(other_args: List[str], data_type: str):
|
||||
data_type : str
|
||||
select data type to see data between valuation, performance and spectrum
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="group_data",
|
||||
@@ -156,12 +160,12 @@ def view_group_data(other_args: List[str], data_type: str):
|
||||
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
return None
|
||||
|
||||
if isinstance(ns_parser.group, List):
|
||||
ns_parser.group = ns_parser.group[0]
|
||||
|
||||
if data_type == "valuation" or data_type == "performance":
|
||||
if data_type in ("valuation", "performance"):
|
||||
df_group = get_valuation_performance_data(ns_parser.group, data_type)
|
||||
print(df_group.to_string())
|
||||
|
||||
@@ -172,7 +176,7 @@ def view_group_data(other_args: List[str], data_type: str):
|
||||
img.show()
|
||||
|
||||
print("")
|
||||
return ns_parser.group
|
||||
return img
|
||||
|
||||
else:
|
||||
print(
|
||||
@@ -180,7 +184,8 @@ def view_group_data(other_args: List[str], data_type: str):
|
||||
)
|
||||
|
||||
print("")
|
||||
return ""
|
||||
return None
|
||||
|
||||
except SystemExit:
|
||||
print("")
|
||||
return None
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
__docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
from typing import List
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from typing import List
|
||||
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
check_positive,
|
||||
parse_known_args_and_warn,
|
||||
)
|
||||
|
||||
from gamestonk_terminal.discovery import marketbeat_model
|
||||
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
__docformat__ = "numpy"
|
||||
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import pandas as pd
|
||||
from pandas.core.frame import DataFrame
|
||||
from datetime import datetime
|
||||
|
||||
from gamestonk_terminal.helper_funcs import get_user_agent
|
||||
|
||||
@@ -180,7 +180,7 @@ def get_trending_list(num: int) -> list:
|
||||
}
|
||||
)
|
||||
|
||||
return articles
|
||||
return articles[:num]
|
||||
|
||||
|
||||
def get_article_data(article_id: int) -> dict:
|
||||
|
||||
@@ -3,8 +3,8 @@ __docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
from typing import List
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
import pandas as pd
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
check_positive,
|
||||
parse_known_args_and_warn,
|
||||
|
||||
@@ -200,7 +200,8 @@ def plot_dark_pools(ticker: str, ats: pd.DataFrame, otc: pd.DataFrame):
|
||||
otc : pd.DataFrame
|
||||
OTC (Non-ATS) Data
|
||||
"""
|
||||
_, axData = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
|
||||
_, _ = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
|
||||
plt.subplot(3, 1, (1, 2))
|
||||
if not ats.empty and not otc.empty:
|
||||
|
||||
@@ -4,6 +4,7 @@ import argparse
|
||||
from typing import List
|
||||
import pandas as pd
|
||||
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
|
||||
@@ -15,6 +16,7 @@ from gamestonk_terminal.portfolio.portfolio_helpers import (
|
||||
|
||||
|
||||
class PortfolioController:
|
||||
""" Portfolio Controller """
|
||||
|
||||
CHOICES = [
|
||||
"help",
|
||||
@@ -129,6 +131,7 @@ class PortfolioController:
|
||||
if broker in self.BROKERS:
|
||||
api = broker + "_api"
|
||||
try:
|
||||
# pylint: disable=eval-used
|
||||
eval(api + ".login()")
|
||||
self.broker_list.add(broker)
|
||||
logged_in = True
|
||||
@@ -179,7 +182,9 @@ class PortfolioController:
|
||||
print("Login to desired brokers\n")
|
||||
for broker in self.broker_list:
|
||||
holdings = pd.concat(
|
||||
[holdings, eval(broker + "_api.return_holdings()")], axis=0
|
||||
# pylint: disable=eval-used
|
||||
[holdings, eval(broker + "_api.return_holdings()")],
|
||||
axis=0,
|
||||
)
|
||||
self.merged_holdings = merge_portfolios(holdings)
|
||||
print_portfolio(self.merged_holdings)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
""" Portfolio Optimization Helper Functions"""
|
||||
""" Portfolio Optimization Helper Functions """
|
||||
__docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
@@ -110,12 +110,12 @@ l_valid_property_infos = [
|
||||
]
|
||||
|
||||
|
||||
def check_valid_property_type(property: str) -> str:
|
||||
def check_valid_property_type(aproperty: str) -> str:
|
||||
""" Check that the property selected is valid """
|
||||
if property in l_valid_property_infos:
|
||||
return property
|
||||
else:
|
||||
raise argparse.ArgumentTypeError(f"{property} is not a valid info")
|
||||
if aproperty in l_valid_property_infos:
|
||||
return aproperty
|
||||
|
||||
raise argparse.ArgumentTypeError(f"{aproperty} is not a valid info")
|
||||
|
||||
|
||||
def process_stocks(list_of_stocks: List[str], period: str = "3mo") -> pd.DataFrame:
|
||||
@@ -133,6 +133,7 @@ def process_stocks(list_of_stocks: List[str], period: str = "3mo") -> pd.DataFra
|
||||
stock_closes: DataFrame
|
||||
DataFrame containing daily (adjusted) close prices for each stock in list
|
||||
"""
|
||||
|
||||
stock_prices = yf.download(
|
||||
list_of_stocks, period=period, progress=False, group_by="ticker"
|
||||
)
|
||||
@@ -155,6 +156,7 @@ def prepare_efficient_frontier(stock_prices: pd.DataFrame):
|
||||
ef: EfficientFrontier
|
||||
EfficientFrontier object
|
||||
"""
|
||||
|
||||
mu = expected_returns.mean_historical_return(stock_prices)
|
||||
S = risk_models.sample_cov(stock_prices)
|
||||
ef = EfficientFrontier(mu, S)
|
||||
@@ -162,13 +164,14 @@ def prepare_efficient_frontier(stock_prices: pd.DataFrame):
|
||||
|
||||
|
||||
def display_weights(weights: dict):
|
||||
"""
|
||||
Print weights in a nice format
|
||||
"""Print weights in a nice format
|
||||
|
||||
Parameters
|
||||
----------
|
||||
weights: dict
|
||||
weights to display. Keys are stocks. Values are either weights or values if -v specified
|
||||
"""
|
||||
|
||||
if not weights:
|
||||
return
|
||||
weight_df = pd.DataFrame.from_dict(data=weights, orient="index", columns=["value"])
|
||||
@@ -185,8 +188,8 @@ def my_autopct(x):
|
||||
"""Function for autopct of plt.pie. This results in values not being printed in the pie if they are 'too small'"""
|
||||
if x > 4:
|
||||
return f"{x:.2f} %"
|
||||
else:
|
||||
return ""
|
||||
|
||||
return ""
|
||||
|
||||
|
||||
def pie_chart_weights(weights: dict, title_opt: str):
|
||||
|
||||
@@ -122,12 +122,8 @@ def property_weighting(stocks: List[str], other_args: List[str]):
|
||||
List of tickers to be included in optimization
|
||||
other_args : List[str]
|
||||
Command line arguments to be processed with argparse
|
||||
|
||||
Returns
|
||||
-------
|
||||
weights: dict
|
||||
Dictionary of weights where keys are the tickers
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="property",
|
||||
@@ -136,7 +132,7 @@ def property_weighting(stocks: List[str], other_args: List[str]):
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
"--property",
|
||||
required=True if "-h" not in other_args else False,
|
||||
required=bool("-h" not in other_args),
|
||||
type=check_valid_property_type,
|
||||
dest="property",
|
||||
help="""Property info to weigh. Use one of:
|
||||
@@ -217,19 +213,16 @@ def property_weighting(stocks: List[str], other_args: List[str]):
|
||||
|
||||
|
||||
def max_sharpe(stocks: List[str], other_args: List[str]):
|
||||
"""
|
||||
Return a portfolio that maximises the Sharpe Ratio
|
||||
"""Return a portfolio that maximises the Sharpe Ratio
|
||||
|
||||
Parameters
|
||||
----------
|
||||
stocks: List[str]
|
||||
stocks : List[str]
|
||||
List of the stocks to be included in the weights
|
||||
|
||||
Returns
|
||||
-------
|
||||
weights: dict
|
||||
Dictionary of weights where keys are the tickers.
|
||||
other_args : List[str]
|
||||
argparse other args
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False, prog="maxsharpe", description="Maximise the Sharpe Ratio"
|
||||
)
|
||||
@@ -273,7 +266,7 @@ def max_sharpe(stocks: List[str], other_args: List[str]):
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return None
|
||||
return
|
||||
|
||||
if len(stocks) < 2:
|
||||
print("Please have at least 2 loaded tickers to calculate weights.\n")
|
||||
@@ -309,19 +302,16 @@ def max_sharpe(stocks: List[str], other_args: List[str]):
|
||||
|
||||
|
||||
def min_volatility(stocks: List[str], other_args: List[str]):
|
||||
"""
|
||||
Return a portfolio that optimizes for minimum volatility
|
||||
"""Return a portfolio that optimizes for minimum volatility
|
||||
|
||||
Parameters
|
||||
----------
|
||||
stocks: List[str]
|
||||
stocks : List[str]
|
||||
List of the stocks to be included in the weights
|
||||
|
||||
Returns
|
||||
-------
|
||||
weights: dict
|
||||
Dictionary of weights where keys are the tickers.
|
||||
other_args : List[str]
|
||||
argparse other args
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="min_volatility",
|
||||
@@ -354,7 +344,7 @@ def min_volatility(stocks: List[str], other_args: List[str]):
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return None
|
||||
return
|
||||
|
||||
if len(stocks) < 2:
|
||||
print("Please have at least 2 loaded tickers to calculate weights.\n")
|
||||
@@ -390,19 +380,16 @@ def min_volatility(stocks: List[str], other_args: List[str]):
|
||||
|
||||
|
||||
def max_quadratic_utility(stocks: List[str], other_args: List[str]):
|
||||
"""
|
||||
Return a portfolio that maximises the quadratic utility, given some risk aversion
|
||||
"""Return a portfolio that maximises the quadratic utility, given some risk aversion
|
||||
|
||||
Parameters
|
||||
----------
|
||||
stocks: List[str]
|
||||
stocks : List[str]
|
||||
List of the stocks to be included in the weights
|
||||
|
||||
Returns
|
||||
-------
|
||||
weights: dict
|
||||
Dictionary of weights where keys are the tickers.
|
||||
other_args : List[str]
|
||||
argparse other args
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="max_quadratic_utility",
|
||||
@@ -458,7 +445,7 @@ def max_quadratic_utility(stocks: List[str], other_args: List[str]):
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return None
|
||||
return
|
||||
|
||||
if len(stocks) < 2:
|
||||
print("Please have at least 2 loaded tickers to calculate weights.\n")
|
||||
@@ -499,20 +486,15 @@ def max_quadratic_utility(stocks: List[str], other_args: List[str]):
|
||||
|
||||
|
||||
def efficient_risk(stocks: List[str], other_args: List[str]):
|
||||
"""
|
||||
Return a portfolio that maximises return for a target risk. The resulting portfolio will have
|
||||
a volatility less than the target (but not guaranteed to be equal)
|
||||
"""Return a portfolio that maximises return for a target risk. The resulting portfolio will have
|
||||
a volatility less than the target (but not guaranteed to be equal)
|
||||
|
||||
Parameters
|
||||
----------
|
||||
stocks: List[str]
|
||||
stocks : List[str]
|
||||
List of the stocks to be included in the weights
|
||||
|
||||
Returns
|
||||
-------
|
||||
weights: dict
|
||||
Dictionary of weights where keys are the tickers.
|
||||
other_args : List[str]
|
||||
argparse other args
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="effrisk",
|
||||
@@ -568,7 +550,7 @@ def efficient_risk(stocks: List[str], other_args: List[str]):
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return None
|
||||
return
|
||||
|
||||
if len(stocks) < 2:
|
||||
print("Please have at least 2 loaded tickers to calculate weights.\n")
|
||||
@@ -609,19 +591,16 @@ def efficient_risk(stocks: List[str], other_args: List[str]):
|
||||
|
||||
|
||||
def efficient_return(stocks: List[str], other_args: List[str]):
|
||||
"""
|
||||
Return a portfolio that minimises volatility for a given target return ('Markowitz portfolio')
|
||||
"""Displays a portfolio that minimises volatility for a given target return ('Markowitz portfolio')
|
||||
|
||||
Parameters
|
||||
----------
|
||||
stocks: List[str]
|
||||
stocks : List[str]
|
||||
List of the stocks to be included in the weights
|
||||
|
||||
Returns
|
||||
-------
|
||||
weights: dict
|
||||
Dictionary of weights where keys are the tickers.
|
||||
other_args : List[str]
|
||||
argparse other args
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="effret",
|
||||
@@ -676,7 +655,7 @@ def efficient_return(stocks: List[str], other_args: List[str]):
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return None
|
||||
return
|
||||
|
||||
if len(stocks) < 2:
|
||||
print("Please have at least 2 loaded tickers to calculate weights.\n")
|
||||
@@ -717,6 +696,16 @@ def efficient_return(stocks: List[str], other_args: List[str]):
|
||||
|
||||
|
||||
def show_ef(stocks: List[str], other_args: List[str]):
|
||||
"""Display efficient frontier
|
||||
|
||||
Parameters
|
||||
----------
|
||||
stocks : List[str]
|
||||
List of the stocks to be included in the weights
|
||||
other_args : List[str]
|
||||
argparse other args
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="ef",
|
||||
@@ -756,7 +745,7 @@ def show_ef(stocks: List[str], other_args: List[str]):
|
||||
mu = expected_returns.mean_historical_return(stock_prices)
|
||||
S = risk_models.sample_cov(stock_prices)
|
||||
ef = EfficientFrontier(mu, S)
|
||||
fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
_, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
|
||||
# Generate random portfolios
|
||||
n_samples = ns_parser.n_port
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Portfolio Optimization Controller Module"""
|
||||
""" Portfolio Optimization Controller Module """
|
||||
__docformat__ = "numpy"
|
||||
|
||||
|
||||
import argparse
|
||||
from typing import List
|
||||
import matplotlib.pyplot as plt
|
||||
@@ -34,6 +33,7 @@ class PortfolioOptimization:
|
||||
"yolo",
|
||||
]
|
||||
|
||||
# pylint: disable=dangerous-default-value
|
||||
def __init__(self, tickers: List[str] = []):
|
||||
"""
|
||||
Construct Portfolio Optimization
|
||||
@@ -113,12 +113,12 @@ class PortfolioOptimization:
|
||||
|
||||
def call_add(self, other_args: List[str]):
|
||||
"""Process add command"""
|
||||
self.add_stocks(self, other_args)
|
||||
self.add_stocks(other_args)
|
||||
|
||||
def call_select(self, other_args: List[str]):
|
||||
"""Process select command"""
|
||||
self.tickers = []
|
||||
self.add_stocks(self, other_args)
|
||||
self.add_stocks(other_args)
|
||||
|
||||
def call_equal(self, other_args: List[str]):
|
||||
"""Process equal command"""
|
||||
@@ -168,7 +168,6 @@ class PortfolioOptimization:
|
||||
print({"GME": 200})
|
||||
print("")
|
||||
|
||||
@staticmethod
|
||||
def add_stocks(self, other_args: List[str]):
|
||||
""" Add ticker or Select tickes for portfolio to be optimized """
|
||||
parser = argparse.ArgumentParser(
|
||||
|
||||
@@ -5,6 +5,7 @@ import numpy as np
|
||||
import pandas as pd
|
||||
from pandas.plotting import register_matplotlib_converters
|
||||
from statsmodels.tsa.holtwinters import ExponentialSmoothing
|
||||
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
check_positive,
|
||||
parse_known_args_and_warn,
|
||||
@@ -18,19 +19,18 @@ from gamestonk_terminal.prediction_techniques.pred_helper import (
|
||||
price_prediction_backtesting_color,
|
||||
print_prediction_kpis,
|
||||
)
|
||||
|
||||
from gamestonk_terminal.config_plot import PLOT_DPI
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
|
||||
register_matplotlib_converters()
|
||||
|
||||
trend = "Ad" # Additive damped, A Additive, N None
|
||||
seasonal = "N" # None, A Additive, M Multiplicative
|
||||
seasonal_periods = 5
|
||||
# trend = "Ad" # Additive damped, A Additive, N None
|
||||
# seasonal = "N" # None, A Additive, M Multiplicative
|
||||
# seasonal_periods = 5
|
||||
|
||||
|
||||
def check_valid_trend(trend: str) -> str:
|
||||
if trend == "N" or trend == "A" or trend == "Ad":
|
||||
if trend in ("N", "A", "Ad"):
|
||||
return trend
|
||||
raise argparse.ArgumentTypeError(
|
||||
"Invalid trend selected. Choose between 'N', 'A', and 'Ad'"
|
||||
@@ -38,7 +38,7 @@ def check_valid_trend(trend: str) -> str:
|
||||
|
||||
|
||||
def check_valid_seasonal(seasonal: str) -> str:
|
||||
if seasonal == "N" or seasonal == "A" or seasonal == "M":
|
||||
if seasonal in ("N", "A", "M"):
|
||||
return seasonal
|
||||
raise argparse.ArgumentTypeError(
|
||||
"Invalid seasonal selected. Choose between 'N', 'A', and 'M'"
|
||||
|
||||
@@ -408,27 +408,6 @@ def _plot_and_print_results(
|
||||
)
|
||||
plt.plot(df_pred.index, df_pred[df_pred.columns[0]], lw=2, c="tab:green")
|
||||
else:
|
||||
"""
|
||||
# Looks too noisy to output all loops predictions
|
||||
for idx_loop in range(ns_parser.n_loops):
|
||||
plt.plot(
|
||||
[df_stock.index[-1], df_pred.index[0]],
|
||||
[
|
||||
df_stock["5. adjusted close"].values[-1],
|
||||
df_pred[df_pred.columns[idx_loop]].values[0],
|
||||
],
|
||||
lw=0.5,
|
||||
c="tab:green",
|
||||
linestyle="--",
|
||||
)
|
||||
plt.plot(
|
||||
df_pred.index,
|
||||
df_pred[df_pred.columns[idx_loop]],
|
||||
lw=1,
|
||||
ls="--",
|
||||
c="tab:green",
|
||||
)
|
||||
"""
|
||||
df_quantiles = pd.DataFrame()
|
||||
df_quantiles["Quantile 10%"] = df_pred.quantile(0.1, axis=1)
|
||||
df_quantiles["Median"] = df_pred.quantile(0.5, axis=1)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import argparse
|
||||
from typing import List
|
||||
import pandas as pd
|
||||
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
|
||||
@@ -14,7 +16,6 @@ from gamestonk_terminal.prediction_techniques import (
|
||||
regression,
|
||||
sma,
|
||||
)
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
|
||||
|
||||
class PredictionTechniquesController:
|
||||
@@ -59,7 +60,6 @@ class PredictionTechniquesController:
|
||||
choices=self.CHOICES,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def print_help(self):
|
||||
""" Print help """
|
||||
|
||||
@@ -110,7 +110,7 @@ class PredictionTechniquesController:
|
||||
|
||||
def call_help(self, _):
|
||||
"""Process Help command"""
|
||||
self.print_help(self)
|
||||
self.print_help()
|
||||
|
||||
def call_q(self, _):
|
||||
"""Process Q command - quit the menu"""
|
||||
@@ -170,6 +170,7 @@ class PredictionTechniquesController:
|
||||
|
||||
def call_prophet(self, other_args: List[str]):
|
||||
"""Process prophet command"""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from gamestonk_terminal.prediction_techniques import fbprophet
|
||||
|
||||
fbprophet.fbprophet(other_args, self.ticker, self.stock)
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from colorama import Fore, Style
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
from sklearn.metrics import (
|
||||
mean_absolute_error,
|
||||
r2_score,
|
||||
mean_squared_error,
|
||||
)
|
||||
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
|
||||
|
||||
def price_prediction_color(val: float, last_val: float) -> str:
|
||||
if float(val) > last_val:
|
||||
|
||||
@@ -3,10 +3,11 @@ __docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
from typing import List
|
||||
from gamestonk_terminal.helper_funcs import parse_known_args_and_warn
|
||||
from finvizfinance.quote import finvizfinance
|
||||
from PIL import Image
|
||||
|
||||
from gamestonk_terminal.helper_funcs import parse_known_args_and_warn
|
||||
|
||||
|
||||
def view(other_args: List[str], ticker: str):
|
||||
"""View historical price with trendlines. [Source: Finviz]
|
||||
|
||||
@@ -69,7 +69,7 @@ def ema(l_args, s_ticker, s_interval, df_stock):
|
||||
offset=ns_parser.n_offset,
|
||||
).dropna()
|
||||
|
||||
_, axPrice = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
_, _ = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
plt.title(f"{ns_parser.n_length} EMA on {s_ticker}")
|
||||
if s_interval == "1440min":
|
||||
plt.plot(
|
||||
|
||||
@@ -3,10 +3,12 @@ __docformat__ = "numpy"
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import pandas as pd
|
||||
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
|
||||
@@ -18,7 +20,6 @@ from gamestonk_terminal.technical_analysis import volume as ta_volume
|
||||
from gamestonk_terminal.technical_analysis import finbrain_view
|
||||
from gamestonk_terminal.technical_analysis import tradingview_view
|
||||
from gamestonk_terminal.technical_analysis import finviz_view
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
|
||||
|
||||
class TechnicalAnalysisController:
|
||||
@@ -65,7 +66,6 @@ class TechnicalAnalysisController:
|
||||
choices=self.CHOICES,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
|
||||
@@ -106,7 +106,6 @@ class TechnicalAnalysisController:
|
||||
print(" ad chaikin accumulation/distribution line values")
|
||||
print(" obv on balance volume")
|
||||
print("")
|
||||
return
|
||||
|
||||
def switch(self, an_input: str):
|
||||
"""Process and dispatch input
|
||||
@@ -118,6 +117,7 @@ class TechnicalAnalysisController:
|
||||
True - quit the program
|
||||
None - continue in the menu
|
||||
"""
|
||||
|
||||
(known_args, other_args) = self.ta_parser.parse_known_args(an_input.split())
|
||||
|
||||
# Due to Finviz implementation of Spectrum, we delete the generated spectrum figure
|
||||
@@ -134,7 +134,7 @@ class TechnicalAnalysisController:
|
||||
|
||||
def call_help(self, _):
|
||||
"""Process Help command"""
|
||||
self.print_help(self)
|
||||
self.print_help()
|
||||
|
||||
def call_q(self, _):
|
||||
"""Process Q command - quit the menu"""
|
||||
|
||||
@@ -2,8 +2,9 @@ import argparse
|
||||
from typing import List
|
||||
import requests
|
||||
import pandas as pd
|
||||
from gamestonk_terminal import config_terminal as cfg
|
||||
from tradingview_ta import TA_Handler
|
||||
|
||||
from gamestonk_terminal import config_terminal as cfg
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
parse_known_args_and_warn,
|
||||
)
|
||||
|
||||
14
terminal.py
14
terminal.py
@@ -33,13 +33,7 @@ from gamestonk_terminal.cryptocurrency import crypto_controller
|
||||
from gamestonk_terminal.screener import screener_controller
|
||||
from gamestonk_terminal.portfolio_optimization import po_controller
|
||||
|
||||
# import warnings
|
||||
# warnings.simplefilter("always")
|
||||
|
||||
|
||||
# pylint: disable=too-many-branches
|
||||
|
||||
|
||||
# pylint: disable=too-many-statements,too-many-branches
|
||||
def main():
|
||||
"""
|
||||
Gamestonk Terminal is an awesome stock market terminal that has been developed for fun,
|
||||
@@ -361,9 +355,9 @@ def main():
|
||||
|
||||
if b_quit:
|
||||
break
|
||||
else:
|
||||
if not main_cmd:
|
||||
should_print_help = True
|
||||
|
||||
if not main_cmd:
|
||||
should_print_help = True
|
||||
|
||||
print(
|
||||
"Hope you enjoyed the terminal. Remember that stonks only go up. Diamond hands.\n"
|
||||
|
||||
Reference in New Issue
Block a user