The laboratory starts with the host (off in demo mode) and runs its queue next to market data and trading. The page lists every trial with status, verdict and headline figures, refreshing itself while one is queued or running, and offers the form for a new test: strategy, data origin and market, instruments, period, initial capital and the grid, with the thresholds stated before the run. The form posts with the antiforgery token; errors come back as a short code. The report page shows the protocol checks, the chosen variant against buy and hold (table and chart), results per year, cost sensitivity, the Deflated Sharpe Ratio, PBO, walk-forward windows, purged CV paths, the look-ahead result, every variant with its zone score, what the backtest does not model, the data used and the trades. A comparison page puts two finished tests side by side and says whether they read the same data. The improvements of 8.7 and the cost estimates of 11.6 have their sections, empty until Phases 9 and 8. The equity chart takes amounts in their own currency and its labels as parameters. The profit factor has no value without a losing trade. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
126 lines
5.9 KiB
Plaintext
126 lines
5.9 KiB
Plaintext
@inject ShellData Shell
|
|
|
|
@* Equity against the "senza bot" comparison (SPEC 13.4): one scale, 2 px lines, faint grid, direct label on the last
|
|
point, legend, and the same numbers in a table. Lines are SVG stretched to the box; texts and the end point are
|
|
HTML placed in percent, so nothing gets distorted at any width. *@
|
|
@if (Points.Count >= 2)
|
|
{
|
|
var values = Points.Select(p => Value(p.Equity)).ToList();
|
|
var bench = Points.Select(p => p.Benchmark is { } b ? Value(b) : (decimal?)null).ToList();
|
|
var all = values.Concat(bench.OfType<decimal>()).ToList();
|
|
var (lo, hi, step) = Scale(all.Min(), all.Max());
|
|
double X(int i) => i * 1000.0 / (Points.Count - 1);
|
|
double Y(decimal v) => (double)((hi - v) / (hi - lo)) * 1000.0;
|
|
string Line(IEnumerable<(int I, decimal V)> pts) => string.Join(" ", pts.Select(p => Fmt(X(p.I)) + "," + Fmt(Y(p.V))));
|
|
var equityLine = Line(values.Select((v, i) => (i, v)));
|
|
var benchLine = Line(bench.Select((v, i) => (i, v)).Where(p => p.v is not null).Select(p => (p.i, p.v!.Value)));
|
|
var last = values[^1];
|
|
<figure class="chart" aria-label="@Label">
|
|
<div class="chart-box">
|
|
<div class="chart-axis" aria-hidden="true">
|
|
@for (var t = lo; t <= hi; t += step)
|
|
{
|
|
<span style="top:@Pct(Y(t) / 10)">@Format.Number(t)</span>
|
|
}
|
|
</div>
|
|
<div class="chart-plot">
|
|
<svg viewBox="0 0 1000 1000" preserveAspectRatio="none" aria-hidden="true" focusable="false">
|
|
@for (var t = lo; t <= hi; t += step)
|
|
{
|
|
<line class="grid" x1="0" x2="1000" y1="@Fmt(Y(t))" y2="@Fmt(Y(t))" vector-effect="non-scaling-stroke" />
|
|
}
|
|
<polygon class="area" points="0,1000 @equityLine 1000,1000" />
|
|
@if (benchLine.Length > 0)
|
|
{
|
|
<polyline class="bench" points="@benchLine" vector-effect="non-scaling-stroke" />
|
|
}
|
|
<polyline class="equity" points="@equityLine" vector-effect="non-scaling-stroke" />
|
|
</svg>
|
|
@if (bench[^1] is { } lastBench)
|
|
{
|
|
// Two labels never overlap: the lower one moves down when they are closer than one line.
|
|
var gap = Math.Abs(Y(last) - Y(lastBench)) / 10;
|
|
var benchTop = gap < 7 ? Y(last) / 10 + (Y(lastBench) >= Y(last) ? 7 : -7) : Y(lastBench) / 10;
|
|
<span class="end-dot bench-dot" style="left:100%;top:@Pct(Y(lastBench) / 10)"></span>
|
|
<span class="end-label bench-label" style="top:@Pct(benchTop)">@Text(Points[^1].Benchmark!.Value, 0)</span>
|
|
}
|
|
<span class="end-dot" style="left:100%;top:@Pct(Y(last) / 10)"></span>
|
|
<span class="end-label" style="top:@Pct(Y(last) / 10)">@Text(Points[^1].Equity, 0)</span>
|
|
</div>
|
|
</div>
|
|
<figcaption class="legend">
|
|
<span class="key key-equity">@EquityLabel</span>
|
|
@if (benchLine.Length > 0)
|
|
{
|
|
<span class="key key-bench">@BenchmarkLabel</span>
|
|
}
|
|
</figcaption>
|
|
<details class="chart-table">
|
|
<summary>Vedi i numeri in una tabella</summary>
|
|
<div class="table-wrap">
|
|
<table class="table">
|
|
<thead><tr><th scope="col">Giorno</th><th scope="col" class="num">@EquityColumn</th><th scope="col" class="num">@BenchmarkColumn</th></tr></thead>
|
|
<tbody>
|
|
@foreach (var p in Points.AsEnumerable().Reverse())
|
|
{
|
|
<tr><td>@Format.LongDate(p.Day)</td><td class="num">@Text(p.Equity)</td><td class="num">@(p.Benchmark is { } b ? Text(b) : "—")</td></tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</details>
|
|
</figure>
|
|
}
|
|
|
|
@code {
|
|
[Parameter, EditorRequired]
|
|
public IReadOnlyList<EquityPoint> Points { get; set; } = [];
|
|
|
|
[Parameter]
|
|
public string Currency { get; set; } = "EUR";
|
|
|
|
/// <summary>True when the amounts are already in <see cref="Currency"/> (a backtest report): no conversion from euro.</summary>
|
|
[Parameter]
|
|
public bool Native { get; set; }
|
|
|
|
[Parameter]
|
|
public string Label { get; set; } = "Patrimonio nel tempo, con il bot e senza";
|
|
|
|
[Parameter]
|
|
public string EquityLabel { get; set; } = "Con Anubis";
|
|
|
|
[Parameter]
|
|
public string BenchmarkLabel { get; set; } = "Senza bot: Bitcoin e S&P 500 comprati e tenuti";
|
|
|
|
[Parameter]
|
|
public string EquityColumn { get; set; } = "Con il bot";
|
|
|
|
[Parameter]
|
|
public string BenchmarkColumn { get; set; } = "Senza bot";
|
|
|
|
private decimal Value(decimal amount) => Native ? amount : Shell.Convert(amount, Currency);
|
|
|
|
private string Text(decimal amount, int decimals = 2) => Native ? Format.Money(amount, Currency, decimals: decimals) : Shell.Money(amount, Currency, decimals: decimals);
|
|
|
|
private static string Fmt(double v) => v.ToString("0.##", CultureInfo.InvariantCulture);
|
|
|
|
private static string Pct(double v) => v.ToString("0.###", CultureInfo.InvariantCulture) + "%";
|
|
|
|
// Round steps (1, 2, 2.5, 3, 5 times a power of ten) giving three to five grid lines.
|
|
internal static (decimal Lo, decimal Hi, decimal Step) Scale(decimal min, decimal max)
|
|
{
|
|
if (max <= min)
|
|
{
|
|
max = min + 1;
|
|
}
|
|
|
|
var raw = (double)(max - min) / 4;
|
|
var power = Math.Pow(10, Math.Floor(Math.Log10(raw)));
|
|
var step = new[] { 1, 2, 2.5, 3, 5, 10 }.Select(m => m * power).First(s => s >= raw);
|
|
var stepValue = (decimal)step;
|
|
var lo = Math.Floor(min / stepValue) * stepValue;
|
|
var hi = Math.Ceiling(max / stepValue) * stepValue;
|
|
return (lo, hi == lo ? lo + stepValue : hi, stepValue);
|
|
}
|
|
}
|