Skip to content

taskscape/InterestCalculatorCSV

Repository files navigation

Interest Calculator

A C# console application that calculates interest rates and total cost of borrowing for fixed amounts over specified periods, using monthly capitalization.

Features

  • CSV Input: Reads borrowing data and parameters from CSV files
  • Monthly Capitalization: Calculates interest and commission with monthly compounding
  • Variable Rates: Supports different interest/commission rates for different time periods
  • Detailed Reports: Generates human-readable markdown files with complete calculation breakdowns

Requirements

  • .NET 8.0 SDK or later

Project Structure

InterestCalculator/
├── Models/
│   ├── Borrowing.cs              # Borrowing record model
│   ├── BorrowingParameter.cs     # Parameter period model
│   ├── BorrowingCalculation.cs   # Calculation result model
│   └── CapitalizationPeriod.cs   # Single period calculation
├── Services/
│   ├── CsvReaderService.cs       # CSV file parser
│   ├── InterestCalculatorService.cs  # Interest calculation logic
│   └── MarkdownGeneratorService.cs   # Report generator
├── Program.cs                    # Application entry point
├── borrowing.csv                 # Sample borrowing data
├── parameters.csv                # Sample parameters
└── InterestCalculator.csproj     # Project file

Input Files

borrowing.csv

Contains the borrowing records with the following fields:

Field Description Format
amount Principal amount borrowed Decimal (e.g., 10000.00)
start_date Start date of borrowing yyyy-MM-dd
end_date End date of borrowing yyyy-MM-dd
interest_rate Annual interest rate Decimal (e.g., 0.08 for 8%)
commission Annual commission rate Decimal (e.g., 0.02 for 2%)

Example:

amount,start_date,end_date,interest_rate,commission
10000.00,2024-01-01,2024-06-30,0.08,0.02
25000.50,2024-03-15,2024-12-15,0.065,0.015

parameters.csv

Contains borrowing parameters for different time periods:

Field Description Format
interest_rate Annual interest rate for the period Decimal
commission Annual commission rate for the period Decimal
start_date Start date of this parameter period yyyy-MM-dd
end_date End date of this parameter period yyyy-MM-dd

Example:

interest_rate,commission,start_date,end_date
0.075,0.018,2024-01-01,2024-03-31
0.08,0.02,2024-04-01,2024-06-30
0.085,0.022,2024-07-01,2024-09-30

Usage

Basic Usage

  1. Place borrowing.csv and parameters.csv in the same directory as the executable
  2. Run the application:
dotnet run

Command Line Arguments

You can override default file paths:

dotnet run <borrowing_file> <parameters_file> <output_directory>

Example:

dotnet run "C:\data\loans.csv" "C:\data\rates.csv" "C:\reports"

Output

The application generates markdown files named calculation N.md for each borrowing, where N is the borrowing number (1-based).

Each report includes:

  1. Summary: Principal amount, dates, rates, and duration
  2. Total Costs: Total interest, commission, and final amount owed
  3. Monthly Capitalization Details: Table showing each period's calculations
  4. Detailed Breakdown: Step-by-step calculation for each period

Calculation Logic

For each capitalization period:

  1. Daily Interest Rate = Annual Interest Rate ÷ Days in Year
  2. Interest Amount = Opening Balance × Daily Interest Rate × Days in Period
  3. Daily Commission Rate = Annual Commission Rate ÷ Days in Year
  4. Commission Amount = Opening Balance × Daily Commission Rate × Days in Period
  5. Total Capitalization = Interest Amount + Commission Amount
  6. Closing Balance = Opening Balance + Total Capitalization

The closing balance becomes the opening balance for the next period.

Rate Lookup

When calculating each period, the application:

  1. First checks if any parameter period covers the capitalization period
  2. Falls back to the borrowing's own rates if no matching parameter is found

Building

dotnet build

Running Tests

dotnet run

Check the output directory for generated reports.

License

MIT License

About

Interest calculator based on monthly interest capitalisation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages