窗口聚合序列函数
与网格聚合函数一样,所有窗口聚合 C 序列函数都接受两个输入序列迭代器参数,即 input
和 interval
。
窗口聚合函数与网格聚合函数在确定其滑动窗口间隔方式上的差异在窗口与网格聚合页面中有描述。
所有窗口聚合函数的结果都会在结果序列中返回,作为每个间隔计算出的聚合值。与网格聚合函数一样,输入序列会根据 interval 参数(类型为 uint8)的值进行分割,该参数确定了组中的最大元素数量,但实际数量可能更少。因此,输入序列将被划分为间隔大小的块,在这些块上执行操作。函数采用以下形式:
MCO_RET mco_seq_window_agg_operation_TYPE(
mco_seq_iterator_h result,
mco_seq_iterator_h input,
mco_size_t interval
);
其中 TYPE 是分析函数页面中列出的类型之一,operation 是以下类型之一。
max
mco_seq_window_agg_max_TYPE()
返回每个元素窗口中具有最大值的相同类型的序列结果。
min
mco_seq_window_agg_min_TYPE()
返回每个元素窗口中具有最小值的相同类型的序列结果。
sum
mco_seq_window_agg_sum_TYPE()
返回具有相同类型的序列结果,其中包含每个元素窗口的总和。
avg
mco_seq_window_agg_avg_TYPE()
返回具有每个元素窗口平均值的双精度结果序列。
var
mco_seq_window_agg_var_TYPE()
返回具有每个元素窗口方差的双精度结果序列。
var_samp
mco_seq_window_agg_var_samp_TYPE()
返回每个元素窗口样本方差的双精度结果序列。
agg_dev
mco_seq_window_agg_dev_TYPE()
返回每个元素窗口的标准差的双精度结果序列。
agg_dev_samp
mco_seq_window_agg_dev_samp_TYPE()
返回每个元素窗口的样本标准差的双精度结果序列。
agg_ema
mco_seq_window_agg_ema_TYPE()
返回具有指数移动平均(EMA)指标的双精度结果序列,该指标具有间隔周期。计算权重递减系数:
EMA函数
指数移动平均(EMA)C API 函数 mco_seq_window_agg_ema_TYPE()
使用窗口聚合 EMA函数页面描述的算法来计算 EMA。
以下是演示此函数的示例代码片段:
{
mco_trans_h trans;
mco_cursor_t quote_cursor;
Quote quote;
mco_seq_iterator_t close_iterator, ema_iterator;
MCO_RET rc;
...
for (rc = mco_cursor_first(trans, "e_cursor);
rc != MCO_S_CURSOR_END;
rc = mco_cursor_next(trans, "e_cursor))
{
Quote_from_cursor(trans, "e_cursor, "e);
Quote_close_iterator("e, &close_iterator);
mco_seq_window_agg_ema_float(&ema_iterator, &close_iterator[0], 7);
...
}
mco_trans_commit(trans);
}
agg_atr
mco_seq_window_agg_atr_TYPE()
返回具有窗口大小为 period 的平均真实范围(ATR)指标的双精度结果序列。请参阅 窗口聚合ATR 函数页面。
ATR函数
以下是演示此函数的示例代码片段:
{
mco_trans_h trans;
mco_cursor_t quote_cursor;
Quote quote;
mco_seq_iterator_t close_iterator, atr_iterator;
MCO_RET rc;
...
for (rc = mco_cursor_first(trans, "e_cursor);
rc != MCO_S_CURSOR_END;
rc = mco_cursor_next(trans, "e_cursor))
{
Quote_from_cursor(trans, "e_cursor, "e);
Quote_close_iterator("e, &close_iterator);
mco_seq_window_agg_atr_float(&atr_iterator, &close_iterator[0], 7);
...
}
mco_trans_commit(trans);
}
示例
以下是一个展示窗口聚合函数的示例代码片段:
{
mco_trans_h trans;
mco_cursor_t quote_cursor;
Quote quote;
mco_seq_iterator_t close_iterator, max_iterator;
MCO_RET rc;
...
for (rc = mco_cursor_first(trans, "e_cursor);
rc != MCO_S_CURSOR_END;
rc = mco_cursor_next(trans, "e_cursor))
{
Quote_from_cursor(trans, "e_cursor, "e);
Quote_close_iterator("e, &close_iterator);
mco_seq_window_agg_max_float(&max_iterator, &close_iterator, 7);
...
}
...
}