Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix for SIA menu #4294

Merged
merged 6 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions openbb_terminal/portfolio/attribution_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@

from openbb_terminal.decorators import log_start_end
from openbb_terminal.rich_config import console
from openbb_terminal.etf import fmp_model

logger = logging.getLogger(__name__)


SPY_SECTORS_MAP = {
"S&P 500 Materials (Sector)": "basic_materials",
"S&P 500 Industrials (Sector)": "industrials",
"S&P 500 Consumer Discretionary (Sector)": "consumer_cyclical",
"S&P 500 Consumer Staples (Sector)": "consumer_defensive",
"S&P 500 Health Care (Sector)": "healthcare",
"S&P 500 Financials (Sector)": "financial_services",
"S&P 500 Information Technology (Sector)": "technology",
"S&P 500 Telecommunication Services (Sector)": "communication_services",
"S&P 500 Utilities (Sector)": "utilities",
"S&P 500 Real Estate (Sector)": "realestate",
"S&P 500 Energy (Sector)": "energy",
"S&P 500 Materials (Sector)": "Basic Materials",
"S&P 500 Industrials (Sector)": "Industrials",
"S&P 500 Consumer Discretionary (Sector)": "Consumer Cyclical",
"S&P 500 Consumer Staples (Sector)": "Consumer Defensive",
"S&P 500 Health Care (Sector)": "Healthcare",
"S&P 500 Financials (Sector)": "Financial Services",
"S&P 500 Information Technology (Sector)": "Technology",
"S&P 500 Telecommunication Services (Sector)": "Communication Services",
"S&P 500 Utilities (Sector)": "Utilities",
"S&P 500 Real Estate (Sector)": "Real Estate",
"S&P 500 Energy (Sector)": "Energy",
}

PF_SECTORS_MAP = {
Expand Down Expand Up @@ -64,23 +65,18 @@ def get_spy_sector_contributions(
"""

# Sector Map

sectors_ticker = "SPY"

# Load in info
sp500_tickers_data = get_daily_sector_prices(start_date, end_date)
try:
weight_data = yf.Ticker(sectors_ticker).info["sectorWeightings"]
except Exception as _: # noqa
console.print(
"[red]This functionality is currently unstable and will be removed in the near future."
)
return pd.DataFrame()

weight_data = fmp_model.get_etf_sector_weightings(sectors_ticker)

# reformat Data
weights: Dict[str, dict] = {"SPY": {}}

for sector in weight_data:
weights[sectors_ticker].update(sector)
weight_formatted = float(sector["weightPercentage"].strip("%")) / 100
weights[sectors_ticker][sector['sector']] = weight_formatted

# add the sectors + dates + adj close to the dataframe
records = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Optional

import financedatabase as fd
import yfinance as yf
import yahooquery as yq
from requests.exceptions import ReadTimeout
from tqdm import tqdm

Expand Down Expand Up @@ -179,22 +179,12 @@ def get_json(symbol: str) -> dict:
Dictionary of json data
"""

data_stores = yf.data.TickerData(symbol).get_json_data_stores()

if "QuoteSummaryStore" not in data_stores:
# Problem in data. Either delisted, or Yahoo spam triggered
return {}

data = data_stores["QuoteSummaryStore"]
# add data about Shares Outstanding for companies' tickers if they are available
data = dict()
try:
data["annualBasicAverageShares"] = data_stores["QuoteTimeSeriesStore"][
"timeSeries"
]["annualBasicAverageShares"]
data["summaryProfile"] = yq.Ticker(symbol).summary_profile[symbol]
return data
except Exception:
pass

return data
return data


@log_start_end(log=logger)
Expand Down
40 changes: 39 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ y-py = "!=0.5.5" # Untraceable third level dependency that requires cargo to be
psutil = "!=5.9.4" # Forecasting menu and IPyKernel dependency broken on MacOs
tenacity = "<8.0.0" # Finviz, papermill and plotly dep. Pinned to avoid pip resolution conflict due to finviz 1.4.5 release bug
intrinio-sdk = "^6.22.2"
yahooquery = "^2.3.0"

[tool.poetry.dev-dependencies]
pytest = "^6.2.2"
Expand Down
2 changes: 2 additions & 0 deletions requirements-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ quandl==3.7.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and p
rapidfuzz==2.13.7 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
rdflib==6.2.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
regex==2022.10.31 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
requests-futures==1.0.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
requests-oauthlib==1.3.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
requests==2.28.2 ; python_version >= "3.8" and python_version < "3.11" and python_full_version != "3.9.7"
retrying==1.3.4 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
Expand Down Expand Up @@ -359,6 +360,7 @@ xarray==2023.1.0 ; python_version >= "3.8" and python_full_version != "3.9.7" an
xgboost==1.7.3 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
xlsxwriter==3.0.8 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
y-py==0.5.4 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
yahooquery==2.3.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
yarl==1.8.2 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
yfinance==0.2.12 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
zipp==3.13.0 ; python_full_version != "3.9.7" and python_version < "3.11" and python_version >= "3.8"
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ quandl==3.7.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and p
rapidfuzz==2.13.7 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
rdflib==6.2.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
regex==2022.10.31 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
requests-futures==1.0.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
requests-oauthlib==1.3.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
requests==2.28.2 ; python_version >= "3.8" and python_version < "3.11" and python_full_version != "3.9.7"
retrying==1.3.4 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
Expand Down Expand Up @@ -248,6 +249,7 @@ widgetsnbextension==4.0.5 ; python_version >= "3.8" and python_full_version != "
win32-setctime==1.1.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11" and sys_platform == "win32"
wrapt==1.14.1 ; python_version >= "3.8" and python_version < "3.11" and python_full_version != "3.9.7"
y-py==0.5.4 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
yahooquery==2.3.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
yarl==1.8.2 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
yfinance==0.2.12 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
zipp==3.13.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
Expand Down