使用Esper计算指数移动平均线

时间:2012-12-16 14:16:51

标签: exponential esper moving-average complex-event-processing

寻找一种使用Esper(EPL)语句在5 EMA5和EMA20窗口上计算指数移动平均线的方法。

我有一个priceEvent(timeStamp,symbol和price)流,我在5的滑动窗口上写了一个简单的移动avrage SMA。但对Esper来说还是一个新手,正在寻找一种在滑动窗口上计算指数移动平均线(EMA)的方法。

http://www.iexplain.org/ema-how-to-calculate/

如果有人可以帮助我编写抛物线SAR函数,那将会很有帮助

1 个答案:

答案 0 :(得分:3)

Ok伙计们,我做了更多的学习和研究,以找到寻找指数移动平均线的解决方案,下面是有助于计算ema5的EPL语句

//create a named window EMA5 Window
create window EMA5Window.win:length(1) as select price as ema5 from Quote

//insert the mean of first 5 events 
insert into EMA5Window select Avg(price) as ema5 from Quote.win:firstlength(5)

//after 5 events calculate todays ema = (today's price)/3 +  (yesterday's ema)*2/3, refer to http://www.iexplain.org/ema-how-to-calculate/ for ema formula 

insert into EMA5Window select ((price)*(1/3)+(2/3)*(select ema5 from EMA5Window)) as ema5 from Quote output after 5 events

// now select the ema5 as below
select ema5 as ema5 from EMA5Window output after 5 events

一旦完成,计算抛物线SAR的工作将会更新。 感谢