I am trying to adjust an specific value (di) based on equation (Arps - for decline curve analysis) so the sum of my original + predicted values (new_sum) match my reference value (sum_reference).
The original values:
df = pd.DataFrame({"YEAR":[2019, 2020, 2021, 2022, 2023],
"DATA":[0.5, 1, 2, 3, 4]})
df
Out[40]:
YEAR DATA
0 2019 0.5
1 2020 1.0
2 2021 2.0
3 2022 3.0
4 2023 4.0
Some parameters I should use and then the decline equation:
sum_reference = 15 # the reference number I should have after the sum of original and predicted values
n_periods = 3 # number of years I should do my prediction for
qi = 4 # last data
di = 0.5 # temporary decline rate
# Equation
eq = qi / (1 + di * np.arange(1, n_periods + 1))
eq_df = pd.DataFrame({"YEAR":np.nan,
"DATA":eq},
index=np.arange(1, n_periods + 1))
# Adding new data to dataframe
df = pd.concat([df, eq_df])
df
Out[43]:
YEAR DATA
0 2019.0 0.500000
1 2020.0 1.000000
2 2021.0 2.000000
3 2022.0 3.000000
4 2023.0 4.000000
1 NaN 2.666667
2 NaN 2.000000
3 NaN 1.600000
# New sum
new_sum = df["DATA"].sum()
When I look at the difference between the sums (sum_reference - new_sum), I get -1.766. Now I need to adjust my temporary decline rate "di" (automatically find a new number) so this sum difference be 0.
I was working on this problem in Excel and I could find this value while using Goal Seeker tool. But how I can use the same in Python? Or maybe another method?