Merge branch 'develop' into feature/remove-cash

This commit is contained in:
James Maslek
2023-02-07 16:58:58 -05:00
committed by GitHub
3 changed files with 69 additions and 9 deletions

View File

@@ -302,14 +302,12 @@ def get_property_weights(
prop = {}
prop_sum = 0
for stock in symbols:
stock_prop = yf.Ticker(stock).info[s_property]
if stock_prop is None:
stock_prop = 0
stock_prop = get_prop(symbol=stock, prop=s_property)
prop[stock] = stock_prop
prop_sum += stock_prop
if prop_sum == 0:
console.print(f"No {s_property} was found on list of tickers provided", "\n")
console.print(f"No '{s_property}' was found on list of tickers provided", "\n")
return None, None
weights = {k: value * v / prop_sum for k, v in prop.items()}
@@ -317,6 +315,48 @@ def get_property_weights(
return weights, stock_returns
@log_start_end(log=logger)
def get_prop(symbol, prop) -> float:
"""Get property from yfinance
Parameters
----------
symbol : str
Stock ticker
prop : str
Property to get
Returns
-------
dict
Ticker info
"""
prop = yahoo_finance_model.fast_info_map.get(prop, prop)
try:
info = yf.Ticker(symbol).info
except Exception as _: # noqa
info = None
try:
fast_info = yf.Ticker(symbol).fast_info
except Exception as _: # noqa
fast_info = None
info_dict = {}
if info:
info_dict.update(dict(info))
if fast_info:
info_dict.update(dict(fast_info))
if info_dict:
value = info_dict.get(prop, 0.0)
if not value:
return 0.0
return value
return 0.0
@log_start_end(log=logger)
def get_mean_risk_portfolio(
symbols: List[str],
@@ -1365,6 +1405,9 @@ def get_black_litterman_portfolio(
value=value,
)
if benchmark is None:
return None, stock_returns
factor = time_factor[freq.upper()]
risk_free_rate = risk_free_rate / factor

View File

@@ -19,9 +19,29 @@ logger = logging.getLogger(__name__)
# pylint: disable=R0912, E1101
fast_info_map = {
"previousClose": "previous_close",
"twoHundredDayAverage": "two_hundred_day_average",
"regularMarketDayHigh": "day_high",
"averageDailyVolume10Day": "ten_day_average_volume",
"regularMarketPreviousClose": "regular_market_previous_close",
"fiftyDayAverage": "fifty_day_average",
"open": "open",
"averageVolume10days": "ten_day_average_volume",
"regularMarketDayLow": "day_low",
"currency": "currency",
"marketCap": "market_cap",
"averageVolume": "three_month_average_volume",
"dayLow": "day_low",
"volume": "last_volume",
"fiftyTwoWeekHigh": "year_high",
"fiftyTwoWeekLow": "year_low",
"dayHigh": "day_high",
"regularMarketPrice": "last_price",
}
yf_info_choices = [
"previousClose",
"regularMarketOpen",
"twoHundredDayAverage",
"trailingAnnualDividendYield",
"payoutRatio",
@@ -30,7 +50,6 @@ yf_info_choices = [
"navPrice",
"averageDailyVolume10Day",
"totalAssets",
"regularMarketPreviousClose",
"fiftyDayAverage",
"trailingAnnualDividendRate",
"open",
@@ -47,11 +66,9 @@ yf_info_choices = [
"priceHint",
"currency",
"trailingPE",
"regularMarketVolume",
"lastMarket",
"maxSupply",
"openInterest",
"marketCap",
"volumeAllCurrencies",
"strikePrice",
"averageVolume",

2
pyproject.toml vendored
View File

@@ -159,7 +159,7 @@ target-version = "py38"
# This is an introductory addition of ruff. We should look to adding:
# D: pydocstyle, PD: pandas-vet
# All options here: https://github.com/charliermarsh/ruff#supported-rules
select = ["E", "W", "F", "Q", "W", "S", "UP", "I", "PLC", "PLE", "PLR", "PLW"]
select = ["E", "W", "F", "Q", "S", "UP", "I", "PLC", "PLE", "PLR", "PLW"]
# These ignores should be seen as temporary solutions to problems that will NEED fixed
ignore = ["S105", "S106", "S107", "S110", "PLR2004", "PLR0911", "PLR0913", "PLR0912", "PLR0915"]