Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Offers financial risk modeling methods such as Value at Risk, Expected Shortfall, credit risk, stress testing, and Monte Carlo simulation.
70% 74%+4 ptsof test cases passed
Passed 17 of 23 test cases with the skill, and 16 of 23 without it.
We are setting up a credit risk pipeline in Python to analyze default probabilities and exposure risk. Could you provide a function that fits a logistic regression model on borrower credit features against a default indicator, returning a dictionary with the ROC AUC score, intercept, and coefficient odds ratios? Additionally, provide a helper function that takes individual probability of default, loss given default, and exposure at default values, returning a dictionary with the calculated expected loss and 99% unexpected loss.
Sets LogisticRegression parameter class_weight to balanced
3 of 3 safety checks passed
A skill for quantitative financial risk modeling, covering Value at Risk, Expected Shortfall, credit risk, stress testing, and Monte Carlo simulation methods. Essential for financial engineering research and regulatory risk analysis.
| Method | Description | Pros | Cons |
|---|---|---|---|
| Historical simulation | Replay past returns | No distributional assumption | Assumes past repeats |
| Variance-covariance | Assume normal returns | Fast, analytical | Underestimates tail risk |
| Monte Carlo simulation | Simulate from fitted model | Flexible distributions | Computationally expensive |
| Filtered historical simulation | GARCH + historical innovations | Captures volatility clustering | More complex |
import numpy as np
import pandas as pd
from scipy.stats import norm, t as t_dist
def historical_var(returns: np.ndarray, confidence: float = 0.99,
horizon_days: int = 1) -> dict:
"""
Compute Value at Risk using historical simulation.
returns: array of daily log returns
confidence: confidence level (e.g., 0.99 for 99% VaR)
horizon_days: risk horizon in days
"""
# Scale returns to horizon
if horizon_days > 1:
# Rolling sum for overlapping returns
scaled_returns = pd.Series(returns).rolling(horizon_days).sum().dropna().values
else:
scaled_returns = returns
alpha = 1 - confidence
var = -np.percentile(scaled_returns, alpha * 100)
es = -np.mean(scaled_returns[scaled_returns <= -var])
Next to this one in the catalogue, plus more from the same author.