'Formula to calculate adjusted close price like yahoofinance in python

So, I have been trying to create a manual function in python that calculates the adjusted closing price of stocks using dividends and stock splits data but I couldn't get results similar to yahoo finance

Can someone please help ?

Thanks

Image

            open       close   adj close    volume  dividends  stock splits
47    127.666664  127.766663   99.105476  13274857   1.100000           0.0
293   158.533340  159.833328  126.355896   4965291   3.000000           0.0
532   234.333328  226.600006  181.832520  11126308   3.500000           0.0
780   222.199997  222.266663  181.591782  10778008   4.000000           0.0
1023  209.199997  202.933334  169.113434  20673919   4.166667           0.0
1266  235.600006  237.666672  199.166885   7362553   1.333333           0.0
1517  315.000000  317.450012  270.044617   9482413   4.750000           0.0
1759  272.399994  272.299988  236.060104   9244273   5.150000           0.0
2000  302.149994  299.750000  264.834930  13737694   5.750000           0.0
2275  200.350006  199.800003  185.603943  34710176  10.150000           0.0
2436  212.000000  207.050003  196.897675  51546288   5.000000           0.0
2508  208.699997  209.300003  204.572861  30719587   5.750000           0.0
2678  226.000000  219.449997  219.449997  22745228   5.250000           0.0
            open       close  adj close    volume  dividends  stock splits
1290  243.300003  252.350006  211.47168  27944232        0.0           1.5

So, The zero column is the index, What I did here is I selected all the indexes in df having dividends and stock splits

The 1,2 columns show the stock open and close price data, 5 and 6 column shows the dividends and stock splits data of the company

So, using 1,2,5, and 6 columns I want to calculate the adjusted closing price, which should be exactly or very similar to 3 column "adj close" price.

Basically, What I want to figure out is

"adj close" = Some_Mathematical_Formula_Using("open", "close", "dividends", "stock splits")

If the formula answer matches with the given "adj close" column data then I'll be using the same formula for calculating "adj open"

Please use the below data to use the formula and above data to get total dividends and stock splits data

            open       close   adj close    volume  dividends  stock splits
1285  235.033340  236.066666  197.826096  12047383        0.0           0.0
1286  236.066666  239.300003  200.535645  10245025        0.0           0.0
1287  240.000000  245.666672  205.870972  15696559        0.0           0.0
1288  246.633331  244.199997  204.641907  11554816        0.0           0.0
1289  245.333328  245.600006  205.815109  20901951        0.0           0.0
1290  243.300003  252.350006  211.471680  27944232        0.0           1.5


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source