mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 13:32:08 +00:00
round1 edits
This commit is contained in:
@@ -15,7 +15,7 @@ from gamestonk_terminal.comparison_analysis import yahoo_finance_api as yf_api
|
||||
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
|
||||
from gamestonk_terminal.portfolio_optimization import port_optimization_controller as po_controller
|
||||
from gamestonk_terminal.menu import session
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
|
||||
@@ -109,7 +109,7 @@ class ComparisonAnalysisController:
|
||||
print(" performance brief performance comparison")
|
||||
print(" technical brief technical comparison")
|
||||
print("")
|
||||
print(" po portfolio optimzation from selected tickers")
|
||||
print(" >po portfolio optimzation from selected tickers")
|
||||
print("")
|
||||
return
|
||||
|
||||
@@ -318,7 +318,7 @@ class ComparisonAnalysisController:
|
||||
|
||||
def call_po(self, _):
|
||||
"""Open Portfolio Optimization menu with ticker and similar"""
|
||||
port_optimization_controller.menu([self.ticker] + self.similar)
|
||||
return po_controller.menu([self.ticker] + self.similar)
|
||||
|
||||
|
||||
def menu(stock: pd.DataFrame, ticker: str, start: datetime, interval: str):
|
||||
|
||||
@@ -60,7 +60,7 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open):
|
||||
)
|
||||
print(" pa portfolio analysis, \t\t supports: robinhood, alpaca, ally ")
|
||||
print(" crypto cryptocurrencies, \t\t uses coingecko api")
|
||||
print(" po portfolio analysis, \t\t UPDATE ME BEFORE PR")
|
||||
print(" po portfolio analysis, \t\t menu to explore portfolio optimizations")
|
||||
|
||||
if s_ticker:
|
||||
print(
|
||||
|
||||
@@ -4,7 +4,7 @@ __docformat__ = "numpy"
|
||||
import argparse
|
||||
from typing import List
|
||||
|
||||
def optimize(list_of_stocks:List, other_args:List[str]):
|
||||
def optimize(list_of_stocks:List[str], other_args:List[str]):
|
||||
"""
|
||||
|
||||
Parameters
|
||||
@@ -18,6 +18,14 @@ def optimize(list_of_stocks:List, other_args:List[str]):
|
||||
Dictionary of weights where keys are the tickers
|
||||
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="optimize",
|
||||
)
|
||||
|
||||
parse
|
||||
|
||||
weights = {}
|
||||
n_stocks = len(list_of_stocks)
|
||||
for stock in list_of_stocks:
|
||||
@@ -25,4 +33,25 @@ def optimize(list_of_stocks:List, other_args:List[str]):
|
||||
|
||||
return weights
|
||||
|
||||
def equal_weight(list_of_stocks:List[str]):
|
||||
"""
|
||||
Equally weighted portfolio, where weight = 1/# of stocks
|
||||
|
||||
Parameters
|
||||
----------
|
||||
list_of_stocks: List[str]
|
||||
List of tickers to be included in optimization
|
||||
|
||||
Returns
|
||||
-------
|
||||
weights : dict
|
||||
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)
|
||||
|
||||
return weights
|
||||
|
||||
|
||||
@@ -17,9 +17,10 @@ class PortfolioOptimization:
|
||||
CHOICES = ["help",
|
||||
"q",
|
||||
"quit",
|
||||
"clear",
|
||||
"select",
|
||||
"add",
|
||||
"optimize"]
|
||||
"equal_weight",
|
||||
"mkt_cap"]
|
||||
|
||||
def __init__(self,
|
||||
tickers:Set[str] = None
|
||||
@@ -46,7 +47,11 @@ class PortfolioOptimization:
|
||||
)
|
||||
print("")
|
||||
print(" add add ticker to optimize")
|
||||
print(" optimize run optimization")
|
||||
print(" select overwrite current tickers with new tickers")
|
||||
print("")
|
||||
print("Optimization:")
|
||||
print(" equal_weight equally weighted portfolio")
|
||||
print(" mkt_cap marketcap weighted portfolio")
|
||||
print("")
|
||||
|
||||
|
||||
@@ -86,6 +91,16 @@ class PortfolioOptimization:
|
||||
print("Optimal Weights for Equal Weighting:")
|
||||
print(weights)
|
||||
print("")
|
||||
def call_equal_weight(self, other_args:List[str]):
|
||||
weights = po_api.equal_weight(self.tickers, other_args)
|
||||
print("Optimal Weights for Equal Weighting:")
|
||||
print(weights)
|
||||
print("")
|
||||
|
||||
def call_mkt_cap(self,other_args:List[str]):
|
||||
print("TODO")
|
||||
def call_select(self,other_args:List[str]):
|
||||
print("TODO")
|
||||
|
||||
@staticmethod
|
||||
def add_stocks(self, other_args: List[str]):
|
||||
@@ -105,7 +120,7 @@ class PortfolioOptimization:
|
||||
help="add tickers to optimzation.",
|
||||
)
|
||||
try:
|
||||
# For the case where a user uses: 'select NIO,XPEV,LI'
|
||||
|
||||
if other_args:
|
||||
if "-" not in other_args[0]:
|
||||
other_args.insert(0, "-t")
|
||||
|
||||
Reference in New Issue
Block a user