fix prediction candles updates. fix for trend prediction.

This commit is contained in:
Dobromir Popov
2025-11-22 19:25:27 +02:00
parent 44379ae2e4
commit 20fe481ec5
6 changed files with 461 additions and 24 deletions

View File

@@ -1615,29 +1615,41 @@ class RealTrainingAdapter:
# FIXED: Ensure shape is [1, 1] not [1] to match BCELoss requirements
trade_success = torch.tensor([[1.0 if profit_loss_pct > 0 else 0.0]], dtype=torch.float32) # [1, 1]
# NEW: Trend vector target for trend analysis optimization
# Calculate expected trend from entry to exit
direction = training_sample.get('direction', 'NONE')
# REAL TREND CALCULATION from actual price data (NO MORE SYNTHETIC DATA!)
# Use last 10 candles to calculate actual trend angle, steepness, direction
if direction == 'LONG':
# Upward trend: positive angle, positive direction
trend_angle = 0.785 # ~45 degrees in radians (pi/4)
trend_direction = 1.0 # Upward
elif direction == 'SHORT':
# Downward trend: negative angle, negative direction
trend_angle = -0.785 # ~-45 degrees
trend_direction = -1.0 # Downward
# Get price data from the batch to calculate actual trend
price_data = price_data_1m if price_data_1m is not None else (
price_data_1s if price_data_1s is not None else price_data_1h)
if price_data is not None and price_data.shape[1] >= 10:
# price_data shape: [batch=1, seq_len=200, features=5] -> OHLCV
recent_closes = price_data[0, -10:, 3] # Last 10 close prices [10]
# Calculate actual price change and time delta
price_start = recent_closes[0].item()
price_end = recent_closes[-1].item()
price_delta = price_end - price_start
time_delta = 9.0 # 10 candles = 9 intervals
# Calculate real angle using atan2
import math
trend_angle = math.atan2(price_delta, time_delta * price_start / 100.0) # Normalize by price scale
# Calculate real steepness (magnitude of change)
if price_start > 0:
price_change_pct = abs(price_delta / price_start)
trend_steepness = min(price_change_pct * 100.0, 1.0) # Scale and cap at 1.0
else:
trend_steepness = 0.0
# Calculate real direction
trend_direction = 1.0 if price_delta > 0 else (-1.0 if price_delta < 0 else 0.0)
else:
# No trend
# Fallback if no price data available (should rarely happen)
trend_angle = 0.0
trend_direction = 0.0
# Steepness based on profit potential
if exit_price and entry_price and entry_price > 0:
price_change_pct = abs((exit_price - entry_price) / entry_price)
trend_steepness = min(price_change_pct * 10, 1.0) # Normalize to [0, 1]
else:
trend_steepness = 0.0
trend_direction = 0.0
# Create trend target tensor [batch, 3]: [angle, steepness, direction]
trend_target = torch.tensor([[trend_angle, trend_steepness, trend_direction]], dtype=torch.float32) # [1, 3]