Have you tried going step by step? I had the same problems with similar if-functions, yet resolved them by adding to it piece by piece.
One pointer though, after monthly_changes, is there an addition? If not, how will the function know what to do withthe next value?
If you cant get it to work as a complete formula, you can allways calculate it partially and hide the results for the frontend, bit still use them for your further calculations.
Hope that helps.