yfinance-cache icon indicating copy to clipboard operation
yfinance-cache copied to clipboard

`Adj Close` column returns inconsistent results

Open botcs opened this issue 5 months ago • 4 comments

The Adj Close column is only appearing when adjust_divs=False but has a different value based on whether the adjust_splits argument is True or False.

[EDIT] The Adj Close column is only appearing when adjust_divs=False and the Close has a different value based on whether the adjust_splits argument is True or False. The Close should stay unadjusted in either case in my opinion

import yfinance_cache as yfc
t = yfc.Ticker("VOD")

print("\n\nadjust_splits=False, adjust_divs=False")
print(t.history(period="max", adjust_splits=False, adjust_divs=False))
print("\n\nadjust_splits=False, adjust_divs=True")
print(t.history(period="max", adjust_splits=False, adjust_divs=True))
print("\n\nadjust_splits=True, adjust_divs=False")
print(t.history(period="max", adjust_splits=True, adjust_divs=False))
print("\n\nadjust_splits=True, adjust_divs=True")
print(t.history(period="max", adjust_splits=True, adjust_divs=True))

Prints:

adjust_splits=False, adjust_divs=False
                                Open       High        Low      Close   Volume  Dividends  Stock Splits  Repaired?  Final?                        FetchDate  Adj Close
Date                                                                                                                                                                  
1988-11-02 00:00:00-05:00  30.375002  30.500001  30.375002  30.375002   471100        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00   7.252554
1988-11-03 00:00:00-05:00  30.375002  30.624996  30.375002  30.500001   214100        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00   7.282395
1988-11-04 00:00:00-05:00  30.375002  30.375002  30.124998  30.250006   231900        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00   7.222707
1988-11-07 00:00:00-05:00  30.250006  30.375002  30.124998  30.375002   185200        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00   7.252554
1988-11-08 00:00:00-05:00  30.624996  30.750004  30.624996  30.750004   194700        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00   7.342089
...                              ...        ...        ...        ...      ...        ...           ...        ...     ...                              ...        ...
2025-07-16 00:00:00-04:00  10.890000  11.020000  10.880000  11.010000  9295900        0.0           0.0      False    True 2025-07-22 14:19:41.210799+00:00  11.010000
2025-07-17 00:00:00-04:00  10.900000  10.970000  10.890000  10.940000  4981700        0.0           0.0      False    True 2025-07-22 14:19:41.210799+00:00  10.940000
2025-07-18 00:00:00-04:00  10.980000  11.030000  10.950000  10.970000  6237300        0.0           0.0      False    True 2025-07-23 08:41:11.381687+00:00  10.970000
2025-07-21 00:00:00-04:00  11.030000  11.200000  11.030000  11.130000  5930700        0.0           0.0      False   False 2025-07-23 08:41:11.381687+00:00  11.130000
2025-07-22 00:00:00-04:00  11.220000  11.330000  11.210000  11.320000  8396500        0.0           0.0      False   False 2025-07-23 08:41:11.381687+00:00  11.320000

[9247 rows x 11 columns]


adjust_splits=False, adjust_divs=True
                                Open       High        Low      Close   Volume  Dividends  Stock Splits  Repaired?  Final?                        FetchDate
Date                                                                                                                                                       
1988-11-02 00:00:00-05:00   7.252554   7.282399   7.252554   7.252554   471100        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00
1988-11-03 00:00:00-05:00   7.252550   7.312240   7.252550   7.282395   214100        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00
1988-11-04 00:00:00-05:00   7.252551   7.252551   7.192859   7.222707   231900        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00
1988-11-07 00:00:00-05:00   7.222709   7.252554   7.192861   7.252554   185200        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00
1988-11-08 00:00:00-05:00   7.312241   7.342089   7.312241   7.342089   194700        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00
...                              ...        ...        ...        ...      ...        ...           ...        ...     ...                              ...
2025-07-16 00:00:00-04:00  10.890000  11.020000  10.880000  11.010000  9295900        0.0           0.0      False    True 2025-07-22 14:19:41.210799+00:00
2025-07-17 00:00:00-04:00  10.900000  10.970000  10.890000  10.940000  4981700        0.0           0.0      False    True 2025-07-22 14:19:41.210799+00:00
2025-07-18 00:00:00-04:00  10.980000  11.030000  10.950000  10.970000  6237300        0.0           0.0      False    True 2025-07-23 08:41:11.381687+00:00
2025-07-21 00:00:00-04:00  11.030000  11.200000  11.030000  11.130000  5930700        0.0           0.0      False   False 2025-07-23 08:41:11.381687+00:00
2025-07-22 00:00:00-04:00  11.220000  11.330000  11.210000  11.320000  8396500        0.0           0.0      False   False 2025-07-23 08:41:11.381687+00:00

[9247 rows x 10 columns]


adjust_splits=True, adjust_divs=False
                                Open       High        Low      Close   Volume  Dividends  Stock Splits  Repaired?  Final?                        FetchDate  Adj Close
