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.
- Features
- Technology Stack
- Prerequisites
- Installation
- Running the Application
- API Documentation
- Project Structure
- Database Schema
- Credit Scoring Methodology
- Troubleshooting
- 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
- Liquidity Ratios: Current Ratio
- Leverage Ratios: Debt/Equity, Debt/EBITDA
- Coverage Ratios: Interest Coverage
- Profitability Ratios: Profit Margin, EBITDA Margin, ROE
- Debt/EBITDA
- Debt/Equity
- Current Ratio
- Interest Coverage
- Fixed Charge Coverage
- 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
- React 18: UI library
- Recharts: Data visualization
- Lucide React: Icon library
- Tailwind CSS: Styling (utility classes)
Before you begin, ensure you have the following installed:
-
Python 3.8 or higher
python --version
-
Node.js 16+ and npm (for frontend development)
node --version npm --version
-
pip (Python package manager)
pip --version
Create a project directory and add the files:
mkdir credittheory
cd credittheoryPlace the following files in this directory:
app.py(backend)requirements.txtREADME.md
On macOS/Linux:
python3 -m venv venv
source venv/bin/activateOn Windows:
python -m venv venv
venv\Scripts\activateYou should see (venv) in your terminal prompt.
pip install -r requirements.txtThis will install:
- Flask (web framework)
- Flask-CORS (cross-origin support)
- Flask-SQLAlchemy (database ORM)
- SQLAlchemy (database toolkit)
The database will be automatically initialized when you first run the application. It includes seed data with 3 sample companies and their financial statements.
Navigate to the frontend directory:
cd frontendInstall frontend dependencies:
npm installThis will install React, Recharts, and other required packages.
On Windows:
setup.batOn macOS/Linux:
chmod +x setup.sh
./setup.sh-
Activate virtual environment:
# Windows venv\Scripts\activate # macOS/Linux source venv/bin/activate
-
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:
- Health check: http://localhost:5000/api/health
- Get companies: http://localhost:5000/api/companies
In a new terminal window:
-
Navigate to frontend directory:
cd frontend -
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.
http://localhost:5000/api
GET /api/healthResponse:
{
"status": "healthy",
"message": "credittheory API is running"
}GET /api/companiesResponse:
[
{
"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"
}
]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"
}
]
}POST /api/companies
Content-Type: application/json
{
"name": "New Company Inc",
"industry": "Healthcare"
}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
}GET /api/companies/{company_id}/financial-statementsPOST /api/companies/{company_id}/covenants
Content-Type: application/json
{
"covenant_type": "Debt/EBITDA",
"threshold": 3.0
}GET /api/companies/{company_id}/covenantsGET /api/dashboard/summaryResponse:
{
"total_companies": 3,
"risk_distribution": {
"low": 1,
"medium": 1,
"high": 1
},
"covenant_status": {
"total": 12,
"breached": 1,
"warning": 2,
"compliant": 9
}
}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
| 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 |
| 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 % |
| 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 |
The credit score (0-100) is calculated using four weighted components:
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)
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
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
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)
Credit Score = (Liquidity Γ 0.20) + (Leverage Γ 0.30) +
(Profitability Γ 0.25) + (Coverage Γ 0.25)
- 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)
- Low Risk: Credit Score β₯ 70
- Medium Risk: Credit Score 50-69
- High Risk: Credit Score < 50
- Approve: Credit Score β₯ 70
- Review: Credit Score 50-69
- Reject: Credit Score < 50
Solution:
# Make sure virtual environment is activated
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows
# Reinstall dependencies
pip install -r requirements.txtSolution: The backend includes CORS support. Ensure:
- Backend is running on port 5000
- Frontend is configured to use
http://localhost:5000/api - Flask-CORS is installed:
pip install Flask-CORS
Solution:
# Delete existing database
rm credittheory.db
# Restart Flask application
python app.pyThe database will be automatically recreated with seed data.
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 5001Solution:
- Check backend is running: Visit
http://localhost:5000/api/health - Verify API_BASE_URL in frontend matches backend URL
- Check browser console for CORS errors
- Ensure Flask-CORS is enabled in backend
- Replace SQLite with PostgreSQL or MySQL
- Set up environment variables for configuration
- Implement authentication and authorization
- Add SSL/TLS certificates
- Set up monitoring and logging
- Configure reverse proxy (nginx/Apache)
- Add user authentication and role-based access
- Implement email alerts for covenant breaches
- Add export to PDF/Excel functionality
- Build detailed reporting modules
- Integrate with external data sources (SEC EDGAR, market data)
- Add predictive analytics and trends
- Implement audit trails
This project is for educational and demonstration purposes.
For issues or questions:
- Check the troubleshooting section
- Review API documentation
- Check Flask and SQLAlchemy documentation
# 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/companiesThat's it! credittheory is now running and ready for credit analysis!