refactor: Improve numeric output readability with rounding and formatting
This commit is contained in:
parent
6ca78eb83f
commit
4a3464b2d9
@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import numpy as np
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from db.db_connection import create_client
|
from db.db_connection import create_client
|
||||||
@ -356,7 +357,10 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf
|
|||||||
entry_price=last_day['close'],
|
entry_price=last_day['close'],
|
||||||
target_price=results['upper_band'].iloc[-1]
|
target_price=results['upper_band'].iloc[-1]
|
||||||
)
|
)
|
||||||
print(f"Debug: Position calculation result: {position}") # Debug line
|
# Format debug position output with rounded values
|
||||||
|
debug_position = {k: round(float(v), 2) if isinstance(v, (float, np.float64)) else v
|
||||||
|
for k, v in position.items()}
|
||||||
|
print(f"Debug: Position calculation result: {debug_position}") # Debug line
|
||||||
signal_data.update({
|
signal_data.update({
|
||||||
'shares': position['shares'],
|
'shares': position['shares'],
|
||||||
'position_value': position['position_value'],
|
'position_value': position['position_value'],
|
||||||
@ -416,17 +420,17 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf
|
|||||||
print(f"Target (Upper Band): ${signal['upper_band']:.2f}")
|
print(f"Target (Upper Band): ${signal['upper_band']:.2f}")
|
||||||
|
|
||||||
if 'shares' in signal:
|
if 'shares' in signal:
|
||||||
# Convert numpy float64 to regular float if needed
|
# Convert numpy float64 to regular float and round to 2 decimal places
|
||||||
position_value = float(signal['position_value'])
|
position_value = round(float(signal['position_value']), 2)
|
||||||
stop_loss = float(signal['stop_loss'])
|
stop_loss = round(float(signal['stop_loss']), 2)
|
||||||
potential_loss = float(signal['potential_loss'])
|
potential_loss = round(float(signal['potential_loss']), 2)
|
||||||
potential_profit = float(signal['potential_profit'])
|
potential_profit = round(float(signal['potential_profit']), 2)
|
||||||
risk_reward = float(signal['risk_reward_ratio'])
|
risk_reward = round(float(signal['risk_reward_ratio']), 2)
|
||||||
target_price = float(signal['upper_band']) # Use upper band as target
|
target_price = round(float(signal['upper_band']), 2)
|
||||||
|
|
||||||
# Calculate percentage gains/losses
|
# Calculate percentage gains/losses and round to 1 decimal place
|
||||||
profit_percentage = (potential_profit / position_value) * 100
|
profit_percentage = round((potential_profit / position_value) * 100, 1)
|
||||||
loss_percentage = (abs(potential_loss) / position_value) * 100
|
loss_percentage = round((abs(potential_loss) / position_value) * 100, 1)
|
||||||
|
|
||||||
print("\nPosition Details:")
|
print("\nPosition Details:")
|
||||||
print(f"Shares: {signal['shares']:,}")
|
print(f"Shares: {signal['shares']:,}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user