Chapter 33 Exercises: Financial Calculations in COBOL

These exercises are organized into five tiers of increasing difficulty. They cover interest calculations, amortization, currency handling, rounding strategies, tax calculations, present/future value, net present value, and day count conventions. Work through them sequentially to build mastery, or jump to the tier that matches your current skill level.


Tier 1: Foundation (Exercises 1-7)

These exercises test your recall of financial arithmetic syntax and your understanding of COMP-3 field declarations, basic interest formulas, and the ROUNDED phrase.

Exercise 1: Financial Field Declarations

Declare appropriate WORKING-STORAGE fields for each of the following financial values. Use COMP-3 storage, signed fields where appropriate, and enough decimal places for precision. Justify your PIC clause choices.

a) A bank account balance that can hold up to $999,999,999.99 b) An annual interest rate expressed as a decimal (e.g., 0.0525 for 5.25%) c) A daily interest rate derived from dividing the annual rate by 365 d) An intermediate calculation field for accumulating interest over 30 years e) A currency exchange rate accurate to six decimal places f) A tax rate percentage field (e.g., 22.50%)

Exercise 2: Simple Interest Calculation

Write a COBOL program that calculates simple interest using the formula I = P * R * T where P is principal, R is the annual rate, and T is time in years. Use the following test values:

  • Principal: $25,000.00
  • Annual Rate: 4.75%
  • Time: 3 years

Requirements: 1. Use COMP-3 for all monetary and rate fields 2. Apply the ROUNDED phrase on the final interest calculation 3. Include ON SIZE ERROR handling 4. Display the principal, rate, time, interest earned, and total amount (P + I)

Exercise 3: Daily Interest Accrual

Write a program that calculates daily interest on a savings account balance of $50,000.00 at an annual rate of 3.25% for 30 days. Use the Actual/365 day count convention (divide annual rate by 365).

Requirements: 1. Calculate the daily rate with at least 10 decimal places of precision 2. Accrue interest day by day using a PERFORM VARYING loop 3. Display the accrued interest after each day for days 1, 10, 20, and 30 4. Compare the daily accrual result to the simple formula: P * R * (30/365)

Exercise 4: Rounding Mode Comparison

Write a program that demonstrates the difference between truncation and rounding for the following divisions:

100 / 3
200 / 7
1000 / 6
255 / 11
999 / 13

For each division: 1. Store the result in a PIC S9(7)V99 COMP-3 field WITHOUT ROUNDED (truncation) 2. Store the result in a PIC S9(7)V99 COMP-3 field WITH ROUNDED 3. Display both results side by side 4. Calculate and display the difference between them

Exercise 5: Compound Interest by Frequency

Write a program that computes compound interest for a $10,000.00 principal at 6.00% annual rate over 5 years for each of the following compounding frequencies:

  • Annual (n=1)
  • Semi-annual (n=2)
  • Quarterly (n=4)
  • Monthly (n=12)
  • Daily (n=365)

Use iterative multiplication (PERFORM VARYING loop) to calculate (1 + r/n)^(n*t). Display the future value and total interest earned for each frequency in a formatted table.

Exercise 6: Currency Conversion

Write a program that converts $1,500.00 USD to five foreign currencies using the following exchange rates:

Currency Rate (USD to Foreign)
EUR 0.921450
GBP 0.790325
JPY 149.875000
CAD 1.362500
CHF 0.881200

Requirements: 1. Store exchange rates in a table using OCCURS 2. Use COMP-3 fields with 6 decimal places for rates 3. Round all converted amounts to 2 decimal places (except JPY, which uses 0) 4. Display each conversion result with the currency code

Exercise 7: Basic Tax Bracket Calculation

Write a program that calculates income tax using three simple brackets:

Taxable Income Range Rate
$0 - $20,000 10%
$20,001 - $60,000 15%
Over $60,000 25%

Calculate the tax on a taxable income of $75,000.00. Show the tax computed in each bracket and the total tax. Use COMP-3 for all monetary fields and apply ROUNDED on each bracket calculation.


Tier 2: Skill Building (Exercises 8-14)

These exercises require you to apply financial formulas to practical scenarios involving amortization, present value, and multi-step calculations.

Exercise 8: Monthly Loan Payment

