Skip to content

analyzing credit risk when given sufficient company data

Notifications You must be signed in to change notification settings

isnaimul/creditTheory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 

Repository files navigation

CreditTheory Overall Proposal- Automated Credit Analysis Platform

creditTheory is a comprehensive credit analysis and monitoring platform designed for banking institutions and financial analysts. It automates credit scoring, financial statement analysis, and covenant monitoring to streamline the credit review process.

Table of Contents


Features

Core Functionality

  • Automated Credit Scoring: 0-100 scale credit scoring with letter ratings (AAA to B-)
  • Financial Statement Analysis: Comprehensive analysis of balance sheets, income statements, and cash flow
  • Covenant Monitoring: Real-time tracking of loan covenants with breach detection
  • Risk Assessment: Multi-dimensional risk evaluation across liquidity, leverage, profitability, and coverage
  • Portfolio Management: Monitor multiple companies simultaneously

Key Metrics Calculated

  • Liquidity Ratios: Current Ratio
  • Leverage Ratios: Debt/Equity, Debt/EBITDA
  • Coverage Ratios: Interest Coverage
  • Profitability Ratios: Profit Margin, EBITDA Margin, ROE

Covenant Types Supported

  1. Debt/EBITDA
  2. Debt/Equity
  3. Current Ratio
  4. Interest Coverage
  5. Fixed Charge Coverage

Technology Stack

Backend

  • Python 3.8+: Core programming language
  • Flask: Lightweight web framework
  • SQLAlchemy: ORM for database operations
  • SQLite: Database (easily replaceable with PostgreSQL/MySQL)
  • Flask-CORS: Cross-origin resource sharing

Frontend

  • React 18: UI library
  • Recharts: Data visualization
  • Lucide React: Icon library
  • Tailwind CSS: Styling (utility classes)

Prerequisites

Before you begin, ensure you have the following installed:

  1. Python 3.8 or higher

    python --version
  2. Node.js 16+ and npm (for frontend development)

    node --version
    npm --version
  3. pip (Python package manager)

    pip --version

Installation

Step 1: Clone or Download the Project

Create a project directory and add the files:

mkdir credittheory
cd credittheory

Place the following files in this directory:

  • app.py (backend)
  • requirements.txt
  • README.md

Step 2: Set Up Python Virtual Environment

On macOS/Linux:

python3 -m venv venv
source venv/bin/activate

On Windows:

python -m venv venv
venv\Scripts\activate

You should see (venv) in your terminal prompt.

Step 3: Install Python Dependencies

pip install -r requirements.txt

This will install:

  • Flask (web framework)
  • Flask-CORS (cross-origin support)
  • Flask-SQLAlchemy (database ORM)
  • SQLAlchemy (database toolkit)

Step 4: Initialize the Database

The database will be automatically initialized when you first run the application. It includes seed data with 3 sample companies and their financial statements.

Step 5: Set Up the Frontend

Navigate to the frontend directory:

cd frontend

Install frontend dependencies:

npm install

This will install React, Recharts, and other required packages.


Running the Application

Option 1: Automated Setup (Recommended)

On Windows:

setup.bat

On macOS/Linux:

chmod +x setup.sh
./setup.sh

Option 2: Manual Setup

Start the Backend Server

  1. Activate virtual environment:

    # Windows
    venv\Scripts\activate
    
    # macOS/Linux
    source venv/bin/activate
  2. Run the Flask app:

    python app.py

You should see output like:

============================================================
credittheory Backend Server Starting
============================================================
Server running on: http://localhost:5000
API documentation: http://localhost:5000/api/health
============================================================

The backend API is now running! You can test it by visiting:

Start the Frontend

In a new terminal window:

  1. Navigate to frontend directory:

    cd frontend
  2. Start the React development server:

    npm start

The frontend will automatically open at http://localhost:3000

Important: Make sure the backend is running on port 5000 before starting the frontend.


API Documentation

Base URL

http://localhost:5000/api

Endpoints

1. Health Check

GET /api/health

Response:

{
  "status": "healthy",
  "message": "credittheory API is running"
}

2. Get All Companies

GET /api/companies

Response:

[
  {
    "id": 1,
    "name": "TechCorp Industries",
    "industry": "Technology",
    "credit_score": 78.5,
    "credit_rating": "A-",
    "risk_level": "Low",
    "created_at": "2024-01-01T00:00:00",
    "updated_at": "2024-12-01T00:00:00"
  }
]

3. Get Company Details

GET /api/companies/{company_id}

Response:

