Add the tournament statistics and the surrogate series of the control
The championship judge needs statistics the single-trial protocol does not have: one common number of trials for the whole field and the bar it sets, a field variance taken on annualised Sharpe ratios so crypto and weekday markets compare, the common probability of overfitting on one calendar, the effective number of bets, a block-bootstrap interval and the control against chance. The control replays a rule on surrogate prices where every day all instruments change sign together, centred on the mean for long-only rules, so sizes, tails and correlations stay while any tendency to revert or to go on is lost. Instruments with corporate actions are refused for now. The seeded SplitMix64 generator of the tests moves to Anubis.Core as SeededRandom, unchanged, so the control and the intervals draw from it; the tests keep calling it Gen through a global alias. refs #124 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b564871391
commit
8967575d2c
8 files changed
+1264
-84
No files matched your search
@@ -29,87 +29,3 @@ internal static class Property
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fixed-seed generator based on SplitMix64. Unlike a seeded <see cref="Random"/>, its sequence is
|
||||
/// fixed by this code, so it stays the same on every platform and .NET version.
|
||||
/// </summary>
|
||||
internal sealed class Gen(int seed)
|
||||
{
|
||||
private ulong _state = unchecked((ulong)(long)seed);
|
||||
|
||||
public ulong NextUInt64()
|
||||
{
|
||||
var z = _state += 0x9E3779B97F4A7C15UL;
|
||||
z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9UL;
|
||||
z = (z ^ (z >> 27)) * 0x94D049BB133111EBUL;
|
||||
return z ^ (z >> 31);
|
||||
}
|
||||
|
||||
/// <summary>Uniform integer in [<paramref name="minInclusive"/>, <paramref name="maxExclusive"/>).</summary>
|
||||
public long Long(long minInclusive, long maxExclusive)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(minInclusive, maxExclusive);
|
||||
var range = unchecked((ulong)(maxExclusive - minInclusive));
|
||||
var limit = ulong.MaxValue - (ulong.MaxValue % range);
|
||||
ulong x;
|
||||
do
|
||||
{
|
||||
x = NextUInt64();
|
||||
}
|
||||
while (x >= limit);
|
||||
|
||||
return unchecked(minInclusive + (long)(x % range));
|
||||
}
|
||||
|
||||
public int Int(int minInclusive, int maxExclusive) => (int)Long(minInclusive, maxExclusive);
|
||||
|
||||
public bool Bool() => (NextUInt64() & 1UL) == 1UL;
|
||||
|
||||
/// <summary>Uniform value in [0, 1).</summary>
|
||||
public double Double() => (NextUInt64() >> 11) * (1.0 / (1UL << 53));
|
||||
|
||||
/// <summary>A standard normal value (Box–Muller), for synthetic price series and returns.</summary>
|
||||
public double Normal()
|
||||
{
|
||||
var u = 1.0 - Double();
|
||||
var v = Double();
|
||||
return Math.Sqrt(-2.0 * Math.Log(u)) * Math.Cos(2.0 * Math.PI * v);
|
||||
}
|
||||
|
||||
/// <summary>A decimal in [<paramref name="min"/>, <paramref name="max"/>] with at most <paramref name="scale"/> decimals.</summary>
|
||||
public decimal Decimal(decimal min, decimal max, int scale)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(min, max);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(scale);
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(scale, 18);
|
||||
|
||||
var unit = 1m;
|
||||
for (var i = 0; i < scale; i++)
|
||||
{
|
||||
unit /= 10m;
|
||||
}
|
||||
|
||||
var low = decimal.Ceiling(min / unit);
|
||||
var high = decimal.Floor(max / unit);
|
||||
if (low > high)
|
||||
{
|
||||
throw new ArgumentException("Nessun valore con questa scala nell'intervallo.", nameof(scale));
|
||||
}
|
||||
|
||||
var steps = high - low;
|
||||
if (steps >= long.MaxValue)
|
||||
{
|
||||
throw new ArgumentException("Intervallo troppo ampio per questa scala.", nameof(scale));
|
||||
}
|
||||
|
||||
var k = Long(0, (long)steps + 1);
|
||||
return (low + k) * unit;
|
||||
}
|
||||
|
||||
public T Pick<T>(IReadOnlyList<T> items)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfZero(items.Count);
|
||||
return items[Int(0, items.Count)];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user