Write a program that calculates the monthly payment for a fixed-rate loan using the standard amortization formula:

M = P * [r(1+r)^n] / [(1+r)^n - 1]

Where P = principal, r = monthly rate, n = total payments.

Test data: - Loan amount: $200,000.00 - Annual interest rate: 6.50% - Term: 30 years (360 months)

Display the monthly payment amount, total of all payments, and total interest paid over the life of the loan.

Exercise 9: 12-Month Amortization Schedule

Extend Exercise 8 to generate an amortization schedule for the first 12 months. For each month, display:

  1. Payment number
  2. Payment amount
  3. Interest portion (balance * monthly rate)
  4. Principal portion (payment - interest)
  5. Remaining balance

After the 12th month, display cumulative totals for interest paid and principal paid. Verify that the cumulative principal paid equals the difference between the original balance and the remaining balance.

Exercise 10: Future Value of Annuity

Write a program that calculates the future value of a series of regular deposits using the formula:

FV = PMT * [((1+r)^n - 1) / r]

Test data: - Monthly deposit: $500.00 - Annual interest rate: 7.00% - Time period: 20 years (240 months)

Display the total deposits made, the future value, and the interest earned (future value minus total deposits).

Exercise 11: Present Value Calculation

Write a program that calculates the present value of a future sum using the formula:

PV = FV / (1 + r)^n

Calculate how much you need to invest today to have $100,000.00 in 10 years at each of these annual discount rates: 3%, 5%, 7%, 10%.

Display a table showing each rate, the present value, and the implied interest earned.

Exercise 12: Net Present Value (NPV)

Write a program that calculates the NPV of an investment with the following cash flows:

Year Cash Flow
0 -$50,000.00 (initial investment)
1 $12,000.00
2 $15,000.00
3 $18,000.00
4 $20,000.00
5 $10,000.00

Use a discount rate of 8%. Store cash flows in a table. Display each discounted cash flow and the total NPV. State whether the investment should be accepted (NPV > 0) or rejected.

Exercise 13: Day Count Convention Comparison

Write a program that calculates interest on a $100,000.00 loan at 5.00% for a period from January 15 to April 15 (90 actual days) using three different day count conventions:

  1. Actual/365: Interest = P * R * (Actual Days / 365)
  2. Actual/360: Interest = P * R * (Actual Days / 360)
  3. 30/360: Interest = P * R * (Days using 30/360 / 360)

For the 30/360 convention, calculate days as: (Year2 - Year1) * 360 + (Month2 - Month1) * 30 + (Day2 - Day1).

Display the interest amount under each convention and explain which produces the most and least interest.

Exercise 14: Graduated Withholding Tax

Write a program that applies 2024 US federal tax brackets to four different incomes: $30,000, $65,000, $120,000, and $250,000. Use a table to store the bracket thresholds and rates:

Bracket Floor Bracket Ceiling Rate
$0 | $11,600 10%
$11,601 | $47,150 12%
$47,151 | $100,525 22%
$100,526 | $191,950 24%
$191,951 | $243,725 32%
$243,726 | $609,350 35%
$609,351 (unlimited) 37%

For each income, display the tax in each applicable bracket, the total tax, and the effective tax rate (total tax / income * 100).


Tier 3: Analysis and Problem Solving (Exercises 15-21)

These exercises require you to analyze precision issues, compare approaches, and handle edge cases in financial calculations.

Exercise 15: Amortization Penny Reconciliation

Write a program that generates a complete amortization schedule for a $15,000.00 loan at 8.00% for 3 years (36 months). After generating all 36 months:

  1. Verify that the sum of all principal portions equals the original loan amount
  2. Handle the final payment adjustment so the balance reaches exactly zero
  3. Display any penny discrepancy before and after the final payment adjustment
  4. Show the total interest paid and total of all payments

Explain in comments why the final payment almost always differs from the regular payment.

Exercise 16: Precision Loss in Repeated Calculations

Write a program that demonstrates precision loss by performing the following experiment:

  1. Start with $1,000,000.00
  2. Calculate 5% interest on this amount
  3. Add the interest to the balance
  4. Repeat steps 2-3 for 100 iterations

