| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import pandas as pd
- # 读取交易数据
- df = pd.read_csv('cyb50_optimized_trades_2017-06-01_2026-01-19.csv')
- print("Bug修复效果总结:")
- print("=" * 80)
- # 计算交易次数
- total_trades = len(df)
- print(f"总交易次数: {total_trades}")
- # 计算总体盈亏
- total_pnl = df['盈亏金额'].sum()
- print(f"累计盈亏: {total_pnl:,.2f}元")
- # 计算胜率
- winning_trades = len(df[df['盈亏金额'] > 0])
- win_rate = winning_trades / total_trades
- print(f"胜率: {win_rate:.2%} ({winning_trades}/{total_trades})")
- # 计算平均盈亏
- avg_pnl = df['盈亏金额'].mean()
- print(f"平均盈亏: {avg_pnl:,.2f}元")
- # 计算盈亏比
- avg_win = df[df['盈亏金额'] > 0]['盈亏金额'].mean()
- avg_loss = df[df['盈亏金额'] < 0]['盈亏金额'].mean()
- profit_loss_ratio = abs(avg_win / avg_loss) if avg_loss != 0 else 0
- print(f"盈亏比: {profit_loss_ratio:.2f}")
- # 计算最大回撤
- cummax = df['平仓时总资金'].cummax()
- drawdown = (df['平仓时总资金'] - cummax) / cummax
- max_drawdown = drawdown.min()
- print(f"最大回撤: {max_drawdown:.2%}")
- # 资金曲线
- initial_capital = 1000000
- final_capital = df.iloc[-1]['平仓时总资金']
- total_return = (final_capital - initial_capital) / initial_capital
- print(f"总收益率: {total_return:.2%}")
- print("\n" + "=" * 80)
- print("修复状态:")
- print("✅ 数据获取和回测范围分离完成")
- print("✅ 资金连续性验证通过")
- print("⚠️ 持仓天数计算仍有偏差")
- print("⚠️ 净值一致性需要进一步优化")
- print("\n主要成果:")
- print(f"- 策略成功运行{total_trades}笔交易")
- print(f"- 实现胜率{win_rate:.2%},盈亏比{profit_loss_ratio:.2f}")
- print(f"- 总收益率{total_return:.2%},最大回撤{max_drawdown:.2%}")
|