浏览代码

Enhance P&L reporting by incorporating Return on Equity (ROE) calculations across multiple modules.

- Added ROE calculations to telegram_bot.py, external_event_monitor.py, simple_position_tracker.py, and notification_manager.py for improved performance insights.
- Updated P&L messages to display ROE alongside realized P&L, providing clearer metrics for users.
- Ensured consistency in ROE calculations across different components to enhance overall reporting accuracy.
Carles Sentis 1 周之前
父节点
当前提交
d6a9a8bc70

+ 10 - 2
src/backup/telegram_bot.py

@@ -3081,6 +3081,10 @@ This will place a limit {exit_side} order at ${profit_price:,.2f} to capture pro
         pnl_percent = pnl_data['pnl_percent']
         pnl_percent = pnl_data['pnl_percent']
         pnl_emoji = "🟢" if pnl >= 0 else "🔴"
         pnl_emoji = "🟢" if pnl >= 0 else "🔴"
         
         
+        # Calculate ROE (Return on Equity) for partial close
+        cost_basis = amount * avg_entry
+        roe = (pnl / cost_basis) * 100 if cost_basis > 0 else 0
+        
         partial_value = amount * price
         partial_value = amount * price
         
         
         message = f"""
         message = f"""
@@ -3096,7 +3100,7 @@ This will place a limit {exit_side} order at ${profit_price:,.2f} to capture pro
 {pnl_emoji} <b>Partial P&L:</b>
 {pnl_emoji} <b>Partial P&L:</b>
 • Entry Price: ${avg_entry:,.2f}
 • Entry Price: ${avg_entry:,.2f}
 • Exit Value: ${partial_value:,.2f}
 • Exit Value: ${partial_value:,.2f}
-• P&L: ${pnl:,.2f} ({pnl_percent:+.2f}%)
+• P&L: ${pnl:,.2f} ({roe:+.2f}% ROE)
 • Result: {"PROFIT" if pnl >= 0 else "LOSS"}
 • Result: {"PROFIT" if pnl >= 0 else "LOSS"}
 
 
 💰 <b>Position Status:</b>
 💰 <b>Position Status:</b>
@@ -3119,6 +3123,10 @@ This will place a limit {exit_side} order at ${profit_price:,.2f} to capture pro
         pnl_percent = pnl_data['pnl_percent']
         pnl_percent = pnl_data['pnl_percent']
         pnl_emoji = "🟢" if pnl >= 0 else "🔴"
         pnl_emoji = "🟢" if pnl >= 0 else "🔴"
         
         
+        # Calculate ROE (Return on Equity) for consistency
+        cost_basis = amount * avg_entry
+        roe = (pnl / cost_basis) * 100 if cost_basis > 0 else 0
+        
         entry_count = position.get('entry_count', 1)
         entry_count = position.get('entry_count', 1)
         exit_value = amount * price
         exit_value = amount * price
         
         
@@ -3134,7 +3142,7 @@ This will place a limit {exit_side} order at ${profit_price:,.2f} to capture pro
 • Exit Value: ${exit_value:,.2f}
 • Exit Value: ${exit_value:,.2f}
 
 
 {pnl_emoji} <b>Total P&L:</b>
 {pnl_emoji} <b>Total P&L:</b>
-• P&L: ${pnl:,.2f} ({pnl_percent:+.2f}%)
+• P&L: ${pnl:,.2f} ({roe:+.2f}% ROE)
 • Result: {"PROFIT" if pnl >= 0 else "LOSS"}
 • Result: {"PROFIT" if pnl >= 0 else "LOSS"}
 • Entry Points Used: {entry_count}
 • Entry Points Used: {entry_count}
 
 

+ 16 - 2
src/monitoring/external_event_monitor.py

@@ -221,6 +221,13 @@ class ExternalEventMonitor:
                 pnl_emoji = "🟢" if realized_pnl and realized_pnl >= 0 else "🔴"
                 pnl_emoji = "🟢" if realized_pnl and realized_pnl >= 0 else "🔴"
                 pnl_text = f"{formatter.format_price_with_symbol(realized_pnl)}" if realized_pnl is not None else "N/A"
                 pnl_text = f"{formatter.format_price_with_symbol(realized_pnl)}" if realized_pnl is not None else "N/A"
                 
                 