Perform this calculation three ways: a) Using PIC S9(11)V99 COMP-3 (2 decimal places) b) Using PIC S9(11)V9(4) COMP-3 (4 decimal places) c) Using PIC S9(11)V9(8) COMP-3 (8 decimal places)

Compare the final balances from all three approaches. Discuss which approach is most accurate and why.

Exercise 17: Adjustable Rate Mortgage Simulation

Write a program that simulates a 5/1 adjustable rate mortgage (ARM):

  • Loan amount: $300,000.00
  • Initial rate: 4.50% (fixed for the first 5 years / 60 months)
  • After year 5, the rate adjusts annually:
  • Year 6: 5.50%
  • Year 7: 6.25%
  • Year 8: 5.75%
  • Year 9: 6.00%
  • Year 10: 5.50%
  • Term: 30 years

For each rate change, recalculate the monthly payment based on the remaining balance and remaining term. Generate yearly summaries showing the rate, monthly payment, total interest for the year, total principal for the year, and ending balance.

Exercise 18: Rule of 72 Verification

The Rule of 72 states that the number of years to double your money is approximately 72 / (interest rate as a percentage). Write a program that:

  1. For rates of 2%, 4%, 6%, 8%, 10%, 12%, 15%, and 20%: a) Calculate the Rule of 72 estimate (72 / rate) b) Calculate the actual doubling time using compound interest iteration c) Display both values and the percentage error of the Rule of 72

  2. Start with $10,000 and compound annually until the balance exceeds $20,000

  3. Show which rates produce the most and least accurate Rule of 72 estimates

Exercise 19: Currency Round-Trip Accuracy

Write a program that tests round-trip conversion accuracy:

  1. Start with $10,000.00 USD
  2. Convert to EUR at rate 0.921450
  3. Convert EUR back to USD at rate 1.085250 (the inverse rate, slightly adjusted for spread)
  4. Show the loss from the round-trip

Repeat this for 100 consecutive round-trip conversions, accumulating the balance each time. Display the balance after every 10th conversion and the total percentage lost after all 100 round trips.

Exercise 20: Bond Price Calculation

Write a program that calculates the price of a bond using the present value of future cash flows:

Bond parameters: - Face value: $1,000.00 - Coupon rate: 5.00% (semi-annual payments of $25.00) - Years to maturity: 10 (20 semi-annual periods) - Yield to maturity: 6.00% (3.00% per semi-annual period)

Price = Sum of PV of all coupon payments + PV of face value at maturity

Use a PERFORM VARYING loop to discount each coupon payment. Display each discounted coupon, the discounted face value, and the total bond price. State whether the bond trades at a premium or discount to face value.

Exercise 21: Effective Annual Rate

Write a program that computes the effective annual rate (EAR) for a stated nominal rate of 12.00% with different compounding frequencies:

EAR = (1 + r/n)^n - 1

Calculate and display the EAR for: - Annual compounding (n=1) - Semi-annual (n=2) - Quarterly (n=4) - Monthly (n=12) - Weekly (n=52) - Daily (n=365)

Show that more frequent compounding produces a higher effective rate. Calculate the difference in interest earned on $100,000 over one year between annual and daily compounding.


Tier 4: Design and Implementation (Exercises 22-28)

These exercises require you to design complete solutions incorporating multiple financial concepts.

Exercise 22: Complete Loan Comparison Tool

Write a program that compares three loan options for a $250,000 home purchase:

Option Rate Term Points
A 6.25% 30 years 0
B 5.75% 30 years 1.5
C 5.50% 15 years 1.0

Points are an upfront fee equal to a percentage of the loan amount (1 point = 1% = $2,500).

For each option, calculate: 1. Monthly payment 2. Total interest over the life of the loan 3. Total cost (total payments + points paid) 4. Break-even month for Option B vs. Option A (when does the lower monthly payment offset the upfront cost of points?)

Display a comparison table with all results.

Exercise 23: Retirement Savings Projection

Write a program that projects retirement savings with the following parameters:

  • Current age: 30
  • Retirement age: 65
  • Current savings: $25,000.00
  • Monthly contribution: $750.00 (increases 3% annually)
  • Expected annual return: 7.5% (compounded monthly)

Generate a year-by-year projection showing: 1. Year and age 2. Annual contributions for that year 3. Investment growth for the year 4. Year-end balance 5. Cumulative contributions to date

