Monthly (Periodic) Mortgage Insurance Premium Calculation – HUD  HUD.gov / U.S. Department of Housing and Urban Development (HUD)
The formula for calculating the monthly mortgage insurance premium became effective May 1, 1998 (see attached Mortgagee Letter 9822).
Below is the monthly mortgage insurance premium (mip) calculation with examples and pseudocode using the current initial and annual mip rates for mortgages assigned an fha case number prior to 4 October 2010. See FHA Single Family Home Policy Manual 4000.1 Exhibit 1.0 Mortgage Insurance Premiums [pdf] for current upfront and annual mip rates.
premium calculation
(round to the second decimal place based on the value of the third decimal place).
round to 530.80
result rounded to second decimal place based on value in third decimal place.
round to 519.12
result rounded to second decimal place based on value in third decimal place.
rounded to 43.26
This is the annual premium.
calculation of the annual average outstanding balance
To start, use the original loan amount as the previous balance. repeat the following steps for the remaining months of the year (11 iterations). the computation of the following years is the same. the second year will start with the last result of the first year.

multiply the previous balance by the annual interest rate of the contract. round the result to two (2) decimal places based on the value in the third decimal place.
divides the result by 1200. rounds the result to two (2) decimal places based on the value in 3rd decimal place.
add previous balance.
subtract payment from p&i. note: for an arm, use original interest rate and original p&i for all years. for gem/gpm calculate the current p&i based on the amortization schedule. see the table below.
when calculating the last year, add the 12 results from that year and divide the total by 12.
the new monthly p&i for gem/gpm is not calculated if the twelfth month of the case has not been reached or if the payment number is greater than the maximum number of months.
premium calculation example
*based on the original amortization schedule.
calculate the average annual outstanding balance:
 106,605.00 * 7.5 = 799,537.5000 (rounded to 799,537.50)
 799,537.50 / 1,200 = 666.28125 (rounded to 666.28 )
 666.28 + 106 605.007 = 1.2
107,271.28 – 745.40 = 106,525.88
 106,525.88 * 7.5 = 798,944.1000 (rounded to 798,944.10)
 798,944.10 / 1200 = 665.78675 (rounded to 665.79)
 665.79 + 106,525.88 = 1.67.1
 li>107,191.67 – 745.40 = 106,446.27
 106,446.27 * 7.5 = 798,347.025 (rounded to 798,347.03)
 798,347.03 / 1200 = 665.2891916 (rounded to 665.29)
 665.29 + 106,446.27
1.57 li>107,111.56 – 745.40 = 106,366.16
 106,366.16 * 7.5 = 797,746.20 (rounded to 797,746.20)
 797,746.20 / 1200 = 664.7885 (rounded to 664.79)
 664.79 + 106,366.16 = <195,030
. li>107,030.95 – 745.40 = 106,285.55
 106,285.55 * 7.5 = 797,141.625 (rounded to 797,141.63)
 797,141.63 / 1200 = 664.2847 (rounded to 664.28)
 664.28 + 106,285.55 = 106,949,
 li>106,949.83 – 745.40 = 106,204.43
 106,204.43 * 7.5 = 796,533.225 (rounded to 796,533.23)
 796,533.23 / 1200 = 663.77769 (rounded to 663.78)
 663.78 + 106,204.43 = 8,201.8
li>106,868.21 – 745.40 = 106,122.81
 106,122.81 * 7.5 = 795,921.075 (rounded to 795,921.08)
 795,921.08/ 1200 = 663.2675666 (rounded to 663.27)
 663.267+ 106 122.8 <6.818
10 li>106,786.08 – 745.40 = 106,040.68
 106,040.68 * 7.5 = 795,305.10 (rounded to 795,305.10)
 795,305.10 / 1200 = 662.75425 (rounded to 662.75)
 662.75 + 106,040.68 = 106,703
106,703.43 – 745.40 = 105,958.03
 105,958.03 * 7.5 = 794,685.225 (rounded to 794,685.23)
 794,685.23 / 1200 = 662.2376916 (rounded to 662.24)
 662.234+ 105,958.06
