Spaces:
Sleeping
Sleeping
| package com.rods.backtestingstrategies.entity; | |
| import jakarta.persistence.*; | |
| import lombok.*; | |
| import java.time.LocalDate; | |
| // JPA requirement | |
| // Force factory usage | |
| public class TradeSignal { | |
| private Long id; | |
| // Date on which signal is generated | |
| private LocalDate signalDate; | |
| private SignalType signalType; | |
| // Price at signal generation (usually close price) | |
| private double price; | |
| // Optional: identify which strategy generated this signal | |
| private String strategyName; | |
| /* ========================== | |
| Factory Methods | |
| ========================== */ | |
| public static TradeSignal buy(Candle candle) { | |
| return new TradeSignal( | |
| null, | |
| candle.getDate(), | |
| SignalType.BUY, | |
| candle.getClosePrice(), | |
| null | |
| ); | |
| } | |
| public static TradeSignal sell(Candle candle) { | |
| return new TradeSignal( | |
| null, | |
| candle.getDate(), | |
| SignalType.SELL, | |
| candle.getClosePrice(), | |
| null | |
| ); | |
| } | |
| public static TradeSignal hold() { | |
| return new TradeSignal( | |
| null, | |
| null, | |
| SignalType.HOLD, | |
| 0.0, | |
| null | |
| ); | |
| } | |
| /* ========================== | |
| Optional helpers | |
| ========================== */ | |
| public TradeSignal withStrategyName(String strategyName) { | |
| this.strategyName = strategyName; | |
| return this; | |
| } | |
| } | |