it might be better
This commit is contained in:
@@ -33,9 +33,9 @@ impl Strategy {
|
||||
portfolio_value: f64,
|
||||
available_cash: f64,
|
||||
signal: &TradeSignal,
|
||||
) -> u64 {
|
||||
) -> f64 {
|
||||
if available_cash <= 0.0 {
|
||||
return 0;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
let position_value = if signal.atr_pct > MIN_ATR_PCT {
|
||||
@@ -51,7 +51,9 @@ impl Strategy {
|
||||
};
|
||||
|
||||
let position_value = position_value.min(available_cash);
|
||||
(position_value / price).floor() as u64
|
||||
// Use fractional shares — Alpaca supports them for paper trading.
|
||||
// Truncate to 4 decimal places to avoid floating point dust.
|
||||
((position_value / price) * 10000.0).floor() / 10000.0
|
||||
}
|
||||
|
||||
/// Check if stop-loss, trailing stop, or time exit should trigger.
|
||||
|
||||
Reference in New Issue
Block a user