10.0 li>106,620.27 – 745.40 = 105,874.87
 105,874.87 * 7.5 = 794,061.525 (rounded to 794,061.53)
 794,061.53 / 1200 = 661.7179416 (rounded to 661.72)
 661.72 + 105,874.85
69.53 li>106,536.59 – 745.40 = 105,791.19
 105,791.19 * 7.5 = 793,433.925 (rounded to 793,433.93)
 793,433.93 / 1200 = 661.19494 (rounded to 661.19)
 661.19 + 105,791.19 = 106,452 <38,452
li>106,452.38 – 745.40 = 105,706.98
 105,706.98 * 7.5 = 792,802.3500
 792,802.35 / 1200 = 660.668625
 660.67 + 105,706.98 = 106,367, 65
 106,367.640 – 210.25
210.2 >
 105,622.25 * 7.5 = 792,166.8750
 792,166.88 / 1200 = 660.139066
 660.14 + 105,622.25 = 106,282, 39
 106,282.39.4 3 65.94 = 74 >
 105,536.99 * 7.5 = 791,527.4250
 791,527.43 / 1200 = 659.60619
 659.61 + 105,536.99 = 106,196, 60
 106,196.640
5.2 = 745.2 >
 105,451.20 * 7.5 = 790,884.000
 790,884.00 / 1200 = 659.07000
 659.07 + 105,451.20 = 106,110, 27
 106,110.270 – = 4.8.5 >
 105,364.87 * 7.5 = 790,236.5250
 790,236.53 / 1200 = 658.53041
 658.53 + 105,364.87 = 106,023, 40
 106,023.40,
710.50 – 710.50 >
 105,278.00 * 7.5 = 789,585.0000
 789,585.00 / 1200 = 657.987500
 657.99 + 105,278.00 = 105,935, 99
 105,935.5.5, 94 = 9 1.04 >
 105,190.59 * 7.5 = 788,929.4250
 788,929.43 / 1200 = 657.441191
 657.44 + 105,190.59 = 105,848, 03
 105,848.05.3
0.41 = 25.40 >
 105,102.63 * 7.5 = 788,269.72500
 788,269.73 / 1200 = 656.891441
 656.89 + 105,102.63 = 105,759, 52
 105.759.5120 – 7 >
 105,014.12 * 7.5 = 787,605.9000
 787,605.00 / 1200 = 656.338250
 656.34 + 105,014.12 = 105,670, 46
 105,670.46 9 = 2 15.4 >
 104,925.06 * 7.5 = 786,937.95000
 786,936.95 / 1200 = 655.781625
 655.78 + 104,925.06 = 105,580, 84
 105,580.44.48 3 5
 105,580.44.8 5
5 >
 104,835.44 * 7.5 = 786,265.80000
 786,265.80 / 1200 = 655.221500
 655.22 + 104,835.44 = 105,490, 66
 105,490,64,7 4 5
 104,745.26 * 7.5 = 785,589.45,000
 785,588.45 / 1,200 = 654.657875
 654.66 + 104,745 .26 = 105,399.92
 105,3995.94.5 = 7 >
this is the annual mip
pseudocode
input values
interest = interest rate mip = annual mip rate months = years from amortization date * 12 orig_mtg = original mortgage amount p_i = monthly principal & initial interest = initial mip factor withhold_value = a variable to store intermittent results total_amount = a variable to sum the last 12 months start last_value = orig_mtg total_amount = last_value for (i = 2 to months) withhold_value = last_value * interest [round withhold_value to 2 places after decimal] hold_val = hold_val / 1200 [round hold_val to 2 places after decimal] hold_val = hold_val + last_val hold_val = hold_val – p_i last_val = hold_val total_amt = total_amt + last_val if (remainder(i / 12) = 0) and ( i <> months) then total_amt = 0 end if next i total_amt = total_amt / 12 total_amt = total_amt * mip [round total_amt to 2 places after the decimal] total_amt = total_amt / (1 + up) [round total_amt to 2 places after the decimal] total_amt = total_amt / 12 [round total_amt to 2 places after the decimal] print: monthly premium = total_amt end