mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 14:02:06 +00:00
* Add lookup commands * main ETF commands * Add technical analysis to ETF * add prediction techniques to ETF * add comparison analysis to etf * allow to select nr of holdings on load * add shold and summary commands to ETF * minor improvs * screener on ETF menu * add etf/scr wsj commands * readd compare command * add sbc to etf/screener * rename chold and shold * fix rogue etf and reset * minor corrections * minor menu print improv * legend of weights and title of plot * refactor screener to screener and disc on ETF * add ETF scripts
55 lines
1.2 KiB
Python
55 lines
1.2 KiB
Python
"""Yahoo Finance model"""
|
|
__docformat__ = "numpy"
|
|
|
|
from typing import Dict
|
|
import yfinance as yf
|
|
|
|
|
|
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()
|
|
|
|
|
|
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 ""
|