Skip to content

About

A C-based financial debt settlement optimizer that minimizes peer-to-peer transaction overhead using a Greedy Choice Heuristic and multi-currency conversion rules

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ’ธ Global Debt Settlement Optimizer

Language License Build Program

A console-based C implementation designed to minimize the number of financial transactions required to settle outstanding debts among a group of participants, featuring dynamic multi-currency conversion and transaction processing fees.


๐Ÿ“Œ Project Overview

In real-world peer-to-peer (P2P) systems, expense sharing platforms, and banking clearinghouses, entities frequently exchange funds, generating a complex web of mutual credits and debts. Settling each balance individually is inefficient and results in unnecessary platform fee overhead.

This project uses a Greedy Choice Heuristic and Two-Pointer settlement walk to find the minimum number of payments required to settle all debts. It converts foreign transactions (INR, EUR, GBP) into base USD using static exchange rates, applies a simulated 2% transaction fee, computes net balances, and prints the optimal settlement transactions.


๐Ÿ“ Problem Statement

Design and implement an advanced Financial Settlement Optimization System that minimizes the number of transactions required to settle debts among multiple banks or entities located across different regions, each possibly supporting different payment methods and currencies.

The program must:

  1. Input $N$ participants and $T$ transactions.
  2. Read transaction details: from, to, amount, and currency.
  3. Convert foreign currencies to USD and deduct a 2% platform fee from each transaction.
  4. Calculate net balances and split participants into debtors and creditors.
  5. Compute and display the minimal transactions required to achieve settlement.

โœจ Features

  • ๐ŸŒ Multi-Currency Conversion: Seamlessly handles transactions in USD, INR, EUR, and GBP.
  • ๐Ÿ“‰ Simulated Platform Fees: Deducts a 2% platform fee from every raw transfer to match real-world banking clearing rules.
  • โšก Greedy Optimization Engine: Pairs the largest debtor with the largest creditor to resolve the network in minimal steps.
  • ๐Ÿ›ก๏ธ Floating-Point Stability: Utilizes #define EPSILON 1e-9 checks to handle decimal precision limits safely without infinite loops.
  • ๐Ÿ“ Extensive Reporting: Centralized project files, including execution reports and screenshots.

๐Ÿง  Algorithm & Logic

The project maps financial entities as nodes and transaction values as weighted directional links:

  1. Net Balance Calculation: $$\text{Balance}[i] = \sum \text{Received}[i] - \sum \text{Sent}[i]$$
  2. Subset Division:
    • Creditors: Entities with balance $> \text{EPSILON}$
    • Debtors: Entities with balance $< -\text{EPSILON}$
  3. Sorting:
    • Sort creditors in descending order (largest credit first) using custom casting comparators in qsort.
    • Sort debtors in ascending order (most negative debt first).
  4. Greedy Matching:
    • Settle by the minimum of the debtor's absolute liability and the creditor's balance.
    • Decrement/increment balances by the settled amount.
    • Shift list index pointers once a balance falls below EPSILON.
    • Repeat until all lists are completely walked.

๐Ÿ—๏ธ Data Structures Used

  • Transaction struct: Stores sender index (from), receiver index (to), transaction amount, and currency string.
  • Participant struct: Stores entity ID (id) and the computed net balance (balance).
  • Arrays: Fast, contiguous storage for active transactions and active participants.
  • qsort: QuickSort from the C standard library (stdlib.h) is used to sort debtors and creditors using custom pointer-casting comparator functions.

โฑ๏ธ Complexity Analysis

  • Time Complexity:
    • Input Parsing: $\mathcal{O}(T)$ where $T$ is the number of transactions.
    • Sorting: $\mathcal{O}(N \log N)$ where $N$ is the number of participants.
    • Settlement Loop: $\mathcal{O}(N)$ since at least one participant is fully settled in each step.
    • Total Time Complexity: $\mathcal{O}(T + N \log N)$
  • Space Complexity:
    • $\mathcal{O}(N + T)$ to hold participant records and the transaction journal.

