非连续收益Pandas的Sharpe比计算

pgx2nnw8  于 2023-01-24  发布在  其他
关注(0)|答案(1)|浏览(112)

给定一个连续的每日时间序列回报率数据框架,年化滚动夏普比率是直接向前的。

rolling_sharpe=np.sqrt(252)*(returns_data.rolling(20).mean()/returns_data.rolling(20).std())

如何计算夏普比率时,回报是不连续的?有些时期,没有交易,因此没有回报,所以我想计算夏普比率的每一束回报数据。样本数据如下:-

returns_data=pd.read_clipboard(Total Portfolio Returns
2012-02-22 00:00:00 0
2012-02-23 00:00:00 0.0195621
2012-02-24 00:00:00 0.051800228
2012-02-27 00:00:00 0.062210527
2012-02-28 00:00:00 0.023068532
2012-02-29 00:00:00 0.030447514
2012-03-01 00:00:00 0.039470875
2012-03-02 00:00:00 0.041177472
2012-03-05 00:00:00 0
2012-03-06 00:00:00 0
2012-03-07 00:00:00 0
2012-03-08 00:00:00 0
2012-03-09 00:00:00 0
2012-03-12 00:00:00 0
2012-03-13 00:00:00 0
2012-03-14 00:00:00 0
2012-03-15 00:00:00 0
2012-03-16 00:00:00 0
2012-03-19 00:00:00 -0.032309446
2012-03-20 00:00:00 -0.032239217
2012-03-21 00:00:00 0.010980041
2012-03-22 00:00:00 0.038623866
2012-03-23 00:00:00 0.005617434
2012-03-26 00:00:00 -0.029235655
2012-03-27 00:00:00 0.060884076
2012-03-28 00:00:00 0.063963053
2012-03-29 00:00:00 0.014430555
2012-03-30 00:00:00 0.027769974
2012-04-02 00:00:00 0.00163598
2012-04-03 00:00:00 -0.050771732
2012-04-04 00:00:00 -0.030861199
2012-04-05 00:00:00 -0.006455398
2012-04-06 00:00:00 0.056793855
2012-04-09 00:00:00 0
2012-04-10 00:00:00 0
2012-04-11 00:00:00 0
2012-04-12 00:00:00 0
2012-04-13 00:00:00 0
2012-04-16 00:00:00 0
2012-04-17 00:00:00 0
2012-04-18 00:00:00 0
2012-04-19 00:00:00 0
2012-04-20 00:00:00 0
2012-04-23 00:00:00 -0.009774184
2012-04-24 00:00:00 -0.010373539
2012-04-25 00:00:00 -0.005179848
2012-04-26 00:00:00 0.051854418
2012-04-27 00:00:00 0.008663732
2012-04-30 00:00:00 0.002851698
2012-05-01 00:00:00 -0.037775443
2012-05-02 00:00:00 -0.060803098
2012-05-03 00:00:00 -0.168344995
2012-05-04 00:00:00 -0.1643259
2012-05-07 00:00:00 -0.162943278
2012-05-08 00:00:00 -0.157669982
2012-05-09 00:00:00 0.007172067
2012-05-10 00:00:00 -0.089246612
2012-05-11 00:00:00 0.038920745
2012-05-14 00:00:00 0.08533624
2012-05-15 00:00:00 0.140922585
2012-05-16 00:00:00 0.045546428
2012-05-17 00:00:00 -0.020234243
2012-05-18 00:00:00 -0.02541043
2012-05-21 00:00:00 -0.022630628
2012-05-22 00:00:00 -0.023286229
2012-05-23 00:00:00 -0.023451882
2012-05-24 00:00:00 0.017431513
2012-05-25 00:00:00 0.034835403
2012-05-28 00:00:00 0.034835403
2012-05-29 00:00:00 0.05351944
2012-05-30 00:00:00 0.0439659
2012-05-31 00:00:00 -0.005033751
2012-06-01 00:00:00 0
2012-06-04 00:00:00 0
2012-06-05 00:00:00 0
2012-06-06 00:00:00 0
2012-06-07 00:00:00 0
2012-06-08 00:00:00 0
2012-06-11 00:00:00 0
2012-06-12 00:00:00 0
2012-06-13 00:00:00 0
2012-06-14 00:00:00 0
2012-06-15 00:00:00 0
2012-06-18 00:00:00 0
2012-06-19 00:00:00 0
2012-06-20 00:00:00 0
2012-06-21 00:00:00 0
2012-06-22 00:00:00 0
2012-06-25 00:00:00 0
2012-06-26 00:00:00 -3.10925E-05
2012-06-27 00:00:00 -0.010098048
2012-06-28 00:00:00 -0.003800967
2012-06-29 00:00:00 -0.008551493
2012-07-02 00:00:00 -0.008650458
2012-07-03 00:00:00 0.06753602
2012-07-04 00:00:00 0.06753602
2012-07-05 00:00:00 0.064107726
2012-07-06 00:00:00 0.08186377
2012-07-09 00:00:00 0.116135651
2012-07-10 00:00:00 0.163811492
2012-07-11 00:00:00 0.102048994
2012-07-12 00:00:00 0.054056035
2012-07-13 00:00:00 0
2012-07-16 00:00:00 0
2012-07-17 00:00:00 0
2012-07-18 00:00:00 0
2012-07-19 00:00:00 0
2012-07-20 00:00:00 0
2012-07-23 00:00:00 0
2012-07-24 00:00:00 0
2012-07-25 00:00:00 0
2012-07-26 00:00:00 0
2012-07-27 00:00:00 0
2012-07-30 00:00:00 0
2012-07-31 00:00:00 0
2012-08-01 00:00:00 0
2012-08-02 00:00:00 0
2012-08-03 00:00:00 0
2012-08-06 00:00:00 0
2012-08-07 00:00:00 0
2012-08-08 00:00:00 0
2012-08-09 00:00:00 0.013050241
2012-08-10 00:00:00 0.015368784
2012-08-13 00:00:00 0.021910829
2012-08-14 00:00:00 0.010870417
2012-08-15 00:00:00 0.040988129
2012-08-16 00:00:00 0.04271743
2012-08-17 00:00:00 0.045133597
2012-08-20 00:00:00 0.03176928
2012-08-21 00:00:00 0.038841389
2012-08-22 00:00:00 0.035873994
2012-08-23 00:00:00 -0.004644754
2012-08-24 00:00:00 0.001197716
2012-08-27 00:00:00 0.002871442
2012-08-28 00:00:00 -0.00191597
2012-08-29 00:00:00 -0.00334029
2012-08-30 00:00:00 0
2012-08-31 00:00:00 0
2012-09-03 00:00:00 0
2012-09-04 00:00:00 0
2012-09-05 00:00:00 0
2012-09-06 00:00:00 0
2012-09-07 00:00:00 0
2012-09-10 00:00:00 0
2012-09-11 00:00:00 0
2012-09-12 00:00:00 0
2012-09-13 00:00:00 0
2012-09-14 00:00:00 0
2012-09-17 00:00:00 0
2012-09-18 00:00:00 0
2012-09-19 00:00:00 0
2012-09-20 00:00:00 0
2012-09-21 00:00:00 0
2012-09-24 00:00:00 0
2012-09-25 00:00:00 0
2012-09-26 00:00:00 0
2012-09-27 00:00:00 0
2012-09-28 00:00:00 0
2012-10-01 00:00:00 0
2012-10-02 00:00:00 0
2012-10-03 00:00:00 0
2012-10-04 00:00:00 0
2012-10-05 00:00:00 0
2012-10-08 00:00:00 0
2012-10-09 00:00:00 0
2012-10-10 00:00:00 0
2012-10-11 00:00:00 0
2012-10-12 00:00:00 0
2012-10-15 00:00:00 0
2012-10-16 00:00:00 0
2012-10-17 00:00:00 0
2012-10-18 00:00:00 0
2012-10-19 00:00:00 -0.016470636
2012-10-22 00:00:00 -0.022171895
2012-10-23 00:00:00 -0.031943297
2012-10-24 00:00:00 -0.042078149
2012-10-25 00:00:00 -0.05182068
2012-10-26 00:00:00 -0.013149637
2012-10-29 00:00:00 -0.013149637
2012-10-30 00:00:00 -0.013149637
2012-10-31 00:00:00 -0.028141269
2012-11-01 00:00:00 0.012524822
2012-11-02 00:00:00 0.088510834
2012-11-05 00:00:00 0.028744559
2012-11-06 00:00:00 -0.044610743
2012-11-07 00:00:00 -0.035459158
2012-11-08 00:00:00 -0.038806271
2012-11-09 00:00:00 -0.011205795
2012-11-12 00:00:00 -0.008085491
2012-11-13 00:00:00 -0.023009917
2012-11-14 00:00:00 -0.022537759
2012-11-15 00:00:00 -0.022313854
2012-11-16 00:00:00 0
2012-11-19 00:00:00 0
2012-11-20 00:00:00 0
2012-11-21 00:00:00 0
2012-11-22 00:00:00 0
2012-11-23 00:00:00 0
2012-11-26 00:00:00 0
2012-11-27 00:00:00 0
2012-11-28 00:00:00 0
2012-11-29 00:00:00 0
2012-11-30 00:00:00 -0.001710408
2012-12-03 00:00:00 -0.003487885
2012-12-04 00:00:00 0.00628604
2012-12-05 00:00:00 0.017448479
2012-12-06 00:00:00 0.017667159
2012-12-07 00:00:00 0
2012-12-10 00:00:00 0
2012-12-11 00:00:00 0
2012-12-12 00:00:00 0
2012-12-13 00:00:00 0
2012-12-14 00:00:00 0
2012-12-17 00:00:00 0
2012-12-18 00:00:00 0.007414493
2012-12-19 00:00:00 0.015113605
2012-12-20 00:00:00 -0.006102573
2012-12-21 00:00:00 -0.000169615
2012-12-24 00:00:00 0.00799941
2012-12-25 00:00:00 -0.017361619
2012-12-26 00:00:00 -0.041363863
2012-12-27 00:00:00 -0.051628063
2012-12-28 00:00:00 -0.068880623
2012-12-31 00:00:00 -0.07590269
2013-01-01 00:00:00 -0.07590269
2013-01-02 00:00:00 -0.093055071
2013-01-03 00:00:00 -0.087476145
2013-01-04 00:00:00 -0.104103242
2013-01-07 00:00:00 -0.104915475
2013-01-08 00:00:00 -0.024219063
2013-01-09 00:00:00 0.018873641
2013-01-10 00:00:00 0.031090737
2013-01-11 00:00:00 0.044943615
2013-01-14 00:00:00 0.039555769
2013-01-15 00:00:00 -0.019785013
2013-01-16 00:00:00 -0.092697754
2013-01-17 00:00:00 -0.192494102
2013-01-18 00:00:00 -0.27857451
2013-01-21 00:00:00 -0.27857451
2013-01-22 00:00:00 -0.370994362
2013-01-23 00:00:00 -0.387015428
2013-01-24 00:00:00 -0.336950171
2013-01-25 00:00:00 -0.331424599
2013-01-28 00:00:00 -0.282345495
2013-01-29 00:00:00 -0.262183612
2013-01-30 00:00:00 -0.231922813
2013-01-31 00:00:00 -0.320258699
2013-02-01 00:00:00 -0.190866381
2013-02-04 00:00:00 -0.230374716
2013-02-05 00:00:00 -0.176725687
2013-02-06 00:00:00 -0.167805214
2013-02-07 00:00:00 -0.107030441
2013-02-08 00:00:00 -0.092097127
2013-02-11 00:00:00 -0.0533792
2013-02-12 00:00:00 -0.042017275
2013-02-13 00:00:00 -0.057243635
2013-02-14 00:00:00 -0.033419335
2013-02-15 00:00:00 -0.043839537
2013-02-18 00:00:00 -0.043839537
2013-02-19 00:00:00 -0.027742817
2013-02-20 00:00:00 -0.022871311
2013-02-21 00:00:00 -0.040679227
2013-02-22 00:00:00 0
2013-02-25 00:00:00 0.003009876
2013-02-26 00:00:00 -0.008645656
2013-02-27 00:00:00 0.001742188
2013-02-28 00:00:00 0.018534214
2013-03-01 00:00:00 0.040604355
2013-03-04 00:00:00 0.058067539
2013-03-05 00:00:00 0.050239311
2013-03-06 00:00:00 0.020020819
2013-03-07 00:00:00 0.017623767
2013-03-08 00:00:00 0.00819074
2013-03-11 00:00:00 0.008091362
2013-03-12 00:00:00 0.008893257
2013-03-13 00:00:00 0.001483761
2013-03-14 00:00:00 0.00671589
2013-03-15 00:00:00 0.013704296
2013-03-18 00:00:00 0.01209166
2013-03-19 00:00:00 -0.005345721
2013-03-20 00:00:00 -0.00830554
2013-03-21 00:00:00 -0.010961494
2013-03-22 00:00:00 0.019410859
2013-03-25 00:00:00 0.021191705
2013-03-26 00:00:00 0.028222459
2013-03-27 00:00:00 0.02849361
2013-03-28 00:00:00 -0.003775246
2013-03-29 00:00:00 -0.003775246
2013-04-01 00:00:00 -0.001112213
2013-04-02 00:00:00 0.006807362
2013-04-03 00:00:00 0.009599506
2013-04-04 00:00:00 -0.001074554
2013-04-05 00:00:00 -0.000689773
2013-04-08 00:00:00 -0.00707936
2013-04-09 00:00:00 -0.015818302
2013-04-10 00:00:00 -0.011836624
2013-04-11 00:00:00 -0.00140599
2013-04-12 00:00:00 -0.013308448
2013-04-15 00:00:00 -0.027554731
2013-04-16 00:00:00 -0.034646775
2013-04-17 00:00:00 -0.015772954
2013-04-18 00:00:00 0.01737469
2013-04-19 00:00:00 -0.003346315
2013-04-22 00:00:00 -0.033677858
2013-04-23 00:00:00 -0.060589823
2013-04-24 00:00:00 -0.006210338
2013-04-25 00:00:00 -0.034153624
2013-04-26 00:00:00 -0.027677138
2013-04-29 00:00:00 -0.045828069
2013-04-30 00:00:00 -0.112631944
2013-05-01 00:00:00 -0.086033584
2013-05-02 00:00:00 -0.066904323
2013-05-03 00:00:00 -0.127560826
2013-05-06 00:00:00 -0.10413789
2013-05-07 00:00:00 -0.099175296
2013-05-08 00:00:00 0.044232881
2013-05-09 00:00:00 0.04008942
2013-05-10 00:00:00 -0.139435146
2013-05-13 00:00:00 -0.0803603
2013-05-14 00:00:00 0.042851987
2013-05-15 00:00:00 0.055435825
2013-05-16 00:00:00 0.037367582
2013-05-17 00:00:00 0.056216793
2013-05-20 00:00:00 0.063087452
2013-05-21 00:00:00 0.043206724
2013-05-22 00:00:00 0.017772516
2013-05-23 00:00:00 0
2013-05-24 00:00:00 0
2013-05-27 00:00:00 0
2013-05-28 00:00:00 0
2013-05-29 00:00:00 0
2013-05-30 00:00:00 0
2013-05-31 00:00:00 -0.031052121
2013-06-03 00:00:00 -0.02489847
2013-06-04 00:00:00 -0.042416071
2013-06-05 00:00:00 -0.105458411
2013-06-06 00:00:00 -0.163118082
2013-06-07 00:00:00 -0.182620576
2013-06-10 00:00:00 -0.220923417
2013-06-11 00:00:00 -0.262924987
2013-06-12 00:00:00 -0.315178309
2013-06-13 00:00:00 -0.330515949
2013-06-14 00:00:00 -0.24161157
2013-06-17 00:00:00 -0.287435566
2013-06-18 00:00:00 -0.197473298
2013-06-19 00:00:00 -0.362315289
2013-06-20 00:00:00 -0.428660824
2013-06-21 00:00:00 -0.397121184
2013-06-24 00:00:00 -0.119113776
2013-06-25 00:00:00 -0.032167918
2013-06-26 00:00:00 0.060651466
2013-06-27 00:00:00 0.190167654
2013-06-28 00:00:00 0.029187161
2013-07-01 00:00:00 -0.013609113
2013-07-02 00:00:00 -0.007566765
2013-07-03 00:00:00 0.021678873
2013-07-04 00:00:00 0.021678873
2013-07-05 00:00:00 -0.070642511
2013-07-08 00:00:00 -0.087321363
2013-07-09 00:00:00 -0.059671721
2013-07-10 00:00:00 -0.043260944
2013-07-11 00:00:00 0.053428796
2013-07-12 00:00:00 -0.095002838
2013-07-15 00:00:00 -0.098042701
2013-07-16 00:00:00 -0.024271743
2013-07-17 00:00:00 -0.091858663
2013-07-18 00:00:00 -0.03572997
2013-07-19 00:00:00 -0.068186415
2013-07-22 00:00:00 -0.03765266
2013-07-23 00:00:00 -0.043138225
2013-07-24 00:00:00 0.014404702
2013-07-25 00:00:00 0.030305338
2013-07-26 00:00:00 0.017492736
2013-07-29 00:00:00 -0.068957874
2013-07-30 00:00:00 -0.050808949
2013-07-31 00:00:00 -0.019752697
2013-08-01 00:00:00 -0.101666589
2013-08-02 00:00:00 -0.092371578
2013-08-05 00:00:00 -0.100030261
2013-08-06 00:00:00 -0.082087643
2013-08-07 00:00:00 -0.087011979
2013-08-08 00:00:00 -0.096261868
2013-08-09 00:00:00 -0.068113528
2013-08-12 00:00:00 -0.076462134
2013-08-13 00:00:00 -0.078881746
2013-08-14 00:00:00 -0.079862522
2013-08-15 00:00:00 -0.072794269
2013-08-16 00:00:00 -0.071174026
2013-08-19 00:00:00 -0.033344677
2013-08-20 00:00:00 -0.03071869
2013-08-21 00:00:00 0
2013-08-22 00:00:00 0
2013-08-23 00:00:00 0
2013-08-26 00:00:00 0
2013-08-27 00:00:00 0
2013-08-28 00:00:00 0
2013-08-29 00:00:00 0
2013-08-30 00:00:00 0
2013-09-02 00:00:00 0
2013-09-03 00:00:00 0
2013-09-04 00:00:00 0
2013-09-05 00:00:00 0
2013-09-06 00:00:00 0
2013-09-09 00:00:00 0
2013-09-10 00:00:00 0
2013-09-11 00:00:00 0
2013-09-12 00:00:00 0
2013-09-13 00:00:00 -0.00204141
2013-09-16 00:00:00 -0.013604333
2013-09-17 00:00:00 -0.027362773
2013-09-18 00:00:00 -0.027100937
2013-09-19 00:00:00 -0.032577621
2013-09-20 00:00:00 -0.011232651
2013-09-23 00:00:00 -0.012531919
2013-09-24 00:00:00 -0.017062539
2013-09-25 00:00:00 0.021095288
2013-09-26 00:00:00 -0.016106339
2013-09-27 00:00:00 -0.035970207
2013-09-30 00:00:00 -0.043884349
2013-10-01 00:00:00 -0.032012077
2013-10-02 00:00:00 -0.082380915
2013-10-03 00:00:00 -0.066150164
2013-10-04 00:00:00 -0.079175649
2013-10-07 00:00:00 -0.056552561
2013-10-08 00:00:00 -0.026518754
2013-10-09 00:00:00 -0.022201148
2013-10-10 00:00:00 -0.020658421
2013-10-11 00:00:00 0
2013-10-14 00:00:00 0
2013-10-15 00:00:00 0
2013-10-16 00:00:00 0
2013-10-17 00:00:00 0
2013-10-18 00:00:00 0
2013-10-21 00:00:00 0.005690514
2013-10-22 00:00:00 -0.051106141
2013-10-23 00:00:00 -0.017436119
2013-10-24 00:00:00 -0.040166378
2013-10-25 00:00:00 -0.00141043
2013-10-28 00:00:00 0.02601729
2013-10-29 00:00:00 0.056487852
2013-10-30 00:00:00 0.009296636
2013-10-31 00:00:00 0.100782048
2013-11-01 00:00:00 0.112388754
2013-11-04 00:00:00 0.04362284
2013-11-05 00:00:00 0.027570239
2013-11-06 00:00:00 0.021350855
2013-11-07 00:00:00 0
2013-11-08 00:00:00 0
2013-11-11 00:00:00 0
2013-11-12 00:00:00 0
2013-11-13 00:00:00 0
2013-11-14 00:00:00 0
2013-11-15 00:00:00 0
2013-11-18 00:00:00 0
2013-11-19 00:00:00 0
2013-11-20 00:00:00 0
2013-11-21 00:00:00 0
2013-11-22 00:00:00 0
2013-11-25 00:00:00 0
2013-11-26 00:00:00 0
2013-11-27 00:00:00 0
2013-11-28 00:00:00 0
2013-11-29 00:00:00 0
2013-12-02 00:00:00 0
2013-12-03 00:00:00 0
2013-12-04 00:00:00 0
2013-12-05 00:00:00 0
2013-12-06 00:00:00 0
2013-12-09 00:00:00 0
2013-12-10 00:00:00 0
2013-12-11 00:00:00 0
2013-12-12 00:00:00 0
2013-12-13 00:00:00 0
2013-12-16 00:00:00 0
2013-12-17 00:00:00 0
2013-12-18 00:00:00 0
2013-12-19 00:00:00 0
2013-12-20 00:00:00 0
2013-12-23 00:00:00 0
2013-12-24 00:00:00 0
2013-12-25 00:00:00 0
2013-12-26 00:00:00 0
2013-12-27 00:00:00 0
2013-12-30 00:00:00 0
2013-12-31 00:00:00 0
2014-01-01 00:00:00 0
2014-01-02 00:00:00 0
2014-01-03 00:00:00 0
2014-01-06 00:00:00 0
2014-01-07 00:00:00 0
2014-01-08 00:00:00 0
2014-01-09 00:00:00 0
2014-01-10 00:00:00 0
2014-01-13 00:00:00 0
2014-01-14 00:00:00 0
2014-01-15 00:00:00 0
2014-01-16 00:00:00 0
2014-01-17 00:00:00 0
2014-01-20 00:00:00 0
2014-01-21 00:00:00 -0.003009291
2014-01-22 00:00:00 -0.011036476
2014-01-23 00:00:00 -0.002468122
2014-01-24 00:00:00 -0.023811655
2014-01-27 00:00:00 -0.04209
2014-01-28 00:00:00 -0.029701348
2014-01-29 00:00:00 -0.068001648
2014-01-30 00:00:00 -0.033411437
2014-01-31 00:00:00 -0.029981004
2014-02-03 00:00:00 -0.04302006
2014-02-04 00:00:00 -0.07553861
2014-02-05 00:00:00 -0.040348554
2014-02-06 00:00:00 0.004742504
2014-02-07 00:00:00 -0.026291026
2014-02-10 00:00:00 0.001275557
2014-02-11 00:00:00 -0.031719608
2014-02-12 00:00:00 -0.037413674
2014-02-13 00:00:00 -0.041068841
2014-02-14 00:00:00 -0.015821462
2014-02-17 00:00:00 -0.015821462
2014-02-18 00:00:00 -0.006913356
2014-02-19 00:00:00 -0.026756193
2014-02-20 00:00:00 -0.032224745
2014-02-21 00:00:00 -0.03035761
2014-02-24 00:00:00 -0.02576399
2014-02-25 00:00:00 -0.025881909
2014-02-26 00:00:00 0
2014-02-27 00:00:00 0
2014-02-28 00:00:00 0
2014-03-03 00:00:00 0
2014-03-04 00:00:00 0
2014-03-05 00:00:00 -0.001188303
2014-03-06 00:00:00 0.007363393
2014-03-07 00:00:00 -0.003359008
2014-03-10 00:00:00 -0.00238304
2014-03-11 00:00:00 -0.016016524
2014-03-12 00:00:00 -0.029452267
2014-03-13 00:00:00 -0.053702443
2014-03-14 00:00:00 -0.074401157
2014-03-17 00:00:00 -0.079012053
2014-03-18 00:00:00 -0.083202923
2014-03-19 00:00:00 -0.12442983
2014-03-20 00:00:00 -0.151378178
2014-03-21 00:00:00 -0.149018905
2014-03-24 00:00:00 -0.179436588
2014-03-25 00:00:00 -0.051508869
2014-03-26 00:00:00 0.019784193
2014-03-27 00:00:00 -0.103779468
2014-03-28 00:00:00 -0.055177281
2014-03-31 00:00:00 -0.028958653
2014-04-01 00:00:00 0.021940656
2014-04-02 00:00:00 0.171662239
2014-04-03 00:00:00 0.111081693
2014-04-04 00:00:00 0.092541439
2014-04-07 00:00:00 0.046070524
2014-04-08 00:00:00 0
2014-04-09 00:00:00 0
2014-04-10 00:00:00 0
2014-04-11 00:00:00 0
2014-04-14 00:00:00 0
2014-04-15 00:00:00 0
2014-04-16 00:00:00 -0.014144202
2014-04-17 00:00:00 0.029819599
2014-04-18 00:00:00 0.029819599
2014-04-21 00:00:00 0.055398557
2014-04-22 00:00:00 0.052547195
2014-04-23 00:00:00 0.049172856
2014-04-24 00:00:00 0.021218448
2014-04-25 00:00:00 -0.016876744
2014-04-28 00:00:00 -0.00369895
2014-04-29 00:00:00 0.255167274
2014-04-30 00:00:00 0.327482554
2014-05-01 00:00:00 0.001878053
2014-05-02 00:00:00 0.00655974
2014-05-05 00:00:00 0.006459876
2014-05-06 00:00:00 0.005758527
2014-05-07 00:00:00 0.008199731
2014-05-08 00:00:00 0
2014-05-09 00:00:00 0
2014-05-12 00:00:00 0
2014-05-13 00:00:00 0
2014-05-14 00:00:00 0
2014-05-15 00:00:00 0.007393639
2014-05-16 00:00:00 0.014535202
2014-05-19 00:00:00 0.005924295
2014-05-20 00:00:00 0.013695579
2014-05-21 00:00:00 0.013266665
2014-05-22 00:00:00 0.008902221
2014-05-23 00:00:00 0.010481935
2014-05-26 00:00:00 0.010481935
2014-05-27 00:00:00 0.035054531
2014-05-28 00:00:00 0.011118599
2014-05-29 00:00:00 0.020560505
2014-05-30 00:00:00 0.027539339
2014-06-02 00:00:00 0.014752899
2014-06-03 00:00:00 0.003066032
2014-06-04 00:00:00 -0.047843163
2014-06-05 00:00:00 -0.054205237
2014-06-06 00:00:00 -0.048331663
2014-06-09 00:00:00 -0.058128882
2014-06-10 00:00:00 -0.008664456
2014-06-11 00:00:00 -0.004668962
2014-06-12 00:00:00 0.030936686
2014-06-13 00:00:00 0.054554623
2014-06-16 00:00:00 0.059419214
2014-06-17 00:00:00 0
2014-06-18 00:00:00 0
2014-06-19 00:00:00 0
2014-06-20 00:00:00 0
2014-06-23 00:00:00 0
2014-06-24 00:00:00 0
2014-06-25 00:00:00 0
2014-06-26 00:00:00 0
2014-06-27 00:00:00 0
2014-06-30 00:00:00 0
2014-07-01 00:00:00 0
2014-07-02 00:00:00 0
2014-07-03 00:00:00 0
2014-07-04 00:00:00 0
2014-07-07 00:00:00 0
2014-07-08 00:00:00 0
2014-07-09 00:00:00 0
2014-07-10 00:00:00 0
2014-07-11 00:00:00 0
2014-07-14 00:00:00 0
2014-07-15 00:00:00 0
2014-07-16 00:00:00 0
2014-07-17 00:00:00 0
2014-07-18 00:00:00 0
2014-07-21 00:00:00 0
2014-07-22 00:00:00 0.000912375
2014-07-23 00:00:00 -0.00122359
2014-07-24 00:00:00 -0.02883136
2014-07-25 00:00:00 -0.049045542
2014-07-28 00:00:00 -0.058515951
2014-07-29 00:00:00 -0.043148325
2014-07-30 00:00:00 -0.13325259
2014-07-31 00:00:00 -0.227254651
2014-08-01 00:00:00 -0.20618476
2014-08-04 00:00:00 -0.220594741
2014-08-05 00:00:00 -0.263349223
2014-08-06 00:00:00 -0.235023027
2014-08-07 00:00:00 -0.174164215
2014-08-08 00:00:00 -0.1231073
2014-08-11 00:00:00 -0.064870435
2014-08-12 00:00:00 -0.032873781
2014-08-13 00:00:00 -0.004954648
2014-08-14 00:00:00 -0.021762924
2014-08-15 00:00:00 -0.01477102
2014-08-18 00:00:00 0.006393443
2014-08-19 00:00:00 -0.000819617
2014-08-20 00:00:00 0.000245528
2014-08-21 00:00:00 0.003708757
2014-08-22 00:00:00 -0.021200548
2014-08-25 00:00:00 -0.009091008
2014-08-26 00:00:00 -0.014595777
2014-08-27 00:00:00 -0.008708162
2014-08-28 00:00:00 0.001714076
2014-08-29 00:00:00 0.002229085
2014-09-01 00:00:00 0.002229085
2014-09-02 00:00:00 0.007926282
2014-09-03 00:00:00 -0.002779637
2014-09-04 00:00:00 -0.006719782
2014-09-05 00:00:00 0.000529773
2014-09-08 00:00:00 -0.016123388
2014-09-09 00:00:00 -0.001669907
2014-09-10 00:00:00 -0.013132579
2014-09-11 00:00:00 -0.009915986
2014-09-12 00:00:00 -0.021542735
2014-09-15 00:00:00 -0.016070889
2014-09-16 00:00:00 -0.010521565
2014-09-17 00:00:00 0.012585887
2014-09-18 00:00:00 0.007678928
2014-09-19 00:00:00 0.009150104
2014-09-22 00:00:00 0.003282854
2014-09-23 00:00:00 -0.006029097
2014-09-24 00:00:00 -0.011660572
2014-09-25 00:00:00 -0.016339454
2014-09-26 00:00:00 -0.013165164
2014-09-29 00:00:00 -0.01343622
2014-09-30 00:00:00 -0.007282518
2014-10-01 00:00:00 -0.013576284
2014-10-02 00:00:00 -0.00678095
2014-10-03 00:00:00 -0.027837798
2014-10-06 00:00:00 -0.021032163
2014-10-07 00:00:00 -0.002767984
2014-10-08 00:00:00 0.009244277
2014-10-09 00:00:00 0.016441689
2014-10-10 00:00:00 0.025396328
2014-10-13 00:00:00 0
2014-10-14 00:00:00 0
2014-10-15 00:00:00 -0.025643129
2014-10-16 00:00:00 -0.034493538
2014-10-17 00:00:00 0.053826353
2014-10-20 00:00:00 0.108819777
2014-10-21 00:00:00 0.1675089
2014-10-22 00:00:00 0.153832066
2014-10-23 00:00:00 0.114162102
2014-10-24 00:00:00 0.116804557
2014-10-27 00:00:00 0.129672435
2014-10-28 00:00:00 0.154088569
2014-10-29 00:00:00 0.230874787
2014-10-30 00:00:00 0.297788871
2014-10-31 00:00:00 0.115307059
2014-11-03 00:00:00 0.066283574
2014-11-04 00:00:00 0.010013018
2014-11-05 00:00:00 -0.036951805
2014-11-06 00:00:00 -0.053908062
2014-11-07 00:00:00 -0.05450928
2014-11-10 00:00:00 -0.043921826
2014-11-11 00:00:00 -0.011116737
2014-11-12 00:00:00 0.05108424
2014-11-13 00:00:00 0.044371945
2014-11-14 00:00:00 0.093157583
2014-11-17 00:00:00 0.051750967
2014-11-18 00:00:00 0.011223035
2014-11-19 00:00:00 0.0130991
2014-11-20 00:00:00 0.014675415
2014-11-21 00:00:00 0.011647648
2014-11-24 00:00:00 0.002252668
2014-11-25 00:00:00 0.001329151
2014-11-26 00:00:00 0.002898408
2014-11-27 00:00:00 0.002898408
2014-11-28 00:00:00 0.000216158
2014-12-01 00:00:00 -0.00456323
2014-12-02 00:00:00 0.001014282
2014-12-03 00:00:00 -0.001355768
2014-12-04 00:00:00 -0.014429809
2014-12-05 00:00:00 -0.009193921
2014-12-08 00:00:00 -0.011736651
2014-12-09 00:00:00 -0.004930051
2014-12-10 00:00:00 -0.009353646
2014-12-11 00:00:00 -0.007736339
2014-12-12 00:00:00 0.000833985
2014-12-15 00:00:00 0.018561737
2014-12-16 00:00:00 -0.00631084
2014-12-17 00:00:00 0.013447671
2014-12-18 00:00:00 0.003411133
2014-12-19 00:00:00 0.002885577
2014-12-22 00:00:00 0.004643325
2014-12-23 00:00:00 -0.003495581
2014-12-24 00:00:00 0.005484176
2014-12-25 00:00:00 0.005484176
2014-12-26 00:00:00 0.007994824
2014-12-29 00:00:00 0.005891716
2014-12-30 00:00:00 -0.006383894
2014-12-31 00:00:00 -0.013172087
2015-01-01 00:00:00 0.000254388
2015-01-02 00:00:00 -0.003877185
2015-01-05 00:00:00 -0.019592295
2015-01-06 00:00:00 -0.015846463
2015-01-07 00:00:00 -0.014633653
2015-01-08 00:00:00 -0.013059721
2015-01-09 00:00:00 -0.020836692
2015-01-12 00:00:00 -0.019238134
2015-01-13 00:00:00 0
2015-01-14 00:00:00 0
2015-01-15 00:00:00 0


我想另一列夏普比率和计算夏普比率02-03-2012的回报率,直到02-03-2012和类似的夏普比率06-04-2012的数据从19-03-2012到06-04-2012等。
请引导。

u5rb5r59

u5rb5r591#

可能太晚了,但你可以用

df_data.fillna(method="ffill", inplace=True)

用于填充NaN,使用创建

df.replace(0, np.nan, inplace=True)

对于一般的目的可能有助于不同的方法。
如果您想删除日期,甚至可以使用returns_data = returns_data.dropna(subset=[“your subset”])。

相关问题