From 6ca78eb83fffdc70f9fea73dc10c4f771be84fd0 Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Thu, 6 Feb 2025 22:55:12 -0800 Subject: [PATCH] refactor: Convert numpy float64 values to Python floats in position calculation --- src/trading/position_calculator.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/trading/position_calculator.py b/src/trading/position_calculator.py index e5ea7f3..bc62d0e 100644 --- a/src/trading/position_calculator.py +++ b/src/trading/position_calculator.py @@ -24,13 +24,13 @@ class PositionCalculator: dict: Position details including shares and dollar amounts """ # Calculate stop loss price (6% below entry) - stop_loss = entry_price * (1 - self.stop_loss_percentage) + stop_loss = float(entry_price * (1 - self.stop_loss_percentage)) # Calculate risk amount in dollars - risk_amount = self.account_size * self.risk_percentage + risk_amount = float(self.account_size * self.risk_percentage) # Calculate per-share risk - risk_per_share = abs(entry_price - stop_loss) + risk_per_share = float(abs(entry_price - stop_loss)) if risk_per_share == 0: raise ValueError("Entry price cannot equal stop loss price") @@ -39,7 +39,7 @@ class PositionCalculator: shares = int(risk_amount / risk_per_share) # Calculate total position value - position_value = shares * entry_price + position_value = float(shares * entry_price) result = { "shares": shares, @@ -47,15 +47,16 @@ class PositionCalculator: "risk_amount": risk_amount, "risk_per_share": risk_per_share, "stop_loss": stop_loss, - "potential_loss": shares * (stop_loss - entry_price) + "potential_loss": float(shares * (stop_loss - entry_price)) } # Add target price calculations if provided if target_price: + target_price = float(target_price) result.update({ "target_price": target_price, - "potential_profit": shares * (target_price - entry_price), - "risk_reward_ratio": abs((target_price - entry_price) / (entry_price - stop_loss)) + "potential_profit": float(shares * (target_price - entry_price)), + "risk_reward_ratio": float(abs((target_price - entry_price) / (entry_price - stop_loss))) }) return result