At retirement, calculate the monthly income available if the retiree draws down the balance over 25 years at a 4.5% annual return.

Exercise 24: Multi-Currency Invoice System

Write a program that processes an invoice with line items in three currencies:

Item Amount Currency
1 5,250.00 USD
2 4,800.00 EUR
3 850,000 JPY
4 3,200.00 GBP
5 6,100.00 CAD

Requirements: 1. Define a currency table with codes and exchange rates to USD 2. Convert each line item to USD 3. Calculate the subtotal in USD 4. Apply a 8.25% tax on the USD subtotal 5. Calculate the grand total 6. Display the invoice with original amounts, USD equivalents, and totals 7. Handle JPY correctly (zero decimal places in the original currency)

Exercise 25: Depreciation Calculator

Write a program that calculates depreciation for an asset valued at $150,000.00 with a salvage value of $15,000.00 and a useful life of 10 years using three methods:

  1. Straight-line: Annual depreciation = (Cost - Salvage) / Life
  2. Double declining balance: Rate = 2/Life, applied to book value each year (switch to straight-line when it produces a larger deduction)
  3. Sum-of-years-digits: Factor = Remaining years / Sum of years (1+2+...+10 = 55)

For each method, generate a 10-year schedule showing: year, beginning book value, depreciation expense, accumulated depreciation, and ending book value.

Exercise 26: Payroll Tax Calculation Engine

Write a program that calculates payroll for an employee earning $8,500.00 gross per bi-weekly pay period. Apply the following deductions:

Federal tax brackets (annualized, then divided by 26 for bi-weekly): - Use the bracket table from Exercise 14

State tax: 5.75% flat rate

FICA: - Social Security: 6.2% on earnings up to $168,600 annually - Medicare: 1.45% on all earnings, plus 0.9% additional on earnings over $200,000

Pre-tax deductions: - 401(k): 6% of gross - Health insurance: $250.00 per pay period

Calculate net pay after all deductions. Track year-to-date totals for a full year (26 pay periods) and show when the Social Security cap is reached.

Exercise 27: Internal Rate of Return (IRR) Approximation

Write a program that approximates the IRR for the following investment cash flows using the bisection method:

Year Cash Flow
0 -$100,000
1 $25,000
2 $30,000
3 $35,000
4 $40,000
5 $20,000

Algorithm: 1. Set a low rate (0%) and a high rate (50%) 2. Calculate NPV at the midpoint rate 3. If NPV > 0, the IRR is higher (adjust low bound) 4. If NPV < 0, the IRR is lower (adjust high bound) 5. Repeat until the rate converges within 0.0001 (0.01%)

Display the NPV at each iteration and the final IRR estimate.

Exercise 28: Mortgage with Escrow and PMI

Write a program that calculates the total monthly housing payment including:

  • Loan amount: $280,000.00
  • Purchase price: $350,000.00 (LTV = 80%)
  • Annual interest rate: 6.75%
  • Term: 30 years
  • Property tax: $4,200.00 per year
  • Homeowner's insurance: $1,800.00 per year
  • PMI rate: 0.55% annually (required when LTV > 80%, which applies if the down payment is less than 20%)

Calculate: 1. Monthly P&I (principal and interest) 2. Monthly property tax escrow 3. Monthly insurance escrow 4. Monthly PMI (if applicable) 5. Total monthly payment (PITI + PMI)

Since the down payment is exactly 20% in this scenario, PMI is not required. Modify the scenario to a $315,000 loan on the same $350,000 home (10% down, LTV = 90%) and show the PMI-inclusive payment.


Tier 5: Advanced Challenges (Exercises 29-35)

These exercises push the boundaries of COBOL financial computation with complex scenarios requiring multiple interacting calculations.

Exercise 29: Yield to Maturity Solver

Write a program that solves for the yield to maturity (YTM) of a bond using iterative approximation:

Bond parameters: - Face value: $1,000.00 - Coupon rate: 4.50% (semi-annual) - Years to maturity: 15 - Current market price: $925.00

Use a bisection approach: start with a low yield (1%) and a high yield (15%), calculate the bond price at the midpoint yield, and narrow the range until the calculated price matches the market price within $0.01. Display the final YTM as both a semi-annual and annualized rate.

