24
24
ENABLE_TQDM = False
25
25
26
26
try :
27
+ import logging
28
+
27
29
import yfinance as yf
28
30
31
+ logging .disable (logging .ERROR )
32
+
29
33
ENABLE_YFINANCE = True
30
34
except ImportError :
31
35
ENABLE_YFINANCE = False
@@ -497,12 +501,15 @@ def get_historical_data_from_yahoo_finance(
497
501
interval = "1d"
498
502
499
503
try :
500
- historical_data = yf .Ticker (ticker ).history (
504
+ historical_data = yf .download (
505
+ tickers = ticker ,
506
+ progress = False ,
507
+ actions = True ,
501
508
start = start_timestamp ,
502
509
end = end_timestamp ,
503
510
interval = interval ,
504
- )
505
- except (HTTPError , URLError , RemoteDisconnected ):
511
+ ). droplevel ( level = 1 , axis = 1 )
512
+ except (HTTPError , URLError , RemoteDisconnected , IndexError ):
506
513
return pd .DataFrame ()
507
514
508
515
if historical_data .loc [start :end ].empty :
@@ -526,8 +533,6 @@ def get_historical_data_from_yahoo_finance(
526
533
~ historical_data .index .duplicated (keep = "first" )
527
534
]
528
535
529
- historical_data ["Adj Close" ] = historical_data ["Close" ]
530
-
531
536
if "Stock Splits" in historical_data and "Capital Gains" in historical_data :
532
537
historical_data = historical_data .drop (
533
538
columns = ["Stock Splits" , "Capital Gains" ]
@@ -537,6 +542,10 @@ def get_historical_data_from_yahoo_finance(
537
542
else :
538
543
historical_data = historical_data .drop (columns = ["Capital Gains" ])
539
544
545
+ historical_data = historical_data [
546
+ ["Open" , "High" , "Low" , "Close" , "Adj Close" , "Volume" , "Dividends" ]
547
+ ]
548
+
540
549
historical_data = enrich_historical_data (
541
550
historical_data = historical_data ,
542
551
start = start ,
0 commit comments