我想对矢量进行滚动计算。
我使用ifelse
语句来编写它但是我有点陷入困境,我目前的数据是:
Prob <- 0.6
Bet <- 10
Spread <- Bet
Trans <- 0.998
> IndTest
N225.Open Close High Low S.High S.Low S.OC
2007-01-04 17322.50 17353.67 17379.46 17315.76 56.96094 6.740234 31.16992
2007-01-05 17315.54 17091.59 17327.13 17011.10 11.59180 304.439453 -223.94922
2007-01-09 17018.89 17237.77 17261.03 16983.97 242.13867 34.919922 218.87891
2007-01-10 17192.42 16942.40 17199.42 16847.57 7.00000 344.849610 -250.01953
2007-01-11 16958.57 16838.17 17057.45 16758.46 98.87891 200.109374 -120.40039
D.Pos D.Neg H.S.Avg L.S.Avg P.D.Up P.D.Dn P.Bal
2007-01-04 1 0 NA NA NA NA NA
2007-01-05 1 0 NA NA NA NA NA
2007-01-09 1 0 103.56380 115.3665 1 0 1023.5667
2007-01-10 1 0 86.91016 228.0697 1 0 857.3634
2007-01-11 1 0 116.00586 193.2930 1 0 1147.7385`
我目前的代码是;
Ind$P.Bal <- ifelse(IndTest$S.High>IndTest$H.S.Avg & IndTest$P.D.Up > Prob,
Bet*TestInd$H.S.Avg*Spread-Trans, Bet*IndTest$S.OC*Spread-Trans)
我试图让下面的内容沿着向量进行迭代;
IndTest$P.Bal <- ifelse(IndTest[4,5]> IndTest[3,10] & IndTest[3,12] > Prob,
Bet*IndTest[3,10]*Spread-Trans,Bet*IndTest[4,7])