rename_po/ update dependencies

This commit is contained in:
Jamie
2021-04-12 17:20:07 -04:00
parent dcf87e3017
commit 1e59b48557
4 changed files with 35 additions and 13 deletions

View File

@@ -16,7 +16,7 @@ from gamestonk_terminal.comparison_analysis import market_watch_api as mw_api
from gamestonk_terminal.comparison_analysis import finbrain_api as f_api
from gamestonk_terminal.comparison_analysis import finviz_compare_view
from gamestonk_terminal.portfolio_optimization import (
port_optimization_controller as po_controller,
po_controller as po_controller,
)
from gamestonk_terminal.menu import session
from prompt_toolkit.completion import NestedCompleter

View File

@@ -34,14 +34,14 @@ class PortfolioOptimization:
"yolo",
]
def __init__(self, tickers: List[str] = None):
def __init__(self, tickers: List[str] = []):
"""
Construct Portfolio Optimization
"""
self.po_parser = argparse.ArgumentParser(add_help=False, prog="po")
self.po_parser.add_argument("cmd", choices=self.CHOICES)
self.tickers = set(tickers)
self.tickers = list(set(tickers))
# These will allow the ca menu to be re-access
self.ca_ticker = None
self.ca_similar = None
@@ -103,7 +103,7 @@ class PortfolioOptimization:
self.add_stocks(self, other_args)
def call_select(self, other_args: List[str]):
self.tickers = set([])
self.tickers = []
self.add_stocks(self, other_args)
def call_equal_weight(self, other_args: List[str]):

View File

@@ -33,7 +33,7 @@ period_choices = [
]
def equal_weight(list_of_stocks: List[str], _):
def equal_weight(list_of_stocks: List[str], other_args: List[str]):
"""
Equally weighted portfolio, where weight = 1/# of stocks
@@ -48,12 +48,36 @@ def equal_weight(list_of_stocks: List[str], _):
Dictionary of weights where keys are the tickers
"""
weights = {}
n_stocks = len(list_of_stocks)
for stock in list_of_stocks:
weights[stock] = round(1 / n_stocks, 5)
parser = argparse.ArgumentParser(
add_help=False,
prog="equal_weight",
description="Return equally weighted portfolio holdings",
)
return weights
parser.add_argument(
"-v",
"--value",
default=1,
type=float,
dest="value",
help="Portfolio amount to determine amount spent on each",
)
try:
ns_parser = parse_known_args_and_warn(parser, other_args)
if not ns_parser:
return
weights = {}
values = {}
n_stocks = len(list_of_stocks)
for stock in list_of_stocks:
weights[stock] = round(1 / n_stocks, 5)
values[stock] = ns_parser.value * round(1 / n_stocks, 5)
return values
except Exception as e:
print(e)
print("")
def property_weighting(list_of_stocks: List[str], property_type: str, _):

View File

@@ -31,9 +31,7 @@ from gamestonk_terminal.residuals_analysis import ra_controller
from gamestonk_terminal.portfolio import port_controller
from gamestonk_terminal.cryptocurrency import crypto_controller
from gamestonk_terminal.screener import screener_controller
from gamestonk_terminal.portfolio_optimization import (
port_optimization_controller as po_controller,
)
from gamestonk_terminal.portfolio_optimization import po_controller
# import warnings
# warnings.simplefilter("always")