2018年6月19日火曜日

Upload EPS data

download eps raw data from here.

select Additional Info = index earnings

Choose necessary data and cut&paste to the new file. This is important as number only support to convert the entire original file into the separated CSV.
Save it as ".csv".

expected as below.

$nkf -Lu eps.csv
date,eps
12/31/2019,44.08
9/30/2019,42.26
<..skip...>
1988/6/30,6.22
1988/3/31,5.53


as.xts(rev(read.csv("~/eps.csv")[,2]),seq(as.Date(mondate(as.Date("1988-01-01"))),as.Date(mondate(as.Date("1988-01-01"))+ length(read.csv("~/eps.csv")[,2])*3-1),by="quarters"))

Don't forget "rev()" as eps.csv stores data in the inverse order.
Do as.Date() -> mondate() -> as.Date() conversion otherwise unable to use by="quarters"argument.

           [,1]
1988-01-01 5.53
1988-04-01 6.22
1988-07-01 6.38
1988-10-01 5.62
1989-01-01 6.74
1989-04-01 6.48
<...skip...>
            [,1]
2018-07-01 38.18
2018-10-01 40.03
2019-01-01 38.20
2019-04-01 40.22
2019-07-01 42.26
2019-10-01 44.08

calculate annual eps data with filter(). Don't forget as.vector() as as.xts() accept only vector for the 1st arg.

as.xts(as.vector(na.omit(filter(eps,rep(1,4)))),seq(as.Date(mondate(as.Date("2019-10-01"))-124*3),as.Date(mondate(as.Date("2019-10-01"))),by="quarters"))
             [,1]
1988-10-01  23.75
1989-01-01  24.96
1989-04-01  25.22
<...skip...>
2019-04-01 156.63
2019-07-01 160.71
2019-10-01 164.76

0 件のコメント: