This workspace contains a suite of notebooks for natural gas price modeling, storage contract valuation, and loan default risk analytics. Each notebook addresses a distinct financial modeling challenge using real-world datasets and machine learning.
-
jp_morgan.ipynb / jp_morgan_2.ipynb
Natural Gas Price Forecasting & Storage Contract Valuation- Loads and processes historical natural gas prices from
Nat_Gas.csv. - Builds a Random Forest regression model to estimate future prices.
- Simulates and values storage contracts with customizable injection/withdrawal schedules and costs.
- Includes scenario analysis and visualizations of price trends and seasonality.
- Loads and processes historical natural gas prices from
-
jp_morgan_3.ipynb
Loan Default Risk Modeling- Loads loan data from
Task 3 and 4_Loan_Data.csv. - Engineers features for credit risk analysis.
- Trains and compares multiple classification models (Logistic Regression, Random Forest, Gradient Boosting, SVM).
- Evaluates model performance with ROC curves, confusion matrices, and precision-recall analysis.
- Provides functions for expected loss calculation and portfolio-level risk assessment.
- Loads loan data from
-
jp_morgan_4.ipynb
FICO Score Quantization & Rating Map Creation- Analyzes the relationship between FICO scores and default rates.
- Implements quantization algorithms (Uniform, MSE, Log-Likelihood) to create optimal FICO rating buckets.
- Visualizes bucket statistics and default rate discrimination.
- Generates rating maps for use in credit risk models.
-
Nat_Gas.csv
Historical natural gas price data. -
Task 3 and 4_Loan_Data.csv
Loan-level data for credit risk modeling.
-
Install Dependencies
- Python 3.8+
- Required packages: pandas, numpy, matplotlib, seaborn, scikit-learn, scipy
pip install pandas numpy matplotlib seaborn scikit-learn scipy -
Run Notebooks
- Open any notebook in Jupyter or VS Code.
- Ensure the relevant CSV files are in the workspace root.
- Execute cells to reproduce analysis, modeling, and visualizations.
-
Key Functions
estimate_gas_price(date)– Predicts natural gas price for a given date.price_storage_contract(...)– Values a storage contract and returns detailed economics.calculate_expected_loss(loan_features)– Computes expected loss for a loan scenario.FICOQuantizer– Class for creating and visualizing FICO rating buckets.
# Natural Gas Storage Contract Valuation
results = price_storage_contract(
injection_dates=['2024-06-15', '2024-07-15'],
withdrawal_dates=['2024-12-15', '2025-01-15'],
injection_volumes=[50000, 50000],
withdrawal_volumes=[50000, 50000],
injection_rate=60000,
withdrawal_rate=60000,
max_storage_capacity=100000,
storage_cost_per_day=1000,
injection_cost_per_mmbtu=0.10,
withdrawal_cost_per_mmbtu=0.10
)
print(f"Net Contract Value: ${results['net_contract_value']:,.2f}")
# Loan Expected Loss Calculation
example_loan = {
'credit_lines_outstanding': 2,
'loan_amt_outstanding': 5000,
'total_debt_outstanding': 15000,
'income': 60000,
'years_employed': 3,
'fico_score': 650,
'debt_to_income': 15000/60000,
'loan_to_income': 5000/60000,
'credit_utilization': 15000/3,
'income_per_year': 60000/3
}
result = calculate_expected_loss(example_loan)
print(f"Probability of Default: {result['probability_of_default']:.2%}")
print(f"Expected Loss: ${result['expected_loss']:.2f}")
- All notebooks include code for plotting trends, distributions, ROC curves, and bucket statistics.
This workspace is for educational and analytical purposes only.