1139 lines
40 KiB
Rust
1139 lines
40 KiB
Rust
use super::{contract::*, matching::*, replay::*, scalar::Posting};
|
|
use serde_json::json;
|
|
use std::time::Instant;
|
|
|
|
fn id(s: &str) -> Id {
|
|
serde_json::from_value(json!(s)).unwrap()
|
|
}
|
|
fn t(n: i64) -> EventTime {
|
|
n.try_into().unwrap()
|
|
}
|
|
fn p(s: &str) -> Posting {
|
|
s.parse().unwrap()
|
|
}
|
|
fn pos(s: &str) -> Positive {
|
|
p(s).try_into().unwrap()
|
|
}
|
|
fn nn(s: &str) -> NonNegative {
|
|
p(s).try_into().unwrap()
|
|
}
|
|
fn venue(name: &str, start: i64, end: i64) -> VenueSession {
|
|
VenueSession {
|
|
session_id: id(name),
|
|
opens_at: t(start),
|
|
closes_at: t(end),
|
|
}
|
|
}
|
|
fn series(name: &str, symbol: &str) -> ReplaySeries {
|
|
ReplaySeries {
|
|
series_id: id(name),
|
|
instrument_id: id(symbol),
|
|
adjustment: PriceAdjustment::Raw,
|
|
sessions: vec![venue("day1", 0, 10000000)],
|
|
}
|
|
}
|
|
fn bar(
|
|
series: &str,
|
|
symbol: &str,
|
|
start: i64,
|
|
end: i64,
|
|
available: i64,
|
|
seq: u64,
|
|
open: &str,
|
|
close: &str,
|
|
volume: &str,
|
|
) -> PreparedBar {
|
|
PreparedBar {
|
|
series_id: id(series),
|
|
instrument_id: id(symbol),
|
|
interval_start: t(start),
|
|
interval_end: t(end),
|
|
event_time: t(end),
|
|
available_at: t(available),
|
|
source_sequence: seq.try_into().unwrap(),
|
|
open: pos(open),
|
|
high: p(open).max(p(close)).try_into().unwrap(),
|
|
low: p(open).min(p(close)).try_into().unwrap(),
|
|
close: pos(close),
|
|
volume: nn(volume),
|
|
}
|
|
}
|
|
fn fixture() -> (PreparedReplay, ReplayConfig) {
|
|
let matching:MatchingConfig=serde_json::from_value(json!({
|
|
"risk":{"ledger":{"version":1,"sessionId":"run","accountId":"account","baseCurrency":"USD","reserveOwnerId":"reserve","ownerIds":["A"],"initialCapital":"10000","riskSession":{"calendarId":"account","calendarRevision":"1","sessionId":"risk1","startsAt":0}},
|
|
"feeRate":"0.01","maxOrderQuantity":"1000000","maxPositionQuantity":"1000000","maxSymbolExposure":"1000000","maxGrossExposure":"1000000","maxDailyLoss":"1000000","maxDrawdownAmount":"1000000","maxMarkAgeMs":10000000},
|
|
"owners":[{"ownerId":"A","mode":"Target"}],"series":[{"instrumentId":"X","seriesId":"X-bars","mode":"Open"}],"halfSpreadRate":"0","slippageRate":"0","latencyMs":0
|
|
})).unwrap();
|
|
(
|
|
PreparedReplay {
|
|
dataset_id: id("frozen-fixture"),
|
|
eligibility: DatasetEligibility::Eligible,
|
|
limitations: vec!["previous completed volume capacity; zero modeled latency".into()],
|
|
bounds: ReplayBounds {
|
|
warmup_start: t(0),
|
|
trade_start: t(10),
|
|
trade_end: t(30),
|
|
},
|
|
series: vec![series("X-bars", "X")],
|
|
bars: vec![
|
|
bar("X-bars", "X", 0, 10, 10, 7, "10", "11", "100"),
|
|
bar("X-bars", "X", 10, 20, 20, 3, "12", "13", "100"),
|
|
bar("X-bars", "X", 20, 30, 30, 9, "14", "15", "100"),
|
|
],
|
|
},
|
|
ReplayConfig {
|
|
matching,
|
|
participation_rate: nn("1"),
|
|
cadence: vec![DecisionCadence {
|
|
owner_id: id("A"),
|
|
series_ids: vec![id("X-bars")],
|
|
}],
|
|
allow_exploratory: false,
|
|
risk_boundaries: vec![],
|
|
},
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn published_delta_cursor_bounds() {
|
|
let (input, config) = fixture();
|
|
let mut replay = Replay::new(input, config).unwrap();
|
|
assert_eq!(replay.observations_since(0).count(), 0);
|
|
assert_eq!(replay.observations_since(usize::MAX).count(), 0);
|
|
next(&mut replay).unwrap();
|
|
assert_eq!(replay.observations_since(0).count(), 1);
|
|
assert_eq!(replay.observations_since(1).count(), 0);
|
|
assert_eq!(replay.observations_since(usize::MAX).count(), 0);
|
|
}
|
|
fn next(r: &mut Replay) -> Option<DecisionBarrier> {
|
|
loop {
|
|
match r.advance(100).unwrap() {
|
|
ReplayStep::Decision(b) => return Some(b),
|
|
ReplayStep::Complete => return None,
|
|
ReplayStep::Failed { diagnostic } => panic!("replay failed: {diagnostic}"),
|
|
ReplayStep::Progress { .. } => {}
|
|
}
|
|
}
|
|
}
|
|
fn target(r: &mut Replay, b: &DecisionBarrier, quantity: &str) -> MatchingOutcome {
|
|
let decisions = b
|
|
.owner_ids
|
|
.iter()
|
|
.map(|owner| StrategyDecision {
|
|
version: Version,
|
|
session_id: id("run"),
|
|
barrier_id: b.barrier_id.clone(),
|
|
revision: b.revision,
|
|
decision: DecisionIdentity {
|
|
owner_id: owner.clone(),
|
|
decision_id: id(&format!("{}-{owner:?}", b.at.get())),
|
|
sequence: (b.at.get() as u64).try_into().unwrap(),
|
|
},
|
|
intent: StrategyIntent::Target {
|
|
targets: vec![Target {
|
|
instrument_id: id("X"),
|
|
quantity: nn(quantity),
|
|
}],
|
|
},
|
|
})
|
|
.collect();
|
|
r.submit(DecisionSubmission {
|
|
barrier_id: b.barrier_id.clone(),
|
|
decisions,
|
|
})
|
|
.unwrap()
|
|
}
|
|
fn no_change(r: &mut Replay, b: &DecisionBarrier) -> MatchingOutcome {
|
|
let decisions = b
|
|
.owner_ids
|
|
.iter()
|
|
.map(|owner| StrategyDecision {
|
|
version: Version,
|
|
session_id: id("run"),
|
|
barrier_id: b.barrier_id.clone(),
|
|
revision: b.revision,
|
|
decision: DecisionIdentity {
|
|
owner_id: owner.clone(),
|
|
decision_id: id(&format!("{}-{owner:?}", b.at.get())),
|
|
sequence: (b.at.get() as u64).try_into().unwrap(),
|
|
},
|
|
intent: StrategyIntent::Target { targets: vec![] },
|
|
})
|
|
.collect();
|
|
r.submit(DecisionSubmission {
|
|
barrier_id: b.barrier_id.clone(),
|
|
decisions,
|
|
})
|
|
.unwrap()
|
|
}
|
|
fn complete(r: &mut Replay) {
|
|
while let Some(b) = next(r) {
|
|
no_change(r, &b);
|
|
}
|
|
}
|
|
fn fill_prices(r: &Replay) -> Vec<Posting> {
|
|
r.financial()
|
|
.receipts()
|
|
.iter()
|
|
.flat_map(|r| &r.outcome.effects)
|
|
.filter_map(|effect| {
|
|
if let MatchingEffect::Risk { command, outcome } = effect {
|
|
if let super::risk::RiskCommandBody::Fill { price, .. } = command.body {
|
|
if outcome.financial.is_some()
|
|
&& outcome.disposition == super::risk::RiskDisposition::Accepted
|
|
{
|
|
return Some(price.into());
|
|
}
|
|
}
|
|
}
|
|
None
|
|
})
|
|
.collect()
|
|
}
|
|
#[test]
|
|
fn adjacent_open_zero_latency() {
|
|
let (input, config) = fixture();
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(10));
|
|
assert_eq!(b.observation_count, 1);
|
|
assert_eq!(r.observations().next().unwrap().close, pos("11"));
|
|
target(&mut r, &b, "2");
|
|
complete(&mut r);
|
|
assert_eq!(fill_prices(&r), vec![p("12")]);
|
|
assert_eq!(r.financial().ledger().cash(), p("9975.76"));
|
|
assert_eq!(r.financial().ledger().equity().unwrap(), p("10005.76"));
|
|
}
|
|
#[test]
|
|
fn positive_latency_skips_open() {
|
|
let (input, mut config) = fixture();
|
|
config.matching.latency_ms = 1.try_into().unwrap();
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
target(&mut r, &b, "2");
|
|
complete(&mut r);
|
|
assert_eq!(fill_prices(&r), vec![p("14")]);
|
|
}
|
|
#[test]
|
|
fn future_ohlcv_does_not_change_open_fill() {
|
|
let (input, config) = fixture();
|
|
let mut changed = input.clone();
|
|
changed.bars[1].high = pos("999");
|
|
changed.bars[1].low = pos("1");
|
|
changed.bars[1].close = pos("888");
|
|
changed.bars[1].volume = nn("0");
|
|
let mut traces = vec![];
|
|
for data in [input, changed] {
|
|
let mut r = Replay::new(data, config.clone()).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
target(&mut r, &b, "2");
|
|
let _ = next(&mut r).unwrap();
|
|
traces.push((fill_prices(&r), r.financial().ledger().cash()));
|
|
}
|
|
assert_eq!(traces[0], traces[1]);
|
|
assert_eq!(traces[0].0, vec![p("12")]);
|
|
}
|
|
#[test]
|
|
fn future_suffix_mutation() {
|
|
let (input, config) = fixture();
|
|
let mut changed = input.clone();
|
|
changed.bars[2].open = pos("999");
|
|
changed.bars[2].high = pos("999");
|
|
let mut prefix = vec![];
|
|
for data in [input, changed] {
|
|
let mut r = Replay::new(data, config.clone()).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
target(&mut r, &b, "2");
|
|
let b = next(&mut r).unwrap();
|
|
prefix.push((
|
|
b,
|
|
r.observations().cloned().collect::<Vec<_>>(),
|
|
r.financial().checkpoint(),
|
|
));
|
|
}
|
|
assert_eq!(prefix[0], prefix[1]);
|
|
}
|
|
#[test]
|
|
fn daily_close_target_survives_to_open() {
|
|
let (mut input, config) = fixture();
|
|
input.bounds.trade_start = t(0);
|
|
input.bounds.trade_end = t(40);
|
|
input.series[0].sessions = vec![
|
|
venue("day1", 0, 10),
|
|
venue("day2", 20, 30),
|
|
venue("day3", 35, 40),
|
|
];
|
|
input.bars = vec![
|
|
bar("X-bars", "X", 0, 10, 10, 0, "10", "11", "100"),
|
|
bar("X-bars", "X", 20, 30, 30, 1, "12", "13", "100"),
|
|
bar("X-bars", "X", 35, 40, 40, 2, "14", "15", "100"),
|
|
];
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(10));
|
|
target(&mut r, &b, "2");
|
|
complete(&mut r);
|
|
assert_eq!(fill_prices(&r), vec![p("12")]);
|
|
let fill = r
|
|
.financial()
|
|
.receipts()
|
|
.iter()
|
|
.find(|r| {
|
|
r.outcome.effects.iter().any(|e| {
|
|
matches!(
|
|
e,
|
|
MatchingEffect::Risk {
|
|
command: super::risk::RiskCommand {
|
|
body: super::risk::RiskCommandBody::Fill { .. },
|
|
..
|
|
},
|
|
..
|
|
}
|
|
)
|
|
})
|
|
})
|
|
.unwrap();
|
|
let MatchingInput::Engine(c) = &fill.input else {
|
|
panic!()
|
|
};
|
|
assert_eq!(c.key.at, t(20));
|
|
}
|
|
#[test]
|
|
fn feature_timeframe_does_not_duplicate_liquidity() {
|
|
let (input, config) = fixture();
|
|
let mut extra = input.clone();
|
|
extra.series.push(series("feature", "X"));
|
|
extra.bars.extend([
|
|
bar("feature", "X", 0, 5, 5, 0, "10", "99", "9999"),
|
|
bar("feature", "X", 5, 15, 15, 1, "99", "999", "9999"),
|
|
]);
|
|
let mut traces = vec![];
|
|
for data in [input, extra] {
|
|
let mut r = Replay::new(data, config.clone()).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
target(&mut r, &b, "150");
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(20));
|
|
no_change(&mut r, &b);
|
|
complete(&mut r);
|
|
traces.push((fill_prices(&r), r.financial().ledger().economic_snapshot()));
|
|
}
|
|
assert_eq!(traces[0], traces[1]);
|
|
assert_eq!(traces[0].0.len(), 2);
|
|
}
|
|
#[test]
|
|
fn equal_timestamp_symbol_permutation() {
|
|
let (mut input, mut config) = fixture();
|
|
input.series.push(series("Y-bars", "Y"));
|
|
input
|
|
.bars
|
|
.extend(input.bars.clone().into_iter().map(|mut b| {
|
|
b.series_id = id("Y-bars");
|
|
b.instrument_id = id("Y");
|
|
b
|
|
}));
|
|
config.matching.series.push(ExecutionSeries {
|
|
instrument_id: id("Y"),
|
|
series_id: id("Y-bars"),
|
|
mode: ExecutionMode::Open,
|
|
});
|
|
config.matching.owners.push(OwnerMode {
|
|
owner_id: id("B"),
|
|
mode: StrategyMode::Target,
|
|
});
|
|
config.matching.risk.ledger.owner_ids.push(id("B"));
|
|
config.cadence.push(DecisionCadence {
|
|
owner_id: id("B"),
|
|
series_ids: vec![id("Y-bars")],
|
|
});
|
|
config.risk_boundaries.push(RiskSessionIdentity {
|
|
calendar_id: id("account"),
|
|
calendar_revision: id("1"),
|
|
session_id: id("risk2"),
|
|
starts_at: t(10),
|
|
});
|
|
let mut changed = input.clone();
|
|
changed.bars.reverse();
|
|
changed.series.reverse();
|
|
let mut reversed = config.clone();
|
|
reversed.cadence.reverse();
|
|
reversed.matching.series.reverse();
|
|
reversed.matching.owners.reverse();
|
|
reversed.matching.risk.ledger.owner_ids.reverse();
|
|
let mut traces = vec![];
|
|
for (data, cfg) in [(input, config), (changed, reversed)] {
|
|
let mut r = Replay::new(data, cfg).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.owner_ids, vec![id("A"), id("B")]);
|
|
assert_eq!(b.observation_count, 2);
|
|
assert_eq!(b.revision, r.financial().admission_revision());
|
|
assert_ne!(
|
|
b.revision,
|
|
r.financial().ledger().economic_snapshot().revision
|
|
);
|
|
target(&mut r, &b, "2");
|
|
complete(&mut r);
|
|
traces.push(r.checkpoint());
|
|
}
|
|
assert_eq!(traces[0], traces[1]);
|
|
}
|
|
#[test]
|
|
fn warmup_cannot_trade() {
|
|
let (mut input, config) = fixture();
|
|
input.bounds.trade_start = t(20);
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
assert!(matches!(
|
|
r.submit(DecisionSubmission {
|
|
barrier_id: id("invented"),
|
|
decisions: vec![]
|
|
}),
|
|
Err(ReplayError::InvalidSubmission)
|
|
));
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(20));
|
|
assert_eq!(b.observation_count, 2);
|
|
assert!(fill_prices(&r).is_empty());
|
|
assert!(!r.financial().receipts().iter().any(|r| matches!(
|
|
&r.input,
|
|
MatchingInput::Engine(MatchingCommand {
|
|
body: MatchingCommandBody::Execute { .. },
|
|
..
|
|
})
|
|
)));
|
|
target(&mut r, &b, "2");
|
|
complete(&mut r);
|
|
assert_eq!(fill_prices(&r), vec![p("14")]);
|
|
}
|
|
#[test]
|
|
fn stale_mark_timestamp_preserved() {
|
|
let (mut input, mut config) = fixture();
|
|
input.bars[0].available_at = t(15);
|
|
config.matching.risk.max_mark_age_ms = 2.try_into().unwrap();
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(15));
|
|
assert_eq!(
|
|
r.financial().ledger().mark(&id("X")).unwrap().event_time,
|
|
t(10)
|
|
);
|
|
assert!(
|
|
matches!(b.inputs[0].availability,InputAvailability::Stale {event_time,available_at} if event_time==t(10)&&available_at==t(15))
|
|
);
|
|
target(&mut r, &b, "2");
|
|
complete(&mut r);
|
|
assert!(fill_prices(&r).is_empty());
|
|
}
|
|
#[test]
|
|
fn delayed_older_observation_preserves_mark_and_capacity() {
|
|
let (mut input, config) = fixture();
|
|
input.bounds.trade_end = t(40);
|
|
input.bars[0].available_at = t(25);
|
|
input.bars[0].volume = nn("999");
|
|
input.bars[1].volume = nn("2");
|
|
input
|
|
.bars
|
|
.push(bar("X-bars", "X", 30, 40, 40, 15, "16", "17", "100"));
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(20));
|
|
target(&mut r, &b, "10");
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(25));
|
|
assert_eq!(
|
|
r.financial().ledger().mark(&id("X")).unwrap().price,
|
|
pos("14")
|
|
);
|
|
assert_eq!(r.latest_observation(&id("X-bars")).unwrap().volume, nn("2"));
|
|
no_change(&mut r, &b);
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(
|
|
r.financial().ledger().owner_quantity(&id("A"), &id("X")),
|
|
p("2")
|
|
);
|
|
no_change(&mut r, &b);
|
|
complete(&mut r);
|
|
assert_eq!(fill_prices(&r), vec![p("14"), p("16")]);
|
|
}
|
|
#[test]
|
|
fn delayed_close_at_prior_open_timestamp_cannot_regress_mark() {
|
|
let (mut input, config) = fixture();
|
|
input.bars[1].available_at = t(25);
|
|
input.bars[2].open = pos("30");
|
|
input.bars[2].high = pos("30");
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
no_change(&mut r, &b);
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(25));
|
|
let mark = r.financial().ledger().mark(&id("X")).unwrap();
|
|
assert_eq!(mark.event_time, t(20));
|
|
assert_eq!(mark.price, pos("30"));
|
|
}
|
|
#[test]
|
|
fn mid_session_start_retains_true_session_open() {
|
|
let (mut input, config) = fixture();
|
|
input.bounds.warmup_start = t(5);
|
|
input.bars[0].interval_start = t(5);
|
|
let mut r = Replay::new(input.clone(), config.clone()).unwrap();
|
|
let _ = next(&mut r).unwrap();
|
|
let MatchingInput::Engine(c) = &r.financial().receipts()[0].input else {
|
|
panic!()
|
|
};
|
|
assert_eq!(c.key.at, t(0));
|
|
let mut bad = config;
|
|
bad.matching.risk.ledger.risk_session.starts_at = t(5);
|
|
assert!(matches!(
|
|
Replay::new(input, bad),
|
|
Err(ReplayError::InvalidInput(
|
|
"initial account clock follows true preceding venue open"
|
|
))
|
|
));
|
|
}
|
|
#[test]
|
|
fn terminal_observations_mark_only_and_later_rows_unavailable() {
|
|
let (mut input, config) = fixture();
|
|
input.series.push(series("feature", "X"));
|
|
input
|
|
.bars
|
|
.push(bar("feature", "X", 0, 30, 31, 0, "99", "999", "10"));
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
target(&mut r, &b, "2");
|
|
complete(&mut r);
|
|
assert_eq!(r.observations().count(), 3);
|
|
assert_eq!(
|
|
r.financial().ledger().mark(&id("X")).unwrap().price,
|
|
pos("15")
|
|
);
|
|
assert_eq!(r.checkpoint().submissions.len(), 2);
|
|
assert!(r.latest_observation(&id("feature")).is_none());
|
|
}
|
|
#[test]
|
|
fn equal_time_feature_series_sequence_ties_stable_and_missing_explicit() {
|
|
let (mut input, config) = fixture();
|
|
input.series.extend([
|
|
series("feature-z", "X"),
|
|
series("feature-a", "X"),
|
|
series("missing", "X"),
|
|
]);
|
|
input.bars.extend([
|
|
bar("feature-z", "X", 0, 10, 10, 7, "10", "99", "1"),
|
|
bar("feature-a", "X", 0, 10, 10, 7, "10", "88", "1"),
|
|
bar("missing", "X", 0, 20, 20, 7, "10", "88", "1"),
|
|
]);
|
|
let mut changed = input.clone();
|
|
changed.bars.reverse();
|
|
let mut results = vec![];
|
|
for data in [input, changed] {
|
|
let mut r = Replay::new(data, config.clone()).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
assert!(b
|
|
.inputs
|
|
.iter()
|
|
.any(|i| i.series_id == id("missing") && i.availability == InputAvailability::Missing));
|
|
results.push((
|
|
b,
|
|
r.observations()
|
|
.map(|b| b.series_id.clone())
|
|
.collect::<Vec<_>>(),
|
|
r.checkpoint(),
|
|
));
|
|
}
|
|
assert_eq!(results[0], results[1]);
|
|
assert_eq!(
|
|
results[0].1,
|
|
vec![id("X-bars"), id("feature-a"), id("feature-z")]
|
|
);
|
|
}
|
|
#[test]
|
|
fn restore_before_and_after_every_decision_and_at_complete() {
|
|
let (input, config) = fixture();
|
|
let mut r = Replay::new(input.clone(), config.clone()).unwrap();
|
|
loop {
|
|
let step = r.advance(1).unwrap();
|
|
let checkpoint = r.checkpoint();
|
|
r = Replay::restore(input.clone(), config.clone(), &checkpoint).unwrap();
|
|
assert_eq!(checkpoint, r.checkpoint());
|
|
match step {
|
|
ReplayStep::Decision(b) => {
|
|
target(&mut r, &b, "2");
|
|
let cp = r.checkpoint();
|
|
r = Replay::restore(input.clone(), config.clone(), &cp).unwrap();
|
|
}
|
|
ReplayStep::Complete => break,
|
|
ReplayStep::Progress { .. } => {}
|
|
other => panic!("{other:?}"),
|
|
}
|
|
}
|
|
let mut uninterrupted = Replay::new(input, config).unwrap();
|
|
while let Some(b) = next(&mut uninterrupted) {
|
|
target(&mut uninterrupted, &b, "2");
|
|
}
|
|
assert_eq!(r.checkpoint(), uninterrupted.checkpoint());
|
|
assert_eq!(r.reporting().unwrap(), uninterrupted.reporting().unwrap());
|
|
}
|
|
|
|
fn reporting_boundary(name: &str, at: i64) -> RiskSessionIdentity {
|
|
RiskSessionIdentity {
|
|
calendar_id: id("account"),
|
|
calendar_revision: id("1"),
|
|
session_id: id(name),
|
|
starts_at: t(at),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn two_session_marks_follow_observations_without_changing_earlier_risk_reset() {
|
|
let (mut input, mut config) = fixture();
|
|
input.bounds.trade_start = t(0);
|
|
config.risk_boundaries = vec![
|
|
reporting_boundary("risk2", 20),
|
|
reporting_boundary("risk3", 30),
|
|
];
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
assert!(r.reporting().is_err());
|
|
let b = next(&mut r).unwrap();
|
|
target(&mut r, &b, "2");
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(20));
|
|
// Existing reset runs before the completed observation's13 mark.
|
|
assert_eq!(
|
|
Posting::from(r.financial().risk().state().daily_baseline),
|
|
p("9999.76")
|
|
);
|
|
no_change(&mut r, &b);
|
|
complete(&mut r);
|
|
let facts = r.reporting().unwrap();
|
|
assert_eq!(facts.initial_equity, p("10000"));
|
|
assert_eq!(facts.sessions.len(), 2);
|
|
assert_eq!(facts.sessions[0].session.session_id, id("risk1"));
|
|
assert_eq!(facts.sessions[0].period_start, t(0));
|
|
assert_eq!(facts.sessions[0].period_end, t(20));
|
|
assert_eq!(facts.sessions[0].equity, p("10001.76"));
|
|
assert_eq!(facts.sessions[1].equity, p("10005.76"));
|
|
assert!(!facts
|
|
.sessions
|
|
.iter()
|
|
.any(|s| s.partial_start || s.partial_end));
|
|
assert_eq!(facts.occupied_ms, "20");
|
|
assert_eq!(facts.elapsed_ms, "30");
|
|
}
|
|
|
|
#[test]
|
|
fn reporting_clips_warmup_initial_and_final_periods_and_deduplicates_exact_end() {
|
|
for exact_start in [false, true] {
|
|
for exact_end in [false, true] {
|
|
let (input, mut config) = fixture();
|
|
config.risk_boundaries = vec![
|
|
reporting_boundary("warmup", 5),
|
|
reporting_boundary("risk2", 20),
|
|
];
|
|
if exact_start {
|
|
config.risk_boundaries.push(reporting_boundary("start", 10));
|
|
}
|
|
if exact_end {
|
|
config.risk_boundaries.push(reporting_boundary("end", 30));
|
|
}
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
complete(&mut r);
|
|
let facts = r.reporting().unwrap();
|
|
assert_eq!(facts.sessions.len(), 2);
|
|
assert_eq!(
|
|
facts.sessions[0].session.session_id,
|
|
id(if exact_start { "start" } else { "warmup" })
|
|
);
|
|
assert_eq!(facts.sessions[0].period_start, t(10));
|
|
assert_eq!(facts.sessions[0].partial_start, !exact_start);
|
|
assert!(!facts.sessions[0].partial_end);
|
|
assert_eq!(facts.sessions[1].partial_end, !exact_end);
|
|
assert_eq!(facts.sessions[1].period_end, t(30));
|
|
assert!(facts.sessions.iter().all(|s| s.equity == p("10000")));
|
|
assert_eq!(facts.occupied_ms, "0");
|
|
assert!(facts.occupied_intervals.is_empty());
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn reporting_boundary_without_decision_and_terminal_stale_mark_use_only_available_facts() {
|
|
let (mut input, mut config) = fixture();
|
|
config.risk_boundaries = vec![reporting_boundary("risk2", 15)];
|
|
input.bars[2].available_at = t(31); // Final close15 is not available by end30.
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
target(&mut r, &b, "2");
|
|
complete(&mut r);
|
|
let facts = r.reporting().unwrap();
|
|
assert_eq!(facts.sessions[0].period_end, t(15));
|
|
assert_eq!(facts.sessions[0].equity, p("9999.76"));
|
|
// Last available authoritative mark is the open14, not the future close15.
|
|
assert_eq!(facts.sessions[1].equity, p("10003.76"));
|
|
assert_eq!(
|
|
facts.sessions[1].equity,
|
|
r.financial().ledger().equity().unwrap()
|
|
);
|
|
assert_eq!(r.observations().count(), 2);
|
|
}
|
|
|
|
#[test]
|
|
fn reporting_restore_every_event_including_partial_observation_groups() {
|
|
let (mut input, mut config) = fixture();
|
|
input.series.push(series("Y-bars", "Y"));
|
|
input
|
|
.bars
|
|
.extend(input.bars.clone().into_iter().map(|mut bar| {
|
|
bar.series_id = id("Y-bars");
|
|
bar.instrument_id = id("Y");
|
|
bar
|
|
}));
|
|
config.matching.series.push(ExecutionSeries {
|
|
instrument_id: id("Y"),
|
|
series_id: id("Y-bars"),
|
|
mode: ExecutionMode::Open,
|
|
});
|
|
config.risk_boundaries = vec![
|
|
reporting_boundary("risk2", 20),
|
|
reporting_boundary("risk3", 30),
|
|
];
|
|
let mut uninterrupted = Replay::new(input.clone(), config.clone()).unwrap();
|
|
while let Some(b) = next(&mut uninterrupted) {
|
|
target(&mut uninterrupted, &b, "2");
|
|
}
|
|
let mut resumed = Replay::new(input.clone(), config.clone()).unwrap();
|
|
loop {
|
|
let step = resumed.advance(1).unwrap();
|
|
let cp = resumed.checkpoint();
|
|
resumed = Replay::restore(input.clone(), config.clone(), &cp).unwrap();
|
|
assert_eq!(resumed.checkpoint(), cp);
|
|
match step {
|
|
ReplayStep::Decision(b) => {
|
|
target(&mut resumed, &b, "2");
|
|
resumed =
|
|
Replay::restore(input.clone(), config.clone(), &resumed.checkpoint()).unwrap();
|
|
}
|
|
ReplayStep::Complete => break,
|
|
ReplayStep::Progress { .. } => {}
|
|
other => panic!("unexpected {other:?}"),
|
|
}
|
|
}
|
|
assert_eq!(uninterrupted.checkpoint(), resumed.checkpoint());
|
|
assert_eq!(
|
|
uninterrupted.reporting().unwrap(),
|
|
resumed.reporting().unwrap()
|
|
);
|
|
assert_eq!(resumed.reporting().unwrap().sessions.len(), 2);
|
|
}
|
|
#[test]
|
|
fn altered_input_config_and_checkpoint_rejected() {
|
|
let (input, config) = fixture();
|
|
let mut r = Replay::new(input.clone(), config.clone()).unwrap();
|
|
let _ = next(&mut r);
|
|
let cp = r.checkpoint();
|
|
let mut changed = input.clone();
|
|
changed.bars[2].volume = nn("101");
|
|
assert!(matches!(
|
|
Replay::restore(changed, config.clone(), &cp),
|
|
Err(ReplayError::InvalidCheckpoint)
|
|
));
|
|
let mut changed = config.clone();
|
|
changed.matching.latency_ms = 1.try_into().unwrap();
|
|
assert!(matches!(
|
|
Replay::restore(input.clone(), changed, &cp),
|
|
Err(ReplayError::InvalidCheckpoint)
|
|
));
|
|
let mut bad = cp.clone();
|
|
bad.pending.as_mut().unwrap().revision = 999.try_into().unwrap();
|
|
assert!(matches!(
|
|
Replay::restore(input.clone(), config.clone(), &bad),
|
|
Err(ReplayError::InvalidCheckpoint)
|
|
));
|
|
let mut bad = cp;
|
|
bad.observation_count += 1;
|
|
assert!(matches!(
|
|
Replay::restore(input, config, &bad),
|
|
Err(ReplayError::InvalidCheckpoint)
|
|
));
|
|
}
|
|
#[test]
|
|
fn bounded_advance_and_atomic_due_owner_validation() {
|
|
let (input, config) = fixture();
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
assert_eq!(r.advance(0), Err(ReplayError::InvalidBudget));
|
|
assert!(matches!(
|
|
r.advance(1).unwrap(),
|
|
ReplayStep::Progress { processed: 1 }
|
|
));
|
|
assert_eq!(r.observations().count(), 0);
|
|
let b = next(&mut r).unwrap();
|
|
let cp = r.checkpoint();
|
|
assert_eq!(r.advance(1000).unwrap(), ReplayStep::Decision(b.clone()));
|
|
assert!(matches!(
|
|
r.submit(DecisionSubmission {
|
|
barrier_id: b.barrier_id.clone(),
|
|
decisions: vec![]
|
|
}),
|
|
Err(ReplayError::InvalidSubmission)
|
|
));
|
|
assert_eq!(cp, r.checkpoint());
|
|
target(&mut r, &b, "2");
|
|
assert!(matches!(
|
|
r.submit(DecisionSubmission {
|
|
barrier_id: b.barrier_id,
|
|
decisions: vec![]
|
|
}),
|
|
Err(ReplayError::InvalidSubmission)
|
|
));
|
|
}
|
|
#[test]
|
|
fn explicit_input_contract_rejections() {
|
|
let (input, config) = fixture();
|
|
let mut bad = input.clone();
|
|
bad.bars.clear();
|
|
assert!(Replay::new(bad, config.clone()).is_err());
|
|
let mut bad = input.clone();
|
|
bad.eligibility = DatasetEligibility::Ineligible;
|
|
assert!(Replay::new(bad, config.clone()).is_err());
|
|
let mut bad = input.clone();
|
|
bad.eligibility = DatasetEligibility::Exploratory;
|
|
assert!(Replay::new(bad.clone(), config.clone()).is_err());
|
|
let mut allowed = config.clone();
|
|
allowed.allow_exploratory = true;
|
|
assert!(Replay::new(bad, allowed).is_ok());
|
|
let mut bad = input.clone();
|
|
bad.series[0].adjustment = PriceAdjustment::ProviderAdjusted;
|
|
assert!(Replay::new(bad, config.clone()).is_err());
|
|
let mut bad = config.clone();
|
|
bad.matching.series[0].mode = ExecutionMode::Quote;
|
|
assert!(Replay::new(input.clone(), bad).is_err());
|
|
let mut bad = input.clone();
|
|
bad.series[0].sessions = vec![venue("a", 0, 10), venue("b", 10, 30)];
|
|
assert!(matches!(
|
|
Replay::new(bad, config.clone()),
|
|
Err(ReplayError::InvalidInput(
|
|
"overlapping or abutting retained sessions are unsupported"
|
|
))
|
|
));
|
|
let mut bad = input.clone();
|
|
bad.bars[1].source_sequence = bad.bars[0].source_sequence;
|
|
assert!(Replay::new(bad, config.clone()).is_err());
|
|
let mut bad = input.clone();
|
|
bad.bars[1].available_at = t(19);
|
|
assert!(Replay::new(bad, config.clone()).is_err());
|
|
let mut bad = config.clone();
|
|
bad.participation_rate = nn("1.1");
|
|
assert!(Replay::new(input, bad).is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn financial_failure_is_terminal_with_reproducible_diagnostic_prefix() {
|
|
let (mut input, config) = fixture();
|
|
let maximum = super::scalar::MAX_POSTING;
|
|
input.bars[0].high = pos(maximum);
|
|
input.bars[0].close = pos(maximum);
|
|
let mut r = Replay::new(input.clone(), config.clone()).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
let outcome = target(&mut r, &b, "2");
|
|
assert!(matches!(outcome.status, AttemptStatus::Failed { .. }));
|
|
assert!(matches!(r.advance(100).unwrap(), ReplayStep::Failed { .. }));
|
|
let checkpoint = r.checkpoint();
|
|
let restored = Replay::restore(input, config, &checkpoint).unwrap();
|
|
assert_eq!(restored.checkpoint(), checkpoint);
|
|
assert!(matches!(
|
|
r.submit(DecisionSubmission {
|
|
barrier_id: b.barrier_id,
|
|
decisions: vec![]
|
|
}),
|
|
Err(ReplayError::Terminal)
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn irrelevant_old_sessions_do_not_backdate_initialization() {
|
|
let (mut input, config) = fixture();
|
|
input.series[0].sessions.insert(0, venue("old", -20, -10));
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
complete(&mut r);
|
|
let MatchingInput::Engine(first) = &r.financial().receipts()[0].input else {
|
|
panic!()
|
|
};
|
|
assert_eq!(first.key.at, t(0));
|
|
}
|
|
|
|
#[test]
|
|
fn automatic_execution_failure_preserves_committed_prefix_and_restores() {
|
|
let (mut input, mut config) = fixture();
|
|
config.matching.slippage_rate = nn("0.9");
|
|
input.bars[1].open = pos(super::scalar::MAX_POSTING);
|
|
input.bars[1].high = pos(super::scalar::MAX_POSTING);
|
|
let mut r = Replay::new(input.clone(), config.clone()).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
target(&mut r, &b, "2");
|
|
assert!(matches!(r.advance(100).unwrap(), ReplayStep::Failed { .. }));
|
|
let receipt = r.financial().receipts().last().unwrap();
|
|
assert!(matches!(
|
|
receipt.outcome.status,
|
|
AttemptStatus::Failed { .. }
|
|
));
|
|
assert!(!receipt.outcome.effects.is_empty());
|
|
assert!(fill_prices(&r).is_empty());
|
|
let checkpoint = r.checkpoint();
|
|
let mut restored = Replay::restore(input, config, &checkpoint).unwrap();
|
|
assert_eq!(restored.checkpoint(), checkpoint);
|
|
assert!(matches!(
|
|
restored.advance(100).unwrap(),
|
|
ReplayStep::Failed { .. }
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn same_time_risk_boundary_venue_opens_and_marks_have_monotone_keys() {
|
|
let (mut input, mut config) = fixture();
|
|
input.series.push(ReplaySeries {
|
|
sessions: vec![venue("Y-day", 10, 30)],
|
|
..series("Y-bars", "Y")
|
|
});
|
|
input
|
|
.bars
|
|
.push(bar("Y-bars", "Y", 10, 20, 20, 7, "20", "21", "100"));
|
|
config.matching.series.push(ExecutionSeries {
|
|
instrument_id: id("Y"),
|
|
series_id: id("Y-bars"),
|
|
mode: ExecutionMode::Open,
|
|
});
|
|
config.risk_boundaries.push(RiskSessionIdentity {
|
|
calendar_id: id("account"),
|
|
calendar_revision: id("1"),
|
|
session_id: id("risk2"),
|
|
starts_at: t(10),
|
|
});
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(10));
|
|
assert_eq!(
|
|
r.financial().risk().state().risk_session.session_id,
|
|
id("risk2")
|
|
);
|
|
let at10 = r
|
|
.financial()
|
|
.receipts()
|
|
.iter()
|
|
.filter_map(|r| match &r.input {
|
|
MatchingInput::Engine(c) if c.key.at == t(10) => Some(c),
|
|
_ => None,
|
|
})
|
|
.collect::<Vec<_>>();
|
|
assert!(at10.windows(2).all(|w| w[0].key < w[1].key));
|
|
assert!(at10.iter().any(
|
|
|c| matches!(c.body, MatchingCommandBody::OpenSession { .. })
|
|
&& c.key.instrument_id == id("Y")
|
|
));
|
|
no_change(&mut r, &b);
|
|
complete(&mut r);
|
|
}
|
|
|
|
#[test]
|
|
fn sequential_equal_time_marks_can_latch_risk_before_synchronized_barrier() {
|
|
let (mut input, mut config) = fixture();
|
|
for b in &mut input.bars {
|
|
b.open = pos("100");
|
|
b.high = pos("100");
|
|
b.low = pos("100");
|
|
b.close = pos("100");
|
|
}
|
|
input.series.push(series("Y-bars", "Y"));
|
|
input
|
|
.bars
|
|
.extend(input.bars.clone().into_iter().map(|mut b| {
|
|
b.series_id = id("Y-bars");
|
|
b.instrument_id = id("Y");
|
|
b
|
|
}));
|
|
input.bars[1].close = pos("50");
|
|
input.bars[1].low = pos("50");
|
|
input.bars[4].close = pos("150");
|
|
input.bars[4].high = pos("150");
|
|
config.matching.series.push(ExecutionSeries {
|
|
instrument_id: id("Y"),
|
|
series_id: id("Y-bars"),
|
|
mode: ExecutionMode::Open,
|
|
});
|
|
config.matching.risk.fee_rate = nn("0");
|
|
config.matching.risk.max_daily_loss = pos("10");
|
|
config.matching.risk.max_drawdown_amount = pos("10");
|
|
// A reporting sample uses the final observation-group equity without
|
|
// changing the existing sequential risk latch.
|
|
config.risk_boundaries.push(reporting_boundary("risk2", 20));
|
|
let mut permuted = input.clone();
|
|
permuted.bars.reverse();
|
|
let mut checkpoints = vec![];
|
|
for data in [input, permuted] {
|
|
let mut r = Replay::new(data, config.clone()).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
r.submit(DecisionSubmission {
|
|
barrier_id: b.barrier_id.clone(),
|
|
decisions: vec![StrategyDecision {
|
|
version: Version,
|
|
session_id: id("run"),
|
|
barrier_id: b.barrier_id,
|
|
revision: b.revision,
|
|
decision: DecisionIdentity {
|
|
owner_id: id("A"),
|
|
decision_id: id("pair"),
|
|
sequence: 1.try_into().unwrap(),
|
|
},
|
|
intent: StrategyIntent::Target {
|
|
targets: vec![
|
|
Target {
|
|
instrument_id: id("X"),
|
|
quantity: nn("1"),
|
|
},
|
|
Target {
|
|
instrument_id: id("Y"),
|
|
quantity: nn("1"),
|
|
},
|
|
],
|
|
},
|
|
}],
|
|
})
|
|
.unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(20));
|
|
assert_eq!(r.financial().ledger().equity().unwrap(), p("10000"));
|
|
assert!(r.financial().risk().state().daily_halted);
|
|
assert!(r.financial().risk().state().drawdown_halted);
|
|
checkpoints.push(r.checkpoint());
|
|
no_change(&mut r, &b);
|
|
complete(&mut r);
|
|
assert_eq!(r.reporting().unwrap().sessions[0].equity, p("10000"));
|
|
assert!(r.financial().risk().state().daily_halted);
|
|
assert!(r.financial().risk().state().drawdown_halted);
|
|
}
|
|
assert_eq!(checkpoints[0], checkpoints[1]);
|
|
assert!(MODEL_LIMITATIONS
|
|
.iter()
|
|
.any(|s| s.contains("intermediate equity")));
|
|
}
|
|
#[test]
|
|
fn no_known_volume_and_zero_capacity_cannot_fill() {
|
|
let (mut input, config) = fixture();
|
|
input.bars[0].volume = nn("0");
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
target(&mut r, &b, "2");
|
|
let b = next(&mut r).unwrap();
|
|
assert!(fill_prices(&r).is_empty());
|
|
no_change(&mut r, &b);
|
|
complete(&mut r);
|
|
assert_eq!(fill_prices(&r), vec![p("14")]);
|
|
}
|
|
|
|
#[test]
|
|
fn unknown_completed_volume_does_not_fill_a_live_order() {
|
|
let (mut input, mut config) = fixture();
|
|
input.bounds.trade_start = t(0);
|
|
input.bars[0].available_at = t(25);
|
|
input.bars[1].available_at = t(25);
|
|
input.series.push(series("feature", "X"));
|
|
input
|
|
.bars
|
|
.push(bar("feature", "X", 0, 11, 11, 0, "10", "10", "9999"));
|
|
config.cadence[0].series_ids = vec![id("feature")];
|
|
let mut r = Replay::new(input, config).unwrap();
|
|
let b = next(&mut r).unwrap();
|
|
assert_eq!(b.at, t(11));
|
|
assert!(r.latest_observation(&id("X-bars")).is_none());
|
|
target(&mut r, &b, "2");
|
|
assert!(r
|
|
.financial()
|
|
.orders()
|
|
.any(|o| o.status == OrderStatus::Open));
|
|
complete(&mut r);
|
|
assert!(fill_prices(&r).is_empty());
|
|
assert_eq!(r.financial().ledger().cash(), p("10000"));
|
|
assert!(r
|
|
.financial()
|
|
.orders()
|
|
.all(|o| o.status == OrderStatus::Cancelled));
|
|
}
|
|
|
|
#[test]
|
|
#[ignore = "manual release component measurement; no timing CI assertion"]
|
|
fn replay_scaling_measurement() {
|
|
for instruments in [1, 2] {
|
|
for count in [1000, 10000, 100000] {
|
|
let (mut input, mut config) = fixture();
|
|
let per_instrument = count / instruments;
|
|
if instruments == 2 {
|
|
input.series.push(series("Y-bars", "Y"));
|
|
config.matching.series.push(ExecutionSeries {
|
|
instrument_id: id("Y"),
|
|
series_id: id("Y-bars"),
|
|
mode: ExecutionMode::Open,
|
|
});
|
|
}
|
|
input.bounds.trade_start = t(10);
|
|
input.bounds.trade_end = t((per_instrument * 10) as i64);
|
|
input.bars = (0..count)
|
|
.map(|i| {
|
|
let (series, symbol) = if i < per_instrument {
|
|
("X-bars", "X")
|
|
} else {
|
|
("Y-bars", "Y")
|
|
};
|
|
let index = i % per_instrument;
|
|
bar(
|
|
series,
|
|
symbol,
|
|
(index * 10) as i64,
|
|
((index + 1) * 10) as i64,
|
|
((index + 1) * 10) as i64,
|
|
index as u64,
|
|
"10",
|
|
"10",
|
|
"100",
|
|
)
|
|
})
|
|
.collect();
|
|
// One barrier/buy, then mark-only traversal measures the cursor rather
|
|
// than pretending 100k orders have no F05 journal/memory cost.
|
|
input.series.push(series("cadence", "X"));
|
|
input
|
|
.bars
|
|
.push(bar("cadence", "X", 0, 10, 10, 0, "10", "10", "100"));
|
|
config.cadence[0].series_ids = vec![id("cadence")];
|
|
let mut expected = None;
|
|
for repeat in 0..3 {
|
|
let data = input.clone();
|
|
let cfg = config.clone();
|
|
let started = Instant::now();
|
|
let mut r = Replay::new(data, cfg).unwrap();
|
|
let load = started.elapsed();
|
|
let started = Instant::now();
|
|
while let Some(b) = next(&mut r) {
|
|
target(&mut r, &b, "1");
|
|
}
|
|
let traverse = started.elapsed();
|
|
assert_eq!(fill_prices(&r), vec![p("10")]);
|
|
assert_eq!(r.financial().ledger().cash(), p("9989.9"));
|
|
assert_eq!(r.financial().ledger().equity().unwrap(), p("9999.9"));
|
|
let started = Instant::now();
|
|
let checkpoint = r.checkpoint();
|
|
let checkpoint_time = started.elapsed();
|
|
let bytes = serde_json::to_vec(&checkpoint).unwrap();
|
|
if let Some(expected) = &expected {
|
|
assert_eq!(&bytes, expected);
|
|
} else {
|
|
expected = Some(bytes.clone());
|
|
}
|
|
drop(r);
|
|
let data = input.clone();
|
|
let cfg = config.clone();
|
|
let started = Instant::now();
|
|
let restored = Replay::restore(data, cfg, &checkpoint).unwrap();
|
|
let restore = started.elapsed();
|
|
assert_eq!(restored.checkpoint(), checkpoint);
|
|
println!("replay instruments={instruments} execution_bars={count} total_bars={} repeat={repeat} load_us={} replay_us={} checkpoint_us={} restore_us={} checkpoint_bytes={} fills=1",count+1,load.as_micros(),traverse.as_micros(),checkpoint_time.as_micros(),restore.as_micros(),bytes.len());
|
|
}
|
|
}
|
|
}
|
|
}
|