Currently I have my function with if, return, elif, return and else return statement/conditions.
I would like to add couple if and else condition within my return in python. Within my calculation, I need to either add or subtract but this depends different conditions. I need help in replicating the below SQL case statement in python.
SET AccruedInterest =
CASE WHEN scheduleleg ='L' THEN 1 ELSE -1 END
* Principal
*(AllInRate /100)
*(360 *(Year@(ReportDate) - Year@(StartDate) + 30 * (Month@(ReportDate) - Month@(StartDate))
+ CASE WHEN DAY(ReportDate) > 30 THEN 30 ELSE DAY(ReportDate) END
- CASE WHEN DAY(StartDate) > 30 THEN 30 ELSE DAY(StartDate) END
/360
WHERE Basis ='30/360'
I specifically need to add below conditions into my python function.
+ CASE WHEN DAY(ReportDate) > 30 THEN 30 ELSE DAY(ReportDate) END
- CASE WHEN DAY(StartDate) > 30 THEN 30 ELSE DAY(StartDate) END
This is my current function and conditions in Python.
#Accrued Calc for 30/360 Basis
def accrued_30_360(row):
if row['Type'] == 'L' and row['Current Filter'] == 'Current CF':
return 1 * row['Principal/GrossAmount'] * (row['All in Rate']/100)* (360 *(Settlement.year - row['Start Date YEAR']) + 30 * (Settlement.month - row['Start Date MONTH'])
elif row['Type'] == 'D':
return -1 * row['Principal/GrossAmount'] * (row['All in Rate']/100)* (360 *(Settlement.year - row['Start Date YEAR']) + 30 * (Settlement.month - row['Start Date MONTH'])
else:
return ''
Thanks