
    N j-                     v    S SK rS SKJrJr  S SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  \
 S3r " S	 S
5      rg)    N)DictOptional)utils)YfConfig)
_BASE_URL_)YfData)YFDataExceptionz/v10/finance/quoteSummary/c                      \ rS rSrSrS\S\4S jrS\4S jr\	S\4S j5       r
\	S\\\\   4   4S	 j5       r\	S\R                  4S
 j5       r\	S\\\4   4S j5       r\	S\R                  4S j5       r\	S\R                  4S j5       r\	S\R                  4S j5       r\	S\\\4   4S j5       r\	S\\\4   4S j5       rS rSS jr\SS j5       rSS jrSS jrS rSrg)	FundsData   z
ETF and Mutual Funds Data
Queried Modules: quoteType, summaryProfile, fundProfile, topHoldings

Notes: 
- fundPerformance module is not implemented as better data is queryable using history
datasymbolc                     Xl         X l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l	        SU l
        SU l        g)zi
Args:
    data (YfData): The YfData object for fetching data.
    symbol (str): The symbol of the fund.
N)_data_symbol_quote_type_description_fund_overview_fund_operations_asset_classes_top_holdings_equity_holdings_bond_holdings_bond_ratings_sector_weightings)selfr   r   s      h/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/yfinance/scrapers/funds.py__init__FundsData.__init__   sf     
   ! # $ #! $"!"&    returnc                 T    U R                   c  U R                  5         U R                   $ )zH
Returns the quote type of the fund.

Returns:
    str: The quote type.
)r   _fetch_and_parser   s    r   
quote_typeFundsData.quote_type/   s(     #!!#r    c                 T    U R                   c  U R                  5         U R                   $ )zJ
Returns the description of the fund.

Returns:
    str: The description.
)r   r#   r$   s    r   descriptionFundsData.description:   s(     $!!#   r    c                 T    U R                   c  U R                  5         U R                   $ )zW
Returns the fund overview.

Returns:
    Dict[str, Optional[str]]: The fund overview.
)r   r#   r$   s    r   fund_overviewFundsData.fund_overviewF   (     &!!#"""r    c                 T    U R                   c  U R                  5         U R                   $ )zO
Returns the fund operations.

Returns:
    pd.DataFrame: The fund operations.
)r   r#   r$   s    r   fund_operationsFundsData.fund_operationsR   (       (!!#$$$r    c                 T    U R                   c  U R                  5         U R                   $ )z[
Returns the asset classes of the fund.

Returns:
    Dict[str, float]: The asset classes.
)r   r#   r$   s    r   asset_classesFundsData.asset_classes^   r-   r    c                 T    U R                   c  U R                  5         U R                   $ )zU
Returns the top holdings of the fund.

Returns:
    pd.DataFrame: The top holdings.
)r   r#   r$   s    r   top_holdingsFundsData.top_holdingsj   (     %!!#!!!r    c                 T    U R                   c  U R                  5         U R                   $ )z[
Returns the equity holdings of the fund.

Returns:
    pd.DataFrame: The equity holdings.
)r   r#   r$   s    r   equity_holdingsFundsData.equity_holdingsv   r1   r    c                 T    U R                   c  U R                  5         U R                   $ )zW
Returns the bond holdings of the fund.

Returns:
    pd.DataFrame: The bond holdings.
)r   r#   r$   s    r   bond_holdingsFundsData.bond_holdings   r-   r    c                 T    U R                   c  U R                  5         U R                   $ )zY
Returns the bond ratings of the fund.

Returns:
    Dict[str, float]: The bond ratings.
)r   r#   r$   s    r   bond_ratingsFundsData.bond_ratings   r8   r    c                 T    U R                   c  U R                  5         U R                   $ )zc
Returns the sector weightings of the fund.

Returns:
    Dict[str, float]: The sector weightings.
)r   r#   r$   s    r   sector_weightingsFundsData.sector_weightings   s(     ""*!!#&&&r    c                     SR                  / SQ5      nUSU R                  SS.nU R                  R                  [        U R                  -   US9nU$ )zP
Fetches the raw JSON data from the API.