๐Ÿ“ Project Structure

global-debt-settlement-optimizer/
โ”œโ”€โ”€ README.md                  # Project documentation
โ”œโ”€โ”€ LICENSE                    # MIT License
โ”œโ”€โ”€ .gitignore                 # Excludes binary executables
โ”œโ”€โ”€ Makefile                   # Automation script for compilation
โ”œโ”€โ”€ CONTRIBUTING.md            # Pull request and style guidelines
โ”œโ”€โ”€ CODE_OF_CONDUCT.md         # Community behavior standards
โ”œโ”€โ”€ CHANGELOG.md               # Versioning log
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ project1.c             # C source code
โ”‚
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ DSA_Question.pdf       # Original project prompt sheet
โ”‚   โ””โ”€โ”€ Project1_Report.pdf    # Complete project report
โ”‚
โ””โ”€โ”€ screenshots/               # Visual records of program execution
    โ”œโ”€โ”€ debt_optimizer_circular.png
    โ”œโ”€โ”€ debt_optimizer_multi_currency.png
    โ”œโ”€โ”€ debt_optimizer_normal.png
    โ””โ”€โ”€ debt_optimizer_zero_tx.png

โš™๏ธ Compilation & Execution

๐Ÿ“‹ Prerequisites

You need a C compiler (gcc) and make installed on your system.

๐Ÿ› ๏ธ Compilation

Open your terminal in this directory and run:

# Using Makefile
make compile

# Or compile manually using GCC
gcc src/project1.c -o project1.exe -lm

โ–ถ๏ธ Execution

Run the compiled binary executable:

# Windows PowerShell
.\project1.exe

# Linux / macOS
./project1.exe

๐Ÿ“ฅ Sample Input

Enter number of participants: 4
Enter number of transactions: 5

Enter transactions (from to amount currency)
0 1 100 USD
1 2 200 INR
2 3 50 EUR
3 0 20 USD
1 3 70 GBP

๐Ÿ“ค Sample Output

Optimized Transactions:
0 -> 3 : 78.40 USD
2 -> 3 : 45.08 USD
2 -> 1 : 6.47 USD

All debts settled using minimum transactions.

๐Ÿ“ธ Execution Screenshots

1. Standard Run Settle Plan (Sample Case)

Standard Run

2. Dynamic Currency Conversion and 2% Fee Deduction

Multi-Currency Settle

3. Zero Transaction Edge Case

Zero Transactions

4. Cyclic Debt Cancellation

Circular Debt


๐Ÿ”ฎ Future Enhancements

  • Cyclic Debt Removal: Add graph traversal (DFS/Tarjan's) to identify and collapse circular dependencies before calculating net balances.
  • Persistent Storage: Add file I/O to read input from a CSV ledger or database.
  • Web UI visualization: Build a lightweight interactive network graph dashboard showing nodes (participants) and directed edges (transfers) using React & D3.js.

๐ŸŽ“ Learning Outcomes

  • Gained hands-on experience applying a Greedy choice strategy to solve NP-complete related network simplifications.
  • Developed robust knowledge of C standard library sorting routines and custom comparator casts.
  • Understood and corrected floating-point arithmetic limitations in C using epsilon bounds.
  • Practiced clean software design patterns, decoupling directories for code, docs, and assets.

๐Ÿ‘จโ€๐Ÿ’ป Author

  • Name: Renu K G
  • Institution: Bapuji Institute of Engineering and Technology, Davanagere
  • Program: Technology Orientation Program (TOP 4.0) โ€” COHORT
  • Submission Date: March 14, 2026

๐Ÿ“„ License

This project is licensed under the MIT License.

About

A C-based financial debt settlement optimizer that minimizes peer-to-peer transaction overhead using a Greedy Choice Heuristic and multi-currency conversion rules

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages