我试图将带有rownames中日期的data.frame传递给PerformanceAnalytics
(包)函数。
我的数据如下,尝试运行代码时出现以下错误消息
> charts.PerformanceSummary(x$Return)
Error in checkData(R) :
The data cannot be converted into a time series. If you are trying to pass in names from a data object with one column, you should use the form 'data[rows, columns, drop = FALSE]'. Rownames should have standard date formats, such as '1985-03-15'.
如何解决这个问题?我认为PerformanceAnalytics会自动将我的行识别为日期。
我的数据
> str(x)
'data.frame': 201 obs. of 7 variables:
$ Open : num 69 67.8 64 67.2 68 ...
$ High : num 70 69 67.8 68.8 70.8 ...
$ Low : num 67 66 63.2 64.5 67.5 ...
$ Close : num 68.5 66 67.2 68 68.5 ...
$ Volume : num 2163200 2456100 2783000 2200300 2418000 ...
$ Adj.Close: num 55 53 54 54.6 55 ...
$ Return : num 0 0 0 0 0 0 0 0 0 0 ...
> x
Open High Low Close Volume Adj.Close Return
2008-11-28 69.00 70.00 67.00 68.50 2163200 54.9989 0.000000000
2008-12-01 67.75 69.00 66.00 66.00 2456100 52.9916 0.000000000
2008-12-02 64.00 67.75 63.25 67.25 2783000 53.9953 0.000000000
2008-12-03 67.25 68.75 64.50 68.00 2200300 54.5974 0.000000000
2008-12-04 68.00 70.75 67.50 68.50 2418000 54.9989 0.000000000
2008-12-05 68.00 68.75 63.50 64.50 2162200 51.7873 0.000000000
2008-12-08 67.25 73.50 67.25 72.00 4363100 57.8090 0.000000000
2008-12-09 71.25 76.25 70.00 74.50 4266500 59.8163 0.000000000
2008-12-10 73.75 78.00 73.00 77.50 3395900 62.2250 0.000000000
2008-12-11 76.75 76.75 74.25 76.00 2474600 61.0207 0.000000000
2008-12-12 74.00 74.75 72.25 74.50 3141800 59.8163 0.000000000
2008-12-15 70.00 74.50 67.25 67.25 7125600 53.9953 0.000000000
2008-12-16 66.25 69.50 66.00 69.50 3063200 55.8018 0.000000000
2008-12-17 69.25 70.00 67.00 70.00 2543400 56.2032 0.000000000
2008-12-18 69.50 73.50 69.25 72.25 4366000 58.0098 0.000000000
2008-12-19 70.50 72.00 69.75 71.75 2346600 57.6083 0.000000000
2008-12-22 70.50 71.00 68.25 69.75 3057600 56.0025 0.000000000
2008-12-23 68.75 69.50 67.50 69.25 2327700 55.6011 0.000000000
2008-12-24 69.25 69.25 69.25 69.25 0 55.6011 0.000000000
2008-12-25 69.25 69.25 69.25 69.25 0 55.6011 0.000000000
2008-12-26 69.25 69.25 69.25 69.25 0 55.6011 0.000000000
2008-12-29 69.00 69.75 67.50 68.00 1187600 54.5974 0.000000000
2008-12-30 67.75 68.50 66.50 66.75 1888700 53.5938 0.000000000
2008-12-31 66.75 66.75 66.75 66.75 0 53.5938 0.000000000
2009-01-01 66.75 66.75 66.75 66.75 0 53.5938 0.000000000
2009-01-02 67.75 72.75 67.00 72.25 1887500 58.0098 0.000000000
2009-01-05 73.75 75.50 73.00 74.25 2020400 59.6156 0.000000000
2009-01-06 74.25 74.25 74.25 74.25 0 59.6156 0.000000000
2009-01-07 73.75 75.00 73.50 74.50 2962600 59.8163 0.000000000
2009-01-08 73.00 74.25 71.00 72.25 2239100 58.0098 0.000000000
2009-01-09 72.00 72.25 70.25 71.25 1983600 57.2069 0.000000000
2009-01-12 69.50 71.00 69.00 69.75 1487000 56.0025 0.000000000
2009-01-13 68.75 69.75 67.75 68.75 2859100 55.1996 0.000000000
2009-01-14 69.75 69.75 63.25 64.25 2586900 51.5865 0.000000000
2009-01-15 64.00 66.50 60.75 63.00 4090800 50.5829 0.000000000
2009-01-16 65.00 66.00 64.00 64.75 2455600 51.9880 0.000000000
2009-01-19 66.00 66.00 64.75 65.50 2839200 52.5902 0.000000000
2009-01-20 66.00 66.75 62.25 62.75 2787600 50.3822 0.000000000
2009-01-21 62.00 67.50 61.75 65.25 5090700 52.3894 0.000000000
2009-01-22 67.00 69.00 65.50 65.75 2994600 52.7909 0.000000000
2009-01-23 64.75 66.00 61.25 62.00 4463400 49.7800 0.000000000
2009-01-26 62.00 65.75 61.50 65.75 3698700 52.7909 0.000000000
2009-01-27 66.00 67.25 64.75 65.75 3445900 52.7909 0.000000000
2009-01-28 66.25 69.00 66.00 67.00 2766400 53.7945 0.000000000
2009-01-29 67.00 67.25 62.25 62.75 2090700 50.3822 0.000000000
2009-01-30 63.00 63.75 59.00 60.50 6437600 48.5757 0.000000000
2009-02-02 60.25 62.00 58.75 60.25 3267600 48.3749 0.000000000
2009-02-03 60.75 62.50 59.25 62.50 3148000 50.1815 0.000000000
2009-02-04 62.75 69.50 61.75 68.25 6579500 54.7982 0.000000000
2009-02-05 66.00 69.50 66.00 69.00 6733600 55.4003 0.000000000
2009-02-06 69.00 71.00 68.25 70.00 5031600 56.2032 0.000000000
2009-02-09 69.50 72.00 68.75 71.75 3794200 57.6083 0.000000000
2009-02-10 70.25 72.00 69.75 70.75 2991500 56.8054 0.000000000
2009-02-11 68.75 70.75 68.25 68.50 2566400 54.9989 0.000000000
2009-02-12 67.75 70.25 66.75 70.00 3083800 56.2032 0.000000000
2009-02-13 70.25 71.50 68.00 69.25 2227000 55.6011 0.000000000
2009-02-16 68.50 69.25 67.25 68.75 1087100 55.1996 0.000000000
2009-02-17 67.50 67.50 65.00 65.50 1630200 52.5902 0.000000000
2009-02-18 65.00 65.50 62.50 65.00 40400 52.1887 0.000000000
2009-02-19 65.00 68.00 64.50 66.50 2701100 53.3931 0.000000000
2009-02-20 64.25 65.00 60.75 61.25 5534300 49.1778 0.000000000
2009-02-23 62.00 62.50 58.50 58.75 2524300 47.1706 0.000000000
2009-02-24 58.75 60.25 56.75 58.00 5117600 46.5684 0.000000000
2009-02-25 59.50 61.75 59.25 60.25 4418400 48.3749 0.000000000
2009-02-26 61.50 64.50 60.50 63.50 6482600 50.9844 0.000000000
2009-02-27 61.50 62.75 60.00 62.00 2834500 49.7800 0.000000000
2009-03-02 61.25 61.25 58.00 59.50 3087100 47.7727 0.000000000
2009-03-03 60.00 60.75 57.75 58.50 2606300 46.9698 0.000000000
2009-03-04 60.00 60.00 58.00 59.75 4554800 47.9735 0.000000000
2009-03-05 59.00 59.75 57.25 58.00 2777600 46.5684 0.000000000
2009-03-06 56.50 58.75 56.50 57.50 3338300 46.1669 0.000000000
2009-03-09 58.50 58.75 57.00 58.00 3708500 46.5684 0.000000000
2009-03-10 58.00 61.00 57.50 60.25 5163300 48.3749 0.000000000
2009-03-11 60.00 62.75 59.00 61.50 3668700 49.3786 0.000000000
2009-03-12 61.50 61.75 58.50 61.25 3404600 49.1778 0.000000000
2009-03-13 63.00 64.00 60.75 62.00 4048500 49.7800 0.000000000
2009-03-16 63.00 64.50 62.25 62.50 2945300 50.1815 0.000000000
2009-03-17 62.75 62.75 60.50 60.75 2369800 48.7764 0.000000000
2009-03-18 62.25 62.50 59.25 60.25 1968600 48.3749 0.000000000
2009-03-19 61.00 64.75 60.25 64.25 3730400 51.5865 0.000000000
2009-03-20 63.75 65.00 63.50 63.50 3186200 50.9844 0.000000000
2009-03-23 64.75 65.50 63.00 65.50 2738400 52.5902 0.000000000
2009-03-24 65.50 66.00 63.00 64.50 2994200 51.7873 0.000000000
2009-03-25 63.75 69.00 62.75 67.75 4342500 54.3967 0.000000000
2009-03-26 67.00 69.25 66.75 68.00 8300 54.5974 0.000000000
2009-03-27 67.75 69.50 66.75 68.50 3407200 54.9989 0.000000000
2009-03-30 66.75 67.00 63.75 64.50 3123200 51.7873 0.000000000
2009-03-31 64.00 66.25 63.00 64.50 3261600 51.7873 0.000000000
2009-04-01 64.50 64.75 60.75 64.25 6808900 51.5865 0.000000000
2009-04-02 67.00 73.25 66.75 72.75 8180500 58.4112 0.000000000
2009-04-03 72.00 76.50 71.25 75.75 5628500 60.8199 0.000000000
2009-04-06 76.00 76.75 74.25 75.00 3238900 60.2178 0.000000000
2009-04-07 75.75 76.00 72.25 73.75 3765800 59.2141 0.000000000
2009-04-08 72.00 75.75 71.50 75.50 3177100 60.6192 0.000000000
2009-04-09 75.50 76.00 74.25 76.00 887600 61.0207 0.000000000
2009-04-10 76.00 76.00 76.00 76.00 0 61.0207 0.000000000
2009-04-13 76.00 76.00 76.00 76.00 0 61.0207 0.000000000
2009-04-14 78.00 80.75 77.00 79.00 3923200 63.4294 0.000000000
2009-04-15 78.00 79.00 75.75 76.00 2425700 61.0207 0.000000000
2009-04-16 77.50 79.50 76.00 79.25 3331200 63.6301 0.000000000
2009-04-17 79.25 83.00 79.00 81.25 4058600 65.2359 0.000000000
2009-04-20 80.00 80.50 75.75 76.75 3682800 61.6228 0.000000000
2009-04-21 76.25 76.75 73.25 75.75 3293500 60.8199 0.000000000
2009-04-22 84.00 91.50 82.00 88.00 10525000 70.6555 0.000000000
2009-04-23 89.75 92.75 88.75 90.25 5664200 72.4620 0.000000000
2009-04-24 90.75 94.75 89.50 93.75 3982600 75.2722 0.000000000
2009-04-27 92.25 100.25 91.75 97.50 4702300 78.2831 0.000000000
2009-04-28 95.75 96.00 92.25 95.00 6479800 76.2758 0.000000000
2009-04-29 94.50 97.50 92.75 95.00 2565300 76.2758 0.000000000
2009-04-30 95.00 96.75 92.00 92.00 2480500 73.8671 0.000000000
2009-05-01 92.00 92.00 92.00 92.00 0 73.8671 0.000000000
2009-05-04 95.75 100.00 94.00 100.00 3653000 80.2903 0.086956169
2009-05-05 100.00 101.75 97.75 97.75 3400 78.4838 -0.022499605
2009-05-06 98.00 104.00 96.50 102.75 4010500 82.4983 0.051150683
2009-05-07 104.25 105.00 98.50 99.75 5145800 80.0896 -0.029196965
2009-05-08 101.25 103.25 99.25 100.25 2782200 80.4911 0.005013135
2009-05-11 100.25 100.75 93.50 97.25 3925100 78.0824 -0.029925048
2009-05-12 96.50 99.00 94.00 94.50 2770700 75.8744 -0.028277819
2009-05-13 94.75 95.50 88.25 89.00 4618500 71.4584 -0.058201449
2009-05-14 89.00 92.75 87.50 91.75 2712300 73.6664 0.030899097
2009-05-15 94.00 94.00 91.00 92.50 1675400 74.2686 0.008174690
2009-05-18 91.25 97.75 91.00 97.00 3331500 77.8816 0.048647746
2009-05-19 99.25 103.75 98.75 99.50 5343000 79.8889 0.025773739
2009-05-20 100.25 101.00 98.50 100.25 1169700 80.4911 0.007537968
2009-05-21 100.25 100.25 100.25 100.25 0 80.4911 0.000000000
2009-05-22 98.00 99.50 95.75 96.75 2095400 77.6809 -0.034913177
2009-05-25 96.50 97.75 95.50 96.00 1016600 77.0787 -0.007752227
2009-05-26 94.75 96.75 90.75 96.00 3642600 77.0787 0.000000000
2009-05-27 97.50 98.00 96.75 97.50 3729400 78.2831 0.015625588
2009-05-28 96.25 99.00 96.00 98.00 3575300 78.6845 0.005127543
2009-05-29 99.25 100.00 95.25 95.50 3396900 76.6773 -0.025509471
2009-06-01 97.00 100.75 97.00 100.75 1963400 80.8925 0.054973245
2009-06-02 98.00 99.25 95.75 98.00 3547300 78.6845 -0.027295485
2009-06-03 98.75 98.75 95.75 96.75 1865100 77.6809 -0.012754736
2009-06-04 97.25 98.00 96.75 98.00 2496300 78.6845 0.012919521
2009-06-05 98.75 102.25 98.50 100.25 3226800 80.4911 0.022960049
2009-06-08 100.25 101.00 97.25 99.50 2333200 79.8889 -0.007481572
2009-06-09 100.25 103.00 100.25 102.25 4285900 82.0969 0.027638383
2009-06-10 103.25 105.00 102.50 103.50 3933000 83.1005 0.012224579
2009-06-11 105.75 109.00 105.50 108.00 7400700 86.7136 0.043478679
2009-06-12 108.50 110.50 107.50 109.25 3325200 87.7172 0.011573732
2009-06-15 108.25 108.25 103.50 104.00 1848400 83.5019 -0.048055569
2009-06-16 103.75 105.00 102.75 102.75 21000 82.4983 -0.012018888
2009-06-17 101.50 102.25 97.50 99.00 4273700 79.4874 -0.036496510
2009-06-18 99.75 100.75 98.25 100.00 1910400 80.2903 0.010100972
2009-06-19 100.00 100.00 100.00 100.00 0 80.2903 0.000000000
2009-06-22 99.00 99.75 94.00 94.50 3168000 75.8744 0.000000000
2009-06-23 94.50 98.75 94.25 97.50 2356000 78.2831 0.000000000
2009-06-24 99.00 102.50 98.00 102.00 2184800 81.8961 0.046153001
2009-06-25 101.50 103.00 100.00 103.00 1950300 82.6990 0.009803886
2009-06-26 105.00 107.25 103.75 104.50 2649900 83.9034 0.014563659
2009-06-29 105.00 109.25 104.50 108.75 2420700 87.3157 0.040669389
2009-06-30 109.75 110.50 107.25 107.75 2999500 86.5128 -0.009195368
2009-07-01 108.50 111.50 108.50 111.00 2335800 89.1223 0.030163167
2009-07-02 110.50 111.00 106.75 108.00 3151600 86.7136 -0.027026906
2009-07-03 108.00 108.50 106.00 107.00 809300 85.9107 -0.009259217
2009-07-06 106.75 107.50 104.75 106.25 2030400 85.3085 -0.007009604
2009-07-07 107.00 109.50 105.75 107.50 2644100 86.3121 0.011764361
2009-07-08 107.00 108.75 106.25 106.75 3189000 85.7099 -0.006977006
2009-07-09 108.50 110.25 108.50 109.00 3032300 87.5165 0.021078078
2009-07-10 109.25 111.50 108.25 109.25 2637000 87.7172 0.002293282
2009-07-13 108.75 111.25 106.75 110.00 1901300 88.3194 0.006865244
2009-07-14 111.25 112.00 109.25 110.75 2061800 88.9215 0.006817302
2009-07-15 112.00 116.75 111.25 116.75 4185600 93.7390 0.054176999
2009-07-16 125.00 130.50 124.25 127.50 9537100 102.3702 0.092076937
2009-07-17 129.00 131.00 126.25 129.75 2709700 104.1767 0.017646737
2009-07-20 130.00 132.00 129.50 131.00 1762400 105.1803 0.009633632
2009-07-21 131.50 132.25 126.50 127.25 3644800 102.1695 -0.028625132
2009-07-22 127.50 132.25 127.50 130.75 4810100 104.9796 0.027504294
2009-07-23 131.25 131.25 126.75 130.00 3299000 104.3774 -0.005736353
2009-07-24 129.00 133.50 129.00 133.00 52200 106.7861 0.023076835
2009-07-27 134.50 134.75 130.00 132.00 2038900 105.9832 -0.007518769
2009-07-28 132.00 132.75 128.75 130.00 2058000 104.3774 -0.015151458
2009-07-29 130.00 131.50 127.00 128.25 2245700 102.9724 -0.013460768
2009-07-30 130.25 134.25 129.25 134.00 3305500 107.5890 0.044833373
2009-07-31 133.25 138.25 133.00 135.00 3155600 108.3920 0.007463588
2009-08-03 135.00 138.00 134.00 137.25 1916800 110.1985 0.016666359
2009-08-04 136.75 136.75 131.00 132.50 2139700 106.3847 -0.034608457
2009-08-05 132.00 136.00 132.00 134.50 2780800 107.9905 0.015094276
2009-08-06 135.50 139.25 135.00 136.00 2847500 109.1949 0.011152833
2009-08-07 135.25 141.00 134.50 140.00 3169600 112.4065 0.029411630
2009-08-10 139.75 139.75 137.75 139.00 1840700 111.6036 -0.007142825
2009-08-11 138.75 140.00 135.00 135.25 2143500 108.5927 -0.026978520
2009-08-12 134.75 138.50 134.50 138.50 2653600 111.2021 0.024029240
2009-08-13 139.00 149.75 138.75 143.75 8064400 115.4174 0.037906658
2009-08-14 144.25 148.50 141.50 142.75 40600 114.6145 -0.006956490
2009-08-17 141.25 142.00 137.25 137.50 2820500 110.3992 -0.036778069
2009-08-18 138.00 139.00 134.50 137.25 3389500 110.1985 -0.001817948
2009-08-19 136.00 139.75 134.25 138.50 3337300 111.2021 0.009107202
2009-08-20 141.00 148.25 141.00 147.50 5540400 118.4282 0.064981686
2009-08-21 147.50 154.00 147.25 153.50 5896100 123.2457 0.040678656
2009-08-24 155.50 157.00 150.00 154.00 3100300 123.6471 0.003256909
2009-08-25 151.00 151.00 148.75 149.75 3166000 120.2348 -0.027597089
2009-08-26 148.80 149.80 142.40 146.30 4975000 117.4648 -0.023038255
2009-08-27 144.70 146.30 142.70 145.30 2433000 116.6619 -0.006835239
2009-08-28 147.10 153.50 146.40 152.50 4590400 122.4428 0.049552596
2009-08-31 151.50 152.75 146.80 147.50 2984800 118.4282 -0.032787555
2009-09-01 148.60 148.90 145.10 145.30 3402800 116.6619 -0.014914522
2009-09-02 144.00 146.30 140.50 145.60 3403400 116.9027 0.002064084
2009-09-03 146.10 148.40 144.90 147.00 2835000 118.0268 0.009615689
2009-09-04 149.40 153.25 149.10 153.25 3937700 123.0449 0.042516615
答案 0 :(得分:2)
x$Return
是一个向量,而不是data.frame
,因此没有rownames
。请改用x["Return"]
或as.xts(d)[,"Return"]
。