Prefer replay-qualified Torch calibration
This commit is contained in:
@@ -18,6 +18,7 @@ $RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
||||
$RuntimeDir = Join-Path $RepoRoot "runtime"
|
||||
$LoopLog = Join-Path $RuntimeDir "torch_retrain_until_replay8.log"
|
||||
$GuardReport = Join-Path $RuntimeDir "torch_retrain_guard.json"
|
||||
$ActiveCalibration = Join-Path $RuntimeDir "torch_threshold_calibration.json"
|
||||
$Runner = Join-Path $RepoRoot "tools\run_torch_retrain.ps1"
|
||||
New-Item -ItemType Directory -Force -Path $RuntimeDir | Out-Null
|
||||
|
||||
@@ -45,7 +46,8 @@ function Read-GuardSummary {
|
||||
return [pscustomobject]@{
|
||||
Accepted = $false
|
||||
Reason = "guard_report_missing"
|
||||
ReplayTrades = 0
|
||||
CandidateReplayTrades = 0
|
||||
CurrentReplayTrades = 0
|
||||
WalkForwardTrades = 0
|
||||
}
|
||||
}
|
||||
@@ -54,7 +56,8 @@ function Read-GuardSummary {
|
||||
return [pscustomobject]@{
|
||||
Accepted = [bool]$payload.accepted
|
||||
Reason = [string]$payload.reason
|
||||
ReplayTrades = ConvertTo-IntOrZero $payload.candidate.full_replay.trades
|
||||
CandidateReplayTrades = ConvertTo-IntOrZero $payload.candidate.full_replay.trades
|
||||
CurrentReplayTrades = ConvertTo-IntOrZero $payload.current.full_replay.trades
|
||||
WalkForwardTrades = ConvertTo-IntOrZero $payload.candidate.walk_forward_summary.trades
|
||||
}
|
||||
}
|
||||
@@ -62,14 +65,34 @@ function Read-GuardSummary {
|
||||
return [pscustomobject]@{
|
||||
Accepted = $false
|
||||
Reason = "guard_report_unreadable"
|
||||
ReplayTrades = 0
|
||||
CandidateReplayTrades = 0
|
||||
CurrentReplayTrades = 0
|
||||
WalkForwardTrades = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Read-ActiveReplayTrades {
|
||||
if (-not (Test-Path $ActiveCalibration)) {
|
||||
return 0
|
||||
}
|
||||
try {
|
||||
$payload = Get-Content -Raw -LiteralPath $ActiveCalibration | ConvertFrom-Json
|
||||
return ConvertTo-IntOrZero $payload.full_replay.trades
|
||||
}
|
||||
catch {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
$attempt = 0
|
||||
while ($true) {
|
||||
$activeReplayTrades = Read-ActiveReplayTrades
|
||||
if ($activeReplayTrades -ge $MinReplayTrades) {
|
||||
Write-LoopLog "Stop condition reached: active calibration full_replay.trades=$activeReplayTrades >= $MinReplayTrades."
|
||||
exit 0
|
||||
}
|
||||
|
||||
$attempt += 1
|
||||
if ($SeedStart -gt 0) {
|
||||
$attemptSeed = $SeedStart + $attempt - 1
|
||||
@@ -98,10 +121,14 @@ while ($true) {
|
||||
& powershell.exe @runnerArgs 2>&1 | Tee-Object -FilePath $LoopLog -Append
|
||||
$runnerExit = $LASTEXITCODE
|
||||
$summary = Read-GuardSummary
|
||||
Write-LoopLog "Attempt $attempt finished; runner_exit=$runnerExit accepted=$($summary.Accepted) reason=$($summary.Reason) full_replay.trades=$($summary.ReplayTrades) walk_forward.trades=$($summary.WalkForwardTrades)."
|
||||
Write-LoopLog "Attempt $attempt finished; runner_exit=$runnerExit accepted=$($summary.Accepted) reason=$($summary.Reason) candidate_full_replay.trades=$($summary.CandidateReplayTrades) current_full_replay.trades=$($summary.CurrentReplayTrades) walk_forward.trades=$($summary.WalkForwardTrades)."
|
||||
|
||||
if ($summary.ReplayTrades -ge $MinReplayTrades) {
|
||||
Write-LoopLog "Stop condition reached: full_replay.trades=$($summary.ReplayTrades) >= $MinReplayTrades."
|
||||
if ($summary.Accepted -and $summary.CandidateReplayTrades -ge $MinReplayTrades) {
|
||||
Write-LoopLog "Stop condition reached: accepted candidate full_replay.trades=$($summary.CandidateReplayTrades) >= $MinReplayTrades."
|
||||
exit 0
|
||||
}
|
||||
if ($summary.CurrentReplayTrades -ge $MinReplayTrades) {
|
||||
Write-LoopLog "Stop condition reached: current artifact full_replay.trades=$($summary.CurrentReplayTrades) >= $MinReplayTrades."
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user