Rolling Standard Deviation in a Matrix in R

后端 未结 2 1327
情书的邮戳
情书的邮戳 2021-02-10 13:14

Bellow is a stock daily returns matrix example (ret_matriz)

      IBOV        PETR4        VALE5        ITUB4        BBDC4        PETR3    
[1,]         


        
2条回答
  •  旧时难觅i
    2021-02-10 14:01

    You can use TTR::runSD instead.

    library(quantmod)
    getSymbols("SPY")
    spy <- apply(ROC(SPY), 2, runSD, n=5)
    # head(spy)
    #         SPY.Open    SPY.High     SPY.Low   SPY.Close SPY.Volume SPY.Adjusted
    # [1,]          NA          NA          NA          NA         NA           NA
    # [2,]          NA          NA          NA          NA         NA           NA
    # [3,]          NA          NA          NA          NA         NA           NA
    # [4,]          NA          NA          NA          NA         NA           NA
    # [5,]          NA          NA          NA          NA         NA           NA
    # [6,] 0.004369094 0.003112967 0.001064232 0.005035266  0.1577499  0.005063025
    

提交回复
热议问题