ZAccumulator¶
- class zvt.factors.z.z_factor.ZAccumulator(acc_window: int = 1)¶
Bases:
zvt.contract.factor.Accumulator
- __init__(acc_window: int = 1) None ¶
算法和概念 <实体> 某种状态的k线 [实体] 连续实体排列
两k线的关系有三种: 上涨,下跌,包含 上涨: k线高点比之前高,低点比之前高 下跌: k线低点比之前低,高点比之前低 包含: k线高点比之前高,低点比之前低;反方向,即被包含 处理包含关系,长的k线缩短,上涨时,低点取max(low1,low2);下跌时,高点取min(high1,high2)
第一个顶(底)分型: 出现连续4根下跌(上涨)k线 之后开始寻找 候选底(顶)分型,寻找的过程中有以下状态
<临时顶>: 中间k线比两边的高点高,是一条特定的k线 <临时底>: 中间k线比两边的高点高,是一条特定的k线
<候选顶分型>: 连续的<临时顶>取最大 <候选底分型>: 连续的<临时底>取最小 任何时刻只能有一个候选,其之前是一个确定的分型
<上升k线>: <下降k线>: <连接k线>: 分型之间的k线都可以认为是连接k线,以上为演化过程的中间态 distance(<候选顶分型>, <连接k线>)>=4 则 <候选顶分型> 变成顶分型 distance(<候选底分型>, <连接k线>)>=4 则 <候选底分型> 变成底分型
<顶分型><连接k线><候选底分型> <底分型><连接k线><候选顶分型>
- acc_one(entity_id, df: pandas.core.frame.DataFrame, acc_df: pandas.core.frame.DataFrame, state: dict) -> (<class 'pandas.core.frame.DataFrame'>, <class 'dict'>)¶
df format:
col1 col2 col3 ... timestamp 1.2 0.5 0.3 ... 1.0 0.7 0.2 ...
the new result and state
- Parameters
df – current input df
entity_id – current computing entity_id
acc_df – current result of the entity_id
state – current state of the entity_id
- Returns
new result and state of the entity_id
- acc(input_df: pandas.core.frame.DataFrame, acc_df: pandas.core.frame.DataFrame, states: dict) -> (<class 'pandas.core.frame.DataFrame'>, <class 'dict'>)¶
- Parameters
input_df – new input
acc_df – previous result
states – current states of the entity
- Returns
new result and states