0

我有一个包含这些值的数据框,

2006-01-01        -1.1913                      -1.0560
2006-02-01        -2.1481                       2.3750
2006-03-01        -0.8210                      -2.0268
2006-04-01        -1.7912                       0.8889
2006-05-01        25.1429                       0.0000
2006-06-01        -1.3136                      -1.7455
2006-07-01         0.2324                      -2.6454
2006-08-01        -1.0000                      -0.7636
2006-09-01        -2.2222                      -0.7037
2006-10-01        -1.1685                      -0.1375
2006-11-01         0.4241                     -26.5405
2006-12-01         9.8000                       2.7455
2007-01-01        -1.7613                     -18.7966
2007-02-01        -0.4636                      -2.0048
2007-03-01         0.8459                       2.4521
2007-04-01        -1.7905                      -6.9062
2007-05-01        -2.4438                      -0.0036
2007-06-01        -5.4094                      -1.0458
2007-07-01         1.9556                      -1.5921
2007-08-01         0.0000                       3.7414
2007-09-01        -1.0000                      -1.7642
2007-10-01        12.2000                      -1.3738
2007-11-01        -3.3446                      -0.7758
2007-12-01         1.3611                      -2.3525
2008-01-01       -20.2310                      -1.5364
2008-02-01        -2.7449                      -4.0187
2008-03-01         0.3628                      -0.8034
2008-04-01         2.5537                      -0.0725
2008-05-01        -0.5215                       0.1333
2008-06-01        -0.4924                       0.6203
2008-07-01        -0.6088                      -0.3798
2008-08-01        14.6200                      -0.9227
2008-09-01         0.0000                     -17.3624
2008-10-01         0.8336                      -1.5661
2008-11-01         0.1238                      -1.0000
2008-12-01        -1.0000                      -0.2621
2009-01-01        -0.8090                      -0.3304
2009-02-01        -1.9545                      -0.4709
2009-03-01        -3.0211                       0.6837
2009-04-01        -0.9211                      -0.5718
2009-05-01        -1.7881                      -0.4193
2009-06-01         0.4124                       9.3043
2009-07-01        -3.6667                     -12.5385
2009-08-01        -0.5455                      14.9218
2009-09-01         4.5714                      -1.1215
2009-10-01        -1.0000                      -6.0245
2009-11-01        -1.4773                       0.0000
2009-12-01         0.0000                       0.6305
2010-01-01        -2.6299                       1.0949
2010-02-01        -3.8578                      -1.3323
2010-03-01         3.2557                     -16.9067
2010-04-01        -3.2278                      -4.7673
2010-05-01        -1.1714                      -1.9330
2010-06-01        -0.7720                      -0.3100
2010-07-01        -0.6923                      -1.1209
2010-08-01        -1.1220                      -0.5739
2010-09-01        -0.7470                      -3.5263
2010-10-01         0.0000                      -0.7229
2010-11-01         0.3829                      -1.1057
2010-12-01        -1.0307                      -1.9108
2011-01-01        -1.0912                      -1.6358
2011-02-01        -1.0772                      -1.6500
2011-03-01        -1.1413                      -1.0864
2011-04-01        -0.0332                      -1.5395
2011-05-01        -8.1691                      -2.2804
2011-06-01        -2.1174                       0.6410
2011-07-01        -1.4179                      -0.2997
2011-08-01         0.7956                       0.6583
2011-09-01        -4.5571                      -1.0000
2011-10-01         1.8657                      27.1284
2011-11-01         0.0606                      -0.4861
2011-12-01        28.2857                      -1.0977
2012-01-01        -2.1128                      -2.1809
2012-02-01        -4.7994                      -7.6667
2012-03-01        -0.9325                       2.6376
2012-04-01        -1.9226                      -0.3680
2012-05-01        -1.1292                      -2.9704
2012-06-01         0.0347                      -0.8264
2012-07-01        -1.0000                       0.8725
2012-08-01        -1.0000                       0.2366
2012-09-01        -0.0667                       0.0000
2012-10-01        -1.0000                      -1.1462
2012-11-01        -0.1667                      -0.9000
2012-12-01        -9.2353                      -1.4774
2013-01-01        -2.9306                      -1.0000
2013-02-01        -0.2606                      -0.7375
2013-03-01        -7.0779                      -1.4969
2013-04-01         0.6607                      -0.8166
2013-05-01        -4.7674                      -0.2141
2013-06-01         0.7778                      -5.4528
2013-07-01         0.0000                      -1.3889
2013-08-01         0.0000                      -1.4588
2013-09-01         0.2500                       1.2041
2013-10-01         0.0000                      -0.2918
2013-11-01        -0.5213                     -14.7615
2013-12-01        -0.3497                      13.5193
2014-01-01       -17.6737                       0.0000
2014-02-01        -0.6966                      -2.0138
2014-03-01        -1.0000                      -1.2967
2014-04-01        -1.4444                      -3.7517
2014-05-01         4.5603                      -1.1355
2014-06-01         0.2945                      -1.0628
2014-07-01         5.1440                      -0.4395
2014-08-01        -2.2775                      -1.3264
2014-09-01        -7.7500                      -1.4313
2014-10-01        -0.9530                      -0.4644
2014-11-01        -1.8744                      -1.1038
2014-12-01        -5.7532                      -2.4791
2015-01-01        -0.0404                      -0.1599
2015-02-01        18.5000                      -1.1891
2015-03-01         0.0000                       0.4396
2015-04-01        -1.4286                       0.0105
2015-05-01        -1.1498                       0.5161
2015-06-01        -1.8659                      70.2774
2015-07-01        -0.5928                      -2.6484
2015-08-01        -0.5127                      -1.1814
2015-09-01        -1.2339                      -5.4003
2015-10-01       -11.1905                      13.6607
2015-11-01         3.3000                       0.5686
2015-12-01        -0.7833                      -1.8138
2016-01-01        -1.2413                      -1.1033
2016-02-01        -0.8067                      -0.2074
2016-03-01        -0.4383                      -0.2674
2016-04-01        -0.5349                       1.6885
2016-05-01        -1.0000                      -4.8207
2016-06-01        -1.0530                      -0.7461
2016-07-01        -0.8088                       2.3791
2016-08-01         3.9330                     -12.0278
2016-09-01        -2.0472                      -1.4303
2016-10-01        -0.2364                      -1.0000
2016-11-01         0.8868                       4.8846
2016-12-01        -0.5165                      -0.4641
2017-01-01         0.3880                       3.8539
2017-02-01        -1.5064                       9.5750
2017-03-01        -1.3456                       0.4911
2017-04-01         1.1500                      -2.7050
2017-05-01         0.0000                      -0.5906
2017-06-01         5.9923                      -0.7917
2017-07-01         0.0789                      -0.6207
2017-08-01        -0.8097                       1.0000
2017-09-01        -0.1780                       1.2059
2017-10-01        -1.0000                       0.0000
2017-11-01        -0.6788                      -1.4740
2017-12-01         2.1500                      -1.7727
2018-01-01        -2.0617                      -0.4403
2018-02-01        -1.0000                      -0.0519
2018-03-01        -0.5211                       0.0696
2018-04-01        -1.9722                      -0.5826
2018-05-01        -1.3902                      -4.0403
2018-06-01        -0.0299                      -1.5248
2018-07-01        -1.0000                      -0.4532
2018-08-01        -0.6364                      -5.2667
2018-09-01        -0.8137                      -2.8323
2018-10-01         0.0000                      -1.5286
2018-11-01        -1.0000                      -2.1733
2018-12-01        -1.0000                      -2.0467
2019-01-01        -1.0000                      -0.5583
2019-02-01         0.0000                      -0.3910
2019-03-01        -5.4375                      -0.2152
2019-04-01        -1.0000                      -1.1478
2019-05-01        -1.5917                      -0.6252
2019-06-01        -3.2333                      -2.5271
2019-07-01         0.0000                      -6.7098
2019-08-01        -1.0000                      -1.7618
2019-09-01        17.5882                      -1.1489
2019-10-01        -1.2667                      -1.6582
2019-11-01         0.0000                      -1.4099
2019-12-01         0.0000                       0.1336
   

我想使用以下代码对数据进行回测

bt <- backtest(commercialservices,date.var = "date",in.var = c("date","Standard.Group.Plc.Ord","Sameer.Africa.Plc.Ord"),ret.var = "ret.0.1.m",do.spread = TRUE,by.period = FALSE)

但是当我尝试运行时,当我尝试进行回测时,它会不断出现此错误。另外,我对这一切都很陌生,所以我不确定错误是什么。列名称为日期,但未在数据框中指明,Standard.Group.Plc.Ord 和 Sameer.Africa.Plc.Ord。我通过对原始数据框执行返回来生成 data.frame。

Error in if (length(c(year, month, day, hour, min, sec)) == 6 && all(c(year,  : 
  missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In as_numeric(YYYY) : NAs introduced by coercion
2: In as_numeric(MM) : NAs introduced by coercion
3: In as_numeric(DD) : NAs introduced by coercion
4: In as_numeric(YYYY) : NAs introduced by coercion
5: In as_numeric(MM) : NAs introduced by coercion
6: In as_numeric(DD) : NAs introduced by coercion

我应该对我在这里列出的时间序列回报进行回测。任何人都知道如何修复它,或者其他可能有效的代码。

4

0 回答 0