以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://weistock.com/bbs/index.asp) -- 公式模型编写问题提交 (http://weistock.com/bbs/list.asp?boardid=4) ---- 编写一个时间加权波动率指标,求简单方法 (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=142290) |
-- 作者:tianjixuetu -- 发布时间:2016/11/7 10:49:29 -- 编写一个时间加权波动率指标,求简单方法 计算最近20个周期之内的收盘价偏离ema的程度。 具体表达的部分指标: (收盘价-20日ema均值)乘以当周期的时间,越靠近现在取值越大。 一个个写 ema20:=ema(c,20); cu20:=(c-ema20)*20; c19:=ref(c,1); ema19:=ref(ema20,1); cu19:=(c19-ema19)*19; c18:=ref(c,2); ema18:=ref(ema20,2); cu18:=(c18-ema18)*18; c17:=ref(c,3); ema17:=ref(ema20,3); cu17:=(c17-ema17)*17; c16:=ref(16,4); ema16:=ref(ema20,4); cu16:=(c16-ema16)*16; c15:=ref(c,5); ema15:=ref(ema20,5); cu15:=(c15-ema15)*15 ------------------ 计算出20个周期的cu,然后求均值,得到波动率。 这种计算很多,求一个简单的,运算比较快的
|
-- 作者:jinzhe -- 发布时间:2016/11/7 11:01:05 -- 就这样算,一个个的枚举出来,然后再求和除20 |
-- 作者:tianjixuetu -- 发布时间:2016/11/7 11:15:46 -- 哥,能不能用循环。要计算速度最快的 |
-- 作者:jinzhe -- 发布时间:2016/11/7 11:23:37 -- {ema20:=ema(c,20); cu20:=(ref(c,0)-ref(ema20,0))*20; c19:=ref(c,1); ema19:=ref(ema20,1); cu19:=(c19-ref(ema20,1))*19; c18:=ref(c,2); ema18:=ref(ema20,2); cu18:=(c18-ref(ema20,2))*18; } runmode:0; ss:=0; ema20:=ema(c,20); for i=20 downto 1 do begin ss:=ss+(ref(c,20-i)-ref(ema20,20-i))*i; end sss:ss,linethick0; |
-- 作者:tianjixuetu -- 发布时间:2016/11/7 13:41:20 -- 谢谢 |