{
  "id": 1,
  "name": "TechCorp Industries",
  "industry": "Technology",
  "credit_score": 78.5,
  "credit_rating": "A-",
  "risk_level": "Low",
  "latest_statement": {
    "id": 4,
    "statement_date": "2024-12-01",
    "period_type": "Q4",
    "ratios": {
      "current_ratio": 1.85,
      "debt_to_equity": 0.65,
      "debt_to_ebitda": 2.1,
      "interest_coverage": 8.5,
      "profit_margin": 18.5,
      "ebitda_margin": 28.3,
      "roe": 15.2
    }
  },
  "covenants": [
    {
      "id": 1,
      "covenant_type": "Debt/EBITDA",
      "threshold": 3.0,
      "current_value": 2.1,
      "status": "Compliant"
    }
  ]
}

4. Create Company

POST /api/companies
Content-Type: application/json

{
  "name": "New Company Inc",
  "industry": "Healthcare"
}

5. Add Financial Statement

POST /api/companies/{company_id}/financial-statements
Content-Type: application/json

{
  "statement_date": "2024-12-31",
  "period_type": "Annual",
  "total_assets": 10000000,
  "current_assets": 4000000,
  "total_liabilities": 6000000,
  "current_liabilities": 2000000,
  "total_debt": 3000000,
  "shareholders_equity": 4000000,
  "revenue": 15000000,
  "operating_expenses": 10000000,
  "ebitda": 5000000,
  "interest_expense": 200000,
  "net_income": 3000000
}

6. Get Financial Statements

GET /api/companies/{company_id}/financial-statements

7. Add Covenant

POST /api/companies/{company_id}/covenants
Content-Type: application/json

{
  "covenant_type": "Debt/EBITDA",
  "threshold": 3.0
}

8. Get Covenants

GET /api/companies/{company_id}/covenants

9. Dashboard Summary

GET /api/dashboard/summary

Response:

{
  "total_companies": 3,
  "risk_distribution": {
    "low": 1,
    "medium": 1,
    "high": 1
  },
  "covenant_status": {
    "total": 12,
    "breached": 1,
    "warning": 2,
    "compliant": 9
  }
}

πŸ“ Project Structure

credittheory/
β”œβ”€β”€ app.py                      # Main Flask application
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ README.md                   # Documentation
β”œβ”€β”€ setup.sh                    # Setup script (Mac/Linux)
β”œβ”€β”€ setup.bat                   # Setup script (Windows)
β”œβ”€β”€ credittheory.db             # SQLite database (auto-generated)
β”œβ”€β”€ venv/                      # Virtual environment (auto-generated)
└── frontend/                  # React frontend
    β”œβ”€β”€ package.json           # Frontend dependencies
    β”œβ”€β”€ README.md              # Frontend documentation
    β”œβ”€β”€ public/
    β”‚   β”œβ”€β”€ index.html         # HTML template
    β”‚   β”œβ”€β”€ manifest.json      # PWA manifest
    β”‚   └── robots.txt         # SEO robots file
    └── src/
        β”œβ”€β”€ App.js             # Main React component
        β”œβ”€β”€ index.js           # React entry point
        └── index.css          # Global styles

Database Schema

Tables

1. companies

Column Type Description
id Integer (PK) Unique identifier
name String Company name
industry String Industry sector
credit_score Float 0-100 credit score
credit_rating String Letter rating (AAA-B-)
risk_level String Low/Medium/High
created_at DateTime Creation timestamp
updated_at DateTime Last update timestamp

2. financial_statements

Column Type Description
id Integer (PK) Unique identifier
company_id Integer (FK) Reference to company
statement_date Date Statement period end date
period_type String Q1/Q2/Q3/Q4/Annual
total_assets Float Total assets
current_assets Float Current assets
total_liabilities Float Total liabilities
current_liabilities Float Current liabilities
total_debt Float Total debt
shareholders_equity Float Shareholders' equity
revenue Float Total revenue
operating_expenses Float Operating expenses
ebitda Float EBITDA
interest_expense Float Interest expense
net_income Float Net income
current_ratio Float Calculated ratio
debt_to_equity Float Calculated ratio
debt_to_ebitda Float Calculated ratio
interest_coverage Float Calculated ratio
profit_margin Float Calculated %
ebitda_margin Float Calculated %
roe Float Calculated %

3. covenants

Column Type Description
id Integer (PK) Unique identifier
company_id Integer (FK) Reference to company
covenant_type String Type of covenant
threshold Float Maximum/minimum value
current_value Float Current actual value
status String Compliant/Warning/Breach
last_checked DateTime Last check timestamp

Credit Scoring Methodology

Score Components

The credit score (0-100) is calculated using four weighted components:

1. Liquidity Score (20% weight)

Based on Current Ratio:

  • β‰₯ 2.0: 100 points (Excellent)
  • β‰₯ 1.5: 80 points (Good)
  • β‰₯ 1.0: 60 points (Adequate)
  • β‰₯ 0.75: 40 points (Weak)
  • < 0.75: 20 points (Poor)

2. Leverage Score (30% weight)