Exercise 30: Full 30-Year Amortization with Analysis

Write a complete program that generates a 30-year amortization schedule for a $350,000 mortgage at 6.25% with the following analysis features:

  1. Monthly detail for year 1 and year 30
  2. Yearly summaries for all 30 years
  3. The crossover month (where principal exceeds interest in the payment)
  4. Cumulative totals at 5-year intervals (years 5, 10, 15, 20, 25, 30)
  5. Total interest paid over the life of the loan
  6. Final payment adjustment for exact zero balance
  7. Verification that total principal payments equal the original loan amount
  8. All calculations use COMP-3 with ROUNDED and ON SIZE ERROR

Exercise 31: Multi-Year Tax Projection

Write a program that projects federal income tax over 5 years with the following assumptions:

  • Year 1 income: $85,000
  • Annual income growth: 4%
  • Standard deduction increases 2% annually (starting at $14,600)
  • Tax brackets are fixed at the values from Exercise 14

For each year, calculate: 1. Gross income 2. Standard deduction 3. Taxable income 4. Tax by bracket 5. Total tax 6. Effective tax rate 7. After-tax income

Display a 5-year summary table comparing all years.

Exercise 32: Savings vs. Investment Scenario Analysis

Write a program that compares three wealth-building strategies over 30 years:

  1. Conservative: $1,000/month into savings at 3.5% compounded monthly
  2. Moderate: $800/month into bonds at 5.5% + $200/month into stocks at 9.0%
  3. Aggressive: $1,000/month into stocks at 9.0%, but with 2 market crashes that reduce the balance by 35% (at year 10 and year 20)

For each strategy, generate a year-by-year projection showing contributions, growth, and ending balance. Compare final balances and total returns. Calculate the annualized return for the aggressive strategy after accounting for the crashes.

Exercise 33: Complete Financial Calculator Suite

Write a modular COBOL program that implements a financial calculator with the following functions, each in its own paragraph or section:

  1. Simple interest (I = P * R * T)
  2. Compound interest (A = P * (1 + r/n)^(n*t))
  3. Loan payment (M = P * [r(1+r)^n] / [(1+r)^n - 1])
  4. Present value (PV = FV / (1 + r)^n)
  5. Future value of annuity (FV = PMT * [((1+r)^n - 1) / r])
  6. Net present value (NPV = sum of discounted cash flows)

Test each function with at least two sets of inputs. Use COMP-3 throughout, ROUNDED on all final results, and ON SIZE ERROR on every COMPUTE.

Exercise 34: Day Count Convention Full Implementation

Write a program that implements all four major day count conventions and compares the interest calculated on a $500,000 commercial loan at 6.25% for the period from March 15, 2024 to September 15, 2024:

  1. Actual/Actual: Actual days / actual days in year (366 for leap year 2024)
  2. Actual/360: Actual days / 360
  3. Actual/365: Actual days / 365
  4. 30/360: 30-day months / 360

Calculate the actual number of days between the two dates. For the 30/360 convention, apply the standard adjustments for month-end dates. Display the interest under each convention and the maximum difference between any two conventions.

Exercise 35: Regulatory Interest Disclosure Report

Write a batch processing program that reads a file of 10 loan accounts and produces a Truth in Lending Act (TILA) disclosure report for each. The input file contains:

Account Number (12)
Loan Amount (9V99)
Annual Rate (2V4)
Term Months (3)
Origination Fee (7V99)

For each loan, calculate and display: 1. Monthly payment 2. Total of payments 3. Total interest (finance charge) 4. APR (Annual Percentage Rate) accounting for the origination fee 5. Amount financed (loan amount minus fees)

The APR must account for the origination fee by finding the rate that makes the present value of all payments equal to the amount financed. Use iterative approximation to solve for the APR.


How to Submit

For each exercise: 1. Write complete, compilable COBOL programs 2. Include appropriate comments explaining your approach and financial formulas 3. Use proper fixed-format column alignment 4. Use COMP-3 for all monetary and rate fields 5. Include ROUNDED and ON SIZE ERROR on all financial COMPUTE statements 6. Test your programs with the specified test data 7. Verify results manually or against a financial calculator for at least one test case

Solutions to selected exercises are provided in code/exercise-solutions.cob.