tests/test.sh exit code (0 → resolved); the classification below is post-hoc and cannot change it.ls -la /workspace/app/ /workspace/
/workspace/: total 19 drwxrws--- 4 h2tagent h2tagent 4096 Jun 1 08:53 . drwxr-xr-x 28 root root 4096 Jun 1 09:33 .. -rw-rw---- 1 h2tagent h2tagent 2821 Jun 1 08:20 analysis.R drwxrws--- 2 h2tagent h2tagent 4096 Jun 1 08:53 app drwxrws--- 2 h2tagent h2tagent 4096 Jun 1 08:53 output /workspace/app/: total 424 drwxrws--- 2 h2tagent h2tagent 4096 Jun 1 08:53 . drwxrws--- 4 h2tagent h2tagent 4096 Jun 1 08:53 .. -rw-rw---- 1 h2tagent h2tagent 1725 Jun 1 08:20 dataset_manifest.json -rw-rw---- 1 h2tagent h2tagent 423783 Jun 1 08:20 lgd_workouts_source.csv
cat /workspace/app/dataset_manifest.json
{
"dataset_name": "Defaulted-loan workout panel for Loss Given Default modelling",
"source": "Calibrated to Lending Club historical loan-level disclosures of defaulted accounts and their post-default workout ledger (https://www.lendingclub.com/info/statistics.action , historical bulk files).",
"license": "Synthetic but matches the Lending Club workout schema for grading.",
"columns": {
"loan_id": "Anonymous loan identifier.",
"grade": "Lending Club grade A-G assigned at origination.",
"purpose": "Borrower-stated loan purpose.",
"home_ownership": "RENT / OWN / MORTGAGE.",
"principal_at_default": "Outstanding principal at the moment of default (USD).",
"default_month": "Months from origination to default.",
"workout_months_observed": "Months of post-default observation in the panel.",
"time_to_resolution": "Months from default to terminal resolution (recovery curve flat-lines).",
"is_resolved": "1 if workout_months_observed >= time_to_resolution; else 0 (right-censored workout).",
"recovered_amount": "Cumulative dollars recovered as of the as-of date (USD).",
"annual_inc": "Borrower annual income at origination."
},
"definitions": {
"lgd": "LGD = 1 - recovered_amount / principal_at_default , only valid when is_resolved == 1.",
"censoring": "Rows with is_resolved == 0 are right-censored: their LGD is incompletely observed. Censored rows have partial recovery, so recovered_amount understates the true terminal recovery , a naive mean of recovered/principal is biased downward, and therefore LGD = 1 - recovered/principal is biased upward (naive overestimates true LGD). Restrict to resolved workouts or model the cure mechanism."
}
}cat /workspace/analysis.R
#!/usr/bin/env Rscript
# LGD analysis , DRAFT. Audit and finish.
suppressPackageStartupMessages({
library(readr); library(dplyr); library(tidyr); library(jsonlite); library(ggplot2)
})
LGD_PATH <- Sys.getenv("LGD_PATH", "/workspace/app/lgd_workouts_source.csv")
OUT <- Sys.getenv("LGD_OUTPUT_DIR", "/workspace/output")
dir.create(OUT, showWarnings = FALSE, recursive = TRUE)
df <- read_csv(LGD_PATH, show_col_types = FALSE)
# Naive LGD over all rows (this is the biased baseline)
df <- df %>% mutate(observed_lgd = 1 - recovered_amount / principal_at_default)
naive_lgd <- mean(df$observed_lgd)
# "corrected" , but the draft uses ALL rows again, just trimming outliers
corrected_lgd <- mean(df$observed_lgd[df$observed_lgd > 0.0 & df$observed_lgd < 1.0])
# bootstrap on the wrong (full) dataset , and only 200 reps
set.seed(20260606)
boot <- replicate(200, mean(sample(df$observed_lgd, replace = TRUE)))
ci_lo <- quantile(boot, 0.025); ci_hi <- quantile(boot, 0.975)
bg <- df %>% group_by(grade) %>% summarise(corrected_lgd = mean(observed_lgd), .groups = "drop")
bp <- df %>% group_by(purpose) %>% summarise(corrected_lgd = mean(observed_lgd), .groups = "drop")
panel <- df %>% group_by(grade, purpose) %>%
summarise(n_total = n(), n_resolved = sum(is_resolved),
naive_lgd = mean(observed_lgd),
corrected_lgd = mean(observed_lgd), .groups = "drop")
write_csv(panel, file.path(OUT, "lgd_panel.csv"))
bias_diff <- naive_lgd - corrected_lgd
direction <- if (abs(bias_diff) < 0.05) "close" else if (bias_diff > 0) "materially_overestimates" else "materially_underestimates"
metrics <- list(
data_summary = list(n_total = nrow(df), n_resolved = sum(df$is_resolved),
n_censored = nrow(df) - sum(df$is_resolved),
share_resolved = mean(df$is_resolved)),
naive_lgd = list(value = naive_lgd),
corrected_lgd = list(value = corrected_lgd),
bootstrap_ci = list(ci_low = unname(ci_lo), ci_high = unname(ci_hi)),
lgd_by_grade = setNames(as.list(bg$corrected_lgd), bg$grade),
lgd_by_purpose = setNames(as.list(bp$corrected_lgd), bp$purpose),
bias_assessment = list(naive_minus_corrected = bias_diff, direction = direction)
)
write_json(metrics, file.path(OUT, "metrics.json"), auto_unbox = TRUE,
digits = 6, pretty = TRUE)
cat(paste0("Naive LGD: ", round(naive_lgd, 3),
"\nCorrected: ", round(corrected_lgd, 3),
"\nDirection: ", direction, "\n"),
file = file.path(OUT, "insights.md"))
write_json(list(figures = list()), file.path(OUT, "plot_contract.json"),
auto_unbox = TRUE, pretty = TRUE)
png(file.path(OUT, "fig1_lgd_by_grade.png"), width = 600, height = 400); plot.new(); dev.off()
png(file.path(OUT, "fig2_naive_vs_corrected.png"), width = 600, height = 400); plot.new(); dev.off()head -5 /workspace/app/lgd_workouts_source.csv; echo "---"; wc -l /workspace/app/lgd_workouts_source.csv
loan_id,grade,purpose,home_ownership,principal_at_default,default_month,workout_months_observed,time_to_resolution,is_resolved,recovered_amount,annual_inc LC0000000,C,small_business,MORTGAGE,9248.9,12,16,8,1,2351.97,37618.14 LC0000001,A,debt_consolidation,RENT,14442.6,10,25,15,1,7783.99,135186.3 LC0000002,E,debt_consolidation,RENT,22782.58,42,21,10,1,5707.52,57938.72 LC0000003,C,debt_consolidation,MORTGAGE,10656.93,23,24,14,1,4049.36,110952.14 --- 6001 /workspace/app/lgd_workouts_source.csv
cd /workspace && Rscript -e '
library(readr); library(dplyr)
df <- read_csv("/workspace/app/lgd_workouts_source.csv", show_col_types=FALSE)
cat("n total:", nrow(df), "n resolved:", sum(df$is_resolved), "\n")
cat("grades:", paste(sort(unique(df$grade)), collapse=","), "\n")
cat("purposes:", paste(sort(unique(df$purpose)), collapse=","), "\n")
cat("naive:", mean(1 - df$recovered_amount/df$principal_at_default), "\n")
sub <- df[df$is_resolved == 1, ]
cat("corrected:", mean(1 - sub$recovered_amount/sub$principal_at_default), "\n")
'
n total: 6000 n resolved: 3185
grades: A,B,C,D,E,F,G
purposes: credit_card,debt_consolidation,home_improvement,major_purchase,other,small_business
naive: 0.677057
corrected: 0.5651259
[stderr]
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, unioncommand: create
path: /workspace/analysis.R
file_text: #!/usr/bin/env Rscript
# LGD analysis , defensible portfolio read on the Lending Club defaulted-loan
# workout panel.
#
# Key specification notes:
# * naive_lgd : mean(1 - recovered / principal) across ALL rows
# (biased upward because censored rows have partial
# recovery and therefore inflate observed LGD).
# * corrected_lgd : same mean restricted to is_resolved == 1 (resolutions
# only , the only rows where LGD is fully observed).
# * bootstrap_ci : paired percentile bootstrap over resolved rows only,
# B = 1000, seed = 20260606.
# * lgd_by_grade : corrected mean per grade (A-G), resolved-only.
# * lgd_by_purpose : corrected mean per purpose, resolved-only.
# * panel rows : corrected_lgd is the resolved-only mean for every
# grade x purpose cell that has n_resolved > 0.
suppressPackageStartupMessages({
library(readr)
library(dplyr)
library(tidyr)
library(jsonlite)
library(ggplot2)
})
LGD_PATH <- Sys.getenv("LGD_PATH", "/workspace/app/lgd_workouts_source.csv")
OUT <- Sys.getenv("LGD_OUTPUT_DIR", "/workspace/output")
dir.create(OUT, showWarnings = FALSE, recursive = TRUE)
df <- read_csv(LGD_PATH, show_col_types = FALSE)
# --- observed LGD per row (only meaningful when is_resolved == 1) -------------
df <- df %>%
mutate(observed_lgd = 1 - recovered_amount / principal_at_default)
resolved <- df %>% filter(is_resolved == 1)
# --- headline numbers --------------------------------------------------------
naive_lgd <- mean(df$observed_lgd)
corrected_lgd <- mean(resolved$observed_lgd)
# --- paired bootstrap on the resolved-only subset ----------------------------
set.seed(20260606)
B <- 1000
boot_means <- numeric(B)
resolved_lgd <- resolved$observed_lgd
n_res <- length(resolved_lgd)
for (b in seq_len(B)) {
idx <- sample.int(n_res, size = n_res, replace = TRUE)
boot_means[b] <- mean(resolved_lgd[idx])
}
ci_low <- unname(quantile(boot_means, 0.025))
ci_high <- unname(quantile(boot_means, 0.975))
# --- LGD by grade & purpose (resolved-only) ----------------------------------
by_grade <- resolved %>%
group_by(grade) %>%
summarise(corrected_lgd = mean(observed_lgd), .groups = "drop") %>%
arrange(grade)
by_purpose <- resolved %>%
group_by(purpose) %>%
summarise(corrected_lgd = mean(observed_lgd), .groups = "drop") %>%
arrange(purpose)
# --- grade x purpose panel ---------------------------------------------------
# * n_total / naive_lgd use ALL rows in the cell
# * n_resolved / corrected_lgd use the resolved subset of the cell
totals <- df %>%
group_by(grade, purpose) %>%
summarise(
n_total = n(),
n_resolved = sum(is_resolved == 1),
naive_lgd = mean(observed_lgd),
.groups = "drop"
)
resolved_cell <- resolved %>%
group_by(grade, purpose) %>%
summarise(corrected_lgd = mean(observed_lgd), .groups = "drop")
panel <- totals %>%
left_join(resolved_cell, by = c("grade", "purpose")) %>%
arrange(grade, purpose) %>%
select(grade, purpose, n_total, n_resolved, naive_lgd, corrected_lgd)
write_csv(panel, file.path(OUT, "lgd_panel.csv"))
# --- bias assessment ---------------------------------------------------------
bias_diff <- naive_lgd - corrected_lgd
direction <- if (bias_diff > 0.05) {
"materially_overestimates"
} else if (bias_diff < -0.05) {
"materially_underestimates"
} else {
"close"
}
# --- metrics.json ------------------------------------------------------------
metrics <- list(
data_summary = list(
n_total = nrow(df),
n_resolved = sum(df$is_resolved == 1),
n_censored = sum(df$is_resolved == 0),
share_resolved = mean(df$is_resolved == 1)
),
naive_lgd = list(value = naive_lgd),
corrected_lgd = list(value = corrected_lgd),
bootstrap_ci = list(ci_low = ci_low, ci_high = ci_high),
lgd_by_grade
…[truncated]Existing file was successfully overwritten at /workspace/analysis.R
cd /workspace && LGD_OUTPUT_DIR=/workspace/output Rscript /workspace/analysis.R
LGD analysis complete. n_total=6000 n_resolved=3185 naive=0.6771 corrected=0.5651 diff=0.1119 direction=materially_overestimates CI=[0.5577, 0.5727]
ls -la /workspace/output/; echo '---'; cat /workspace/output/metrics.json
total 65
drwxrws--- 2 h2tagent h2tagent 4096 Jun 1 09:34 .
drwxrws--- 4 h2tagent h2tagent 4096 Jun 1 09:34 ..
-rw-r--r-- 1 h2tagent h2tagent 26368 Jun 1 09:34 fig1_lgd_by_grade.png
-rw-r--r-- 1 h2tagent h2tagent 24587 Jun 1 09:34 fig2_naive_vs_corrected.png
-rw-r--r-- 1 h2tagent h2tagent 674 Jun 1 09:34 insights.md
-rw-r--r-- 1 h2tagent h2tagent 2592 Jun 1 09:34 lgd_panel.csv
-rw-r--r-- 1 h2tagent h2tagent 807 Jun 1 09:34 metrics.json
-rw-r--r-- 1 h2tagent h2tagent 815 Jun 1 09:34 plot_contract.json
---
{
"data_summary": {
"n_total": 6000,
"n_resolved": 3185,
"n_censored": 2815,
"share_resolved": 0.53083333
},
"naive_lgd": {
"value": 0.677057
},
"corrected_lgd": {
"value": 0.56512588
},
"bootstrap_ci": {
"ci_low": 0.55767503,
"ci_high": 0.57265928
},
"lgd_by_grade": {
"A": 0.43529755,
"B": 0.49919225,
"C": 0.57150847,
"D": 0.65262141,
"E": 0.71929622,
"F": 0.79746682,
"G": 0.84954799
},
"lgd_by_purpose": {
"credit_card": 0.5911141,
"debt_consolidation": 0.54887667,
"home_improvement": 0.54207074,
"major_purchase": 0.61012939,
"other": 0.54548081,
"small_business": 0.6255756
},
"bias_assessment": {
"naive_minus_corrected": 0.11193112,
"direction": "materially_overestimates"
}
}cat /workspace/output/plot_contract.json; echo '---'; cat /workspace/output/insights.md; echo '---'; head -15 /workspace/output/lgd_panel.csv
{
"figures": [
{
"name": "fig1_lgd_by_grade",
"series": [
{
"name": "corrected_lgd_by_grade",
"x": [
"A",
"B",
"C",
"D",
"E",
"F",
"G"
],
"y": [
0.43529755,
0.49919225,
0.57150847,
0.65262141,
0.71929622,
0.79746682,
0.84954799
]
}
]
},
{
"name": "fig2_naive_vs_corrected",
"series": [
{
"name": "lgd_estimator",
"x": [
"naive (all rows)",
"corrected (resolved only)"
],
"y": [
0.677057,
0.56512588
]
}
]
}
]
}
---
# LGD read , Lending Club defaulted-loan workout panel
Across 6000 defaulted loans, only 3185 (53.1%) have completed workouts; the remaining 2815 rows are right-censored and their recovered_amount understates the terminal recovery. The **naive** LGD, computed over the full panel, is 67.7%. The **corrected** LGD, computed only on resolved workouts, is 56.5% (95% bootstrap CI 55.8% – 57.3%; B = 1000). The naive estimate therefore **materially_overestimates** true LGD by 11.2 percentage points (naive minus corrected). In portfolio terms the biased baseline is the wrong read: restrict to resolved loans (or model the cure mechanism) before pricing or provisioning.
---
grade,purpose,n_total,n_resolved,naive_lgd,corrected_lgd
A,credit_card,219,136,0.5607065958509241,0.45012049865070586
A,debt_consolidation,564,297,0.5702761415442725,0.4202599413316665
A,home_improvement,114,64,0.5292722852167128,0.4073998487935503
A,major_purchase,67,35,0.6368190733531681,0.5021729573367807
A,other,90,52,0.5730028339585355,0.4161251086238681
A,small_business,86,44,0.6524850156856171,0.501025517461768
B,credit_card,321,165,0.6650274867660854,0.5529570202359294
B,debt_consolidation,796,431,0.6046227193564916,0.4831736900891306
B,home_improvement,144,72,0.5957294070774534,0.4692244006760461
B,major_purchase,92,47,0.6660533581869653,0.5058966135004026
B,other,147,76,0.6134946055553012,0.4707940973640627
B,small_business,107,62,0.6406465639242245,0.5319930675458743
C,credit_card,278,137,0.6975732212004435,0.5846765821152625
C,debt_consolidation,689,376,0.6700856143560795,0.5627652371775993cd /workspace && Rscript -e '
library(jsonlite)
pc <- fromJSON("/workspace/output/plot_contract.json", simplifyVector=FALSE)
stopifnot(is.list(pc$figures))
cat("figures is list/array, length =", length(pc$figures), "\n")
for (f in pc$figures) {
cat(" name=", f$name, " series non-empty=", length(f$series) > 0, "\n")
}
# Check panel has no NaN corrected when n_resolved > 0
panel <- read.csv("/workspace/output/lgd_panel.csv")
bad <- panel[panel$n_resolved > 0 & is.na(panel$corrected_lgd), ]
cat("Rows with n_resolved>0 and NaN corrected_lgd:", nrow(bad), "\n")
cat("Cols:", paste(colnames(panel), collapse=","), "\n")
cat("n rows:", nrow(panel), "\n")
# image dims
for (f in c("fig1_lgd_by_grade.png","fig2_naive_vs_corrected.png")) {
info <- file.info(file.path("/workspace/output", f))
cat(f, "size:", info$size, "bytes\n")
}
'
figures is list/array, length = 2 name= fig1_lgd_by_grade series non-empty= TRUE name= fig2_naive_vs_corrected series non-empty= TRUE Rows with n_resolved>0 and NaN corrected_lgd: 0 Cols: grade,purpose,n_total,n_resolved,naive_lgd,corrected_lgd n rows: 42 fig1_lgd_by_grade.png size: 26368 bytes fig2_naive_vs_corrected.png size: 24587 bytes
python3 -c "
from PIL import Image
for f in ['fig1_lgd_by_grade.png','fig2_naive_vs_corrected.png']:
im = Image.open('/workspace/output/'+f)
print(f, im.size)
"
fig1_lgd_by_grade.png (720, 480) fig2_naive_vs_corrected.png (720, 480)
grep -nE 'file\.copy|file\.rename|file\.link|file\.symlink|file\.append|system\(|system2\(|shell\(|\bpipe\(|saveRDS|writeBin|as\.raw|sink\(|readRDS|readBin|\bload\(' /workspace/analysis.R || echo "No forbidden calls found."No forbidden calls found.
No file changes, the agent left the workspace untouched.
# SyncVals normalized verifier summary # task: lending-club-lgd-bias-correction-r # attempt: 10 status: completed raw_score: 0.0 # reward rule: binary: score 0.0 != 1.0 # => reward = 0.0 (FAIL) # # Note: these tasks score via an external hidden grader; no pytest/verifier # block is embedded in the agent transcript. The block below is the last # sizable tool-output captured in the run (supporting evidence). ---------------------------------------------------------------------- figures is list/array, length = 2 name= fig1_lgd_by_grade series non-empty= TRUE name= fig2_naive_vs_corrected series non-empty= TRUE Rows with n_resolved>0 and NaN corrected_lgd: 0 Cols: grade,purpose,n_total,n_resolved,naive_lgd,corrected_lgd n rows: 42 fig1_lgd_by_grade.png size: 26368 bytes fig2_naive_vs_corrected.png size: 24587 bytes
Reproduce this trial: git checkout 2f94510 && PYTHONPATH=src python3 scripts/build_site.py , then open trial/trial_1bfe20cbd0c342ba. Re-running the agent live requires EVAL_PLATFORM_ENABLE_OAUTH_SMOKE=1 and is non-deterministic.
Trial trial_1bfe20cbd0c342ba · verifier authoritative; classifier explanatory.