R 统计:平均真实范围追踪止损指标
我正在使用以下文章:
创建平均真实范围追踪止损指标在 R 中,我尝试了各种方法来做到这一点,包括 for 循环、pmin 和创建滞后时间序列,但似乎没有任何效果。
你能帮我一下吗?
I am using the following article:
to create the Average True Range Trailing Stop indicator in R. I have tried various ways to do this, including for loops, pmin and creating a lagging time series, and nothing seems to work.
Could you help me out please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你为什么要尝试创建它?它可以在 TTR 包 的
ATR 函数中找到
。更新(更仔细地阅读问题后)。我不确定这是否是解决方案,但我希望它能帮助您朝正确的方向发展。
更新#2:
我错过了文章中的追踪止损逻辑。这段代码更接近地复制了它。请注意,
coredata
调用是必要的,因为trail
是路径相关的,我们需要将昨天的值与今天的值进行比较。 xts/zoo 操作在操作之前按索引合并,因此我们需要在比较之前删除索引。Why are you trying to create it? It's available in the TTR package in the function
ATR
.UPDATE (after reading the question more closely). I'm not exactly sure this is the solution, but I hope it helps you in the right direction.
UPDATE #2:
I missed the trailing stop logic in the article. This code replicates it more closely. Note that the
coredata
calls are necessary becausetrail
is path-dependent and we need to compare yesterday's values with today's. xts/zoo operations merge by index before the operation, so we need to drop the index before comparing.