import pandas as pd

df = pd.read_csv('cyb50_optimized_trades_2017-06-01_2026-01-19.csv')

print('净值一致性分析:')
print('='*80)

# 计算交易累计盈亏
total_trading_pnl = df['盈亏金额'].sum()

# 计算最终净值变化
initial_capital = 1000000
final_net_value = df.iloc[-1]['平仓时总资金']
net_value_change = final_net_value - initial_capital

print(f'初始资金: {initial_capital:,.2f}元')
print(f'最终资金: {final_net_value:,.2f}元')
print(f'净值变化: {net_value_change:,.2f}元')
print(f'交易累计盈亏: {total_trading_pnl:,.2f}元')
print(f'差异: {abs(total_trading_pnl - net_value_change):,.2f}元')

print(f'\n详细分析:')
print('='*80)

# 分析每一笔交易的资金变化
print('前10笔交易的详细资金分析:')
for i in range(min(10, len(df))):
    trade = df.iloc[i]
    print(f"\n交易#{i+1}:")
    print(f"  开仓时资金: {trade['开仓时总资金']:,.2f}元")
    print(f"  平仓时资金: {trade['平仓时总资金']:,.2f}元")
    print(f"  记录盈亏: {trade['盈亏金额']:,.2f}元")
    print(f"  计算盈亏: {trade['平仓时总资金'] - trade['开仓时总资金']:,.2f}元")
    print(f"  盈亏差异: {trade['盈亏金额'] - (trade['平仓时总资金'] - trade['开仓时总资金']):,.2f}元")