File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 33import json
44import numpy as _np
55import pandas as pd
6+ from io import StringIO
67
78from yfinance import utils
89from yfinance .config import YfConfig
@@ -716,6 +717,28 @@ def _fetch_complementary(self):
716717 self ._info [k ] = keydict [k ][- 1 ]["reportedValue" ]["raw" ]
717718 else :
718719 self .info [k ] = None
720+ if self ._info .get ('pegRatio' ) is None :
721+ try :
722+ url = f"https://finance.yahoo.com/quote/{ self ._symbol } /key-statistics"
723+ response = self ._data .cache_get (url = url )
724+
725+ dfs = pd .read_html (StringIO (response .text ))
726+
727+ for df in dfs :
728+ if df .shape [1 ] >= 2 :
729+ mask = df .iloc [:, 0 ].astype (str ).str .contains ("PEG Ratio" , case = False , na = False )
730+
731+ if mask .any ():
732+ val_raw = df .loc [mask , df .columns [1 ]].iloc [0 ]
733+
734+ if val_raw and str (val_raw ).lower () != 'n/a' :
735+ try :
736+ self ._info ['pegRatio' ] = float (val_raw )
737+ except ValueError :
738+ pass
739+ break
740+ except Exception :
741+ pass
719742
720743 def _fetch_calendar (self ):
721744 # secFilings return too old data, so not requesting it for now
You can’t perform that action at this time.
0 commit comments