calculating average balance for compounding period