# Seaborn/Matplotlib 绘图:收盘价+均线+执行点(上) + 资金曲线(下)
# seaborn 主题已在 apply_chinese_font 中设置
fig, axes = plt.subplots(2, 1, figsize=(12, 8), sharex=True, gridspec_kw={"height_ratios": [3, 2]})
ax_price, ax_equity = axes
# 上图:价格与均线
ax_price.plot(bt_df["date"], bt_df["close"], label="Close", color="#2c3e50", linewidth=1.2)
ax_price.plot(bt_df["date"], bt_df["sma_s"], label=f"SMA{SHORT_WINDOW}", color="#e67e22", linewidth=1.2)
ax_price.plot(bt_df["date"], bt_df["sma_l"], label=f"SMA{LONG_WINDOW}", color="#27ae60", linewidth=1.2)
# 买卖点
buy_mask = ~bt_df["exec_buy"].isna()
sell_mask = ~bt_df["exec_sell"].isna()
ax_price.scatter(bt_df.loc[buy_mask, "date"], bt_df.loc[buy_mask, "exec_buy"],
label="BUY@Open+1", color="green", s=50, marker="^", zorder=3)
ax_price.scatter(bt_df.loc[sell_mask, "date"], bt_df.loc[sell_mask, "exec_sell"],
label="SELL@Open+1", color="red", s=50, marker="v", zorder=3)
ax_price.set_title("双均线交叉策略(次日开盘成交)")
ax_price.set_ylabel("Price")
ax_price.legend(loc="best")
# 下图:资金曲线
ax_equity.plot(bt_df["date"], bt_df["equity"], label="Equity", color="#1f77b4", linewidth=1.6)
ax_equity.set_title("资金曲线")
ax_equity.set_ylabel("Equity")
ax_equity.legend(loc="best")
plt.tight_layout()
plt.show()