// TS15_VisibilityTopology: Dual visibility graph topology.
// Standalone model implementation with embedded safety and engine code.
// Market scope: EUR/USD completed-hour return aggregation horizons.
// These are not actual bond maturities or a futures calendar spread.
// Model diagnostic: boundary-versus-bulk visibility asymmetry.
// Quality heuristic: Absolute connectivity contrast across nested windows.
// Limitation: Strict line-of-sight rules are sensitive near ties. A scale-relative tolerance suppresses roundoff edges.
// No claim of profitability, calibration, or independent strategy returns.
// Inputs: 256 newest-first log returns; all must be finite and within [-1,1].
// Output: bounded signed edge; positive buys, negative sells, zero abstains.
// Quality is a heuristic filter, never a calibrated success probability.
// The synthetic suite below is included in the total file line count.
// Regenerate with build_sources.py; compare hashes before deployment.
#include <default.c>
string TS2Algo = "TS15";
string TS2TestLog = "Log/TS15_VisibilityTopology_test.txt";
int TS2Holding = 10;
// R1/R3: IEEE-754 finite validation without lite-C unordered comparisons.
// Supported Zorro Windows targets use 64-bit var and little-endian 32-bit int.
int TSIsFinite(var Value)
{
int Words[2];
memcpy(Words, &Value, sizeof(Value));
return (Words[1] & 0x7ff00000) != 0x7ff00000;
}
// Forex commission per lot; negative quotes are percent, not cash rebates.
// Return -1 on invalid metadata rather than accepting an unknown risk amount.
var TSFeePerLot(var FeeQuote, var UnitsPerLot, var PipSize, var PipValue, var RefPrice)
{
var FeeValue;
if (!TSIsFinite(FeeQuote) || !TSIsFinite(UnitsPerLot) || !TSIsFinite(PipSize) ||
!TSIsFinite(PipValue) || !TSIsFinite(RefPrice))
return -1.;
if (!(UnitsPerLot > 0.) || !(PipSize > 0.) || !(PipValue > 0.) || !(RefPrice > 0.))
return -1.;
if (FeeQuote >= 0.)
FeeValue = FeeQuote * UnitsPerLot / 10000.;
else
FeeValue = (-FeeQuote / 100.) * (PipValue / PipSize) * RefPrice;
if (!TSIsFinite(FeeValue) || FeeValue < 0.)
return -1.;
return FeeValue;
}
var TSUnitStopRisk(var RefPrice)
{
var FeeValue, FeePrice, StopRisk;
if (!TSIsFinite(RefPrice) || !(RefPrice > 0.) || !TSIsFinite(Stop) || !(Stop > 0.) ||
!TSIsFinite(Spread) || !TSIsFinite(Balance) || !TSIsFinite(Equity) ||
!TSIsFinite(MarginCost) || !TSIsFinite(MarginVal))
return -1.;
if (!(Balance > 0.) || !(Equity > 0.) || !(MarginCost > 0.))
return -1.;
// Conservative percentage-fee price through the stop, absent gaps/slippage.
FeePrice = RefPrice + abs(Spread) + Stop;
FeeValue = TSFeePerLot(Commission, LotAmount, PIP, PIPCost, FeePrice);
if (FeeValue < 0.)
return -1.;
StopRisk = (Stop + abs(Spread)) / PIP * PIPCost + FeeValue;
if (!TSIsFinite(StopRisk) || !(StopRisk > 0.))
return -1.;
return StopRisk;
}
// Embedded input, state, and test contracts; identical safety is not novel alpha.
#define TS2_N 256
var TS2Returns[256];
var TS2Quality;
var TS2Statistic;
var TS2Raw;
int TS2Checks;
int TS2Failures;
var TS2Model();
var TS2Bound(var Value)
{
if (!TSIsFinite(Value))
return 0.;
return max(-1., min(1., Value));
}
var TS2Evaluate()
{
int Index;
var Energy;
TS2Quality = 0.;
TS2Statistic = 0.;
TS2Raw = 0.;
Energy = 0.;
for (Index = 0; Index < TS2_N; Index++)
{
if (!TSIsFinite(TS2Returns[Index]))
return 0.;
if (abs(TS2Returns[Index]) > 1.)
return 0.;
Energy += TS2Returns[Index] * TS2Returns[Index];
}
if (Energy < 1.e-24)
return 0.;
TS2Raw = TS2Model();
if (!TSIsFinite(TS2Raw) || abs(TS2Raw) > 1.e12 ||
!TSIsFinite(TS2Quality) || !TSIsFinite(TS2Statistic))
{
TS2Quality = 0.;
TS2Statistic = 0.;
TS2Raw = 0.;
return 0.;
}
TS2Quality = max(0., min(1., TS2Quality));
return TS2Bound(TS2Raw);
}
void TS2Expect(int Passed, string Label)
{
TS2Checks++;
if (!Passed)
{
TS2Failures++;
file_append(TS2TestLog, strf("FAIL: %s\n", Label));
}
}
// BEGIN ANALYTICAL MODEL
// Upper and lower natural-visibility graphs are rebuilt on nested time windows.
// The asymmetry of boundary connectivity measures price-path exposure.
var TS2Model()
{
var Path[96], UpperDegree[96], LowerDegree[96];
var Total, Positive, Negative, Chord, Height, Tolerance;
var RecentUpper, RecentLower, HistoricalUpper, HistoricalLower;
var Boundary, Bulk, Score, WeightSum, Agreement, Drift, RMS;
int Lengths[3] = {24, 48, 96};
int Window, Size, Left, Right, Between, VisibleUp, VisibleDown, Index;
Path[0] = 0.;
for (Index = 1; Index < 96; Index++)
Path[Index] = Path[Index - 1] + TS2Returns[95 - Index];
RMS = 0.;
for (Index = 0; Index < 96; Index++)
RMS += TS2Returns[Index] * TS2Returns[Index] / 96.;
Tolerance = sqrt(RMS) * 1.e-9;
Score = 0.; WeightSum = 0.; Agreement = 0.;
for (Window = 0; Window < 3; Window++)
{
Size = Lengths[Window];
for (Index = 0; Index < Size; Index++)
{
UpperDegree[Index] = 0.;
LowerDegree[Index] = 0.;
}
for (Left = 96 - Size; Left < 95; Left++)
{
for (Right = Left + 1; Right < 96; Right++)
{
VisibleUp = 1;
VisibleDown = 1;
for (Between = Left + 1; Between < Right; Between++)
{
Chord = Path[Left] + (Path[Right] - Path[Left]) * (Between - Left) / (Right - Left);
Height = Path[Between] - Chord;
if (Height >= -Tolerance)
VisibleUp = 0;
if (Height <= Tolerance)
VisibleDown = 0;
if (!VisibleUp && !VisibleDown)
break;
}
if (VisibleUp)
{
UpperDegree[Left - 96 + Size]++;
UpperDegree[Right - 96 + Size]++;
}
if (VisibleDown)
{
LowerDegree[Left - 96 + Size]++;
LowerDegree[Right - 96 + Size]++;
}
}
}
RecentUpper = 0.; RecentLower = 0.;
HistoricalUpper = 0.; HistoricalLower = 0.;
for (Index = 0; Index < Size; Index++)
{
if (Index >= Size - 4)
{
RecentUpper += UpperDegree[Index] / 4.;
RecentLower += LowerDegree[Index] / 4.;
}
else
{
HistoricalUpper += UpperDegree[Index] / (Size - 4.);
HistoricalLower += LowerDegree[Index] / (Size - 4.);
}
}
Boundary = (RecentUpper - RecentLower) / max(1., RecentUpper + RecentLower);
Bulk = (HistoricalUpper - HistoricalLower) / max(1., HistoricalUpper + HistoricalLower);
Total = Boundary - Bulk;
Score += Total / (Window + 1.);
WeightSum += 1. / (Window + 1.);
Agreement += abs(Total) / 3.;
}
Drift = 0.;
for (Index = 0; Index < 12; Index++)
Drift += TS2Returns[Index] / 12.;
Score /= WeightSum;
TS2Statistic = Score;
TS2Quality = min(1., Agreement * 2.);
// Boundary exposure is used only when the recent signed path confirms it.
if (Drift * Score <= 0.)
return 0.;
return TS2Bound(Score * 2.);
}
// END ANALYTICAL MODEL
// Separate repair regression log; the original suite counts stay intact.
int TSRepairChecks = 0;
int TSRepairFailures = 0;
string TSRepairLog = "Log/TS15_VisibilityTopology_repair.txt";
void TSRepairCheck(int Passed, string Label)
{
TSRepairChecks++;
if (!Passed)
{
TSRepairFailures++;
file_append(TSRepairLog, strf("FAIL: %s\n", Label));
}
}
var TSRepairBad(int Kind)
{
int Bits[2];
var Value;
Bits[0] = 0;
Bits[1] = 0x7ff80000;
if (Kind == 1) Bits[1] = 0x7ff00000;
if (Kind == 2) Bits[1] = 0xfff00000;
memcpy(&Value, Bits, sizeof(Value));
return Value;
}
void TSRepairTests()
{
int I, Kind, Position;
var FeeValue, UnitLoss, Budget;
TSRepairChecks = 0; TSRepairFailures = 0;
file_write(TSRepairLog, "Repairs R1-R5: native-safe regression suite\n", 0);
TSRepairCheck(sizeof(FeeValue) == 8, "64-bit var representation");
TSRepairCheck(TSIsFinite(0.), "finite zero");
TSRepairCheck(TSIsFinite(1.), "finite positive");
TSRepairCheck(TSIsFinite(-1.), "finite negative");
for (Kind = 0; Kind < 3; Kind++)
TSRepairCheck(!TSIsFinite(TSRepairBad(Kind)), "reject NaN and both infinities");
TSRepairCheck(abs(TSFeePerLot(0.7, 1000., 0.0001, 0.1, 1.1) - 0.07) < 1.e-6,
"cash commission convention");
TSRepairCheck(TSFeePerLot(0., 1000., 0.0001, 0.1, 1.1) == 0., "zero commission");
FeeValue = TSFeePerLot(-0.02, 1000., 0.0001, 0.1, 1.1);
TSRepairCheck(abs(FeeValue - 0.22) < 1.e-6, "percentage commission convention");
TSRepairCheck(TSFeePerLot(0.7, 1000., 0., 0.1, 1.1) < 0., "invalid pip size");
TSRepairCheck(TSFeePerLot(0.7, 1000., 0.0001, 0., 1.1) < 0., "invalid pip value");
TSRepairCheck(TSFeePerLot(0.7, 0., 0.0001, 0.1, 1.1) < 0., "invalid lot amount");
TSRepairCheck(TSFeePerLot(0.7, 1000., 0.0001, 0.1, -1.) < 0., "invalid fee price");
TSRepairCheck(TSFeePerLot(TSRepairBad(0), 1000., 0.0001, 0.1, 1.1) < 0., "NaN fee quote");
TSRepairCheck(TSFeePerLot(-0.02, 1000., 0.0001, 0.1, TSRepairBad(1)) < 0., "infinite fee price");
TSRepairCheck(TSFeePerLot(-0.02, 1000., TSRepairBad(0), 0.1, 1.1) < 0., "NaN pip metadata");
UnitLoss = (20. * 0.0001 + 0.0001) / 0.0001 * 0.1 + FeeValue;
Budget = 850. * 0.0025;
TSRepairCheck(floor(Budget / UnitLoss) == 0., "percentage fee respects lot-rounding budget");
for (Kind = 0; Kind < 3; Kind++)
{
for (Position = 0; Position < 2; Position++)
{
for (I = 0; I < 256; I++) TS2Returns[I] = 0.0005 + 0.0001 * sin(0.3 * I);
TS2Returns[Position] = TSRepairBad(Kind);
TSRepairCheck(TS2Evaluate() == 0, "non-finite consumed input rejected");
TSRepairCheck(TS2Quality == 0., "invalid return clears quality");
}
}
file_append(TSRepairLog, strf("RESULT: %d checks; %d failures\n", TSRepairChecks, TSRepairFailures));
}
// Synthetic property tests: executed only with -d TS2_SELFTEST.
// Tests do not execute trades, query market data, or establish profitability.
// Known-response anchor: not just a generic bounded-output assertion.
void TS2KnownResponse()
{
int I;
var Edge, Negative;
for (I = 0; I < 256; I++)
TS2Returns[I] = 0.0005;
Edge = TS2Evaluate();
TS2Expect(Edge == 0., "known straight path: model-specific response");
for (I = 0; I < 256; I++)
TS2Returns[I] = -0.0005;
Negative = TS2Evaluate();
TS2Expect(abs(Edge + Negative) < 1.e-7, "known straight path: symmetric response");
}
// Case 1: slow_sine; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case1()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = 0.0008 * sin(0.07 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "slow_sine: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "slow_sine: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "slow_sine: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "slow_sine: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "slow_sine: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "slow_sine: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[15] = 2.;
TS2Expect(TS2Evaluate() == 0., "slow_sine: implausible return rejected");
TS2Expect(TS2Quality == 0., "slow_sine: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "slow_sine: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "slow_sine: quality restored");
}
// Case 2: fast_sine; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case2()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = 0.0012 * sin(1.1 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "fast_sine: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "fast_sine: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "fast_sine: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "fast_sine: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "fast_sine: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "fast_sine: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[52] = 2.;
TS2Expect(TS2Evaluate() == 0., "fast_sine: implausible return rejected");
TS2Expect(TS2Quality == 0., "fast_sine: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "fast_sine: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "fast_sine: quality restored");
}
// Case 3: two_scale_beating; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case3()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = 0.0009 * sin(0.18 * I) + 0.0007 * sin(0.21 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "two_scale_beating: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "two_scale_beating: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "two_scale_beating: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "two_scale_beating: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "two_scale_beating: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "two_scale_beating: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[89] = 2.;
TS2Expect(TS2Evaluate() == 0., "two_scale_beating: implausible return rejected");
TS2Expect(TS2Quality == 0., "two_scale_beating: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "two_scale_beating: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "two_scale_beating: quality restored");
}
// Case 4: amplitude_burst; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case4()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = 0.0004 * sin(0.31 * I) * (1. + 3. * exp(-pow((I - 28.) / 8., 2.)));
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "amplitude_burst: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "amplitude_burst: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "amplitude_burst: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "amplitude_burst: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "amplitude_burst: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "amplitude_burst: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[126] = 2.;
TS2Expect(TS2Evaluate() == 0., "amplitude_burst: implausible return rejected");
TS2Expect(TS2Quality == 0., "amplitude_burst: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "amplitude_burst: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "amplitude_burst: quality restored");
}
// Case 5: chirp_acceleration; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case5()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = 0.001 * sin(0.0018 * I * I + 0.05 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "chirp_acceleration: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "chirp_acceleration: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "chirp_acceleration: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "chirp_acceleration: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "chirp_acceleration: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "chirp_acceleration: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[163] = 2.;
TS2Expect(TS2Evaluate() == 0., "chirp_acceleration: implausible return rejected");
TS2Expect(TS2Quality == 0., "chirp_acceleration: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "chirp_acceleration: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "chirp_acceleration: quality restored");
}
// Case 6: chirp_deceleration; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case6()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = 0.001 * sin(7. * sqrt(I + 1.));
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "chirp_deceleration: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "chirp_deceleration: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "chirp_deceleration: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "chirp_deceleration: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "chirp_deceleration: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "chirp_deceleration: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[200] = 2.;
TS2Expect(TS2Evaluate() == 0., "chirp_deceleration: implausible return rejected");
TS2Expect(TS2Quality == 0., "chirp_deceleration: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "chirp_deceleration: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "chirp_deceleration: quality restored");
}
// Case 7: positive_drift_noise; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case7()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = 0.0003 + 0.0009 * sin(0.77 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "positive_drift_noise: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "positive_drift_noise: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "positive_drift_noise: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "positive_drift_noise: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "positive_drift_noise: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "positive_drift_noise: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[237] = 2.;
TS2Expect(TS2Evaluate() == 0., "positive_drift_noise: implausible return rejected");
TS2Expect(TS2Quality == 0., "positive_drift_noise: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "positive_drift_noise: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "positive_drift_noise: quality restored");
}
// Case 8: negative_drift_noise; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case8()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = -0.0003 + 0.0009 * sin(0.77 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "negative_drift_noise: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "negative_drift_noise: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "negative_drift_noise: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "negative_drift_noise: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "negative_drift_noise: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "negative_drift_noise: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[18] = 2.;
TS2Expect(TS2Evaluate() == 0., "negative_drift_noise: implausible return rejected");
TS2Expect(TS2Quality == 0., "negative_drift_noise: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "negative_drift_noise: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "negative_drift_noise: quality restored");
}
// Case 9: mixed_frequency_drift; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case9()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = 0.0002 + 0.0006 * sin(0.23 * I) + 0.0004 * cos(1.37 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "mixed_frequency_drift: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "mixed_frequency_drift: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "mixed_frequency_drift: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "mixed_frequency_drift: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "mixed_frequency_drift: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "mixed_frequency_drift: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[55] = 2.;
TS2Expect(TS2Evaluate() == 0., "mixed_frequency_drift: implausible return rejected");
TS2Expect(TS2Quality == 0., "mixed_frequency_drift: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "mixed_frequency_drift: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "mixed_frequency_drift: quality restored");
}
// Case 10: alternating_sign; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case10()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = ifelse(I % 2 == 0, 0.001, -0.001);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "alternating_sign: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "alternating_sign: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "alternating_sign: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "alternating_sign: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "alternating_sign: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "alternating_sign: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[92] = 2.;
TS2Expect(TS2Evaluate() == 0., "alternating_sign: implausible return rejected");
TS2Expect(TS2Quality == 0., "alternating_sign: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "alternating_sign: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "alternating_sign: quality restored");
}
// Case 11: three_bar_blocks; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case11()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = ifelse(I % 6 < 3, 0.001, -0.001);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "three_bar_blocks: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "three_bar_blocks: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "three_bar_blocks: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "three_bar_blocks: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "three_bar_blocks: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "three_bar_blocks: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[129] = 2.;
TS2Expect(TS2Evaluate() == 0., "three_bar_blocks: implausible return rejected");
TS2Expect(TS2Quality == 0., "three_bar_blocks: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "three_bar_blocks: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "three_bar_blocks: quality restored");
}
// Case 12: five_bar_blocks; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case12()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = ifelse(I % 10 < 5, 0.001, -0.001);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "five_bar_blocks: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "five_bar_blocks: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "five_bar_blocks: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "five_bar_blocks: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "five_bar_blocks: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "five_bar_blocks: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[166] = 2.;
TS2Expect(TS2Evaluate() == 0., "five_bar_blocks: implausible return rejected");
TS2Expect(TS2Quality == 0., "five_bar_blocks: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "five_bar_blocks: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "five_bar_blocks: quality restored");
}
// Case 13: one_sided_steps; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case13()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = ifelse(I < 24, 0.001, 0.0001) + 0.0001 * sin(I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "one_sided_steps: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "one_sided_steps: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "one_sided_steps: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "one_sided_steps: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "one_sided_steps: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "one_sided_steps: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[203] = 2.;
TS2Expect(TS2Evaluate() == 0., "one_sided_steps: implausible return rejected");
TS2Expect(TS2Quality == 0., "one_sided_steps: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "one_sided_steps: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "one_sided_steps: quality restored");
}
// Case 14: late_reversal; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case14()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = ifelse(I < 12, -0.0008, 0.0005) + 0.0002 * cos(0.7 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "late_reversal: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "late_reversal: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "late_reversal: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "late_reversal: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "late_reversal: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "late_reversal: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[240] = 2.;
TS2Expect(TS2Evaluate() == 0., "late_reversal: implausible return rejected");
TS2Expect(TS2Quality == 0., "late_reversal: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "late_reversal: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "late_reversal: quality restored");
}
// Case 15: middle_reversal; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case15()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = ifelse(I < 64, 0.0006, -0.0004) + 0.0002 * sin(0.43 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "middle_reversal: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "middle_reversal: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "middle_reversal: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "middle_reversal: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "middle_reversal: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "middle_reversal: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[21] = 2.;
TS2Expect(TS2Evaluate() == 0., "middle_reversal: implausible return rejected");
TS2Expect(TS2Quality == 0., "middle_reversal: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "middle_reversal: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "middle_reversal: quality restored");
}
// Case 16: old_reversal; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case16()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = ifelse(I < 160, 0.0004, -0.0007) + 0.0001 * cos(0.91 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "old_reversal: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "old_reversal: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "old_reversal: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "old_reversal: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "old_reversal: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "old_reversal: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[58] = 2.;
TS2Expect(TS2Evaluate() == 0., "old_reversal: implausible return rejected");
TS2Expect(TS2Quality == 0., "old_reversal: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "old_reversal: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "old_reversal: quality restored");
}
// Case 17: volatility_expansion; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case17()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = (0.0002 + 0.001 * exp(-0.015 * I)) * sin(0.81 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "volatility_expansion: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "volatility_expansion: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "volatility_expansion: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "volatility_expansion: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "volatility_expansion: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "volatility_expansion: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[95] = 2.;
TS2Expect(TS2Evaluate() == 0., "volatility_expansion: implausible return rejected");
TS2Expect(TS2Quality == 0., "volatility_expansion: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "volatility_expansion: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "volatility_expansion: quality restored");
}
// Case 18: volatility_contraction; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case18()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = (0.0002 + 0.000004 * I) * sin(0.81 * I);
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "volatility_contraction: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "volatility_contraction: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "volatility_contraction: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "volatility_contraction: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "volatility_contraction: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "volatility_contraction: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[132] = 2.;
TS2Expect(TS2Evaluate() == 0., "volatility_contraction: implausible return rejected");
TS2Expect(TS2Quality == 0., "volatility_contraction: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "volatility_contraction: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "volatility_contraction: quality restored");
}
// Case 19: isolated_recent_up; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case19()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = ifelse(I == 3, 0.008, 0.0002 * sin(0.61 * I));
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "isolated_recent_up: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "isolated_recent_up: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "isolated_recent_up: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "isolated_recent_up: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "isolated_recent_up: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "isolated_recent_up: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[169] = 2.;
TS2Expect(TS2Evaluate() == 0., "isolated_recent_up: implausible return rejected");
TS2Expect(TS2Quality == 0., "isolated_recent_up: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "isolated_recent_up: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "isolated_recent_up: quality restored");
}
// Case 20: isolated_recent_down; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case20()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = ifelse(I == 3, -0.008, 0.0002 * sin(0.61 * I));
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "isolated_recent_down: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "isolated_recent_down: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "isolated_recent_down: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "isolated_recent_down: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "isolated_recent_down: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "isolated_recent_down: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[206] = 2.;
TS2Expect(TS2Evaluate() == 0., "isolated_recent_down: implausible return rejected");
TS2Expect(TS2Quality == 0., "isolated_recent_down: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "isolated_recent_down: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "isolated_recent_down: quality restored");
}
// Case 21: paired_opposite_shocks; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case21()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = ifelse(I == 7, 0.006, ifelse(I == 11, -0.006, 0.0001 * cos(I)));
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "paired_opposite_shocks: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "paired_opposite_shocks: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "paired_opposite_shocks: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "paired_opposite_shocks: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "paired_opposite_shocks: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "paired_opposite_shocks: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[243] = 2.;
TS2Expect(TS2Evaluate() == 0., "paired_opposite_shocks: implausible return rejected");
TS2Expect(TS2Quality == 0., "paired_opposite_shocks: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "paired_opposite_shocks: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "paired_opposite_shocks: quality restored");
}
// Case 22: paired_same_shocks; model 15 perturbation phase 2.055000.
// Covers numerical stability and directional symmetry on this path family.
void TS2Case22()
{
var Snapshot[256], Original, Repeated, Reflected, Restored;
var InitialQuality, InitialStatistic;
int I;
for (I = 0; I < 256; I++)
{
TS2Returns[I] = ifelse(I == 7 || I == 11, 0.006, 0.0001 * cos(I));
TS2Returns[I] += 0.00000003 * sin(2.055000 + I * 0.385000);
Snapshot[I] = TS2Returns[I];
}
Original = TS2Evaluate();
InitialQuality = TS2Quality;
InitialStatistic = TS2Statistic;
TS2Expect(Original == Original && abs(Original) <= 1., "paired_same_shocks: finite bounded edge");
TS2Expect(InitialQuality >= 0. && InitialQuality <= 1., "paired_same_shocks: quality contract");
TS2Expect(InitialStatistic == InitialStatistic && abs(InitialStatistic) < 1.e12, "paired_same_shocks: finite diagnostic");
Repeated = TS2Evaluate();
TS2Expect(abs(Repeated - Original) < 1.e-9, "paired_same_shocks: deterministic evaluation");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "paired_same_shocks: deterministic quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = -Snapshot[I];
Reflected = TS2Evaluate();
TS2Expect(abs(Reflected + Original) < 1.e-7, "paired_same_shocks: directional reflection");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
TS2Returns[24] = 2.;
TS2Expect(TS2Evaluate() == 0., "paired_same_shocks: implausible return rejected");
TS2Expect(TS2Quality == 0., "paired_same_shocks: rejected sample clears quality");
for (I = 0; I < 256; I++)
TS2Returns[I] = Snapshot[I];
Restored = TS2Evaluate();
TS2Expect(abs(Restored - Original) < 1.e-9, "paired_same_shocks: restored input has no stale state");
TS2Expect(abs(TS2Quality - InitialQuality) < 1.e-9, "paired_same_shocks: quality restored");
}