I am attempting to recreate an excel spreadsheet through python, there are a lot of formulas that I need to translate. I have the following formula
=IFERROR(MIN(1,0.05+(1-0.05)*EXP((SUMIFS(O:O,AB:AB,AB2)-SUMIFS(AF:AF,AB:AB,AB2))/(2*(1-0.05)*SUMIFS(AT:AT,AB:AB,AB2)))),1)
I have changed this so that there is a loop for one of the variables, so this filters out all of the others. I believe I am now looping in the AB column so I don't have to use the sumif any longer. I should just be able to sum the columns required. However I'm still unsure how to replicate if error and how to take the exponential of certain functions.
I now have the following code:
amount1 = df_Temp[df_Temp["IMED_PARNT_NAM"] == ns].sum()["MTM_AMT"]
amount2 = df_Temp[df_Temp["IMED_PARNT_NAM"] == ns].sum()['Collateral/# Trades in Netting Set']
amount3 = df_Temp[df_Temp["IMED_PARNT_NAM"] == ns].sum()['Add-On']
amount4 = amount1 - amount2 / 2 * (1 - 0.05) * amount3
df_Temp['Multiplier'] = np.where(0.05 + (1 - 0.05) * np.exp(amount4) > 1,0.05 + (1 - 0.05) * np.exp(amount4), 1)
However, I do not think the above is giving me the desired output that I require from the Excel formula in the first place. Any help is appreciated!
Thanks,
Kieran