+                # Calculate ROE (Return on Equity)
+                roe_text = ""
+                if realized_pnl is not None and entry_price > 0 and amount_from_fill > 0:
+                    cost_basis = amount_from_fill * entry_price
+                    roe = (realized_pnl / cost_basis) * 100
+                    roe_text = f" ({roe:+.2f}%)"
+                
                 message = f"""
                 message = f"""
 🎯 <b>Position Closed (External)</b>
 🎯 <b>Position Closed (External)</b>
 
 
@@ -232,7 +239,7 @@ class ExternalEventMonitor:
 • Exit Price: {formatter.format_price_with_symbol(price_from_fill, token)}
 • Exit Price: {formatter.format_price_with_symbol(price_from_fill, token)}
 • Exit Value: {formatter.format_price_with_symbol(amount_from_fill * price_from_fill)}
 • Exit Value: {formatter.format_price_with_symbol(amount_from_fill * price_from_fill)}
 
 
-{pnl_emoji} <b>P&L:</b> {pnl_text}
+{pnl_emoji} <b>P&L:</b> {pnl_text}{roe_text}
 ✅ <b>Status:</b> {position_side} position closed externally
 ✅ <b>Status:</b> {position_side} position closed externally
 ⏰ <b>Time:</b> {time_str}
 ⏰ <b>Time:</b> {time_str}
 
 
@@ -299,6 +306,13 @@ class ExternalEventMonitor:
                 
                 
                 pnl_emoji = "🟢" if partial_pnl >= 0 else "🔴"
                 pnl_emoji = "🟢" if partial_pnl >= 0 else "🔴"
                 
                 
+                # Calculate ROE for the partial close
+                roe_text = ""
+                if entry_price > 0 and amount_from_fill > 0:
+                    cost_basis = amount_from_fill * entry_price
+                    roe = (partial_pnl / cost_basis) * 100
+                    roe_text = f" ({roe:+.2f}%)"
+                
                 message = f"""
                 message = f"""
 📉 <b>Position Decreased (External)</b>
 📉 <b>Position Decreased (External)</b>
 
 
@@ -311,7 +325,7 @@ class ExternalEventMonitor:
 • Remaining Size: {formatter.format_amount(current_size, token)}
 • Remaining Size: {formatter.format_amount(current_size, token)}
 • Exit Value: {formatter.format_price_with_symbol(amount_from_fill * price_from_fill)}
 • Exit Value: {formatter.format_price_with_symbol(amount_from_fill * price_from_fill)}
 
 
-{pnl_emoji} <b>Partial P&L:</b> {formatter.format_price_with_symbol(partial_pnl)}
+{pnl_emoji} <b>Partial P&L:</b> {formatter.format_price_with_symbol(partial_pnl)}{roe_text}
 📉 <b>Status:</b> {position_side} position size decreased externally  
 📉 <b>Status:</b> {position_side} position size decreased externally  
 ⏰ <b>Time:</b> {time_str}
 ⏰ <b>Time:</b> {time_str}
 
 

+ 9 - 1
src/monitoring/simple_position_tracker.py

@@ -459,6 +459,14 @@ class SimplePositionTracker:
                 pnl = details['realized_pnl']
                 pnl = details['realized_pnl']
                 pnl_emoji = "🟢" if pnl >= 0 else "🔴"
                 pnl_emoji = "🟢" if pnl >= 0 else "🔴"
                 
                 
+                # Calculate ROE (Return on Equity)
+                roe = 0
+                if entry_price > 0 and size > 0:
+                    cost_basis = size * entry_price
+                    roe = (pnl / cost_basis) * 100
+                
+                roe_text = f"({roe:+.2f}%)" if entry_price > 0 else ""
+                
                 message = f"""🎯 <b>Position Closed</b>
                 message = f"""🎯 <b>Position Closed</b>
 
 
 📊 <b>Details:</b>
 📊 <b>Details:</b>
@@ -468,7 +476,7 @@ class SimplePositionTracker:
 • Entry: {formatter.format_price_with_symbol(entry_price, token)}
 • Entry: {formatter.format_price_with_symbol(entry_price, token)}
 • Exit: {formatter.format_price_with_symbol(exit_price, token)}
 • Exit: {formatter.format_price_with_symbol(exit_price, token)}
 
 
