final_summary.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import pandas as pd
  2. # 读取交易数据
  3. df = pd.read_csv('cyb50_optimized_trades_2017-06-01_2026-01-19.csv')
  4. print("Bug修复效果总结:")
  5. print("=" * 80)
  6. # 计算交易次数
  7. total_trades = len(df)
  8. print(f"总交易次数: {total_trades}")
  9. # 计算总体盈亏
  10. total_pnl = df['盈亏金额'].sum()
  11. print(f"累计盈亏: {total_pnl:,.2f}元")
  12. # 计算胜率
  13. winning_trades = len(df[df['盈亏金额'] > 0])
  14. win_rate = winning_trades / total_trades
  15. print(f"胜率: {win_rate:.2%} ({winning_trades}/{total_trades})")
  16. # 计算平均盈亏
  17. avg_pnl = df['盈亏金额'].mean()
  18. print(f"平均盈亏: {avg_pnl:,.2f}元")
  19. # 计算盈亏比
  20. avg_win = df[df['盈亏金额'] > 0]['盈亏金额'].mean()
  21. avg_loss = df[df['盈亏金额'] < 0]['盈亏金额'].mean()
  22. profit_loss_ratio = abs(avg_win / avg_loss) if avg_loss != 0 else 0
  23. print(f"盈亏比: {profit_loss_ratio:.2f}")
  24. # 计算最大回撤
  25. cummax = df['平仓时总资金'].cummax()
  26. drawdown = (df['平仓时总资金'] - cummax) / cummax
  27. max_drawdown = drawdown.min()
  28. print(f"最大回撤: {max_drawdown:.2%}")
  29. # 资金曲线
  30. initial_capital = 1000000
  31. final_capital = df.iloc[-1]['平仓时总资金']
  32. total_return = (final_capital - initial_capital) / initial_capital
  33. print(f"总收益率: {total_return:.2%}")
  34. print("\n" + "=" * 80)
  35. print("修复状态:")
  36. print("✅ 数据获取和回测范围分离完成")
  37. print("✅ 资金连续性验证通过")
  38. print("⚠️ 持仓天数计算仍有偏差")
  39. print("⚠️ 净值一致性需要进一步优化")
  40. print("\n主要成果:")
  41. print(f"- 策略成功运行{total_trades}笔交易")
  42. print(f"- 实现胜率{win_rate:.2%},盈亏比{profit_loss_ratio:.2f}")
  43. print(f"- 总收益率{total_return:.2%},最大回撤{max_drawdown:.2%}")