
    N j              
       >   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SK	r	S SK
Jr  S SKJr  S SKJr  S SKJrJr  S SKrS SKrS SKrS SK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 r# " S S\RH                  5      r%\	RL                  " 5       r' " S S5      r(SHS jr)S r* " S S\RV                  5      r,Sq-Sq. " S S\R^                  5      r0S r1S r2S r3S r4S r5S r6S r7S r8S  r9SHS! jr:S" r;S# r<S$ r=SIS% jr>S& r?SJS'\\@   S(\@S)\\\@      S*\\@   4S+ jjrAS, rB\R                  4S- jrDS. rES/ rFS0 rGS1 rHS2 rIS3 rJS4 rKS5 rLS6 rMSKS7 jrNS8 rOS9 rPS:\@S*\Q4S; jrRSLS= jrS " S> S?5      rTS@\U4SA jrVSHS*\@4SB jjrWSMSC\USD\QSE\@S*\@4SF jjrXS<S/ 4SC\USD\QSE\@S*\@4SG jjrYg)N    )print_functionNwraps)
getmembers)FunctionType)ListOptional)relativedelta)UnknownTimeZoneError)const)YFException)YfConfigc                 *   [        [        U 5      5       VVs1 s H  u  p[        U[        5      (       d  M  UiM      nnn[	        U 5       Vs0 s H3  nUS   S:w  d  M  X;  d  M  [        X5      (       d  M'  U[        X5      _M5     sn$ s  snnf s  snf )Nr   _)r   type
isinstancer   dirhasattrgetattr)objnamevaluedisallowed_namess       _/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/yfinance/utils.py
attributesr   /   s     *49 5, 5e\* 	 5  , .1XS-5T7c> 	!": 	!?Fs?Q 	!gc  XS S,Ss"   B
B
BB%B7Bc                       \ rS rSrS rSrg)IndentLoggerAdapter;   c                 4   [        5       R                  [        R                  5      (       ae  SU R                  S   -  n[        U[        5      (       d  [        U5      nSR                  UR                  S5       Vs/ s H  oCU-   PM	     sn5      nX4$ s  snf )N indent
)	get_yf_loggerisEnabledForloggingDEBUGextrar   strjoinsplit)selfmsgkwargsims        r   processIndentLoggerAdapter.process<   sv    ?''66djj**Ac3''#h))CIIdO<OqUO<=C{ =s   =B N)__name__
__module____qualname____firstlineno__r0   __static_attributes__r2       r   r   r   ;   s    r8   r   c                   *    \ rS rSrSS jrS rS rSrg)IndentationContextH   c                     Xl         g N	increment)r+   r?   s     r   __init__IndentationContext.__init__I   s    "r8   c                 R    [        [        SS5      U R                  -   [        l        g Nr!   r   )r   _indentation_levelr?   r!   r+   s    r   	__enter__IndentationContext.__enter__L   s    $+,>!$Lt~~$]!r8   c                 J    [         =R                  U R                  -  sl        g r=   )rD   r!   r?   )r+   exc_typeexc_valexc_tbs       r   __exit__IndentationContext.__exit__O   s    !!T^^3!r8   r>   N)   )r3   r4   r5   r6   r@   rF   rL   r7   r2   r8   r   r:   r:   H   s    #^4r8   r:   c           	      d    [        [        R                  " U 5      S[        [        SS5      05      $ rC   )r   r%   	getLoggerr   rD   )r   s    r   get_indented_loggerrQ   S   s+    w0067K]_gijCk8lmmr8   c                 0   ^  [        T 5      U 4S j5       nU$ )Nc                     > [        S5      nUR                  STR                   S35        [        5          T" U 0 UD6nS S S 5        UR                  STR                   S35        W$ ! , (       d  f       N/= f)Nyfinancez	Entering z()zExiting )rQ   debugr3   r:   )argsr-   loggerresultfuncs       r   wrapper%log_indent_decorator.<locals>.wrapperY   si    $Z0yr23!4*6*F " 	xb12	 "!s   	A((
A6r   )rY   rZ   s   ` r   log_indent_decoratorr\   X   s     
4[  Nr8   c                   4   ^  \ rS rSrU 4S jrU 4S jrSrU =r$ )MultiLineFormatterg   c                    > [         TU ]  U5        [        R                  " SU5      nU(       a   [	        UR                  S5      5      U l        g SU l        g )Nz%\(levelname\)-(\d+)srN   r   )superr@   _researchintgrouplevel_length)r+   fmtmatch	__class__s      r   r@   MultiLineFormatter.__init__k   s?    

3S938CA/ar8   c                 f  >^ [         TU ]  U5      nUR                  S5      nUS   R                  S5      S   n[        U5      S::  a  U$ US   /nU R                  S:X  a  S[        U5      -  mOSU R                  -  mTS-  mUR                  U4S jUSS   5       5        SR                  U5      $ )Nr"   r   r    rN   c              3   .   >#    U  H
  nTU-   v   M     g 7fr=   r2   ).0linepaddings     r   	<genexpr>,MultiLineFormatter.format.<locals>.<genexpr>   s     B	Wt^	s   )ra   formatr*   lenrf   extendr)   )r+   recordoriginallines	levelname	formattedro   ri   s         @r   rr   MultiLineFormatter.formatq   s    7>&)t$!HNN3'*	u:?O q
I  A%I. 1 11sNGBab	BB99Y''r8   )rf   )r3   r4   r5   r6   r@   rr   r7   __classcell__)ri   s   @r   r^   r^   g   s    @( (r8   r^   Fc                       \ rS rSrS rSrg)YFLogFormatter   c                     UR                   n[        US5      (       a  UR                   SU 3n[        US5      (       a  UR                   SU 3n[        US5      (       a  UR                   SU 3nX!l         g)Nyf_cat: yf_interval	yf_symbolT)r,   r   r   r   r   )r+   ru   r,   s      r   filterYFLogFormatter.filter   s|    jj68$$]]O2cU+C6=))''(3%0C6;''%%&b.C
r8   r2   N)r3   r4   r5   r6   r   r7   r2   r8   r   r}   r}      s    	r8   r}   c                     [         (       a*  [        R                  R                  (       d  [	        5         O4[        R                  R                  (       a  [         (       d
  [        5         [         (       a  [        S5      q[        $ [        c3  [        R                  " S5      q[        R                  [        5       5        [        $ )NrT   )yf_log_indentedr   rU   r%   _disable_debug_mode_enable_debug_moderQ   	yf_loggerrP   	addFilterr}   r2   r8   r   r#   r#      sx     x~~55			'
3	  
	%%j1	N,-r8   c                  N    [         R                  " S[        5        [        5         g )NzXenable_debug_mode() is replaced by: yf.config.debug.logging = True (or False to disable))warningswarnDeprecationWarningr   r2   r8   r   enable_debug_moder      s    MMl  oA  Br8   c                     [         (       d  [        R                  " S5      q[        R	                  [        R
                  5        [        R                  b  [        [        R                  5      S:X  aD  [        R                  " 5       n [        SS9nU R                  U5        [        R                  U 5        [        5       qSq g g )NrT   r   z%(levelname)-8s %(message)s)rg   T)r   r%   rP   r   setLevelr&   handlersrs   StreamHandlerr^   setFormatter
addHandlerrQ   )h	formatters     r   r   r      s     ?%%j1	7==)%Y-?-?)@A)E%%'A*/LMINN9%  #')	 r8   c                      [         (       a>  [        R                  " S5      q[        R	                  [        R
                  5        S qSq g g )NrT   F)r   r%   rP   r   r   NOTSETr2   r8   r   r   r      s:     %%j1	7>>*		 r8   c                 B    [        [        R                  " SU 5      5      $ )Nz ^([A-Z]{2})([A-Z0-9]{9})([0-9])$)boolrb   rh   )strings    r   is_isinr      s    		<fEFFr8   c                 d   [        U 5      (       d  [        S5      eSSKJn  U" U SS9nUR                  (       a  UR                  S   O0 nUR
                  nUR                  SS5      UR                  SS5      UR                  S	S5      UR                  S
S5      UR                  SS5      S.US.$ )NzInvalid ISIN numberrN   )Search)querymax_resultsr   symbol 	shortnamelongname	quoteTypeexchDisp)r   r   r   r   exchange)tickernews)r   
ValueErrorrc   r   quotesr   get)isinr   rc   r   r   s        r   get_all_by_isinr      s    DMM.// $A.F "(V]]1BF;;D jj2.K4

:r2JJ{B/

:r2
 	 	r8   c                 \    [        U 5      nUR                  S0 5      R                  SS5      $ )Nr   r   r   r   r   r   datas     r   get_ticker_by_isinr      s*    4 D88Hb!%%h33r8   c                 <    [        U 5      nUR                  S0 5      $ )Nr   r   r   s     r   get_info_by_isinr      s    4 D88Hb!!r8   c                 <    [        U 5      nUR                  S0 5      $ )Nr   r   r   s     r   get_news_by_isinr      s    4 D88FBr8   c           
         U c  / n [         R                  " U [        R                  [        R                  [        R                  [        R                  [        R                  [        R                  S.S9nSUR                  l        U$ )NOpenHighLowClose	Adj CloseVolume)indexr   Date)_pd	DataFrame_npnanr   r   )r   emptys     r   empty_dfr      s\    }MMsww#''-C DE EKKLr8   c                  2    [         R                  " / SQS9n U $ )N)SymbolCompanyzEarnings DatezEPS EstimatezReported EPSzSurprise(%)columns)r   r   )r   s    r   empty_earnings_dates_dfr      s    MM@AE Lr8   c                 f   ^^^^^ / m/ m/ m/ mUUUUU4S jmU S    H  nT" US5        M     TTTT4$ )ag  
build_template returns the details required to rebuild any of the yahoo finance financial statements in the same order as the yahoo finance webpage. The function is built to be used on the "FinancialTemplateStore" json which appears in any one of the three yahoo finance webpages: "/financials", "/cash-flow" and "/balance-sheet".

Returns:
    - template_annual_order: The order that annual figures should be listed in.
    - template_ttm_order: The order that TTM (Trailing Twelve Month) figures should be listed in.
    - template_order: The order that quarterlies should be in (note that quarterlies have no pre-fix - hence why this is required).
    - level_detail: The level of each individual line item. E.g. for the "/financials" webpage, "Total Revenue" is a level 0 item and is the summation of "Operating Revenue" and "Excise Taxes" which are level 1 items.

c                    > US:  a  gTR                  SU S    35        TR                  SU S    35        TR                  U S    5        TR                  U5        SU ;   a  U S    H  nT" X!S-   5        M     gg)z
A recursive function that visits a node and its children.

Args:
    node: The current node in the data structure.
    level: The depth of the current node in the data structure.
   NtrailingkeyannualchildrenrN   )append)nodelevelchildlevel_detailtemplate_annual_ordertemplate_ordertemplate_ttm_ordertraverses      r   r    build_template.<locals>.traverse  s     19!!HT%[M":;$$vd5k]%;<e/E"j)	* * r8   templater   r2   )r   r   r   r   r   r   r   s     @@@@@r   build_templater     sR     NL+ +$ Ja   4nlRRr8   c                    / n/ nU R                  S0 5      R                  5        Hy  u  p4 U(       al  SU0nU H.  nU(       d  M  UR                  S5      XVR                  S5      '   M0     SU;   a  UR                  U5        M^  SU;   a  UR                  U5        Mw  My  M{     X4$ ! [         a  n[	        SU 35         SnAM  SnAff = f)	a  
retrieve_financial_details returns all of the available financial details under the
"QuoteTimeSeriesStore" for any of the following three yahoo finance webpages:
"/financials", "/cash-flow" and "/balance-sheet".

Returns:
    - TTM_dicts: A dictionary full of all of the available Trailing Twelve Month figures, this can easily be converted to a pandas dataframe.
    - Annual_dicts: A dictionary full of all of the available Annual figures, this can easily be converted to a pandas dataframe.

timeSeriesr   reportedValueasOfDater   r   z,An error occurred while processing the key: N)r   itemsr   KeyErrorprint)r   	TTM_dictsAnnual_dictsr   
timeseriestime_series_dicteaches           r   retrieve_financial_detailsr   )  s     IL88L"5;;=	F$+S> &D =AXXo=V$XXj%9: ' $$$%56_ ''(89 %  > ""  	F@DEE	Fs   AB%B%%
C/CCc                 *   [         R                  R                  U5      R                  S5      nUR	                  U5      nUR
                  R                  R                  SS5      Ul        U(       a  U(       a  [         R                  R                  U5      R                  S5      R	                  U5      nUR                   Vs/ s H  nS[        U5      -   PM     snUl        UR
                  R                  R                  SS5      Ul        UR                  USSS9nOUn[        UR                  R
                  5      Ul        XS'   UR                  UR
                  S/5      nU[        UR                  SS	9   nUR                  S
S9nU$ s  snf )z
format_annual_financial_statement formats any annual financial statement

Returns:
    - _statement: A fully formatted annual financial statement in pandas dataframe.
r   r   r   zTTM r   T)
left_indexright_indexr   reverseallhow)r   r   	from_dict	set_indexreindexr   r(   replacer   mergecamel2titleTsorteddropna)	r   annual_dictsannual_order	ttm_dicts	ttm_orderAnnualTTMcol
_statements	            r   !format_annual_financial_statementr
  G  sJ    ]]$$\2<<WEF^^L)F<<##++Ir:FL Ymm%%i0::7CKKIV 58KK@KSvC(K@IIMM))+r:	\\#$D\I

":<<#5#56J!-~%%z'7'7&HIJF:#5#5tDEJ""u"-J As   Fc                 H   U R                  U5      n [        U R                  5      U l        XS'   U R	                  U R                  S/5      n U [        U R                  SS9   n U R                  SS9n [        R                  " U R                  5      R                  U l        U $ )z
format_quarterly_financial_statements formats any quarterly financial statement

Returns:
    - _statement: A fully formatted quarterly financial statement in pandas dataframe.
r   Tr   r   r   )r   r   r   r   r   r   r   r  r   to_datetimedate)r	  r   orders      r   $format_quarterly_financial_statementr  e  s     ##E*J":<<0J!-~%%z'7'7&HIJF:#5#5tDEJ""u"-J););<AAJr8   stringssepacronymsreturnc           	      v   [        U [        5      (       d  [        U S5      (       d  [        S5      e[	        U 5      S:X  a  U $ [        U S   [        5      (       d  [        S5      e[        U[        5      (       a  [	        U5      S:w  a  [        SU S35      e[        R                  " SU5      (       a  [        SU S35      e[        R                  " U5      U:w  a  US	;  a  [        SU S
35      eUc>  SnSU S3nU  Vs/ s H(  n[        R                  " X4U5      R                  5       PM*     sn$ [        U[        5      (       d)  [        US5      (       a  [        US   [        5      (       d  [        S5      eU H.  n[        R                  " SU5      (       a  M!  [        SU S35      e   SnSU S3nU  Vs/ s H  n[        R                  " X4U5      PM     n nU H6  nSU S3nSU S3nU  Vs/ s H  n[        R                  " X4U5      PM     n nM8     U  Vs/ s H  oUR                  U5      PM     n nU  VVs/ s H*  oU Vs/ s H  owU;  a  UR                  5       OUPM     snPM,     n nnU  Vs/ s H  oQR                  U5      PM     n nU $ s  snf s  snf s  snf s  snf s  snf s  snnf s  snf )N__iter__z<camel2title() 'strings' argument must be iterable of stringsr   rN   z camel2title() 'sep' argument = 'z' must be single characterz[a-zA-Z0-9]z' cannot be alpha-numeric>   r    -z' cannot be special characterz([a-z])([A-Z])z\g<1>z\g<2>z=camel2title() 'acronyms' argument must be iterable of stringsz^[A-Z]+$zEcamel2title() 'acronyms' argument must only contain upper-case, but 'z
' detected(z)([A-Z][a-z]))r   r(   r   	TypeErrorrs   r   rb   rh   escapesubtitler*   r)   )r  r  r  patrepsajs           r   r   r   v  s   '3ww
'C'CVWW
7|qgaj#&&VWWc33s8q=;C5@Z[\\
yy$$;C5@YZ[[
zz###Z"7;C5@]^__se5!6=>g!$**,g>> (C  *(E(EZX`abXcehMiMiWXXyyQ''defdggqrss 
 C3%u
C-45Wswws#WG5 !M"se5!189A3773Q'9  &--Wwws|WG-KRS7aqAq!h.	A5qA7GS$+,Gqxx{GG,N3 ? 6 : .AS,s6   /J=!J5!J! J&	J0
!J++J09J6+J0c                     U R                  S5      S   SR                  S U R                  S5      SS   5       5      -   nU$ )Nr   r   r   c              3   @   #    U  H  oR                  5       v   M     g 7fr=   )r  )rm   xs     r   rp   )snake_case_2_camelCase.<locals>.<genexpr>  s     "G6F77996Fs   rN   )r*   r)   )r  scs     r   snake_case_2_camelCaser&    s;    	
a277"Gaggcl126F"GG	GBIr8   c                    [        U [        5      (       a  [        R                  " U SUS9n U $ [        U [        5      (       a)  [
        R                  R                  [	        U 5      S5      n [        U [
        R                  5      (       aS  [        U [
        R                  5      (       d4  [
        R                  R                  U [
        R                  " S5      5      n [        U [
        R                  5      (       a\  U R                  c'  [        R                  " U 5      R                  U5      n U $ [        R                  " U 5      R                  U5      n  U $ [        SU  S[        U 5       35      e)Nr  )unittzz%Y-%m-%dr   zUnable to parse input dt z	 of type )r   rd   r   	Timestampr(   	_datetimedatetimestrptimer  combinetimetzinfotz_localize
tz_convertr   r   )dtexchange_tzs     r   _parse_user_dtr5    s   "c]]2CK8 I b###,,SWjABb)..))*RASAS2T2T##++B	q0ABBb),,--yy ]]2&22;?
 I ]]2&11+> I 8Id2hZPQQr8   c                    U S   S:X  a  [        [        U S S 5      S9$ U SS  S:X  a  [        [        U S S 5      S9$ U SS  S:X  a  [        [        U S S 5      S9$ U S   S	:X  a  [        [        U S S 5      S
9$ [        R                  " U 5      $ )Nddayswk)weeksmo)monthsy)years)r
   rd   r   	Timedelta)intervals    r   _interval_to_timedeltarD    s    |s#hsm"455	"#$	3x}#566	"#$	C"$677	"	3x}#566}}X&&r8   c                 L    U c  gSn[        [        R                  " X5      5      $ )z0Check if the provided period has a valid format.Fz^[1-9]\d*(d|wk|mo|y)$)r   rerh   )periodvalid_patterns     r   is_valid_period_formatrI    s%    ~ -M/00r8   c                 T   U R                   nU R                  5       nUS   US   -  R                  5       nUS   U-  US'   US   U-  US'   US   U-  US'   UR                  / S	QS
SS9  UR	                  SSSSS.SS9  X! Vs/ s H  oDUR                   ;   d  M  UPM     sn   $ s  snf )Nr   r   r   Adj Openr   Adj Highr   Adj Low)r   r   r   r   rN   Taxisinplace)rK  rL  rM  r   r   rP  )r   copyto_numpydroprenamer   	col_orderdfratiocs        r   auto_adjustr[    s    I	B_r'{*446EZ%'BzNZ%'BzNuI%ByMGG(   IIw   
 )7)QBJJq)7887s   B%B%c                 6   U R                   nU R                  5       nUS   US   -  nUS   U-  US'   US   U-  US'   US   U-  US'   UR                  / S	QS
SS9  UR                  SSSS.SS9  X! Vs/ s H  oDUR                   ;   d  M  UPM     sn   $ s  snf )z3back-adjusted data to mimic true historical prices r   r   r   rK  r   rL  r   rM  )r   r   r   r   rN   TrN  )rK  rL  rM  rQ  )r   rR  rT  rU  rV  s        r   back_adjustr]    s     I	B{Obk)EZ%'BzNZ%'BzNuI%ByMGG,   II   
 )7)QBJJq)7887s   4BBc           	         U S   nU S   S   S   nUS   nUS   nUS   nUS   nUS	   nUnS
U S   ;   a  U S   S
   S   S
   n[         R                  " UUUUUUS.5      n	[         R                  " USS9U	l        U	R	                  SS9  U	$ )N	timestamp
indicatorsquoter   volumeopencloselowhighadjcloser   r  r(  TrP  )r   r   r  r   
sort_index)
r   
timestampsohlcvolumesopenscloseslowshighsrg  r   s
             r   parse_quotesrr    s    k"Jg&q)D8nGLE']F;DLEHT,''%j1!4Z@]]E$)#'%+)1&-/ 0F ??:C8FL
d#Mr8   c                 n   S nS nS nSU ;   Ga  SU S   ;   a  [        U S   S   5      S:  a  [        R                  " [        U S   S   R	                  5       5      S9nUR                  SSS9  [        R                  " UR                  SS	9Ul        UR                  SS9  S
UR                  ;   a+  US
   S:H  R                  5       (       a  UR                  S
SS9nUR                  SS0S9nSU S   ;   a  [        U S   S   5      S:  a|  [        R                  " [        U S   S   R	                  5       5      S9nUR                  SSS9  [        R                  " UR                  SS	9Ul        UR                  SS9  S/Ul	        SU S   ;   a  [        U S   S   5      S:  a  [        R                  " [        U S   S   R	                  5       5      S9nUR                  SSS9  [        R                  " UR                  SS	9Ul        UR                  SS9  US   US   -  US'   US/   nUc*  [        R                  " S/[        R                  " / 5      S9nUc*  [        R                  " S/[        R                  " / 5      S9nUc*  [        R                  " S/[        R                  " / 5      S9nXU4$ )Nevents	dividendsr   )r   r  Tri  r  rh  currencyr   rN   rO  amount	Dividendsr   capitalGainsCapital Gainssplits	numeratordenominatorStock Splits)r   r   )rs   r   r   listvaluesr   r  r   rj  r   r   rT  rU  DatetimeIndex)r   ru  capital_gainsr|  s       r   parse_actionsr    s   IMF4$x.(Sh1L-MPQ-Q$x.5<<>?AI5!ooiooCHIO   .Y...Ij4IR4O3T3T3V3V%NN:AN>	!(((K1H(IIT(^+DN>4R0SVW0WMM$x.8??ABDM##FD#9"%//-2E2EC"PM$$T$2%4$5M!tH~%#d8nX.F*G!*K]]$x.299;<>FVT2??6<<cBFLd+%+K%86-;P%PF>"^,-FMM M):):2)>@	$%S->->r-BD~#$C,=,=b,AC m++r8   c                     U R                   R                  c   U R                   R                  S5      U l         U R                   R                  U5      U l         U $ )NUTC)r   r)  r1  r2  )rX  rC  r)  s      r   	set_df_tzr  G  sA    	xx{{88''.xx""2&BHIr8   c                    UR                  5       nUR                  R                  US'   U R                  R                  U S'   U R                  R                  5       nU R                  USS9n X@l        U R                  U S   :  n[	        U5      nXPR                  U-   U S   :*  -  nUR                  5       (       a  X)    n U R                  / SQSS9n U $ )	N_dateleftr   endstart)r  r  r  rN   rw  )rR  r   r  r   rD  anyrT  )r   rC  tradingPeriodstps_dfidxf_droptds          r   'fix_Yahoo_returning_prepost_unrequestedr  N  s       "Fll''F7Oll''F7O
,,


C\\&f\-FL\\VE]*F		)B||b(F7O;<Fzz|| [[2[;FMr8   c                    US:X  a#  U R                  5       UR                  5       :H  nU$ US:X  a  X-
  R                  S:  nU$ US:X  a  U R                  UR                  :H  nU$ US:X  al  U R                  S-  S-
  nU R                  U-
  S-
  S-  S-   nUR                  U-
  S-
  S-  S-   nUR                  U R                  -
  nXe-
  SU-  -   nUS	:H  nU$ X-
  [        R
                  " U5      :  nU$ )
N1d1wk   1mo3mo   rN      r   )r  r:  monthyearr   rB  )	dt1dt2rC  last_rows_same_intervalshiftq1q2	year_diffquarter_diffs	            r   _dts_in_same_intervalr  k  s    4"%((*
": #" 
U	#&9"2"2Q"6 #" 
U	"%))syy"8 #" 
U	Q!#ii%!#)A-ii%!#)A-HHsxx'	w9,".!"3 #" $'9h0G"G""r8   c                 
   US   S;  a  SnS n[        U 5      S:  GaH  U R                  S   nU R                  S   nU R                  R                  c"  UR                  S5      nUR                  S5      nUR	                  U5      nUR	                  U5      nUS:X  af  UR                  5       UR                  5       :X  aA  U R                  S   n[        R                  " U R                  S S U R                  SS  /5      n X4$ [        XU5      (       GaQ  U R                  S   n	U R                  S   n
X:X  a  U S 4$ U(       a  UR                  S:X  a  U S 4$ U S	   R                  SS  R                  SS5      R                  5       nU(       Ga  US
:X  a  SnOSn[        X-  S-
  5      S:  a  U R                  U	[        R                   4   U R                  U
[        R                   4   -  nX-  S-
  R                  5       S:  R#                  5       (       a0  [        R                    H  nU R                  X4==   S-  ss'   M     OZX-  S-
  R                  5       S:  R#                  5       (       a/  [        R                    H  nU R                  X4==   S-  ss'   M     [$        R&                  " U R                  U
S4   5      (       a!  U S   R                  S   U R                  U
S4'   [$        R&                  " U S   R                  S   5      (       d  [$        R(                  " U S   R                  S   U S   R                  S   /5      U R                  U
S4'   SU R*                  ;   aG  [$        R(                  " U S   R                  S   U S   R                  S   /5      U R                  U
S4'   [$        R&                  " U S   R                  S   5      (       d  [$        R,                  " U S   R                  S   U S   R                  S   /5      U R                  U
S4'   SU R*                  ;   aG  [$        R,                  " U S   R                  S   U S   R                  S   /5      U R                  U
S4'   U S   R                  S   U R                  U
S4'   SU R*                  ;   a!  U S   R                  S   U R                  U
S4'   U R                  U
S4==   U S   R                  S   -  ss'   U R                  U
S4==   U S   R                  S   -  ss'   US:w  a  XR                  U
S	4'   U R                  S   nU R/                  U R                  S   5      n X4$ )Nr7  )r/   r   FrN   r;  r  r  r   r  KWFi  d   g      ?g?g{Gz?r   r   rL  r   rM  r   r   r   ry  g      ?)rs   r   r)  r1  r2  r  ilocr   concatr  secondr   prodabslocr   _PRICE_COLNAMES_r   r   isnannanmaxr   nanminrT  )r   rC  tz_exchangeprepostrepairrv  dropped_rowr  r  idx1idx2sscurrency_dividerY  rZ  s                  r   !fix_Yahoo_returning_live_separater    s    |:%K
6{Qll2ll2<<??"//%(C//%(Cnn[)nn[)t xxzSXXZ'$kk"oV[["%5v{{237G$HIz w %Sx88||B'||B'< "4<'zzQ%t|+N+005==aBGGI  5(*.*-2-a/047 &

41G1G+G H6::VZ\a\r\rVrKs s"21499;dBGGII%*%;%; &

47 3s : 3 &<#3A5::<tCHHJJ%*%;%; &

47 3t ; 3 &< 99VZZf566/5f~/B/B2/FFJJtV|,yy!4!4R!899/2zz6&>;N;Nr;RTZ[aTbTgTghjTk:l/mFJJtV|,!V^^37:zz6*CUCZCZ[]C^`fgq`r`w`wxz`{B|7}

4#34yy!3!3B!788.1jj&-:L:LR:PRXY^R_RdRdegRh9i.jFJJtU{+ FNN269jj&BSBXBXY[B\^den^o^t^tuw^xAy6z

4?3,27O,@,@,D

4=)&..04:;4G4L4LR4PFJJt[01

4>*fX.>.C.CB.GG*

4,-1D1I1I"1MM-979JJt^34$kk"oV\\"%56r8   c           	      *   U R                   (       a  U $ UR                   Vs/ s H  o3U ;  d  M
  UPM     nnUS   nU R                  5       n UR                  S5      =(       d    UR                  S5      n[	        U5      nU(       a  U R
                  R                  U S'   UR
                  R                  US'   [        R                  " [        R                  " U S   U S   R                  S   U-   /5      US   SS9nU R                  SSS	9n UR                  SSS	9nOT[        R                  " [        R                  " U R
                  U R
                  S   U-   5      UR
                  S
S9nUS-  nU(       a  [        [        UR
                  5      5       H{  n	UR
                  U	   R                  5       n
XR
                  S   R                  5       :  d7  XR
                  S   R                  5       [        R                  " SS9-   :  d  Mw  SX'   M}     Oa[        [        UR
                  5      5       H?  n	UR
                  U	   n
XR
                  S   :  d  XR
                  S   U-   :  d  M;  SX'   MA     US:H  nUR!                  5       (       Ga  U(       a  X)    nUR                   (       a  SU S'   U $ U R
                  R                  U S'   UR
                  R                  US'   [        R                  " [        R                  " U S   U S   R                  S   U-   /5      US   SS9nU R                  SSS	9n UR                  SSS	9nGO<0 ["        R$                   Vs0 s H  o3[        R&                  /_M     snESS/0EnUS:X  a  [        R(                  " U5      S    Hk  n	UR
                  U	   n
[+        5       R-                  SU SU
R                  5        S35        [.        R0                  " X/S9n[.        R2                  " X/SS9n Mm     OU R
                  S   nX-   nX-   n[        R(                  " U5      S    H}  n	UR
                  U	   n
Xs=::  a  U:  d  M   O  M$  [+        5       R-                  SU SU
R                  5        S35        [.        R0                  " X/S9n[.        R2                  " X/SS9n M     U R                  5       n [        R                  " [        R                  " U R
                  U R
                  S   U-   5      UR
                  S
S9nUS-  n[        [        UR
                  5      5       H?  n	UR
                  U	   n
XR
                  S   :  d  XR
                  S   U-   :  d  M;  SX'   MA     US:H  nUR!                  5       (       at  U(       d  US;   a!  [5        SU SU SUR
                  U    35      e[+        5       R-                  SU S3S-   [7        X   5      -   5        X)    R9                  5       nX)    nS nU R
                  U   nU" UUU5      nU R;                  U5      nUU   R=                  5       n[?        U) 5      UR@                  S   :  nU(       a  [5        S5      eU$ s  snf s  snf )Nr   r/   r  r  r7  r  )siderN   rw  rightr9  g        ry  r   r  zAdding out-of-range z @ z in new prices row of NaNs)r   r   T)sort)r  r  zThe following 'z8' events are out-of-range, did not expect with interval r   zDiscarding these z events:r"   c                    [        U5      [        [        U5      5      :X  a  Xl        U $ XS'   US;   a1  U R                  S5      R	                  5       n S U R                  l        OFUS:X  a1  U R                  S5      R                  5       n S U R                  l        O[        SU S35      eSU R                  ;   a  U R                  SSS9n U $ )N	_NewIndex)ry  r{  r  z?New index contains duplicates but unsure how to aggregate for ''rN   rw  )
rs   setr   groupbysumr   r  r   r   rT  )rX  	new_indexdata_col_names      r   _reindex_events'safe_merge_dfs.<locals>._reindex_events5  s    y>SY00 HI#;::K(,,.B BHHMn,K(--/B BHHM _`m_nnopqq"**$1-B	r8   z#Data was lost in merge, investigate)!r   r   rj  endswithrD  r   r  r   searchsortedr   r  rT  rangers   r+  	timedeltar  r   r  r   wherer#   rU   r   r   r  r   r(   rR  r)   isnar  shape)df_maindf_subrC  rZ  	data_colsdata_colintradayr  indicesr.   r3  f_outOfRangeempty_row_data	empty_rowlast_dtnext_interval_start_dtnext_interval_end_dtr  r  rX  f_na	data_losts                         r   safe_merge_dfsr    s   }}"NN?Nqw.>NI?|H  "G  %?):):3)?H		)B #==-- ,,++w""3::gg.>AQAVAVWYAZ[]A]@^#_aghoapw}~,,wQ,/W1-""3::gmmW]]2=NQS=S#TV\VbVbipq1s6<<()Aa%%'BMM!$))++r]]25F5K5K5MPYPcPcijPk5k/k
	 * s6<<()AaBMM!$$mmB.?".D(D
	 * b=LM*F||'*$  '}}11GG$ll//F7O&&szz''2BWWEUEZEZ[]E^_aEaDb'ceklset  |B  CGll7l3G[[q[1F\e6L6L M6LCGG96L M\xYZX[\N4<03AaB!O)),@
#bggi[Xr*st #> NI!jj')=DIG	 4 "--+)0&'='B$<03AaB-J6JJJ%--0DXJcRTRYRYR[Q\\v.wx$'MM~T$R	"%**g-A"M 4 ((*G &&szz'--rARUWAW'XZ`ZfZfmtuGqLG3v||,-\\!_a((B--2Cb2H,H!#GJ	 . b=Lx=0z9qrzq{{}  E  K  K  LX  Y  ~Z  [  \  \ 1(8DtKcRXRfNggh&++--(, g&IVY9F	f	Bh<DTE
V\\!_,I?@@Iq @b !Ns   	ZZ$Zc                 r   US;   a  U R                   R                  S:H  U R                   R                  R                  SS/5      -  n[        R
                  " S/U R                  S   -  5      nSU R                   U   R                  -
  X2'   U =R                   [        R                  " US5      -  sl         U $ )N)r  1wr  r            r   )	r   minutehourr   r   arrayr  r   to_timedelta)rX  rC  f_pre_midnightdst_error_hourss       r   fix_Yahoo_dst_issuer  W  s    &&
 ((//Q.288==3E3Er2h3OP))QC"((1+$56*,rxx/G/L/L*L'
C$$_c::Ir8   r)  c                 R     [         R                  " U 5        g! [         a     gf = f)NFT)_tztimezoner   )r)  s    r   is_valid_timezoner  d  s,    R    s    
&&Tc                    [        U [        5      (       d  U $ [        U 5      S:X  a  U $ U S   nU(       d  S HS  nX0;   d  M
  X   c  M  [        X   [        5      (       d  M*  [        R
                  " X   SSS9R                  U5      X'   MU     SU ;   a  S H  nX@S   ;   d  M  [        U S   U   S	   [        5      (       d  M-  S
 H:  n[        R
                  " U S   U   U   SSS9R                  U5      U S   U   U'   M<     U S   U   S	 U S   U   S	 M     SU ;   Ga  U S   nU/ / S.:X  a   U $ [        U[        [        45      (       Ga  [        U[        5      (       a  [        R                  R                  [        R                  " U5      5      nUR                  SS/SS9n[        R
                  " US	   SSS9R                  R                  U5      US	'   [        R
                  " US   SSS9R                  R                  U5      US'   GOr[        U[        5      (       Ga\  [        R                  R                  [        R                  " US   5      5      n[        R                  R                  [        R                  " US   5      5      n	[        R                  R                  [        R                  " US   5      5      n
UR                  SSS
.S9R                  SS/SS9nU	R                  SSS
.S9R                  SS/SS9n	U
R                  SS/SS9n
/ SQnU
R                  U5      R                  U	5      nU H6  n[        R
                  " X|   SSS9R                  R                  U5      X|'   M8     X{   n[        R
                  " WS	   R                  R                   5      Ul        UR"                  R%                  U5      Ul        SUR"                  l        XpS'   U $ )Nr   exchangeTimezoneName)firstTradeDateregularMarketTimer  T)r(  utccurrentTradingPeriod)regularprepostr  )r  r  	gmtoffsetr  r  )r  r  rN   rw  r  r  r  r  	pre_startpre_endr   
post_startpost_end)r  r  r  r  r  r  r   )r   dictrs   rd   r   r  r2  r  r   from_recordsr   hstackrT  r3  rU  r)   r  r   r1  r   )mdtradingPeriodsOnlyr)  kr/   ttpsrX  pre_dfpost_df
regular_dfcolsrZ  s                r   format_history_metadatar  l  s   b$	
2w!|		"	#B8Aw25,beS))OOBEFQQRTUBE 9
 "R'/122z"E[B\]^B_`gBhjm7n7n-OOB/E,Fq,I!,LSV\`allmop 1215a8 . 1215kB1215jA 0 2!""b))< I; dD\**#t$$]]//

3@WWj+6QW?!oobkNQQ\\]_`7OOBuICTJMMXXY[\5	C&&33CJJs5z4JK--44SZZF5LM ]]77

3y>8RS
Y/WX]]_ikv^w~]  A!..<PZ1[.\aacmozb{  CDa  E'__j+-FQ_O
Y__V,11':AOOBEFIITTUWXBE Xr'{~~':':;BHxx++B/BH"BHHM#% Ir8   c                   D    \ rS rSrS
S jrS rSS jrSS jrS rS r	S	r
g)ProgressBari  c                 v    X l         Xl        SU l        SU l        SU l        U R                  S5        SU l        g )Nz[]*2   r   rN   )text
iterationsprog_bar	fill_charwidth_ProgressBar__update_amountelapsed)r+   r  r  s      r   r@   ProgressBar.__init__  s6    	$
Qr8   c                 2   U R                   U R                  :  a  U R                  U l         U R                  S5        [        S[	        U 5      -   S[
        R                  S9  [
        R                  R                  5         [        S[
        R                  S9  g )NrN   r   r  file)r  )r  r  update_iterationr   r(   _sysstderrflushrE   s    r   	completedProgressBar.completed  sb    <<$//)??DLa dSYBT[[9bt{{#r8   Nc                    Uc"  U =R                   S-  sl         U R                   nOU =R                   U-  sl         [        S[        U 5      -   S[        R                  S9  [        R                  R                  5         U R                  5         g )NrN   r  r   r  )r  r   r(   r  r  r   r  )r+   	iterations     r   animateProgressBar.animate  sb    LLALILLI%LdSYBT[[9r8   c                     Ub  UO!U R                   [        U R                  5      -  nU R                  US-  5        U =R                  SU R                    SU R                   SU R
                   3-  sl        g )N      Y@  z of r    )r  floatr  r  r  r  )r+   vals     r   r  ProgressBar.update_iteration  s_    _c$,,t9O*OS5[)2dll^4/@$))MMr8   c                    [        [        US-  S-  5      5      nU R                  S-
  n[        [        US-  U-  5      5      nSU R                  U-  -   SX4-
  -  -   S-   U l        [        U R                  5      S-  [        [        U5      5      -
  nU S3nU R                  SU X`R                  U[        U5      -   S  -   -   U l        g )Nr(     [r    ]%r   )rd   roundr  r  r  rs   r(   )r+   
new_amountpercent_doneall_full
num_hashes	pct_place
pct_strings          r   __update_amountProgressBar.__update_amount  s    5*u"4!=>?::>u 4@AB
dnnz99C8CX<YY\__'1,C4E0FF	$~Q'
a	2j==QZ]`ak]lQlQmCn6nor8   c                 ,    [        U R                  5      $ r=   )r(   r  rE   s    r   __str__ProgressBar.__str__  s    4==!!r8   )r  r  r  r  r  r  )r!  r=   )r3   r4   r5   r6   r@   r!  r%  r  r  r<  r7   r2   r8   r   r  r    s"    $	 N
p"r8   r  placeholdersc                    ^  U 4S jnU$ )z
A decorator to dynamically update the docstring of a function or method.

Args:
    placeholders (dict): A dictionary where keys are placeholder names and values are the strings to insert.
c                    > U R                   (       aA  U R                   nTR                  5        H  u  p#UR                  SU S3U5      nM     Xl         U $ )N{})__doc__r   r   )rY   	docstringr   r   r>  s       r   	decorator$dynamic_docstring.<locals>.decorator  sL    <<I*002
%--3%rlEB	 3$Lr8   r2   )r>  rE  s   ` r   dynamic_docstringrG    s     r8   c                 B    SS K nU c  Sn UR                  SU  S35      nU$ )Nr   zPermitted Keys/Valuesz
    .. list-table:: zT
       :widths: 25 75
       :header-rows: 1

       * - Key
         - Values
    )textwrapdedent)r  rI  tables      r   _generate_table_configurationsrL    s8    }'OO !G  	E Lr8   r   bulletsr  c           	         [        U5      n[        U R                  5       5       H  nX   nUSSU S3-   -  nU Vs/ s H  n[        [	        U5      5      PM     nnU(       a4  [        U5      S:  a%  US-  n[        U5       H  nUSSU S3-   -  nM     Mr  SR                  [        U5      5      n	US	SU	 S3-   -  nM     U$ s  snf )
H
Generate a list-table for the docstring showing permitted keys/values.
   * - r"   r        -
       - ,      )rL  r   keysrs   r(   maxr)   )
r   rM  r  rK  r  r  vlengthsr   	value_strs
             r   generate_list_table_from_dictr\    s     +51EDIIK 4s"%%(./13s1v;/s7|a']"E2eWB// ( 		&.1IUr)B///E ! L 0s   Cc           	      $   [        U5      nU R                  5        GH  nX   nUSSU S3-   -  n[        U[        5      (       Ga:  SnXS;   nU(       Ga  [	        [        UR                  5       5      5      n	Sn
SU	;   n[        [        U	5      5       GH  nX   nXm   nSn[        U[        5      (       a  [        U5      nO&[        U[        5      (       a  [        U5      S:X  a  / n[        U[
        5      (       aE  [	        U5      n[        S U 5       5      nU(       a!  [        R                  " S	S[        U5      5      nUc  [        U5      n[        U
5      S:  a$  [        U
5      [        U5      -   S
:  a	  XzS-   -  nSn
U(       a4  U
S:X  a  U
S-  n
US:X  a  U
S-  n
OU
S-  n
U
S-  n
OU
S-  n
X S3U-   -  n
GM+  US-  nUS:X  a  US-  nOUS-  nSU;   aa  USU S3-   S-   -  nUR                  S5      n[        [        U5      5       H)  nUU   nUSU-   -  nU[        U5      S-
  :  d  M$  US-  nM+     OU(       a  US-  nOUS-  nX} S3U-   -  nUS-  nGM     U
S:w  a  XzS-   -  nOUSSU S3-   -  nXG-  nGMd  U Vs/ s H  n[        [        U5      5      PM     nnU(       a5  [        U5      S:  a&  US-  n[	        U5       H  nUSSU S3-   -  nM     GM  SR                  [	        U5      5      nUSSU S3-   -  nGM     U$ s  snf )rO  rP  rQ  r"   r   r   Nr   c              3   X   #    U  H   n[        U[        [        [        45      v   M"     g 7fr=   )r   rd   r*  r(   )rm   k2vs     r   rp   :generate_list_table_from_dict_universal.<locals>.<genexpr>5  s$     (aW`PSC#uc9J)K)KW`s   (*z	[{}\[\]'](   rV  rT  r)  z| z.  r   z       |     rN   z* r   rR  rS  rU  )rL  rW  r   r  r   r  r  rs   r  r   rb   r  r(   r*   rX  r)   )r   rM  r  concat_keysrK  r  r  	table_addconcat_short_linesk_keyscurrent_lineblock_formatr.   k2	k2_valuesk2_values_str
all_scalark2_values_str_linesr   rn   rY  rZ  r   r[  s                           r   'generate_list_table_from_dict_universalrm    s]    +51EYY[4s"%%fd##I!"!1V[[] 34!&&0s6{+AB &
I$(M!)S11$(O	#It44Y19L$&	!)T22$*9$5	%((aW`(a%a
%,/GGL"c)n,UM$,(+I<(1,#l2Cc-FX2X[]2]!D%88	'))'2-(E1L Av , 4 , 4(D0L(E1L$$b	M(AA!U*	6%-I%-I=0%2$b	)9D)@@I2?2E2Ed2K/%*3/B+C%D':1'= )-@4-G G	#$s+>'?'A#A$-$5I	 &E  , )T 1	 )T 1	%4r])BBI!T)	w ,x  2%!44IUr&_44	E -33Fqs3q6{FG33w<!+&#F^EUr%^33E , !IIfVn5	2i[!333q t L 4s   Lr=   )NN)r    N)FN)T)TN)Z
__future__r   r,  r+  r%   rF  rb   sysr  	threading	functoolsr   inspectr   typesr   typingr   r	   r   numpyr   pandasr   pytzr  dateutil.relativedeltar
   r   rT   r   yfinance.exceptionsr   yfinance.configr   r   LoggerAdapterr   localrD   r:   rQ   r\   	Formatterr^   r   r   Filterr}   r#   r   r   r   r   r   r   r   r   r   r   r   r   r
  r  r(   r   r&  r  r5  rD  rI  r[  r]  rr  r  r  r  r  r  r  r  r   r  r  r  r  rG  rL  r\  rm  r2   r8   r   <module>r     s  , &   	       !     0 %  + $S'//  __& 4 4n
(** (8 	W^^ "  G24
"
 
%SP#<<"+c + +htCy>Q +]abe]f +\
 $'77 (
'19(9,4,,^:#*Up|~
# $ 9x," ,"\D "C  t  VY F GKW[ik _$ _ _SV _ps _r8   