I am a programmer knowing next to nothing to interest calculation and I have to determine a formula to calculate interest on a daily basis compounded monthly. The main problem here is that the interest rate may change at any point in time (we are based on bank prime, which is constantly updated).
In one question on this site, I found the following formula: I= P(1+r/12)^n * (1+(r/360*d))-P which works fine when the calculation starts the first day of the month and the rate never changes. But, because of rate changes, we have to split the calculation into numerous segments, one for each rate. With a partial month at the start and at the end. But splitting the calculation will not compound interest for the part of the month before the partial first month.
So, actually, the question is: how do I calculate interest on a daily basis compounded monthly over a period of time during which the rate may change at any point in time?
I am totally confused as to how I can get an accurate calculation result.
UPDATE: After discussing the issue here, I discovered that the rate will never change for a given loan. However, it may still start on any day during the month. How do I compound this first month?