Returns:
    dict: The raw JSON data.
,)	quoteTypesummaryProfiletopHoldingsfundProfilezfinance.yahoo.comfalse)modules
corsDomainr   	formatted)params)joinr   r   get_raw_json_QUOTE_SUMMARY_URL_)r   rL   params_dictresults       r   _fetchFundsData._fetch   sS     ((XY")9LX\XdXdsz{(()<T\\)IR](^r    Nc                    U R                  5       n US   S   S   nUS   S   U l        U R                  US   5        U R                  US   5        U R	                  US   5        g! [
         a9    [        R                  R                  (       d  e [        U R                   S35      e[         a  n[        R                  R                  (       d  e [        R                  " 5       nUR                  S	U R                   S
U 35        UR                  S5        UR                  S5        UR                  SW 35        UR                  S5         SnAgSnAff = f)z+
Fetches and parses the data from the API.
quoteSummaryrT   r   rG   rH   rI   rJ   z: No Fund data found.zFailed to get fund data for 'z
' reason: zGot response: z------------- N)rU   r   _parse_description_parse_top_holdings_parse_fund_profileKeyErrorr   debughide_exceptionsr	   r   	Exceptionr   get_yf_loggererror)r   rT   r   eloggers        r   r#   FundsData._fetch_and_parse   s.    	*.)(3A6D#K0=D ##D)9$:;$$T-%89$$T-%89 	J>>11!T\\N2G"HII 	*>>11((*FLL8jQRPSTULL)*LL)LL1TF$LL))	*s   AA' 'AE2BEEc                 T    [        U [        5      (       d  U $ U R                  SU5      $ )z
Parses raw values from the data.

Args:
    data: The data to parse.
    default: The default value if data is not a dictionary.

Returns:
    The parsed value or the default value.
raw)
isinstancedictget)r   defaults     r   _parse_raw_valuesFundsData._parse_raw_values   s'     $%%Kxxw''r    c                 2    UR                  SS5      U l        g)zK
Parses the description from the data.

Args:
    data: The data to parse.
longBusinessSummary N)rj   r   )r   r   s     r   rZ   FundsData._parse_description   s     !HH%:B?r    c                 
   U R                  UR                  SS5      5      U R                  UR                  SS5      5      U R                  UR                  SS5      5      U R                  UR                  SS5      5      U R                  UR                  SS5      5      U R                  UR                  SS5      5      S.U l        UR                  S	/ 5      n/ / / pTnU H?  nUR                  US
   5        UR                  US   5        UR                  US   5        MA     [        R
                  " UUUS.5      R                  S5      U l        UR                  S0 5      n[        R
                  " S/ SQU R                  U R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      /SU R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      /05      R                  S5      U l
        UR                  S0 5      n[        R
                  " S/ S QU R                  U R                  UR                  S![        R                  5      5      U R                  UR                  S"[        R                  5      5      U R                  UR                  S#[        R                  5      5      /SU R                  UR                  S$[        R                  5      5      U R                  UR                  S%[        R                  5      5      U R                  UR                  S&[        R                  5      5      /05      R                  S5      U l        [        S' UR                  S(/ 5       5       5      U l        [        S) UR                  S*/ 5       5       5      U l        g)+zL
Parses the top holdings from the data.

Args:
    data: The data to parse.
cashPositionNstockPositionbondPositionpreferredPositionconvertiblePositionotherPosition)rs   rt   ru   rv   rw   rx   holdingsr   holdingNameholdingPercent)SymbolNamezHolding Percentr|   equityHoldingsAverage)zPrice/Earningsz
Price/BookzPrice/SaleszPrice/CashflowzMedian Market Capz3 Year Earnings GrowthpriceToEarningspriceToBookpriceToSalespriceToCashflowmedianMarketCapthreeYearEarningsGrowthCategory AveragepriceToEarningsCatpriceToBookCatpriceToSalesCatpriceToCashflowCatmedianMarketCapCatthreeYearEarningsGrowthCatbondHoldings)DurationMaturityzCredit QualitydurationmaturitycreditQualitydurationCatmaturityCatcreditQualityCatc              3   >   #    U  H  o  H
  o"X   4v   M     M     g 7fN .0dkeys      r   	<genexpr>0FundsData._parse_top_holdings.<locals>.<genexpr>/  s!     !b9TA`aY\-`a-9T   bondRatingsc              3   >   #    U  H  o  H
  o"X   4v   M     M     g 7fr   r   r   s      r   r   r   2  s!     &l>^jkcfQV}jk}>^r   sectorWeightings)rl   rj   r   appendpd	DataFrame	set_indexr   r   NAr   r   ri   r   r   )	r   r   	_holdingsr   _name_holding_percentitemr   r   s	            r   r[   FundsData._parse_top_holdings   sw    !22488ND3QR!33DHH_d4ST 22488ND3QR!%!7!7ATVZ8[!\#'#9#9$((CXZ^:_#`!33DHH_d4ST
 HHZ,	+-r2(DNN4>*LLm,-##D)9$:; 
  \\/+
  9X	 	  88$4b9 "  HLL&&'7';';<Mruu'UV&&'7';';M255'QR&&'7';';NBEE'RS&&'7';';<Mruu'UV&&'7';';<Mruu'UV&&'7';';<UWYW\W\']^ &&'7';';<PRTRWRW'XY&&'7';';<Lbee'TU&&'7';';<Mruu'UV&&'7';';<PRTRWRW'XY&&'7';';<PRTRWRW'XY&&'7';';<XZ\Z_Z_'`a!.
 !$ 9Y% 	* ."5 llALL&&~'9'9*bee'LM&&~'9'9*bee'LM&&~'9'9/255'QR
 &&~'9'9-'OP&&~'9'9-'OP&&~'9'9:Lbee'TU!,
  9Y 	 "!b-QS9T!bb #'&ldhhGY[]>^&l"lr    c                 b   UR                  SS5      UR                  SS5      UR                  SS5      S.U l        UR                  S0 5      nUR                  S0 5      n[        R                  " S/ S	QU R                  U R                  UR                  S
[        R                  5      5      U R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      /SU R                  UR                  S
[        R                  5      5      U R                  UR                  S[        R                  5      5      U R                  UR                  S[        R                  5      5      /05      R                  S5      U l        g)zL
Parses the fund profile from the data.

Args:
    data: The data to parse.
categoryNameNfamily	legalType)r   r   r   feesExpensesInvestmentfeesExpensesInvestmentCat
Attributes)zAnnual Report Expense RatiozAnnual Holdings TurnoverzTotal Net AssetsannualReportExpenseRatioannualHoldingsTurnovertotalNetAssetsr   )	rj   r   r   r   r   rl   r   r   r   )r   r   r   _fund_operations_cats       r   r\   FundsData._parse_fund_profile4  st    !HH^T: HHXt4 HH[$7
  88$<bA#xx(CRH "iLL&&'7';';<VXZX]X]'^_&&'7';';<TVXV[V['\]&&'7';';<Lbee'TU
 &&';'?'?@Z\^\a\a'bc&&';'?'?@XZ\Z_Z_'`a&&';'?'?@PRTRWRW'XY!.
 ! 9\" 	r    )r   r   r   r   r   r   r   r   r   r   r   r   )r!   Nr   ) __name__
__module____qualname____firstlineno____doc__r   strr   r%   propertyr(   r   r   r+   r   r   r/   floatr3   r6   r:   r=   r@   rC   rU   r#   staticmethodrl   rZ   r[   r\   __static_attributes__r   r    r   r   r      s   'V 'S '6	 C 	  	!S 	! 	! 	#tC#$67 	# 	# 	% 	% 	% 	#tCJ/ 	# 	# 	"bll 	" 	" 	% 	% 	% 	#r|| 	# 	# 	"d3:. 	" 	" 	'4E	? 	' 	'
*8 ( ( @JmX#r    r   )pandasr   typingr   r   yfinancer   yfinance.configr   yfinance.constr   yfinance.datar   yfinance.exceptionsr	   rR   r   r   r    r   <module>r      s4     !  $ %   /#$>? D# D#r    