2020年1月23日木曜日

The relationship between cli 1month delta and eps quarter over quater growth. Part 2



  1. separate aes(color=sign) from ggplot in order to draw integrated smooth line.
  2. use scale_color_brewer() to designate label values
  3. apply parameter needs to have dimention. don't use as.vector() beforehand.


cov <- apply.quarterly(SP5[,4],sd)["1990::2018"] /apply.quarterly(SP5[,4],mean)["1990::2018"] 
func <- function(x){if(x > mean(cov)){return("a")}else{return("b")}}
df <- data.frame(
cli=as.vector(apply.quarterly(diff(cli_xts$oecd),mean)["1990::2018"]),
eps=as.vector(diff(eps_year_xts,1)["1990::2018"]),
sign=as.vector(apply(cov,1,func)),
# sign=as.vector(year(index(diff(eps_year_xts,1)["2001::2018"]))),
cov=cov
)
p <- ggplot(df, aes(x=cli,y=eps))
p <- p + geom_point(alpha=0.95,aes(color=sign))
p <- p + geom_smooth(method = "lm")
p <- p + scale_color_brewer(palette="Set1",na.value = "grey50",name = "COV", labels = c("COV more than mean val.","COV less than mean val."))
plot(p)




The relationship between cli 1month delta and eps quarter over quater growth.




1) t.test

t.test between grop of cli delta is minus and plus. result is there is only 0.019% probability that those two groups posess same mean value. This result means they are different groups each other.


t.test(
diff(eps_year_xts,1)["2001::2018"][ apply.quarterly(diff(cli_xts$usa),mean)["2001::2018"] > 0],
diff(eps_year_xts,1)["2001::2018"][ apply.quarterly(diff(cli_xts$usa),mean)["2001::2018"] < 0]
)


# Welch Two Sample t-test

# data:  diff(eps_year_xts, 1)["2001::2018"][apply.quarterly(diff(cli_xts$usa),  and diff(eps_year_xts, 1)["2001::2018"][apply.quarterly(diff(cli_xts$usa),     mean)["2001::2018"] > 0] and     mean)["2001::2018"] < 0]
# t = 3.9531, df = 66.145, p-value = 0.0001903
# alternative hypothesis: true difference in means is not equal to 0
# 95 percent confidence interval:
#  3.115924 9.474840
# sample estimates:
# mean of x mean of y 
#  4.117125 -2.178257 


2) spot diagram


diff(eps_year_xts,1)["2001::2018"][ apply.quarterly(diff(cli_xts$usa),mean)["2001::2018"] > 0]
df <- data.frame(
cli=as.vector(apply.quarterly(diff(cli_xts$oecd),mean)["2001::2018"]),
eps=as.vector(diff(eps_year_xts,1)["2001::2018"]),
sign=as.vector(year(index(diff(eps_year_xts,1)["2001::2018"])))
)
p <- ggplot(df, aes(x=cli,y=eps,color=sign))
p <- p + geom_point(alpha=0.5)
p <- p + geom_smooth(method = "lm")
plot(p)




3)histgram

func <- function(x){if(x > 0){return("p")}else{return("m")}}
df <- data.frame(eps=round(as.vector(diff(eps_year_xts,1)["2001::2018"]),digits=2),
sign=as.vector(apply(apply.quarterly(diff(cli_xts$usa),mean)["2001::2018"],1,func)))
# parameter ase() better be put into a single line.
p <- ggplot(df, aes(x=eps,fill=sign))
p <- p + geom_histogram(bins=50,position = "identity", alpha = 0.5)
plot(p)


2020年1月21日火曜日

EPS 2020JAN21


old data.

> eps_year_xts["2019::"]
             [,1]
2019-01-01 134.39
2019-04-01 135.27
2019-07-01 132.90
2019-10-01 140.45
2020-01-01 142.40
2020-04-01 147.35
2020-07-01 156.01
2020-10-01 161.87

Downloads$ tac eps.txt 
3/31/2019 2834.40 $37.99 $35.02 18.52 21.09 $153.05 $134.39
6/30/2019 2941.76 $40.14 $34.93 19.04 21.75 $154.54 $135.27
9/30/2019  2976.74 $39.81 $33.99 19.46 22.40 $152.97 $132.90
12/31/2019 (12.1%) 3230.78 $40.09 $36.30 20.99 23.65 $158.03 $140.24
3/31/2020 $40.15 $36.63 20.71 23.38 $160.19 $141.85
6/30/2020 $43.39 $39.54 20.29 22.65 $163.44 $146.46
9/30/2020 $45.71 $42.43 19.59 21.41 $169.34 $154.91
12/31/2020 $45.91 $42.31 18.94 20.61 $175.16 $160.92
3/31/2021 $44.28 $40.65 18.50 20.11 $179.29 $164.94
6/30/2021 $47.43 $41.75 18.09 19.84 $183.33 $167.14
9/30/2021 $49.44 $44.52 17.73 19.60 $187.06 $169.22
12/31/2021 $50.07 $44.31 17.35 19.37 $191.22 $171.23


Downloads$ tac eps.txt | awk '{gsub("\\$","",$NF);print "eps_year_xts[\"2019::\"]["NR"] <- "$NF}'
eps_year_xts["2019::"][1] <- 134.39
eps_year_xts["2019::"][2] <- 135.27
eps_year_xts["2019::"][3] <- 132.90
eps_year_xts["2019::"][4] <- 140.24
eps_year_xts["2019::"][5] <- 141.85
eps_year_xts["2019::"][6] <- 146.46
eps_year_xts["2019::"][7] <- 154.91
eps_year_xts["2019::"][8] <- 160.92
eps_year_xts["2019::"][9] <- 164.94
eps_year_xts["2019::"][10] <- 167.14
eps_year_xts["2019::"][11] <- 169.22
eps_year_xts["2019::"][12] <- 171.23

This cause error as the entris for "2021" don't exit in the object at the time. Then, the entries should be appended beforehand.


> eps_year_xts <- append(eps_year_xts,as.xts(c(146.46,154.91,160.92,164.94),seq(as.Date("2021-01-01"),as.Date("2021-10-01"),by='quarters')))


<skip>
2019-10-01 140.24000
2020-01-01 141.85000
2020-04-01 146.46000
2020-07-01 154.91000
2020-10-01 160.92000
2021-01-01 146.46000
2021-04-01 154.91000
2021-07-01 160.92000

2021-10-01 164.94000