Add the Operazioni, Strategie and Rischio screens (refs #45)
The three screens follow mockups 03, 04 and 07. Operazioni shows the balance of the closed trades, filters, a CSV export, and for each trade why it was bought and sold. The reasons come from the decision codes through fixed Italian templates. Strategie shows the four stages towards real money, a card per strategy with its requirements, the procedure of SPEC 12.4, and why each strategy in observation waits. A strategy that failed its backtest cannot be moved into the simulation. Rischio shows the emergency switch, the automatic blocks, the use of each limit, the fall from the peak, the scenarios and the risk events. Stop, close and restart now go through the risk engine. A restart is refused while the STOP file exists. Impostazioni gains the limits, the day-trade guard and the scenarios. Lowering a limit is always allowed. Raising a limit or the entrusted capital while a strategy uses real money needs the phrase and the password. The demo now holds the decisions behind its trades, the 58 days of simulation and the indices of its curves, so it matches the mockups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7041533ce2
commit
13f9c42f61
16 files changed
+2085
-34
No files matched your search
@@ -1,30 +1,298 @@
|
||||
@inherits LoadedComponent
|
||||
@page "/rischio"
|
||||
@inject AnubisHost Host
|
||||
@inject ShellData Shell
|
||||
@inject IClock Clock
|
||||
@using Anubis.Trading
|
||||
@using Anubis.Risk
|
||||
|
||||
<PageTitle>Rischio · Anubis</PageTitle>
|
||||
|
||||
<section class="panel">
|
||||
<h2><Icon Name="shield" Size="18" />Interruttore</h2>
|
||||
@if (_bot == "stopped")
|
||||
{
|
||||
<p class="notice notice-attention" role="status"><Icon Name="alert" Size="16" />"Ferma tutto" è acceso: il bot non apre e non gestisce operazioni finché non lo riattivi.</p>
|
||||
<form method="post" action="/azioni/bot/riattiva" class="form-inline">
|
||||
<AntiforgeryToken />
|
||||
<input type="hidden" name="ritorno" value="/rischio" />
|
||||
<button class="btn" type="submit" data-confirm="Riattivare il bot?">Riattiva il bot</button>
|
||||
</form>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>"Ferma tutto", in alto, blocca il bot. Dopo averlo usato il bot si riattiva solo da qui, mai da solo e mai da Telegram.</p>
|
||||
}
|
||||
@{
|
||||
var v = _view;
|
||||
var c = _currency;
|
||||
}
|
||||
@if (_message is { } message)
|
||||
{
|
||||
<p class="notice notice-loss" role="status"><Icon Name="alert" Size="16" />@message</p>
|
||||
}
|
||||
<div class="risk-top">
|
||||
<section class="panel" aria-labelledby="interruttore">
|
||||
<div class="panel-head">
|
||||
<h2 id="interruttore">Interruttore d'emergenza</h2>
|
||||
<span class="link-state @(v.BotState == "active" ? null : "down")"><span class="dot"></span>@BotText(v.BotState)</span>
|
||||
</div>
|
||||
@if (v.BotState == "stopped")
|
||||
{
|
||||
<p class="notice notice-attention" role="status"><Icon Name="alert" Size="16" /><span>
|
||||
@if (v.Risk.State.Tripped)
|
||||
{
|
||||
<text>L'interruttore è scattato: il calo dal massimo ha superato il @Format.Percent(v.Limits.DrawdownStop * 100m, 0). </text>
|
||||
}
|
||||
Il bot non apre posizioni e non vende per le strategie; gli stop di protezione restano attivi.
|
||||
@if (v.CloseAllPending)
|
||||
{
|
||||
<text> Sta vendendo tutte le posizioni: ciò che è su un mercato chiuso parte all'apertura.</text>
|
||||
}
|
||||
</span></p>
|
||||
@if (v.StopFile)
|
||||
{
|
||||
<p class="note">C'è il file <code>STOP</code> nella cartella dei dati: toglilo, poi conferma qui la ripartenza.</p>
|
||||
}
|
||||
@if (!Shell.IsDemo)
|
||||
{
|
||||
<form method="post" action="/azioni/bot/riattiva" class="form-inline">
|
||||
<AntiforgeryToken />
|
||||
<input type="hidden" name="ritorno" value="/rischio" />
|
||||
<button class="btn" type="submit" disabled="@v.StopFile" data-confirm="@RestartText(v)">Riparti</button>
|
||||
</form>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>Con <strong>Ferma tutto</strong> annullo gli ordini in attesa e non apro nuove posizioni. Gli stop di protezione restano attivi, così quello che è aperto non rimane scoperto. Per ripartire serve la tua conferma, da qui.</p>
|
||||
@if (!Shell.IsDemo)
|
||||
{
|
||||
<div class="choices">
|
||||
<form method="post" action="/azioni/bot/ferma"><AntiforgeryToken /><input type="hidden" name="ritorno" value="/rischio" /><button class="btn btn-danger-solid" type="submit" data-confirm="Ferma tutto: annullo gli ordini in attesa e non apro posizioni finché non riparti da qui. Gli stop restano. Confermi?"><Icon Name="stop" Size="18" />Ferma tutto</button></form>
|
||||
<form method="post" action="/azioni/bot/chiudi"><AntiforgeryToken /><input type="hidden" name="ritorno" value="/rischio" /><button class="btn btn-danger" type="submit" data-confirm="Ferma e chiudi: fermo tutto e vendo a mercato ogni posizione del bot. Ciò che è su un mercato chiuso parte all'apertura e intanto tiene il suo stop. Non si annulla. Confermi?">Ferma e chiudi tutte le posizioni</button></form>
|
||||
</div>
|
||||
}
|
||||
<p class="note">Anche un file chiamato <code>STOP</code> nella cartella dei dati ferma tutto entro un minuto.</p>
|
||||
}
|
||||
</section>
|
||||
<section class="panel" aria-labelledby="blocchi">
|
||||
<h2 id="blocchi">Blocchi automatici</h2>
|
||||
@if (!v.AnyBlock)
|
||||
{
|
||||
<p class="gain status-line"><Icon Name="check" Size="16" />Nessun blocco attivo</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="blocks">
|
||||
@if (v.Risk.State.Tripped)
|
||||
{
|
||||
<li class="loss"><Icon Name="alert" Size="16" />Interruttore scattato @(v.Risk.State.TrippedAt is { } at ? "il " + Moment(at) : ""): aspetta la tua conferma.</li>
|
||||
}
|
||||
@if (v.Risk.State.DailyBlockUntil is { } until && until > Clock.UtcNow)
|
||||
{
|
||||
<li><Icon Name="clock" Size="16" />Perdita del giorno oltre il limite: niente nuovi ingressi fino a @Moment(until).</li>
|
||||
}
|
||||
@if (v.Risk.State.WeeklyHalvingUntil is { } half && half > Clock.UtcNow)
|
||||
{
|
||||
<li><Icon Name="clock" Size="16" />Perdita della settimana oltre il limite: rischio dimezzato fino a @Moment(half).</li>
|
||||
}
|
||||
@if (v.Risk.Measures.Drawdown <= -v.Limits.DrawdownHalf && !v.Risk.State.Tripped)
|
||||
{
|
||||
<li><Icon Name="alert" Size="16" />Calo dal massimo oltre il @Format.Percent(v.Limits.DrawdownHalf * 100m, 0): rischio dimezzato.</li>
|
||||
}
|
||||
@if (v.BotState == "paused")
|
||||
{
|
||||
<li><Icon Name="pause" Size="16" />Bot in pausa: niente nuovi ingressi, stop e uscite proseguono.</li>
|
||||
}
|
||||
@if (v.BotState == "stopped" && !v.Risk.State.Tripped)
|
||||
{
|
||||
<li class="loss"><Icon Name="stop" Size="16" />Ferma tutto acceso.</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
<dl class="block-list">
|
||||
<dt>Prossimo blocco in programma</dt>
|
||||
@if (v.NextCalendarBlock is { } next)
|
||||
{
|
||||
<dd><strong>@Capital(Local(next.From, "dddd d MMMM")), dalle @Local(next.From, "HH:mm") alle @Local(next.To, "HH:mm")</strong><span>@next.Title: in quell'ora non apro posizioni.</span></dd>
|
||||
}
|
||||
else
|
||||
{
|
||||
<dd><span>Nessun dato economico importante nei prossimi 14 giorni.</span></dd>
|
||||
}
|
||||
<dt>Ultimo blocco scattato</dt>
|
||||
@if (v.LastCalendarBlock is { } last)
|
||||
{
|
||||
<dd><strong>@Capital(Local(last.From, "dddd d MMMM")), dalle @Local(last.From, "HH:mm") alle @Local(last.To, "HH:mm")</strong><span>@last.Title.</span></dd>
|
||||
}
|
||||
else
|
||||
{
|
||||
<dd><span>Nessuno negli ultimi 14 giorni.</span></dd>
|
||||
}
|
||||
<dt>Protezione day trade (azioni)</dt>
|
||||
<dd><span>@(v.PdtGuard ? "Accesa: al massimo 3 operazioni in giornata ogni 5 sedute." : "Spenta. Si accende in Impostazioni se il conto Alpaca vale meno di 25.000 $.")</span></dd>
|
||||
</dl>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="panel" aria-labelledby="limiti">
|
||||
<div class="panel-head">
|
||||
<h2 id="limiti">I limiti <span class="note">Valgono per tutte le strategie insieme@(v.World == Worlds.Real ? ", sui conti veri" : ", nel mondo simulato"). Si cambiano dalle <a href="/impostazioni#rischio">impostazioni</a>, mai da soli.</span></h2>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table class="table limits">
|
||||
<thead>
|
||||
<tr><th scope="col">Limite</th><th scope="col" class="num">Adesso</th><th scope="col" class="wide">Quanto ne sto usando</th><th scope="col" class="num">Soglia</th><th scope="col" class="wide">Se lo supero</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var row in v.Rows)
|
||||
{
|
||||
<tr>
|
||||
<th scope="row">@row.Label</th>
|
||||
<td class="num nowrap">@row.Now@if (row.Detail is { } d) {<text> </text><span class="muted">(@d)</span>}</td>
|
||||
<td class="wide">
|
||||
@if (row.Usage is { } u)
|
||||
{
|
||||
<span class="usage @(u >= 0.8m ? "high" : null)" role="img" aria-label="@Format.Percent(u * 100m, 0) del limite"><span style="width: @Css(u * 100m)%"></span></span>
|
||||
}
|
||||
</td>
|
||||
<td class="num nowrap">@row.Threshold</td>
|
||||
<td class="wide">@row.Beyond</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<Pending Title="Limiti e scenari non sono ancora attivi.">Limiti di perdita, calo dal massimo, esposizione e scenari arrivano con le strategie e il controllo del rischio.</Pending>
|
||||
|
||||
<div class="columns">
|
||||
<section class="panel" aria-labelledby="calo">
|
||||
<h2 id="calo">Quanto è sceso dal massimo</h2>
|
||||
<p class="note">Ogni fotografia del patrimonio@(v.Risk.State.PeakFrom is { } from ? " dal " + Local(from, "d MMMM") : " dall'avvio"). A zero vuol dire che il portafoglio era al suo punto più alto.</p>
|
||||
@if (v.Drawdown.Count < 2)
|
||||
{
|
||||
<p class="note">Ancora troppo poche fotografie per disegnare la curva.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
var worst = v.Drawdown.MinBy(p => p.Drawdown)!;
|
||||
var floor = Math.Min(-0.01m, worst.Drawdown * 1.2m);
|
||||
var first = v.Drawdown[0].At;
|
||||
var span = Math.Max(1d, (v.Drawdown[^1].At - first).TotalSeconds);
|
||||
string X(DateTimeOffset at) => Css((decimal)((at - first).TotalSeconds / span) * 560m + 30m);
|
||||
string Y(decimal d) => Css(10m + d / floor * 150m);
|
||||
var points = string.Join(' ', v.Drawdown.Select(p => X(p.At) + "," + Y(p.Drawdown)));
|
||||
<svg class="drawdown" viewBox="0 0 600 190" role="img" aria-label="Calo dal massimo: il peggiore @Format.Percent(worst.Drawdown * 100m, 2) il @Local(worst.At, "d MMMM")">
|
||||
<line x1="30" x2="590" y1="10" y2="10" class="axis" />
|
||||
<text x="0" y="14" class="tick">0%</text>
|
||||
<text x="0" y="164" class="tick">@Format.Percent(floor * 100m, 1)</text>
|
||||
<polygon points="30,10 @points @X(v.Drawdown[^1].At),10" class="area" />
|
||||
<polyline points="@points" class="line" />
|
||||
<circle cx="@X(worst.At)" cy="@Y(worst.Drawdown)" r="4" class="dot" />
|
||||
<text x="@X(worst.At)" y="@(Css(Math.Min(180m, 26m + worst.Drawdown / floor * 150m)))" text-anchor="middle" class="label">@Format.Percent(worst.Drawdown * 100m, 2) il @Local(worst.At, "d MMM")</text>
|
||||
</svg>
|
||||
<p class="note">
|
||||
@if (-worst.Drawdown < v.Limits.DrawdownHalf / 5m)
|
||||
{
|
||||
<text>Le soglie del @Format.Percent(v.Limits.DrawdownHalf * 100m, 0) e del @Format.Percent(v.Limits.DrawdownStop * 100m, 0) sono fuori scala: il calo peggiore è rimasto sotto un quinto del limite.</text>
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>A @Format.Percent(-v.Limits.DrawdownHalf * 100m, 0) il rischio si dimezza, a @Format.Percent(-v.Limits.DrawdownStop * 100m, 0) il bot si ferma e aspetta te.</text>
|
||||
}
|
||||
</p>
|
||||
}
|
||||
</section>
|
||||
<section class="panel" aria-labelledby="scenari">
|
||||
<h2 id="scenari">Se succedesse domani</h2>
|
||||
<p class="note">Quanto perderei con le posizioni di adesso. Gli scenari si cambiano in <a href="/impostazioni#rischio">Impostazioni</a>.</p>
|
||||
@if (!v.HasPositions)
|
||||
{
|
||||
<p class="note">Nessuna posizione aperta: oggi nessuno scenario costerebbe nulla.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="table-wrap">
|
||||
<table class="table">
|
||||
<thead><tr><th scope="col">Scenario</th><th scope="col" class="num">Senza stop</th><th scope="col" class="num">Con gli stop</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var s in v.Scenarios)
|
||||
{
|
||||
<tr>
|
||||
<th scope="row">@s.Scenario.Label</th>
|
||||
<td class="num nowrap"><strong>@Shell.Money(s.WithoutStops, c, decimals: 0)</strong> <span class="muted">(@Format.Percent(s.WithoutStopsShare * 100m, 1, withSign: true))</span></td>
|
||||
<td class="num nowrap muted">@(s.SameWithStops ? "uguale" : "circa " + Shell.Money(s.WithStops ?? 0m, c, decimals: 0))</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="notice notice-attention"><Icon Name="alert" Size="16" />Gli stop non sono una garanzia: in un crollo improvviso il prezzo può saltarli. E nessuno stop protegge dal cambio.</p>
|
||||
}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div class="columns">
|
||||
<section aria-labelledby="mai" class="plain">
|
||||
<h2 id="mai">Cosa il bot non può fare, mai</h2>
|
||||
<ul class="never">
|
||||
<li><Icon Name="ban" Size="16" />Usare soldi presi in prestito o vendere allo scoperto</li>
|
||||
<li><Icon Name="ban" Size="16" />Prelevare o spostare denaro: le chiavi dei conti non lo permettono</li>
|
||||
<li><Icon Name="ban" Size="16" />Toccare posizioni che non ha aperto lui</li>
|
||||
<li><Icon Name="ban" Size="16" />Passare ai soldi veri senza la tua conferma</li>
|
||||
<li><Icon Name="ban" Size="16" />Rischiare di più per recuperare una perdita</li>
|
||||
<li><Icon Name="ban" Size="16" />Comprare di più perché lo suggerisce una notizia o il modello</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section aria-labelledby="eventi" class="plain">
|
||||
<div class="panel-head">
|
||||
<h2 id="eventi">Eventi di rischio</h2>
|
||||
@if (v.Events.Count == 0)
|
||||
{
|
||||
<span class="note">Nessun limite superato dall'avvio</span>
|
||||
}
|
||||
</div>
|
||||
@if (v.Events.Count > 0)
|
||||
{
|
||||
<dl class="events">
|
||||
@foreach (var e in v.Events)
|
||||
{
|
||||
<dt>@Local(e.At, "d MMMM")</dt>
|
||||
<dd class="@(e.Severity is RiskSeverities.Critical or RiskSeverities.High ? "loss" : null)">@e.Message</dd>
|
||||
}
|
||||
</dl>
|
||||
<a href="/diario">Vedi tutto nel diario</a>
|
||||
}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string _bot = "active";
|
||||
private RiskView _view = null!;
|
||||
private string _currency = "EUR";
|
||||
private string? _message;
|
||||
|
||||
protected override async Task LoadAsync() =>
|
||||
_bot = (await Host.Services!.Settings.GetAsync(SettingsStore.BotState.Key)).Value;
|
||||
[CascadingParameter]
|
||||
public HttpContext? HttpContext { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "errore")]
|
||||
public string? Errore { get; set; }
|
||||
|
||||
protected override async Task LoadAsync()
|
||||
{
|
||||
var ct = HttpContext?.RequestAborted ?? CancellationToken.None;
|
||||
var services = Host.Services!;
|
||||
_currency = Shell.Effective((await services.Settings.GetAsync(SettingsStore.Currency.Key, ct)).Value);
|
||||
_view = await RiskView.LoadAsync(services, Clock, Shell.Zone, ct);
|
||||
_message = Errore switch
|
||||
{
|
||||
"file-stop" => "Il file STOP è ancora nella cartella dei dati: toglilo prima di ripartire.",
|
||||
"bot" => "Comando non ammesso nello stato attuale del bot.",
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
private static string BotText(string state) => state switch
|
||||
{
|
||||
"active" => "Il bot sta operando",
|
||||
"paused" => "In pausa",
|
||||
_ => "Fermo",
|
||||
};
|
||||
|
||||
private static string RestartText(RiskView v) => v.Risk.State.Tripped
|
||||
? "Riparti: il massimo di riferimento riparte dal patrimonio di adesso e il bot torna a operare. Confermi?"
|
||||
: "Riparti: il bot torna a operare. Confermi?";
|
||||
|
||||
private static string Css(decimal value) => value.ToString("0.##", CultureInfo.InvariantCulture);
|
||||
|
||||
private string Local(DateTimeOffset at, string format) => TimeZoneInfo.ConvertTime(at, Shell.Zone).ToString(format, CultureInfo.GetCultureInfo("it-IT"));
|
||||
|
||||
private string Moment(DateTimeOffset at) => Local(at, "d MMMM 'alle' HH:mm");
|
||||
|
||||
private static string Capital(string text) => text.Length == 0 ? text : char.ToUpper(text[0], CultureInfo.GetCultureInfo("it-IT")) + text[1..];
|
||||
}
|
||||
Reference in new issue
Block a user