Based on Debt/Equity and Debt/EBITDA:

  • Debt/Equity ≀ 0.5: 100 points
  • Debt/Equity ≀ 1.0: 80 points
  • Debt/Equity ≀ 2.0: 60 points
  • Debt/Equity ≀ 3.0: 40 points
  • Debt/Equity > 3.0: 20 points

3. Profitability Score (25% weight)

Based on Profit Margin and ROE:

  • Profit Margin β‰₯ 20%: 100 points
  • Profit Margin β‰₯ 10%: 80 points
  • Profit Margin β‰₯ 5%: 60 points
  • Profit Margin β‰₯ 0%: 40 points
  • Profit Margin < 0%: 20 points

4. Coverage Score (25% weight)

Based on Interest Coverage Ratio:

  • β‰₯ 10x: 100 points (Excellent)
  • β‰₯ 5x: 80 points (Good)
  • β‰₯ 3x: 60 points (Adequate)
  • β‰₯ 1.5x: 40 points (Weak)
  • < 1.5x: 20 points (Poor)

Overall Credit Score Calculation

Credit Score = (Liquidity Γ— 0.20) + (Leverage Γ— 0.30) + 
               (Profitability Γ— 0.25) + (Coverage Γ— 0.25)

Credit Rating Assignment

  • 90-100: AAA (Exceptional)
  • 85-89: AA+ (Excellent)
  • 80-84: AA (Excellent)
  • 75-79: AA- (Very Good)
  • 70-74: A+ (Good)
  • 65-69: A (Good)
  • 60-64: A- (Adequate)
  • 55-59: BBB+ (Moderate)
  • 50-54: BBB (Moderate)
  • 45-49: BBB- (Acceptable)
  • 40-44: BB+ (Speculative)
  • 35-39: BB (Speculative)
  • 30-34: BB- (High Risk)
  • 25-29: B+ (Very High Risk)
  • 20-24: B (Very High Risk)
  • < 20: B- (Default Risk)

Risk Levels

  • Low Risk: Credit Score β‰₯ 70
  • Medium Risk: Credit Score 50-69
  • High Risk: Credit Score < 50

Lending Recommendations

  • Approve: Credit Score β‰₯ 70
  • Review: Credit Score 50-69
  • Reject: Credit Score < 50

Troubleshooting

Common Issues

Issue 1: "Module not found" errors

Solution:

# Make sure virtual environment is activated
source venv/bin/activate  # macOS/Linux
venv\Scripts\activate     # Windows

# Reinstall dependencies
pip install -r requirements.txt

Issue 2: CORS errors in browser

Solution: The backend includes CORS support. Ensure:

  1. Backend is running on port 5000
  2. Frontend is configured to use http://localhost:5000/api
  3. Flask-CORS is installed: pip install Flask-CORS

Issue 3: Database not created

Solution:

# Delete existing database
rm credittheory.db

# Restart Flask application
python app.py

The database will be automatically recreated with seed data.

Issue 4: Port already in use

Solution:

# Find process using port 5000
lsof -ti:5000  # macOS/Linux
netstat -ano | findstr :5000  # Windows

# Kill the process
kill -9 <PID>  # macOS/Linux
taskkill /PID <PID> /F  # Windows

# Or use a different port
flask run --port 5001

Issue 5: Frontend can't connect to backend

Solution:

  1. Check backend is running: Visit http://localhost:5000/api/health
  2. Verify API_BASE_URL in frontend matches backend URL
  3. Check browser console for CORS errors
  4. Ensure Flask-CORS is enabled in backend

Next Steps

Production Deployment

  1. Replace SQLite with PostgreSQL or MySQL
  2. Set up environment variables for configuration
  3. Implement authentication and authorization
  4. Add SSL/TLS certificates
  5. Set up monitoring and logging
  6. Configure reverse proxy (nginx/Apache)

Feature Enhancements

  1. Add user authentication and role-based access
  2. Implement email alerts for covenant breaches
  3. Add export to PDF/Excel functionality
  4. Build detailed reporting modules
  5. Integrate with external data sources (SEC EDGAR, market data)
  6. Add predictive analytics and trends
  7. Implement audit trails

πŸ“ License

This project is for educational and demonstration purposes.


Support

For issues or questions:

  1. Check the troubleshooting section
  2. Review API documentation
  3. Check Flask and SQLAlchemy documentation

Getting Started Quick Reference

# 1. Set up environment
python3 -m venv venv
source venv/bin/activate  # or venv\Scripts\activate on Windows

# 2. Install dependencies
pip install -r requirements.txt

# 3. Run the application
python app.py

# 4. Test the API
curl http://localhost:5000/api/health
curl http://localhost:5000/api/companies

That's it! credittheory is now running and ready for credit analysis!

About

analyzing credit risk when given sufficient company data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors