* Start building with orlean * Add missing file * Serialize grain state * Remove grain and proxies * update and add plan * Update a bit * Fix backtest grain * Fix backtest grain * Clean a bit
57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using Managing.Domain.Strategies;
|
|
using Orleans;
|
|
|
|
namespace Managing.Domain.Scenarios;
|
|
|
|
/// <summary>
|
|
/// Lightweight scenario class for Orleans serialization
|
|
/// Contains only the essential properties needed for backtesting
|
|
/// </summary>
|
|
[GenerateSerializer]
|
|
public class LightScenario
|
|
{
|
|
public LightScenario(string name, int? loopbackPeriod = 1)
|
|
{
|
|
Name = name;
|
|
Indicators = new List<LightIndicator>();
|
|
LoopbackPeriod = loopbackPeriod;
|
|
}
|
|
|
|
[Id(0)] public string Name { get; set; }
|
|
|
|
[Id(1)] public List<LightIndicator> Indicators { get; set; }
|
|
|
|
[Id(2)] public int? LoopbackPeriod { get; set; }
|
|
|
|
/// <summary>
|
|
/// Converts a full Scenario to a LightScenario
|
|
/// </summary>
|
|
public static LightScenario FromScenario(Scenario scenario)
|
|
{
|
|
var lightScenario = new LightScenario(scenario.Name, scenario.LoopbackPeriod)
|
|
{
|
|
Indicators = scenario.Indicators?.Select(LightIndicator.FromIndicator).ToList() ??
|
|
new List<LightIndicator>()
|
|
};
|
|
return lightScenario;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a LightScenario back to a full Scenario
|
|
/// </summary>
|
|
public Scenario ToScenario()
|
|
{
|
|
var scenario = new Scenario(Name, LoopbackPeriod)
|
|
{
|
|
Indicators = Indicators?.Select(li => li.ToIndicator()).ToList() ?? new List<Indicator>()
|
|
};
|
|
return scenario;
|
|
}
|
|
|
|
public void AddIndicator(LightIndicator indicator)
|
|
{
|
|
if (Indicators == null)
|
|
Indicators = new List<LightIndicator>();
|
|
Indicators.Add(indicator);
|
|
}
|
|
} |