update_nbars
- czsc.utils.update_nbars(da, price_col='close', numbers=(1, 2, 5, 10, 20, 30), move=0) None[source]
在给定的 da 上计算并添加后面 n 根 bar 的累计收益列
收益计量单位:BP;1倍涨幅 = 10000BP
函数的逻辑如下:
首先,检查 price_col 是否在输入的 DataFrame(da)的列名中。如果不在,抛出 ValueError。
确保 move 是一个非负整数。
使用 for 循环遍历 numbers 列表中的每个整数 n, 对于每个整数 n,计算 n 根 bar 的累计收益。
返回 None,表示这个函数会直接修改输入的 DataFrame(da),而不返回新的 DataFrame。
- Parameters:
da – 数据,DataFrame结构
price_col – 价格列
numbers – 考察的bar的数目的列表
move – 收益计算是否要整体移位,move必须是非负整数 一般是当前bar的close计算收益,也可以考虑是下根bar的open。这个时候 move=1。
- Return nbars_cols:
后面n根bar的bp值列名