美文网首页数据-R语言-图表-决策-Linux-Python
R语言用getSymbol从csv中获取行情数据

R语言用getSymbol从csv中获取行情数据

作者: 小驴Donkey | 来源:发表于2018-11-21 16:25 被阅读3次

    获取沪深300、中证500、创业板指和国债指数的行情

    > index_symbols <- c("HS300","ZZ500","CYBZ","GZZS")
    > index_symbols
    [1] "HS300" "ZZ500" "CYBZ"  "GZZS" 
    > getSymbols(Symbols = index_symbols, src = "csv", dir = "data/symbol_data")
    [1] "HS300" "ZZ500" "CYBZ"  "GZZS" 
    > head(HS300)
               HS300.Open HS300.High HS300.Low HS300.Close HS300.Volume
    2008-01-02   5349.763   5404.928  5283.448    5385.103     45668710
    2008-01-03   5381.147   5422.673  5315.948    5422.034     64645878
    2008-01-04   5430.630   5499.085  5422.456    5483.650     51746420
    2008-01-07   5480.442   5569.152  5455.501    5556.593     53485409
    2008-01-08   5575.950   5630.624  5485.234    5528.054     64899501
    2008-01-09   5507.116   5614.678  5490.305    5613.758     46796872
               HS300.Adjusted
    2008-01-02       5385.103
    2008-01-03       5422.034
    2008-01-04       5483.650
    2008-01-07       5556.593
    2008-01-08       5528.054
    2008-01-09       5613.758
    > 
    

    csv的存储路径

    当前工作目录
    |---data
         |---symbol_data
              |---HS300.csv
              |---ZZ500.csv
              |---CYBZ.csv
              |---GZZS.csv
    

    csv内容结构

    date,o,h,l,c,v,a
    2018-10-19,3017.749,3137.747,3009.498,3134.945,98839688.000,3134.945
    2018-10-18,3097.790,3097.790,3043.382,3044.392,73771968.000,3044.392
    2018-10-17,3140.684,3149.134,3062.554,3118.246,76837138.000,3118.246
    2018-10-16,3128.576,3166.092,3089.367,3100.974,68887721.000,3100.974
    2018-10-15,3173.847,3183.130,3120.231,3126.452,69605023.000,3126.452
    

    表头的含义:

    • date 交易日期
    • o 开盘价
    • h 最高价
    • l 最低价
    • c 收盘价
    • v 成交量
    • a 调整后收盘价,没有就直接赋值为收盘价

    相关文章

      网友评论

        本文标题:R语言用getSymbol从csv中获取行情数据

        本文链接:https://www.haomeiwen.com/subject/zarfqqtx.html