-{pnl_emoji} <b>P&L:</b> {formatter.format_price_with_symbol(pnl)}
+{pnl_emoji} <b>P&L:</b> {formatter.format_price_with_symbol(pnl)} {roe_text}
 
 
 ⏰ <b>Time:</b> {time_str}
 ⏰ <b>Time:</b> {time_str}
 📊 Use /stats to view performance"""
 📊 Use /stats to view performance"""

+ 10 - 2
src/notifications/notification_manager.py

@@ -430,12 +430,16 @@ class NotificationManager:
                     pnl = amount * (entry_price - price) 
                     pnl = amount * (entry_price - price) 
                     pnl_percent = ((entry_price - price) / entry_price) * 100
                     pnl_percent = ((entry_price - price) / entry_price) * 100
                 
                 
+                # Calculate ROE (Return on Equity) more clearly
+                cost_basis = amount * entry_price
+                roe = (pnl / cost_basis) * 100
+                
                 pnl_emoji = "🟢" if pnl >= 0 else "🔴"
                 pnl_emoji = "🟢" if pnl >= 0 else "🔴"
                 pnl_info = f"""
                 pnl_info = f"""
 {pnl_emoji} <b>Stop Loss P&L:</b>
 {pnl_emoji} <b>Stop Loss P&L:</b>
 • Entry Price: ${entry_price:,.2f}
 • Entry Price: ${entry_price:,.2f}
 • Exit Price: ${price:,.2f}
 • Exit Price: ${price:,.2f}
-• Realized P&L: ${pnl:,.2f} ({pnl_percent:+.2f}%)
+• Realized P&L: ${pnl:,.2f} ({roe:+.2f}% ROE)
 • Result: {"PROFIT" if pnl >= 0 else "LOSS PREVENTION"}"""
 • Result: {"PROFIT" if pnl >= 0 else "LOSS PREVENTION"}"""
 
 
             # Determine stop loss effectiveness
             # Determine stop loss effectiveness
@@ -516,12 +520,16 @@ class NotificationManager:
                     pnl = amount * (entry_price - price)
                     pnl = amount * (entry_price - price)
                     pnl_percent = ((entry_price - price) / entry_price) * 100 if entry_price != 0 else 0
                     pnl_percent = ((entry_price - price) / entry_price) * 100 if entry_price != 0 else 0
                 
                 
+                # Calculate ROE (Return on Equity) more clearly
+                cost_basis = amount * entry_price
+                roe = (pnl / cost_basis) * 100
+                
                 pnl_emoji = "🟢" if pnl >= 0 else "🔴"
                 pnl_emoji = "🟢" if pnl >= 0 else "🔴"
                 pnl_info = f"""
                 pnl_info = f"""
 {pnl_emoji} <b>Take Profit P&L:</b>
 {pnl_emoji} <b>Take Profit P&L:</b>
 • Entry Price: {formatter.format_price_with_symbol(entry_price, token)}
 • Entry Price: {formatter.format_price_with_symbol(entry_price, token)}
 • Exit Price: {formatter.format_price_with_symbol(price, token)}
 • Exit Price: {formatter.format_price_with_symbol(price, token)}
-• Realized P&L: {formatter.format_price_with_symbol(pnl)} ({pnl_percent:+.2f}%)
+• Realized P&L: {formatter.format_price_with_symbol(pnl)} ({roe:+.2f}% ROE)
 • Result: {"PROFIT SECURED" if pnl >=0 else "MINIMIZED LOSS"}"""
 • Result: {"PROFIT SECURED" if pnl >=0 else "MINIMIZED LOSS"}"""
             
             
             trade_value = amount * price
             trade_value = amount * price

+ 1 - 1
trading_bot.py

@@ -14,7 +14,7 @@ from datetime import datetime
 from pathlib import Path
 from pathlib import Path
 
 
 # Bot version
 # Bot version
-BOT_VERSION = "2.3.174"
+BOT_VERSION = "2.3.175"
 
 
 # Add src directory to Python path
 # Add src directory to Python path
 sys.path.insert(0, str(Path(__file__).parent / "src"))
 sys.path.insert(0, str(Path(__file__).parent / "src"))