实现策略引擎核心功能,包括三种策略计算器和相关DTO定义: 1. 添加双均线策略(ma_trend)计算器 2. 添加吊灯止损策略(chandelier_exit)计算器 3. 添加风险平价策略(risk_parity)计算器 4. 定义策略类型常量类和策略配置DTO 5. 实现策略引擎服务接口和扩展方法 6. 更新项目引用和README文档
55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using AssetManager.Data;
|
|
using AssetManager.Models.DTOs;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace AssetManager.Infrastructure.StrategyEngine.Calculators;
|
|
|
|
/// <summary>
|
|
/// 吊灯止损策略计算器
|
|
/// </summary>
|
|
public class ChandelierExitCalculator : IStrategyCalculator
|
|
{
|
|
private readonly ILogger<ChandelierExitCalculator> _logger;
|
|
|
|
public string StrategyType => AssetManager.Models.DTOs.StrategyType.ChandelierExit;
|
|
|
|
public ChandelierExitCalculator(ILogger<ChandelierExitCalculator> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task<StrategySignal> CalculateAsync(
|
|
string configJson,
|
|
List<Position> positions,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
_logger.LogInformation("计算吊灯止损策略信号");
|
|
|
|
var config = System.Text.Json.JsonSerializer.Deserialize<ChandelierExitConfig>(configJson, new System.Text.Json.JsonSerializerOptions
|
|
{
|
|
PropertyNameCaseInsensitive = true
|
|
}) ?? new ChandelierExitConfig();
|
|
|
|
if (positions.Count == 0)
|
|
{
|
|
return new StrategySignal
|
|
{
|
|
StrategyType = StrategyType,
|
|
Signal = "HOLD",
|
|
Reason = "无持仓",
|
|
GeneratedAt = DateTime.UtcNow
|
|
};
|
|
}
|
|
|
|
// 简单实现:返回持有信号
|
|
await Task.Delay(1, cancellationToken);
|
|
|
|
return new StrategySignal
|
|
{
|
|
StrategyType = StrategyType,
|
|
Signal = "HOLD",
|
|
Reason = "吊灯止损策略暂未实现",
|
|
GeneratedAt = DateTime.UtcNow
|
|
};
|
|
}
|
|
} |