Date                                                                                                                                                                  
1988-11-02 00:00:00-05:00   2.359109   2.368817   2.359109   2.359109  6065707        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00   0.563278
1988-11-03 00:00:00-05:00   2.359109   2.378525   2.359109   2.368817  2756671        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00   0.565595
1988-11-04 00:00:00-05:00   2.359109   2.359109   2.339692   2.349401  2985857        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00   0.560960
1988-11-07 00:00:00-05:00   2.349401   2.359109   2.339692   2.359109  2384566        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00   0.563278
1988-11-08 00:00:00-05:00   2.378525   2.388234   2.378525   2.388234  2506884        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00   0.570232
...                              ...        ...        ...        ...      ...        ...           ...        ...     ...                              ...        ...
2025-07-16 00:00:00-04:00  10.890000  11.020000  10.880000  11.010000  9295900        0.0           0.0      False    True 2025-07-22 14:19:41.210799+00:00  11.010000
2025-07-17 00:00:00-04:00  10.900000  10.970000  10.890000  10.940000  4981700        0.0           0.0      False    True 2025-07-22 14:19:41.210799+00:00  10.940000
2025-07-18 00:00:00-04:00  10.980000  11.030000  10.950000  10.970000  6237300        0.0           0.0      False    True 2025-07-23 08:41:11.381687+00:00  10.970000
2025-07-21 00:00:00-04:00  11.030000  11.200000  11.030000  11.130000  5930700        0.0           0.0      False   False 2025-07-23 08:41:11.381687+00:00  11.130000
2025-07-22 00:00:00-04:00  11.220000  11.330000  11.210000  11.320000  8396500        0.0           0.0      False   False 2025-07-23 08:41:11.381687+00:00  11.320000

[9247 rows x 11 columns]


adjust_splits=True, adjust_divs=True
                                Open       High        Low      Close   Volume  Dividends  Stock Splits  Repaired?  Final?                        FetchDate
Date                                                                                                                                                       
1988-11-02 00:00:00-05:00   0.563278   0.565596   0.563278   0.563278  6065707        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00
1988-11-03 00:00:00-05:00   0.563277   0.567913   0.563277   0.565595  2756671        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00
1988-11-04 00:00:00-05:00   0.563278   0.563278   0.558642   0.560960  2985857        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00
1988-11-07 00:00:00-05:00   0.560960   0.563278   0.558642   0.563278  2384566        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00
1988-11-08 00:00:00-05:00   0.567913   0.570232   0.567913   0.570232  2506884        0.0           0.0       True    True 2025-07-22 14:19:41.210799+00:00
...                              ...        ...        ...        ...      ...        ...           ...        ...     ...                              ...
2025-07-16 00:00:00-04:00  10.890000  11.020000  10.880000  11.010000  9295900        0.0           0.0      False    True 2025-07-22 14:19:41.210799+00:00
2025-07-17 00:00:00-04:00  10.900000  10.970000  10.890000  10.940000  4981700        0.0           0.0      False    True 2025-07-22 14:19:41.210799+00:00
2025-07-18 00:00:00-04:00  10.980000  11.030000  10.950000  10.970000  6237300        0.0           0.0      False    True 2025-07-23 08:41:11.381687+00:00
2025-07-21 00:00:00-04:00  11.030000  11.200000  11.030000  11.130000  5930700        0.0           0.0      False   False 2025-07-23 08:41:11.381687+00:00
2025-07-22 00:00:00-04:00  11.220000  11.330000  11.210000  11.320000  8396500        0.0           0.0      False   False 2025-07-23 08:41:11.381687+00:00

[9247 rows x 10 columns]

botcs avatar Jul 23 '25 09:07 botcs

Why is this important? If I am interested in computing the adjustment factors, I would just look at the ratio of the Close and the Adj Close, but in the above examples there is no such combination where I can just query a single time and get the true adjustment factor, I always need at least two queries.

So for now, I am computing the adjustments directly from the dividends and splits, using the unadjusted Close.

botcs avatar Jul 23 '25 09:07 botcs

different value based on whether the adjust_splits argument is True or False.

It should change. What do you think adjust_splits should do, and how is actual behavior different?

ValueRaider avatar Jul 23 '25 12:07 ValueRaider

If you really need the adjustment factors, I could simply expose them as they are in cache: https://github.com/ValueRaider/yfinance-cache/blob/main/yfinance_cache%2Fyfc_ticker.py#L276-L291

CSF = Cumulative Split Factor

ValueRaider avatar Jul 23 '25 12:07 ValueRaider

Sorry, I should clarify, the raw Close column is different. I think in the case of only one of the adjustments being true the Close shouldn't change, it should always stay unadjusted.

If you really need the adjustment factors, I could simply expose them as they are in cache:

this sounds like a great idea!

botcs avatar Jul 29 '25 09:07 botcs