Spaces:
Running
Running
File size: 3,345 Bytes
da0ce7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | from aureon_baton_link import link_system as _baton_link; _baton_link(__name__)
import sys
from aureon_kraken_ecosystem import AureonKrakenEcosystem, CONFIG
print("🧮 Verifying PnL Accounting Logic...")
# Initialize Bot in Dry Run
bot = AureonKrakenEcosystem(initial_balance=1000.0, dry_run=True)
# Define Trade Parameters
symbol = "ETHGBP"
entry_price = 2000.0
investment = 100.0 # £100 investment
exit_price = 2040.0 # +2% gain
# 1. Simulate BUY
print(f"\n1. Simulating BUY of {symbol}...")
print(f" Investment: £{investment:.2f}")
print(f" Entry Price: £{entry_price:.2f}")
# Calculate expected entry values
entry_fee_rate = CONFIG['KRAKEN_FEE'] # 0.0026
entry_fee = investment * entry_fee_rate
net_investment = investment # In this bot logic, pos_size is the total value, fee is tracked separately usually or deducted.
# Let's look at open_position logic:
# entry_fee = pos_size * CONFIG['KRAKEN_FEE']
# quantity = pos_size / price
quantity = investment / entry_price
print(f" Quantity: {quantity:.6f} ETH")
print(f" Entry Fee ({entry_fee_rate*100}%): £{entry_fee:.4f}")
# Manually inject position into bot
from aureon_kraken_ecosystem import Position
import time
bot.positions[symbol] = Position(
symbol=symbol,
entry_price=entry_price,
quantity=quantity,
entry_fee=entry_fee,
entry_value=investment,
momentum=10.0,
coherence=0.8,
entry_time=time.time(),
dominant_node="TestNode"
)
# 2. Simulate SELL
print(f"\n2. Simulating SELL at £{exit_price:.2f} (+2%)...")
# Calculate expected exit values manually using combined rate
# This matches the penny profit formula which uses (1-f)² where f = fee + slippage + spread
exit_value = quantity * exit_price
gross_pnl = exit_value - investment
fee_rate = CONFIG['KRAKEN_FEE']
slippage_rate = CONFIG['SLIPPAGE_PCT']
spread_rate = CONFIG.get('SPREAD_COST_PCT', 0.001)
total_rate = fee_rate + slippage_rate + spread_rate # Combined rate per leg
exit_fee = exit_value * total_rate # Exit uses combined rate
total_expenses = entry_fee + exit_fee # Both legs use combined rate
net_pnl = gross_pnl - total_expenses
print(f" Exit Value: £{exit_value:.4f}")
print(f" Gross PnL: £{gross_pnl:.4f}")
print(f" Combined Rate per leg: {total_rate*100:.2f}%")
print(f" Expected Exit Fee: £{exit_fee:.4f}")
print(f" Total Expenses: £{total_expenses:.4f}")
print(f" Expected NET PnL: £{net_pnl:.4f}")
# 3. Execute Bot Logic
print("\n3. Executing Bot Close Logic...")
# Capture stdout to see the bot's report
from io import StringIO
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
bot.close_position(symbol, "TEST_SELL", 2.0, exit_price)
sys.stdout = old_stdout
bot_output = mystdout.getvalue()
print(bot_output)
# 4. Verify
print("\n4. Verification Results:")
# Parse bot output for Net PnL
import re
match = re.search(r"Net: [£$€]([+\-0-9.]+)", bot_output)
if match:
bot_net_pnl = float(match.group(1))
diff = abs(bot_net_pnl - net_pnl)
if diff < 0.01:
print(f"✅ SUCCESS: Bot PnL (£{bot_net_pnl:.4f}) matches manual calc (£{net_pnl:.4f})")
else:
print(f"❌ FAILURE: Mismatch! Bot: {bot_net_pnl}, Manual: {net_pnl}")
else:
print("❌ Could not parse Bot output.")
|