【问题标题】:How do I find stock market moves of a certain magnitude over a time series?如何在时间序列中找到一定幅度的股市走势?
【发布时间】:2013-07-12 06:50:41
【问题描述】:

我被 R 弄湿了,在对当前任务进行多次试验和错误之后,我仍然卡住了。我有股票行情的价格数据。我试图在我的数据中找到熊市,定义为价格数据点

提前谢谢..

【问题讨论】:

  • 向您的问题添加数据
  • 看看this posting。有了你可以在那里找到的信息和一点谷歌搜索,你应该能够解决这个任务。为了补充 Dan 博士的回答,“tseries”包还具有 maxdrawdown 功能。

标签: r time-series quantmod quantitative-finance


【解决方案1】:

这是一个版本,它检测价格比以前价格小一定比例(例如 20%)的日期 一些回溯期(例如,60 天)。

## Some prices
set.seed(321)
prices    <- cumprod(1 + rnorm(300, 0.005, 0.05))

## Detection of "bear" periods
threshold <- 0.2
lookback  <- 60  # Set to length(prices) for no lookback restriction
is.bear   <- sapply(1:length(prices),
                    function(i, prices, threshold = 0.2, lookback = length(prices)){
                        (prices[i] / max(tail(prices[1:i], lookback))) < (1 - threshold)
                    },
                    prices = prices, threshold = threshold, lookback = lookback)
## Result
plot(prices, type = "l")
rug(which(is.bear), col = "red", lwd = 2)

【讨论】:

  • 好的,感谢您的反馈。这是否意味着这个答案很好地解决了你的问题?
【解决方案2】:

看看PerformanceAnalytics,特别是DrawdownPeak,它可能就是你要找的东西

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多