it might be better

This commit is contained in:
zastian-dev
2026-02-13 13:43:42 +00:00
parent 1ef03999b7
commit 798c3eafd5
3 changed files with 13 additions and 11 deletions

View File

@@ -199,12 +199,12 @@ impl Backtester {
let shares =
self.strategy
.calculate_position_size(price, portfolio_value, available_cash, signal);
if shares == 0 {
if shares <= 0.0 {
return false;
}
let fill_price = Self::apply_slippage(price, "buy");
let cost = shares as f64 * fill_price;
let cost = shares * fill_price;
if cost > self.cash {
return false;
}
@@ -214,7 +214,7 @@ impl Backtester {
symbol.to_string(),
BacktestPosition {
symbol: symbol.to_string(),
shares: shares as f64,
shares: shares,
entry_price: fill_price,
entry_time: timestamp,
entry_atr: signal.atr,
@@ -229,7 +229,7 @@ impl Backtester {
self.trades.push(Trade {
symbol: symbol.to_string(),
side: "BUY".to_string(),
shares: shares as f64,
shares: shares,
price: fill_price,
timestamp,
pnl: 0.0,