What an account did while the bot was off is now written before the splits and the dividends of those days, once and without acting on it; an attempt cut halfway is taken up from the same point. Until then the account is not valued at today's price, the guard keeps the last figures it knew with their time, and a stop order only cancels what is open. Protective sales of the archive are not continued, and the rest of a stop that fired in part is sold. Also the decisions of the phase (ADR 0020), the manuals and the dates under the equity chart. refs #69 #72 #75 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
135 lines
6.4 KiB
Plaintext
135 lines
6.4 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>
|
|
<div class="chart-days" aria-hidden="true">
|
|
@foreach (var i in Days())
|
|
{
|
|
<span style="left:@Pct(X(i) / 10)">@Format.AxisDay(Points[i].Day, Points[^1].Day.DayNumber - Points[0].Day.DayNumber)</span>
|
|
}
|
|
</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);
|
|
|
|
// Five dates at even distances, first and last included; fewer when there are not enough days.
|
|
private IEnumerable<int> Days() => Enumerable.Range(0, 5).Select(i => i * (Points.Count - 1) / 4).Distinct();
|
|
|
|
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);
|
|
}
|
|
}
|