feat(core): add shared DTOs, MqttTopics constants, DatabaseBootstrapper, and ManagedMqttClient extensions
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using FinlyticCore.Dtos.TechnicalAnalysis;
|
||||
|
||||
namespace FinlyticCore.Dtos.Simulation;
|
||||
|
||||
/// <param name="StrategyParameters">
|
||||
/// Per-run overrides for <paramref name="StrategyKey"/>'s tunable indicator parameters, keyed by
|
||||
/// <c>"{StrategyKey}.{ParameterName}"</c> (e.g. <c>"MeanReversion.RsiOversold"</c>) - see
|
||||
/// <c>TechnicalContext.ParameterOverrides</c>. <see langword="null"/>/empty means "use that strategy's own
|
||||
/// hardcoded defaults". Deliberately scoped to backtesting only - live scanning never applies these.
|
||||
/// </param>
|
||||
public record BacktestRequestDto(
|
||||
string Isin,
|
||||
string Symbol,
|
||||
string StrategyKey,
|
||||
string Timeframe,
|
||||
DateTime StartDateUtc,
|
||||
DateTime EndDateUtc,
|
||||
decimal StartingCapital = 10000m,
|
||||
decimal RiskPerTradePercent = 1.0m, // 1% Risiko pro Trade
|
||||
bool IncludeFeesAndSlippage = true,
|
||||
bool SimulateKnockOutDerivatives = false,
|
||||
decimal? TargetLeverage = 5.0m,
|
||||
Dictionary<string, decimal>? StrategyParameters = null
|
||||
);
|
||||
|
||||
public record BacktestTradeDto(
|
||||
Guid TradeId,
|
||||
DateTime EntryTimeUtc,
|
||||
DateTime ExitTimeUtc,
|
||||
SignalDirection Direction,
|
||||
decimal EntryPrice,
|
||||
decimal ExitPrice,
|
||||
decimal Quantity,
|
||||
decimal InitialStopLoss,
|
||||
decimal RealizedPnlEur,
|
||||
decimal ReturnPercent,
|
||||
decimal RMultiple,
|
||||
string ExitReason, // "TP1_Hit", "TP2_Hit", "BreakEven", "TrailingStop", "KnockedOut", "TimeExpired"
|
||||
decimal MaxAdverseExcursionPercent, // MAE: Maximaler zwischenzeitlicher Buchverlust
|
||||
decimal MaxFavorableExcursionPercent // MFE: Maximaler zwischenzeitlicher Buchgewinn
|
||||
);
|
||||
|
||||
public record EquityPointDto(
|
||||
DateTime TimestampUtc,
|
||||
decimal PortfolioValue,
|
||||
decimal DrawdownPercent
|
||||
);
|
||||
|
||||
public record BacktestReportDto(
|
||||
Guid RunId,
|
||||
string Isin,
|
||||
string Symbol,
|
||||
string StrategyKey,
|
||||
string Timeframe,
|
||||
DateTime StartDateUtc,
|
||||
DateTime EndDateUtc,
|
||||
int TotalTrades,
|
||||
int WinningTrades,
|
||||
int LosingTrades,
|
||||
decimal WinRatePercent,
|
||||
decimal ProfitFactor,
|
||||
decimal MaxDrawdownPercent,
|
||||
decimal TotalReturnPercent,
|
||||
decimal ExpectancyEur,
|
||||
decimal SharpeRatio,
|
||||
decimal AverageRiskRewardRatio,
|
||||
TimeSpan AverageHoldingDuration,
|
||||
List<BacktestTradeDto> Trades,
|
||||
List<EquityPointDto> EquityCurve
|
||||
);
|
||||
|
||||
public record StrategyAssetReliabilityDto(
|
||||
string Isin,
|
||||
string StrategyKey,
|
||||
decimal ReliabilityScore, // 0 - 100
|
||||
decimal WinRatePercent,
|
||||
decimal ProfitFactor,
|
||||
int SampleTradeCount,
|
||||
bool IsStrategyApprovedForAsset,
|
||||
string RecommendedAction // "BOOST_SCORE", "NEUTRAL", "VETO_DISABLE"
|
||||
);
|
||||
|
||||
public record GetReliabilityRequest(
|
||||
string Isin,
|
||||
string StrategyKey,
|
||||
string Timeframe = "15m"
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Filters for <c>MqttTopics.Channels.SimGetBacktestHistory</c>. <see cref="StrategyKey"/> is optional -
|
||||
/// <see langword="null"/> returns every strategy's runs for the ISIN, so the Web UI can show "all history for
|
||||
/// this asset" and let the user narrow down from there.
|
||||
/// </summary>
|
||||
public record GetBacktestHistoryRequest(
|
||||
string Isin,
|
||||
string? StrategyKey = null,
|
||||
int Limit = 20
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// One row of the backtest history list - a lightweight summary (no <c>Trades</c>/<c>EquityCurve</c>) mapped
|
||||
/// 1:1 from a persisted <c>SimulationRunEntity</c>, so listing many runs for an asset stays cheap. Fetch the
|
||||
/// full <see cref="BacktestReportDto"/> for one specific run via <c>SimGetBacktestRunDetail</c> when the user
|
||||
/// drills into it.
|
||||
/// </summary>
|
||||
public record BacktestHistoryEntryDto(
|
||||
Guid RunId,
|
||||
string Isin,
|
||||
string Symbol,
|
||||
string StrategyKey,
|
||||
string Timeframe,
|
||||
DateTime StartDateUtc,
|
||||
DateTime EndDateUtc,
|
||||
int TotalTrades,
|
||||
decimal WinRatePercent,
|
||||
decimal ProfitFactor,
|
||||
decimal MaxDrawdownPercent,
|
||||
decimal TotalReturnPercent,
|
||||
decimal SharpeRatio,
|
||||
DateTime CreatedAtUtc
|
||||
);
|
||||
|
||||
/// <summary>Looks up one specific past backtest run's full report by its RunId (<c>MqttTopics.Channels.SimGetBacktestRunDetail</c>).</summary>
|
||||
public record GetBacktestRunDetailRequest(Guid RunId);
|
||||
|
||||
/// <summary>Looks up a saved parameter profile for one (Isin, StrategyKey) pair (<c>MqttTopics.Channels.SimGetStrategyParameters</c>).</summary>
|
||||
public record GetStrategyParametersRequest(string Isin, string StrategyKey);
|
||||
|
||||
/// <summary>Upserts a saved parameter profile for one (Isin, StrategyKey) pair (<c>MqttTopics.Channels.SimSaveStrategyParameters</c>).</summary>
|
||||
public record SaveStrategyParametersRequest(string Isin, string StrategyKey, Dictionary<string, decimal> Parameters);
|
||||
|
||||
/// <summary>
|
||||
/// A saved set of tunable indicator parameter overrides for one (Isin, StrategyKey) pair, keyed by
|
||||
/// <c>"{StrategyKey}.{ParameterName}"</c> (matching <c>TechnicalContext.ParameterOverrides</c> 1:1) - see
|
||||
/// <c>SimulationStrategyParameterEntity</c>.
|
||||
/// </summary>
|
||||
public record StrategyParameterProfileDto(
|
||||
string Isin,
|
||||
string StrategyKey,
|
||||
Dictionary<string, decimal> Parameters,
|
||||
DateTime UpdatedAtUtc
|
||||
);
|
||||
Reference in New Issue
Block a user