【理财类-01-09】20260810 股票+ETF“差价”收益计算和csv统计(Python) 0.003-0.005

📅 2026/8/25 12:27:19
【理财类-01-09】20260810 股票+ETF“差价”收益计算和csv统计(Python) 0.003-0.005
一、背景需求之前制作了股票差价计算Python包含“沪指”“深指”理财类-01-06】20260716 股票“差价”收益计算和csv统计Pythonhttps://mp.csdn.net/mp_blog/creation/editor/162911231二、最近我买积存金查询豆包问问题的时候问问“黄金类”产品还有其他可以赚“利息差额”的黄金产品发现还有一种股票账户里面“黄金ETF”这是T0的(当天可以反复操作9:00-11:30、13:30-15:00三、测试股票“黄金ETF”于是我要测算一下股票账户里的“黄金ETF”买入后升到多少价位卖出至少可保本。把原来的代码复制一份三、预估买入多少股1、买入价9.360元以股票账户里面的ETF当时的价格 与测算 同时计算“买入价和卖出价*预设股数100-10000*佣金比例沪0.0001843深0.0001654”当佣金正好大于等于5“就确定用这个股数” 推算买入价最大股数卖出价最大股数 豆包、阿夏 20260716 def calc_min_shares(code: str, price: float) - dict: 根据股票代码、价格计算刚好佣金≥5元的最小股数100~10000100递增 :param code: 6位股票代码字符串 :param price: 买入/卖出单价 :return: 单组价格对应的计算结果字典 # 1. 校验股票代码 if len(code) ! 6 or not code.isdigit(): raise ValueError(股票代码必须是6位纯数字) code_prefix code[:2] # 2. 匹配市场佣金费率 if code_prefix in (60, 68): market 沪市 commission_rate 0.0001843 # 0.1843‰ elif code_prefix in (00, 30): market 深市 commission_rate 0.0001654 # 0.1654‰ elif code_prefix in (51,): market ETF commission_rate 0.0002 # ETF 佣金 0.2‰ else: raise ValueError(仅支持60/68开头沪市、00/30开头深市A股代码) min_target_shares None target_commission 0.0 target_amount 0.0 # 3. 遍历100~10000股步长100 for shares in range(100, 10001, 100): trade_amount price * shares real_commission trade_amount * commission_rate if real_commission 5: min_target_shares shares target_amount trade_amount target_commission real_commission break # 4. 组装结果 result { # 股票代码: code, # 市场: market, # 佣金费率: f{commission_rate * 1000}‰, 成交单价: round(price, 2), # 搜索区间: 100 ~ 10000股(100股递增) } if min_target_shares is not None: result[满足佣金≥5最小股数] min_target_shares # result[对应成交总金额] round(target_amount, 2) # result[理论计算佣金] round(target_commission, 4) # result[实际收取佣金(保底5元)] max(5, round(target_commission, 2)) else: result[提示] 100-10000股内全部佣金不足5元统一收5元保底佣金 return result # ---------------------- 测试调用 ---------------------- if __name__ __main__: # 测试案例 try: stock_code 002229 buy_price 9.4 # 买入单价 sell_price 9.7 # 卖出单价 # 分别计算买入、卖出两套数据 buy_result calc_min_shares(stock_code, buy_price) sell_result calc_min_shares(stock_code, sell_price) print( 买入计算结果 ) for k, v in buy_result.items(): print(f{k}: {v}) print(- * 60) print( 卖出计算结果 ) for k, v in sell_result.items(): print(f{k}: {v}) except Exception as e: print(程序异常, e) print(\n 交互式手动输入模式 ) try: # input_code input(请输入6位股票代码) # input_buy float(input(请输入买入单价)) # input_sell float(input(请输入卖出单价)) # input_code 002229 # input_buy 9.3 # input_sell 9.35 input_code 518800 input_buy 9.360 input_sell 9.361 res_buy calc_min_shares(input_code, input_buy) res_sell calc_min_shares(input_code, input_sell) print(\n 手动输入-买入结果 ) for k, v in res_buy.items(): print(f{k}: {v}) print(- * 60) print( 手动输入-卖出结果 ) for k, v in res_sell.items(): print(f{k}: {v}) except Exception as err: print(输入错误, err)假设买入9.360卖出9.361计算结果2700股四、写代码from openpyxl import Workbook from openpyxl.styles import NamedStyle def calc_stock_data(buy_price, sell_price, shares, stock_code): 规则 1. A股买卖过户费卖出印花税0.05% 2. 51开头ETF无过户费、无印花税仅佣金 3. 交易单价、成交总额统一保留3位小数 # 校验6位股票代码 code str(stock_code).strip() if len(code) ! 6 or not code.isdigit(): raise ValueError(股票代码必须是6位纯数字) code_prefix code[:2] # 判定市场与佣金费率 if code_prefix in (60, 68): market 沪市A股 commission_rate 0.0001843 is_etf False elif code_prefix in (00, 30): market 深市A股 commission_rate 0.0001654 is_etf False elif code_prefix 51: market ETF基金 commission_rate 0.0002 is_etf True else: raise ValueError(仅支持60/68沪市A股、00/30深市A股、51开头ETF) transfer_rate 0.00001 # 成交总额 内部计算保留3位小数 buy_total round(buy_price * shares, 3) sell_total round(sell_price * shares, 3) # 买入费用 buy_comm_theory buy_total * commission_rate buy_comm_real max(buy_comm_theory, 5.0) buy_transfer buy_total * transfer_rate if not is_etf else 0.0 buy_total_cost buy_total buy_comm_real buy_transfer # 卖出费用 sell_comm_theory sell_total * commission_rate sell_comm_real max(sell_comm_theory, 5.0) sell_transfer sell_total * transfer_rate if not is_etf else 0.0 stamp_tax sell_total * 0.0005 if not is_etf else 0.0 sell_real_income sell_total - (sell_comm_real sell_transfer stamp_tax) # 盈亏 net_profit sell_real_income - buy_total_cost profit_ratio net_profit / buy_total if buy_total ! 0 else 0 code_text f{code} # 行数据单价、成交总额强制3位手续费保留2位 buy_row [ code_text, market, 买入, round(buy_price, 3), # 单价3位 shares, buy_total, # 成交总额3位 round(buy_comm_theory, 2), round(buy_comm_real, 2), round(buy_transfer, 2), 0.0, round(buy_total_cost, 2), round(net_profit, 2), f{profit_ratio*100:.2f}%, , ] sell_row [ code_text, market, 卖出, round(sell_price, 3), # 卖出价3位 shares, sell_total, # 卖出总额3位 round(sell_comm_theory, 2), round(sell_comm_real, 2), round(sell_transfer, 2), round(stamp_tax, 2), round(sell_real_income, 2), round(net_profit, 2), f{profit_ratio*100:.2f}%, , ] return { net_profit: net_profit, buy_row: buy_row, sell_row: sell_row } if __name__ __main__: # 15列表头 header [ 股票代码, 所属市场, 交易类型, 单价(元), 持股数量(股), 成交总额(元), 理论佣金(元), 实际佣金(元), 过户费(元), 印花税(元), 总金额(元), 净利润(元), 收益率, , ] # 交易记录 transactions [ {stock_code: 601933, buy_price: 3.17, sell_price: 3.22, shares: 15700}, {stock_code: 518800, buy_price: 9.360, sell_price: 9.364, shares: 2700}, {stock_code: 518800, buy_price: 9.360, sell_price: 9.365, shares: 2700}, {stock_code: 518800, buy_price: 9.360, sell_price: 9.366, shares: 2700}, {stock_code: 518800, buy_price: 9.360, sell_price: 9.362, shares: 12700}, {stock_code: 518800, buy_price: 9.360, sell_price: 9.363, shares: 12700}, {stock_code: 518800, buy_price: 9.360, sell_price: 9.364, shares: 12700}, {stock_code: 518800, buy_price: 9.360, sell_price: 9.365, shares: 12700}, {stock_code: 518800, buy_price: 9.360, sell_price: 9.366, shares: 12700}, ] wb Workbook() ws wb.active ws.title 股票盈亏明细 # 创建数字格式固定3位小数样式 style_3dec NamedStyle(nameThreeDecimal) style_3dec.number_format 0.000 wb.add_named_style(style_3dec) # 写入表头第1行 ws.append(header) # 汇总行第2行 sum_line 2 ws.cell(rowsum_line, column15, value净利润合计汇总) all_profit [] sell_line_list [] current_row 3 for item in transactions: res calc_stock_data(**item) # 写入买入行 ws.append(res[buy_row]) # 写入卖出行 ws.append(res[sell_row]) sell_line_list.append(current_row 1) all_profit.append(res[net_profit]) # 空行隔开 ws.append([] * 15) current_row 3 # 设置【单价D列、成交总额F列】整列单元格为3位小数格式 for r in range(2, current_row): ws.cell(rowr, column4).number_format 0.000 ws.cell(rowr, column6).number_format 0.000 # 总盈亏与求和公式 total_all sum(all_profit) sum_formula fSUM({,.join([fL{x} for x in sell_line_list])}) ws.cell(rowsum_line, column12, valuesum_formula) ws.cell(rowsum_line, column15, valuef总计{round(total_all, 2)} 元) # 文件名带总金额 # save_path frD:\股票差价\20260810多笔股票盈亏汇总表合计{round(total_all,2)}元.xlsx save_path frD:\股票差价\20260810多笔股票盈亏汇总表合计.xlsx try: wb.save(save_path) print(f✅ 交易笔数{len(transactions)}) print(f✅ 自动求和公式{sum_formula}) print(f✅ 全部总净利润{round(total_all,2)} 元) print(f✅ 文件保存路径{save_path}) print( 格式说明 ) print(1.D列单价、F列成交总额Excel强制锁定3位小数) print(2.51ETF无过户费、无印花税) print(3.A股正常收取过户费与卖出印花税) except Exception as e: print(f保存失败{e}) print(请手动创建 D:\\股票差价 文件夹)结果显示9,360元2700凑满5元手续费最少涨0.004元可以保本利息差0.69同样9.36增加股数12700最少涨0.004元可以保本利息差3.24稍微多一点按照这个规律在正式账户里操作测试用程序测试后差价都是16.89元再测试其他买入价格8.34或10.56,测试最少买入股数凑满5元手续费*21买入价8.34结果也是至少涨0.004元才能保本价格越低股数越多2买入价10.56结果也是至少涨0.005元才能保本价格越高股数越少3再测试一个5.56结果是至少涨0.003元才能保本价格越低股数越多结论也就是说不能默认“0.004元”保本如果价格低低于500元是0.003元如果价格高低于1000元保本是0.005元最终成果还是要用是2个代码来测算1.计算买入价如9.356卖出价默认加0.001。算出最少买的总股数.2、计算最低卖出价格。新增 ETF已知买入价 1、计算最少买入股数确保手续费佣金在5元以上 2、计算保本卖出价格 豆包 阿夏 20260810 from math import ceil # 可自行修改参数区 etf_code 518800 # ETF代码必须51开头 buy_price 9.36 # 买入单价 commission_rate 0.0002 # ETF佣金费率沿用原项目 min_commission 5.0 # 最低佣金门槛 # # 1. 佣金≥5元需要的最低成交金额 min_trade_amount min_commission / commission_rate # 2. 理论最小股数不限制手数 theory_min_shares ceil(min_trade_amount / buy_price) # 3. 修正向上凑整为100的整数倍一手100股 min_shares ceil(theory_min_shares / 100) * 100 # 4. 买入端计算 buy_total round(buy_price * min_shares, 3) actual_buy_commission max(buy_total * commission_rate, min_commission) buy_total_cost buy_total actual_buy_commission # 5. 默认卖出加价0.001测算 default_add 0.001 sell_price_default buy_price default_add sell_total_default round(sell_price_default * min_shares, 3) actual_sell_commission max(sell_total_default * commission_rate, min_commission) sell_net_default sell_total_default - actual_sell_commission # 6. 反向计算保本卖出价格 break_even_sell_total buy_total_cost actual_sell_commission break_even_sell_price break_even_sell_total / min_shares price_need_rise round(break_even_sell_price - buy_price, 3) # 打印输出 print( ETF保本测算结果51开头ETF无印花税/过户费100股一手) print(fETF代码{etf_code}) print(f买入单价{buy_price:.3f} 元) print(fETF佣金费率{commission_rate:.4f}) print(f触发5元最低佣金理论成交金额{min_trade_amount:.2f} 元) print(f不限制手数理论最少股数{theory_min_shares} 股) print(f交易所规则 100股整数倍 实际最少买入{min_shares} 股) print(f买入成交总额{buy_total:.3f} 元) print(f买入实际佣金{actual_buy_commission:.2f} 元) print(- * 60) print(f保本所需卖出总金额{break_even_sell_total:.3f} 元) print(f保本卖出单价{break_even_sell_price:.3f} 元) print(f股价需要上涨{price_need_rise:.3f} 元 才能覆盖双向佣金保本) print(- * 60) print(f默认上涨0.001后卖出到手净额{sell_net_default:.2f} 元) profit_default sell_net_default - buy_total_cost print(f仅涨0.001元最终盈亏{profit_default:.2f} 元)3. 实际卖出后写入买入卖出价格计算差价 计算单只股票一次买入一次卖出的详细记录买入价、卖出价、股数、计算佣金、实际佣金、过户费、印花费、差价净利润、收益率 结果保存到EXCEL,合计多笔差价总额文件名有金额 最适合列宽居中 包含 沪指、深圳、ETF 豆包、阿夏 20260715 from openpyxl import Workbook from openpyxl.styles import NamedStyle, Alignment def calc_stock_data(buy_price, sell_price, shares, stock_code): 规则 1. A股买卖过户费卖出印花税0.05% 2. 51开头ETF无过户费、无印花税仅佣金 3. 交易单价、成交总额统一保留3位小数 # 校验6位股票代码 code str(stock_code).strip() if len(code) ! 6 or not code.isdigit(): raise ValueError(股票代码必须是6位纯数字) code_prefix code[:2] # 判定市场与佣金费率 if code_prefix in (60, 68): market 沪市A股 commission_rate 0.0001843 is_etf False elif code_prefix in (00, 30): market 深市A股 commission_rate 0.0001654 is_etf False elif code_prefix 51: market ETF基金 commission_rate 0.0002 is_etf True else: raise ValueError(仅支持60/68沪市A股、00/30深市A股、51开头ETF) transfer_rate 0.00001 # 成交总额 内部计算保留3位小数 buy_total round(buy_price * shares, 3) sell_total round(sell_price * shares, 3) # 买入费用 buy_comm_theory buy_total * commission_rate buy_comm_real max(buy_comm_theory, 5.0) buy_transfer buy_total * transfer_rate if not is_etf else 0.0 buy_total_cost buy_total buy_comm_real buy_transfer # 卖出费用 sell_comm_theory sell_total * commission_rate sell_comm_real max(sell_comm_theory, 5.0) sell_transfer sell_total * transfer_rate if not is_etf else 0.0 stamp_tax sell_total * 0.0005 if not is_etf else 0.0 sell_real_income sell_total - (sell_comm_real sell_transfer stamp_tax) # 盈亏 net_profit sell_real_income - buy_total_cost profit_ratio net_profit / buy_total if buy_total ! 0 else 0 code_text f{code} # 行数据单价、成交总额强制3位手续费保留2位 buy_row [ code_text, market, 买入, round(buy_price, 3), # 单价3位 shares, buy_total, # 成交总额3位 round(buy_comm_theory, 2), round(buy_comm_real, 2), round(buy_transfer, 2), 0.0, round(buy_total_cost, 2), round(net_profit, 2), f{profit_ratio*100:.2f}%, , ] sell_row [ code_text, market, 卖出, round(sell_price, 3), # 卖出价3位 shares, sell_total, # 卖出总额3位 round(sell_comm_theory, 2), round(sell_comm_real, 2), round(sell_transfer, 2), round(stamp_tax, 2), round(sell_real_income, 2), round(net_profit, 2), f{profit_ratio*100:.2f}%, , ] return { net_profit: net_profit, buy_row: buy_row, sell_row: sell_row } if __name__ __main__: # 15列表头 header [ 股票代码, 所属市场, 交易类型, 单价(元), 持股数量(股), 成交总额(元), 理论佣金(元), 实际佣金(元), 过户费(元), 印花税(元), 总金额(元), 净利润(元), 收益率, , ] # 交易记录 transactions [ {stock_code: 518800, buy_price: 9.36, sell_price: 9.37, shares: 2700}, # {stock_code: 518800, buy_price: 9.43, sell_price: 9.435, shares: 10000}, # {stock_code: 601933, buy_price: 3.17, sell_price: 3.22, shares: 15700}, ] wb Workbook() ws wb.active ws.title 股票盈亏明细 # 1. 设置F列固定宽度20 ws.column_dimensions[F].width 20 # 2. 创建全局居中对齐样式水平垂直都居中 center_alignment Alignment(horizontalcenter, verticalcenter) # 3. 创建3位小数数字格式 style_3dec NamedStyle(nameThreeDecimal) style_3dec.number_format 0.000 wb.add_named_style(style_3dec) # 写入表头第1行 ws.append(header) # 汇总行第2行 sum_line 2 ws.cell(rowsum_line, column15, value净利润合计汇总) all_profit [] sell_line_list [] current_row 3 for item in transactions: res calc_stock_data(**item) # 写入买入行 ws.append(res[buy_row]) # 写入卖出行 ws.append(res[sell_row]) sell_line_list.append(current_row 1) all_profit.append(res[net_profit]) # 空行隔开 ws.append([] * 15) current_row 3 # 批量设置所有单元格居中 D/F列3位小数 for row in range(1, current_row): for col in range(1, 16): cell ws.cell(rowrow, columncol) cell.alignment center_alignment # 全部居中 # D列(4)、F列(6) 设置三位小数格式 if col 4 or col 6: cell.number_format 0.000 # 总盈亏与求和公式 total_all sum(all_profit) sum_formula fSUM({,.join([fL{x} for x in sell_line_list])}) ws.cell(rowsum_line, column12, valuesum_formula) ws.cell(rowsum_line, column15, valuef总计{round(total_all, 2)} 元) # 文件名带总金额 save_path frD:\股票差价\20260810多笔股票盈亏汇总表合计{round(total_all,2)}元.xlsx # save_path frD:\股票差价\20260810多笔股票盈亏汇总表合计.xlsx try: wb.save(save_path) print(f✅ 交易笔数{len(transactions)}) print(f✅ 自动求和公式{sum_formula}) print(f✅ 全部总净利润{round(total_all,2)} 元) print(f✅ 文件保存路径{save_path}) print( 格式说明 ) print(1. 所有单元格已设置水平垂直居中) print(2. F列成交总额固定列宽20) print(3.D列单价、F列成交总额Excel强制锁定3位小数) print(4.51ETF无过户费、无印花税) print(5.A股正常收取过户费与卖出印花税) except Exception as e: print(f保存失败{e}) print(请手动创建 D:\\股票差价 文件夹)涨0.004能保本涨0.01等于16.89如果涨0.1等于259----------202060824--------运行后每次都要打开D盘找Excel打开有点麻烦 计算单只股票一次买入一次卖出的详细记录买入价、卖出价、股数、计算佣金、实际佣金、过户费、印花费、差价净利润、收益率 结果保存到EXCEL,合计多笔差价总额文件名有金额 最适合列宽居中 包含 沪指、深圳、ETF 运行后自动打开Excel 豆包、阿夏 20260824 import os from openpyxl import Workbook from openpyxl.styles import NamedStyle, Alignment def calc_stock_data(buy_price, sell_price, shares, stock_code): 规则 1. A股买卖过户费卖出印花税0.05% 2. 51开头ETF无过户费、无印花税仅佣金 3. 交易单价、成交总额统一保留3位小数 # 校验6位股票代码 code str(stock_code).strip() if len(code) ! 6 or not code.isdigit(): raise ValueError(股票代码必须是6位纯数字) code_prefix code[:2] # 判定市场与佣金费率 if code_prefix in (60, 68): market 沪市A股 commission_rate 0.0001843 is_etf False elif code_prefix in (00, 30): market 深市A股 commission_rate 0.0001654 is_etf False elif code_prefix in (51,15): market ETF基金 commission_rate 0.0002 is_etf True else: raise ValueError(仅支持60/68沪市A股、00/30深市A股、51/15开头ETF) transfer_rate 0.00001 # 成交总额 内部计算保留3位小数 buy_total round(buy_price * shares, 3) sell_total round(sell_price * shares, 3) # 买入费用 buy_comm_theory buy_total * commission_rate buy_comm_real max(buy_comm_theory, 5.0) buy_transfer buy_total * transfer_rate if not is_etf else 0.0 buy_total_cost buy_total buy_comm_real buy_transfer # 卖出费用 sell_comm_theory sell_total * commission_rate sell_comm_real max(sell_comm_theory, 5.0) sell_transfer sell_total * transfer_rate if not is_etf else 0.0 stamp_tax sell_total * 0.0005 if not is_etf else 0.0 sell_real_income sell_total - (sell_comm_real sell_transfer stamp_tax) # 盈亏 net_profit sell_real_income - buy_total_cost profit_ratio net_profit / buy_total if buy_total ! 0 else 0 code_text f{code} # 行数据单价、成交总额强制3位手续费保留2位 buy_row [ code_text, market, 买入, round(buy_price, 3), # 单价3位 shares, buy_total, # 成交总额3位 round(buy_comm_theory, 2), round(buy_comm_real, 2), round(buy_transfer, 2), 0.0, round(buy_total_cost, 2), round(net_profit, 2), f{profit_ratio*100:.2f}%, , ] sell_row [ code_text, market, 卖出, round(sell_price, 3), # 卖出价3位 shares, sell_total, # 卖出总额3位 round(sell_comm_theory, 2), round(sell_comm_real, 2), round(sell_transfer, 2), round(stamp_tax, 2), round(sell_real_income, 2), round(net_profit, 2), f{profit_ratio*100:.2f}%, , ] return { net_profit: net_profit, buy_row: buy_row, sell_row: sell_row } if __name__ __main__: # 15列表头 header [ 股票代码, 所属市场, 交易类型, 单价(元), 持股数量(股), 成交总额(元), 理论佣金(元), 实际佣金(元), 过户费(元), 印花税(元), 总金额(元), 净利润(元), 收益率, , ] # 交易记录 transactions [ {stock_code: 601933, buy_price: 3.10, sell_price: 3.12, shares: 28100}, {stock_code: 159985, buy_price: 2.165, sell_price: 2.175, shares: 11500}, {stock_code: 159985, buy_price: 2.177, sell_price: 2.180, shares: 80500}, {stock_code: 159985, buy_price: 2.177, sell_price: 2.20, shares: 80500}, {stock_code: 601933, buy_price: 3.05, sell_price: 3.10, shares: 32500}, ] wb Workbook() ws wb.active ws.title 股票盈亏明细 # 1. 设置F列固定宽度20 ws.column_dimensions[F].width 20 # 2. 创建全局居中对齐样式水平垂直都居中 center_alignment Alignment(horizontalcenter, verticalcenter) # 3. 创建3位小数数字格式 style_3dec NamedStyle(nameThreeDecimal) style_3dec.number_format 0.000 wb.add_named_style(style_3dec) # 写入表头第1行 ws.append(header) # 汇总行第2行 sum_line 2 ws.cell(rowsum_line, column15, value净利润合计汇总) all_profit [] sell_line_list [] current_row 3 for item in transactions: res calc_stock_data(**item) # 写入买入行 ws.append(res[buy_row]) # 写入卖出行 ws.append(res[sell_row]) sell_line_list.append(current_row 1) all_profit.append(res[net_profit]) # 空行隔开 ws.append([] * 15) current_row 3 # 批量设置所有单元格居中 D/F列3位小数 for row in range(1, current_row): for col in range(1, 16): cell ws.cell(rowrow, columncol) cell.alignment center_alignment # 全部居中 # D列(4)、F列(6) 设置三位小数格式 if col 4 or col 6: cell.number_format 0.000 # 总盈亏与求和公式 total_all sum(all_profit) sum_formula fSUM({,.join([fL{x} for x in sell_line_list])}) ws.cell(rowsum_line, column12, valuesum_formula) ws.cell(rowsum_line, column15, valuef总计{round(total_all, 2)} 元) # 文件名带上合计总金额 total_str f{round(total_all,2)} # save_path frD:\股票差价\20260824多笔股票盈亏汇总表合计{total_str}元.xlsx save_path frD:\股票差价\20260824多笔股票盈亏汇总表.xlsx try: wb.save(save_path) print(f✅ 交易笔数{len(transactions)}) print(f✅ 自动求和公式{sum_formula}) print(f✅ 全部总净利润{round(total_all,2)} 元) print(f✅ 文件保存路径{save_path}) print( 格式说明 ) print(1. 所有单元格已设置水平垂直居中) print(2. F列成交总额固定列宽20) print(3.D列单价、F列成交总额Excel强制锁定3位小数) print(4.51ETF无过户费、无印花税) print(5.A股正常收取过户费与卖出印花税) # Windows下保存完成自动打开Excel os.startfile(save_path) print( 已自动打开生成的Excel文件) except Exception as e: print(f保存失败{e}) print(请手动创建 D:\\股票差价 文件夹)