将 NA 更改为内插扁条 [英] Change NAs to interpolated flat bars

查看:25
本文介绍了将 NA 更改为内插扁条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一些 OHLC 数据和一些 NA 行,那么 R 包之一中是否已经有一个函数可以插入数据?

If I have some OHLC data, with some NA rows, is there already a function in one of the R packages that will interpolate data?

na.locf 有两个缺点:

  1. 它是平的,然后突然跳跃
  2. 天真地使用,它会重复整个最后一根柱线,包括高/低

更新: na.approx 在第一方面优于 na.locf,感谢 Dirk,但我仍在寻找bar-aware 的现有函数.IE.这将从前一个柱线的收盘价插入到下一个非 NA 柱线的开盘价,并将创建扁平柱线.如果将音量设置为零,则奖励积分!(所以,我怀疑我的问题的答案将是否",我会自己动手……但我会再等一段时间.)

UPDATE: na.approx is superior to na.locf in the first respect, thanks Dirk, but I'm still searching for an existing function that is bar-aware. I.e. that will interpolate from the close of previous bar to the open of the next non-NA bar, and will create flat bars. Bonus points if it sets volume to zero! (So, I suspect the answer to my question is going to be "No", and I'll roll-my-own... but I'll wait a bit longer.)

执行摘要:na.spline富有想象力,请谨慎使用!

Executive summary: na.spline is imaginative, use with care!

这是一些外汇数据(仅限收盘价),原始数据为蓝色,na.approx 连接以绿色显示:

Here is some FX data (close prices only) with the original data in blue, and the na.approx joins shown in green:

然后这里是相同的数据,但是使用了na.spline:

Then here is the same data, but using na.spline:

特别令人担忧的是,na.spline 决定创造一个新的高点!

Of particular concern is that na.spline has decided to create a new high!

推荐答案

除了 na.locf() 之外,动物园:

  • na.aggregate()
  • na.approx()
  • na.fill()
  • na.spline()
  • na.trim()

na.approx()na.spline() 为您提供插值.

and na.approx() or na.spline() offer you interpolation.

这篇关于将 NA 更改为内插扁条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