feat: 搭建回测流程
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package com.lanyuanxiaoyao.leopard.core.strategy;
|
||||
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.Daily;
|
||||
import com.lanyuanxiaoyao.leopard.core.repository.DailyRepository;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 交易策略
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20251016
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TradeEngine {
|
||||
private final DailyRepository dailyRepository;
|
||||
|
||||
public TradeEngine(DailyRepository dailyRepository) {
|
||||
this.dailyRepository = dailyRepository;
|
||||
}
|
||||
|
||||
public void backtest(List<Long> stocks, TradeStrategy strategy) {
|
||||
}
|
||||
|
||||
public interface TradeStrategy {
|
||||
List<Trade> trade(LocalDate now, Asset asset, Map<Long, List<Daily>> dailies);
|
||||
}
|
||||
|
||||
public record Asset(
|
||||
Double cash,
|
||||
Map<Long, Double> stocks
|
||||
) {
|
||||
public Asset() {
|
||||
this(0.0, new HashMap<>());
|
||||
}
|
||||
}
|
||||
|
||||
public record Trade(
|
||||
Long stockId,
|
||||
// 用正负数表达买卖
|
||||
Integer volume
|
||||
) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user