feat(simulation): add quant simulation microservice with virtual backtest broker and replay engine

This commit is contained in:
2026-08-24 21:36:20 +02:00
parent f43ce2b7e9
commit a4959658a2
22 changed files with 2600 additions and 0 deletions
@@ -0,0 +1,191 @@
// <auto-generated />
using System;
using FinlyticSimulation.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FinlyticSimulation.Migrations
{
[DbContext(typeof(SimulationDbContext))]
[Migration("20260819191418_InitialSimulationMigration")]
partial class InitialSimulationMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("FinlyticCore.Entities.Settings.SettingEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Key")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("character varying(150)");
b.Property<DateTime>("LastUpdatedUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("ServiceIdentifier")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<string>("ValueJson")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("Key")
.IsUnique();
b.ToTable("DynamicSettings");
});
modelBuilder.Entity("FinlyticSimulation.Database.Entities.SimulationRunEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("CreatedAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("EndDateUtc")
.HasColumnType("timestamp with time zone");
b.Property<decimal>("ExpectancyEur")
.HasColumnType("decimal(18,4)");
b.Property<string>("Isin")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<int>("LosingTrades")
.HasColumnType("integer");
b.Property<decimal>("MaxDrawdownPercent")
.HasColumnType("decimal(6,2)");
b.Property<decimal>("ProfitFactor")
.HasColumnType("decimal(8,4)");
b.Property<string>("ReportJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<decimal>("SharpeRatio")
.HasColumnType("decimal(8,4)");
b.Property<DateTime>("StartDateUtc")
.HasColumnType("timestamp with time zone");
b.Property<decimal>("StartingCapital")
.HasColumnType("decimal(18,4)");
b.Property<string>("StrategyKey")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("Symbol")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)");
b.Property<string>("Timeframe")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("character varying(10)");
b.Property<decimal>("TotalReturnPercent")
.HasColumnType("decimal(8,2)");
b.Property<int>("TotalTrades")
.HasColumnType("integer");
b.Property<decimal>("WinRatePercent")
.HasColumnType("decimal(6,2)");
b.Property<int>("WinningTrades")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("CreatedAtUtc");
b.HasIndex("Isin", "StrategyKey", "Timeframe");
b.ToTable("simulation_runs");
});
modelBuilder.Entity("FinlyticSimulation.Database.Entities.SimulationStrategyMatrixEntity", b =>
{
b.Property<string>("Isin")
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<string>("StrategyKey")
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("Timeframe")
.HasMaxLength(10)
.HasColumnType("character varying(10)");
b.Property<bool>("IsApproved")
.HasColumnType("boolean");
b.Property<Guid?>("LastBacktestRunId")
.HasColumnType("uuid");
b.Property<decimal>("MaxDrawdownPercent")
.HasColumnType("decimal(6,2)");
b.Property<decimal>("ProfitFactor")
.HasColumnType("decimal(8,4)");
b.Property<string>("RecommendedAction")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)");
b.Property<decimal>("ReliabilityScore")
.HasColumnType("decimal(5,2)");
b.Property<int>("SampleTradesCount")
.HasColumnType("integer");
b.Property<DateTime>("UpdatedAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<decimal>("WinRatePercent")
.HasColumnType("decimal(6,2)");
b.HasKey("Isin", "StrategyKey", "Timeframe");
b.HasIndex("ReliabilityScore");
b.HasIndex("Isin", "IsApproved");
b.ToTable("simulation_strategy_matrix");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,120 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FinlyticSimulation.Migrations
{
/// <inheritdoc />
public partial class InitialSimulationMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "DynamicSettings",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Key = table.Column<string>(type: "character varying(150)", maxLength: 150, nullable: false),
ValueJson = table.Column<string>(type: "text", nullable: false),
ServiceIdentifier = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
LastUpdatedUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DynamicSettings", x => x.Id);
});
migrationBuilder.CreateTable(
name: "simulation_runs",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Isin = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
Symbol = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
StrategyKey = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
Timeframe = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: false),
StartDateUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
EndDateUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
StartingCapital = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
TotalTrades = table.Column<int>(type: "integer", nullable: false),
WinningTrades = table.Column<int>(type: "integer", nullable: false),
LosingTrades = table.Column<int>(type: "integer", nullable: false),
WinRatePercent = table.Column<decimal>(type: "numeric(6,2)", nullable: false),
ProfitFactor = table.Column<decimal>(type: "numeric(8,4)", nullable: false),
MaxDrawdownPercent = table.Column<decimal>(type: "numeric(6,2)", nullable: false),
TotalReturnPercent = table.Column<decimal>(type: "numeric(8,2)", nullable: false),
ExpectancyEur = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
SharpeRatio = table.Column<decimal>(type: "numeric(8,4)", nullable: false),
ReportJson = table.Column<string>(type: "jsonb", nullable: false),
CreatedAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_simulation_runs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "simulation_strategy_matrix",
columns: table => new
{
Isin = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
StrategyKey = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
Timeframe = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: false),
SampleTradesCount = table.Column<int>(type: "integer", nullable: false),
WinRatePercent = table.Column<decimal>(type: "numeric(6,2)", nullable: false),
ProfitFactor = table.Column<decimal>(type: "numeric(8,4)", nullable: false),
MaxDrawdownPercent = table.Column<decimal>(type: "numeric(6,2)", nullable: false),
ReliabilityScore = table.Column<decimal>(type: "numeric(5,2)", nullable: false),
IsApproved = table.Column<bool>(type: "boolean", nullable: false),
RecommendedAction = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
LastBacktestRunId = table.Column<Guid>(type: "uuid", nullable: true),
UpdatedAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_simulation_strategy_matrix", x => new { x.Isin, x.StrategyKey, x.Timeframe });
});
migrationBuilder.CreateIndex(
name: "IX_DynamicSettings_Key",
table: "DynamicSettings",
column: "Key",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_simulation_runs_CreatedAtUtc",
table: "simulation_runs",
column: "CreatedAtUtc");
migrationBuilder.CreateIndex(
name: "IX_simulation_runs_Isin_StrategyKey_Timeframe",
table: "simulation_runs",
columns: new[] { "Isin", "StrategyKey", "Timeframe" });
migrationBuilder.CreateIndex(
name: "IX_simulation_strategy_matrix_Isin_IsApproved",
table: "simulation_strategy_matrix",
columns: new[] { "Isin", "IsApproved" });
migrationBuilder.CreateIndex(
name: "IX_simulation_strategy_matrix_ReliabilityScore",
table: "simulation_strategy_matrix",
column: "ReliabilityScore");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DynamicSettings");
migrationBuilder.DropTable(
name: "simulation_runs");
migrationBuilder.DropTable(
name: "simulation_strategy_matrix");
}
}
}
@@ -0,0 +1,213 @@
// <auto-generated />
using System;
using FinlyticSimulation.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FinlyticSimulation.Migrations
{
[DbContext(typeof(SimulationDbContext))]
[Migration("20260822095033_AddStrategyParameterProfiles")]
partial class AddStrategyParameterProfiles
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("FinlyticCore.Entities.Settings.SettingEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Key")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("character varying(150)");
b.Property<DateTime>("LastUpdatedUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("ServiceIdentifier")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<string>("ValueJson")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("Key")
.IsUnique();
b.ToTable("DynamicSettings");
});
modelBuilder.Entity("FinlyticSimulation.Database.Entities.SimulationRunEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("CreatedAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("EndDateUtc")
.HasColumnType("timestamp with time zone");
b.Property<decimal>("ExpectancyEur")
.HasColumnType("decimal(18,4)");
b.Property<string>("Isin")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<int>("LosingTrades")
.HasColumnType("integer");
b.Property<decimal>("MaxDrawdownPercent")
.HasColumnType("decimal(6,2)");
b.Property<decimal>("ProfitFactor")
.HasColumnType("decimal(8,4)");
b.Property<string>("ReportJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<decimal>("SharpeRatio")
.HasColumnType("decimal(8,4)");
b.Property<DateTime>("StartDateUtc")
.HasColumnType("timestamp with time zone");
b.Property<decimal>("StartingCapital")
.HasColumnType("decimal(18,4)");
b.Property<string>("StrategyKey")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("Symbol")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)");
b.Property<string>("Timeframe")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("character varying(10)");
b.Property<decimal>("TotalReturnPercent")
.HasColumnType("decimal(8,2)");
b.Property<int>("TotalTrades")
.HasColumnType("integer");
b.Property<decimal>("WinRatePercent")
.HasColumnType("decimal(6,2)");
b.Property<int>("WinningTrades")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("CreatedAtUtc");
b.HasIndex("Isin", "StrategyKey", "Timeframe");
b.ToTable("simulation_runs");
});
modelBuilder.Entity("FinlyticSimulation.Database.Entities.SimulationStrategyMatrixEntity", b =>
{
b.Property<string>("Isin")
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<string>("StrategyKey")
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("Timeframe")
.HasMaxLength(10)
.HasColumnType("character varying(10)");
b.Property<bool>("IsApproved")
.HasColumnType("boolean");
b.Property<Guid?>("LastBacktestRunId")
.HasColumnType("uuid");
b.Property<decimal>("MaxDrawdownPercent")
.HasColumnType("decimal(6,2)");
b.Property<decimal>("ProfitFactor")
.HasColumnType("decimal(8,4)");
b.Property<string>("RecommendedAction")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)");
b.Property<decimal>("ReliabilityScore")
.HasColumnType("decimal(5,2)");
b.Property<int>("SampleTradesCount")
.HasColumnType("integer");
b.Property<DateTime>("UpdatedAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<decimal>("WinRatePercent")
.HasColumnType("decimal(6,2)");
b.HasKey("Isin", "StrategyKey", "Timeframe");
b.HasIndex("ReliabilityScore");
b.HasIndex("Isin", "IsApproved");
b.ToTable("simulation_strategy_matrix");
});
modelBuilder.Entity("FinlyticSimulation.Database.Entities.SimulationStrategyParameterEntity", b =>
{
b.Property<string>("Isin")
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<string>("StrategyKey")
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("Parameters")
.IsRequired()
.HasColumnType("jsonb");
b.Property<DateTime>("UpdatedAtUtc")
.HasColumnType("timestamp with time zone");
b.HasKey("Isin", "StrategyKey");
b.ToTable("simulation_strategy_parameters");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,36 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FinlyticSimulation.Migrations
{
/// <inheritdoc />
public partial class AddStrategyParameterProfiles : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "simulation_strategy_parameters",
columns: table => new
{
Isin = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
StrategyKey = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
Parameters = table.Column<string>(type: "jsonb", nullable: false),
UpdatedAtUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_simulation_strategy_parameters", x => new { x.Isin, x.StrategyKey });
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "simulation_strategy_parameters");
}
}
}
@@ -0,0 +1,210 @@
// <auto-generated />
using System;
using FinlyticSimulation.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace FinlyticSimulation.Migrations
{
[DbContext(typeof(SimulationDbContext))]
partial class SimulationDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("FinlyticCore.Entities.Settings.SettingEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Key")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("character varying(150)");
b.Property<DateTime>("LastUpdatedUtc")
.HasColumnType("timestamp with time zone");
b.Property<string>("ServiceIdentifier")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<string>("ValueJson")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("Key")
.IsUnique();
b.ToTable("DynamicSettings");
});
modelBuilder.Entity("FinlyticSimulation.Database.Entities.SimulationRunEntity", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("CreatedAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("EndDateUtc")
.HasColumnType("timestamp with time zone");
b.Property<decimal>("ExpectancyEur")
.HasColumnType("decimal(18,4)");
b.Property<string>("Isin")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<int>("LosingTrades")
.HasColumnType("integer");
b.Property<decimal>("MaxDrawdownPercent")
.HasColumnType("decimal(6,2)");
b.Property<decimal>("ProfitFactor")
.HasColumnType("decimal(8,4)");
b.Property<string>("ReportJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<decimal>("SharpeRatio")
.HasColumnType("decimal(8,4)");
b.Property<DateTime>("StartDateUtc")
.HasColumnType("timestamp with time zone");
b.Property<decimal>("StartingCapital")
.HasColumnType("decimal(18,4)");
b.Property<string>("StrategyKey")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("Symbol")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)");
b.Property<string>("Timeframe")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("character varying(10)");
b.Property<decimal>("TotalReturnPercent")
.HasColumnType("decimal(8,2)");
b.Property<int>("TotalTrades")
.HasColumnType("integer");
b.Property<decimal>("WinRatePercent")
.HasColumnType("decimal(6,2)");
b.Property<int>("WinningTrades")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("CreatedAtUtc");
b.HasIndex("Isin", "StrategyKey", "Timeframe");
b.ToTable("simulation_runs");
});
modelBuilder.Entity("FinlyticSimulation.Database.Entities.SimulationStrategyMatrixEntity", b =>
{
b.Property<string>("Isin")
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<string>("StrategyKey")
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("Timeframe")
.HasMaxLength(10)
.HasColumnType("character varying(10)");
b.Property<bool>("IsApproved")
.HasColumnType("boolean");
b.Property<Guid?>("LastBacktestRunId")
.HasColumnType("uuid");
b.Property<decimal>("MaxDrawdownPercent")
.HasColumnType("decimal(6,2)");
b.Property<decimal>("ProfitFactor")
.HasColumnType("decimal(8,4)");
b.Property<string>("RecommendedAction")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("character varying(30)");
b.Property<decimal>("ReliabilityScore")
.HasColumnType("decimal(5,2)");
b.Property<int>("SampleTradesCount")
.HasColumnType("integer");
b.Property<DateTime>("UpdatedAtUtc")
.HasColumnType("timestamp with time zone");
b.Property<decimal>("WinRatePercent")
.HasColumnType("decimal(6,2)");
b.HasKey("Isin", "StrategyKey", "Timeframe");
b.HasIndex("ReliabilityScore");
b.HasIndex("Isin", "IsApproved");
b.ToTable("simulation_strategy_matrix");
});
modelBuilder.Entity("FinlyticSimulation.Database.Entities.SimulationStrategyParameterEntity", b =>
{
b.Property<string>("Isin")
.HasMaxLength(20)
.HasColumnType("character varying(20)");
b.Property<string>("StrategyKey")
.HasMaxLength(50)
.HasColumnType("character varying(50)");
b.Property<string>("Parameters")
.IsRequired()
.HasColumnType("jsonb");
b.Property<DateTime>("UpdatedAtUtc")
.HasColumnType("timestamp with time zone");
b.HasKey("Isin", "StrategyKey");
b.ToTable("simulation_strategy_parameters");
});
#pragma warning restore 612, 618
}
}
}