Files
OpenBB/openbb_terminal/etf/yfinance_model.py
jmaslek b71abcfbf4 Updating some names (#1575)
* quick econ fix

* black

* keys and feature flags

* terminal name 👀

* some more replacements

* some more replacements

* edit pyproject

* gst -> openbb

* add example portfolios back to git

* Update api from gst

* sorry.  skipping some tests

* another round of names

* another round of test edits

* Missed some .gst refs and update timezone

* water mark stuff

* Fixing Names in terminal.spec and name of GTFF_DEFAULTS to OBBFF_DEFAULTS

* fix more GST to OpenBB Terminal

* Logging : merge conflicts with main

* Revert wrong files

Co-authored-by: Andrew <andrew.kenreich@gmail.com>
Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt>
Co-authored-by: Chavithra PARANA <chavithra@gmail.com>
2022-03-29 09:46:26 -04:00

63 lines
1.4 KiB
Python

"""Yahoo Finance model"""
__docformat__ = "numpy"
import logging
from typing import Dict
import yfinance as yf
from openbb_terminal.decorators import log_start_end
logger = logging.getLogger(__name__)
@log_start_end(log=logger)
def get_etf_sector_weightings(name: str) -> Dict:
"""Return sector weightings allocation of ETF. [Source: Yahoo Finance]
Parameters
----------
name: str
ETF name
Returns
----------
Dict
Dictionary with sector weightings allocation
"""
weights = yf.Ticker(name).info
if "sectorWeightings" in weights:
sectors = {}
for item in weights["sectorWeightings"]:
k = list(item.keys())[0].replace("_", " ").title()
k = "Real Estate" if k == "Realestate" else k
v = round(100 * list(item.values())[0], 2)
sectors[k] = v
sectors = dict(sorted(sectors.items(), key=lambda x: x[1], reverse=True))
return sectors
return dict()
@log_start_end(log=logger)
def get_etf_summary_description(name: str) -> str:
"""Return summary description of ETF. [Source: Yahoo Finance]
Parameters
----------
name: str
ETF name
Returns
----------
str
Summary description of the ETF
"""
data = yf.Ticker(name).info
if "longBusinessSummary" in data:
return data["longBusinessSummary"]
return ""