9.25工作笔记

复制代码
            stg_res = pd.DataFrame()
            stg_res.loc[0, '选币因子'] = str(factor_list)
            stg_res.loc[0, '过滤因子'] = str(filter_list)
            stg_res.loc[0, '持仓周期'] = hold_period
            stg_res.loc[0, 'offset'] = offset
            stg_res.loc[0, '选币数量'] = select_factor_num_str
            stg_res.loc[0, '是否使用现货'] = if_use_spot
            year_return['涨跌幅'] = year_return['涨跌幅'].map(lambda x: float(x[:-1]))
            stg_res['各年收益'] = [year_return.values.reshape(-1).tolist()]

            # 记录回测的各项指标
            cols = ['累积净值', '年化收益', '最大回撤']
            long_rename_cols = {'累积净值': '多头累积净值', '年化收益': '多头年化收益', '最大回撤': '多头最大回撤'}
            long_rename_cols1 = {'累积净值': '多头累积净值_择时', '年化收益': '多头年化收益_择时', '最大回撤': '多头最大回撤_择时'}
            short_rename_cols = {'累积净值': '空头累积净值', '年化收益': '空头年化收益', '最大回撤': '空头最大回撤'}
            short_rename_cols1 = {'累积净值': '空头累积净值_择时', '年化收益': '空头年化收益_择时', '最大回撤': '空头最大回撤_择时'}
            short_rename_cols2 = {'累积净值': '空头累积净值_定投', '年化收益': '空头年化收益_定投', '最大回撤': '空头最大回撤_定投'}

            long_rtn = long_rtn.T
            long_rtn = long_rtn[cols]
            long_rtn = long_rtn.rename(columns=long_rename_cols)
            short_rtn = short_rtn.T
            short_rtn = short_rtn[cols]
            short_rtn = short_rtn.rename(columns=short_rename_cols)

            # 记录回测的各项指标
            stg_res = pd.concat([stg_res, rtn.T, long_rtn, short_rtn], axis=1)
            # 保存文件
            if os.path.exists(result_path):  # 如果文件存在,往原有的文件中添加新的结果
                stg_res.to_csv(result_path, encoding='gbk', index=False, header=False, mode='a')
            else:  # 如果文不件存在,常规的to_csv操作
                stg_res.to_csv(result_path, encoding='gbk', index=False)

需要做的:

  • 多空累计净值_空头择时
  • 空头累计净值_空头择时
  • 空头择时_多空_年化收益
  • 空头择时_空头_年化收益
相关推荐
使一颗心免于哀伤9 小时前
《设计模式之禅》笔记摘录 - 21.状态模式
笔记·设计模式
_落纸2 天前
三大基础无源电子元件——电阻(R)、电感(L)、电容(C)
笔记
Alice-YUE2 天前
【CSS学习笔记3】css特性
前端·css·笔记·html
2303_Alpha2 天前
SpringBoot
笔记·学习
Hello_Embed3 天前
STM32HAL 快速入门(二十):UART 中断改进 —— 环形缓冲区解决数据丢失
笔记·stm32·单片机·学习·嵌入式软件
咸甜适中3 天前
rust语言 (1.88) 学习笔记:客户端和服务器端同在一个项目中
笔记·学习·rust
Grassto3 天前
RAG 从入门到放弃?丐版 demo 实战笔记(go+python)
笔记
Magnetic_h3 天前
【iOS】设计模式复习
笔记·学习·ios·设计模式·objective-c·cocoa
周周记笔记3 天前
学习笔记:第一个Python程序
笔记·学习
丑小鸭是白天鹅3 天前
Kotlin协程详细笔记之切线程和挂起函数
开发语言·笔记·kotlin