2022年5月4日水曜日

R パッケージ アンロード

 

remove.packages('quantmod') # 要注意


unloadNamespace("quantmod")

依存関係 パッケージ package R

 

> tools::package_dependencies(packages = "quantmod",  which = "Depends", reverse =F)
$quantmod
[1] "xts"     "zoo"     "TTR"     "methods"

> tools::package_dependencies(packages = "xts",  which = "Depends", reverse =F)
$xts
[1] "zoo"

> tools::package_dependencies(packages = "zoo",  which = "Depends", reverse =F)
$zoo
[1] "stats"

> tools::package_dependencies(packages = "stats",  which = "Depends", reverse =F)

2022年4月2日土曜日

侵略行為の法的性質とその法的帰結についての備忘録  ロシア ウクライナ


The original is from here.

侵略行為の法的性質とその法的帰結についての備忘録。国際法上の義務の一種に「一般国際法上の強行規範に基づいて発生する義務の重大な違反」(国家責任条文40条1項)がある。義務の性質と違反の程度に特徴あり。

強行規範として禁止される行為として、侵略行為、奴隷取引、人種差別、アパルトヘイト、ジェノサイド。これらはウィーン条約法条約53条との関連で。拷問禁止、国際人道法の基本原則、自決権も強行規範とされることも。網羅的ではないことに注意。

これら規範の重要な法的帰結は、「いかなる国も、(この)重大な違反によりもたらされた状態を合法的なものとして承認してはなら」ないこと。その状態を維持するために支援・援助もしてはならない(国家責任条文40条2項)。国際社会全体による集団的な不承認が求められているということ。

イラクによるクウェート侵攻とその後の併合に対して安保理決議662(1990年)は法的拘束力をもって「法上無効」に。南ローデシアの人種差別、南アのバンツースタン計画も、総会や安保理で集団的不承認の対象に。国際法規則はこうした経緯を経て徐々に発展してきたことに留意すべき。

ロシアのウクライナ侵略によって生じるいかなる効果も国際法上無効のはず。ウクライナ領内のロシアの占領地域がウクライナ領でなくなることは、国際法の観点からはあってはならないこと。しかもロシアの侵略という違法行為は、ウクライナに対してだけでなく、国際社会全体に対して向けられたもの。

しかしロシアとウクライナが両国間の「平和」のためにロシアの占領地がロシア領になったり、2つの「人民共和国」が独立することが認められた場合、国際社会はいかに対応するのか。侵略国が利益を得ても座視することに。ここには国家間の合意が強行規範の義務さえも実質的に効力を失わせる契機がある。 

2022年3月7日月曜日

最小二乗法 予報 lm

 

w <- last(mdf[,13],138) %>%  c(.,c(5374,NA)) %>% matrix(.,nrow=7) %>% t()
i <- 20
r <- lm(w[-i,7] ~ w[-i,1] + w[-i,2] + w[-i,3] + w[-i,4] +w[-i,5] + w[-i,6] )
summary(r)
r$coefficients[1] + r$coefficients[2]*w[20,1] + r$coefficients[3]*w[20,2] + r$coefficients[4]*w[20,3] + r$coefficients[5]*w[20,4] + r$coefficients[6]*w[20,5] + r$coefficients[7]*w[20,6]


2022年2月5日土曜日

ソート、 order 、 sprintf

 


w <- c(); for(i in seq(1,47,1)){w <- append(w,sum(last(dmdf[,i],31)) / sum(last(mdf[,i],31)))}
data.frame(d=sprintf("%.4f",100*w[
order(w,decreasing = T)]),r=pref_jp[order(w,decreasing = T)])
         
sprintf("%.4f", 100 * w[order(w, decreasing = T)])


高知県                                               0.1810
広島県                                               0.1809
山梨県                                               0.1473
三重県                                               0.1328
愛媛県                                               0.1303
山口県                                               0.1295
群馬県                                               0.1190
香川県                                               0.1150
栃木県                                               0.1147
熊本県                                               0.1063
北海道                                               0.1061
石川県                                               0.1034


i <- length(seq(as.Date("2022-01-01"),last(mdf$t),by="day"))
w <- ((last(dmdf[,-48],i) %>% apply(.,2,sum)) / (last(mdf[,-48],i) %>% apply(.,2,sum))) %>%  as.vector(.) %>% data.frame(r=pref_jp,d=.);w <- w[order(w$d,decreasing = T),] ; data.frame(r=w$r,d=sprintf("%.4f",100*w$d))

2022年1月26日水曜日

2022年1月22日土曜日

NYSE TICK INDEX

 

get data from here.

# read csv 
TICK <- read.csv("~/Downloads/NYSETickIndex.csv") 
# inverse entry order
TICK[length(index(TICK)):1,]
# 1) remove "," from data field, 2)convert data data to POSIX compliant
# 3) extract daily low only
TICK <-as.xts(as.numeric(sub(",","",TICK[,5])),as.Date(paste(substr(TICK[,1],1,4),substr(TICK[,1],6,7),substr(TICK[,1],9,10),sep = '-')))

2022年1月4日火曜日

2022 CLI release schedule

 


from here.

17 January 2022
9 February 2022
9 March 2022
11 April 2022
10 May 2022
13 June 2022
11 July 2022
9 August 2022
12 September 2022
11 October 2022
9 November 2022
8 December 2022


#cli 2022 schedule

2021年9月19日日曜日

EPS 2021 SEP19

 $ cat eps.txt

12/31/2022              $57.18  $53.10          20.55   22.38           $218.03 $200.19
9/30/2022               $55.39  $51.09          21.19   23.12           $211.49 $193.83
6/30/2022               $54.10  $49.25          21.90   23.95           $204.64 $187.11
3/31/2022               $51.36  $46.74          22.12   24.06           $202.57 $186.25
12/31/2021              $50.64  $46.75          22.56   24.16           $198.62 $185.46
9/30/2021               $48.54  $44.37          24.07   26.33           $186.16 $170.15
6/30/2021 (Prelim.)     4297.50 $52.03  $48.39          25.53   28.22           $175.52 $158.76
3/31/2021       3972.89 $47.41  $45.95          26.44   30.99           $150.28 $128.20
12/31/2020      3756.07 $38.18  $31.44          30.69   39.90           $122.37 $94.13
9/30/2020       3363.00 $37.90  $32.98          27.26   34.24           $123.37 $98.22
6/30/2020       3100.29 $26.79  $17.83          24.75   31.24           $125.28 $99.23
3/31/2020       2584.59 $19.50  $11.88          18.64   22.22           $138.63 $116.33
12/31/2019      3230.78 $39.18  $35.53          20.56   23.16           $157.12 $139.47
9/30/2019       2976.74 $39.81  $33.99          19.46   22.40           $152.97 $132.90
6/30/2019       2941.76 $40.14  $34.93          19.04   21.75           $154.54 $135.27
3/31/2019       2834.40 $37.99  $35.02          18.52   21.09           $153.05 $134.39

> eps_year_xts["2020::"]
             [,1]
2020-01-01 116.33
2020-04-01  99.23
2020-07-01  98.22
2020-10-01  94.13
2021-01-01 122.64
2021-04-01 144.14
2021-07-01 153.96
2021-10-01 166.77
2022-01-01 170.06
2022-04-01 176.48
2022-07-01 182.75
2022-10-01 188.97

$ 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] <- 139.47
eps_year_xts["2019::"][5] <- 116.33
eps_year_xts["2019::"][6] <- 99.23
eps_year_xts["2019::"][7] <- 98.22
eps_year_xts["2019::"][8] <- 94.13
eps_year_xts["2019::"][9] <- 128.20
eps_year_xts["2019::"][10] <- 158.76
eps_year_xts["2019::"][11] <- 170.15
eps_year_xts["2019::"][12] <- 185.46
eps_year_xts["2019::"][13] <- 186.25
eps_year_xts["2019::"][14] <- 187.11
eps_year_xts["2019::"][15] <- 193.83
eps_year_xts["2019::"][16] <- 200.19

2021年8月12日木曜日

CLI release schedule CLI リリース スケジュール

 
2021
14 September 2021
12 October 2021
10 November 2021
9 December 2021


2022
17 January 2022
9 February 2022
9 March 2022
11 April 2022
10 May 2022
13 June 2022
11 July 2022
9 August 2022
12 September 2022
11 October 2022
9 November 2022
8 December 2022

2021年8月2日月曜日

累積死亡数 vs. 20日前までの累積感染者  致死率

 

original is here.


plot.default(log(cumsum(mdf[,13])[1:543]),log(cumsum(dmdf[,13])[21:563]))
par()$usr
# > par()$usr
# [1] -0.4845012 12.5970321 -0.3095047  8.0471209
plot.default(log(cumsum(mdf[,13])[1:543]),log(cumsum(dmdf[,13])[21:563]),xlim=c(-0.48,12.59),ylim=c(-0.309,8.0471))
par(new=T)
plot.default(log(cumsum(mdf[,13])[1:543]),log(0.01*cumsum(mdf[,13])[1:543]),xlim=c(-0.48,12.59),ylim=c(-0.309,8.0471),type='l')
par(new=T)
plot.default(log(cumsum(mdf[,13])[1:543]),log(0.02*cumsum(mdf[,13])[1:543]),xlim=c(-0.48,12.59),ylim=c(-0.309,8.0471),type='l')


gap <- 20   # shift between positive and death. as new death only comes out after certain number of days of positive.
start <- 500 # day of start should be less than length(mdf$t) - gap 500 means "2021-05-30"
end <- 0 # day to end. 0 means the end of record.
dmdf$t[start]
if(end == 0){
  end <- length(mdf[,13])
}

d <- dmdf[,13][(gap+start):(end)] %>% cumsum()
p <- mdf[,13][start:(end-gap)] %>% cumsum()
df <- data.frame(death=d,positive=p)
# p <- ggplot(df, aes(x = positive, y = death))
# p <- p + geom_point(stat="identity", position="identity")
df <- cbind(df,twopercent=df$positive * 0.02)
df <- cbind(df,onepointfive=df$positive * 0.015)
df <- cbind(df,onepercent=df$positive * 0.01)
df <- cbind(df,halfpercent=df$positive * 0.005)
df <- cbind(df,qpercent=df$positive * 0.0025)
p <- ggplot(df, aes(x = positive, y = death))
p <- p + geom_point(stat="identity", position="identity")
p <- p + geom_path(aes(y=twopercent))
p <- p + geom_path(aes(y=onepointfive))
p <- p + geom_path(aes(y=onepercent))
p <- p + geom_path(aes(y=halfpercent))
p <- p + geom_path(aes(y=qpercent))


plot(p)

2021年7月30日金曜日

EPS 2021JUL30


goto https://www.spglobal.com/ → Documents → Additional Info → Index Earnings

MacBook-Pro-16:~/Downloads$ cat eps.txt 
12/31/2022 $56.05 $52.78 20.65 21.96 $211.18 $198.50
9/30/2022 $53.89 $50.61 21.33 22.71 $204.41 $191.96
6/30/2022 $51.20 $48.23 22.07 23.49 $197.58 $185.62
3/31/2022 $50.04 $46.87 22.65 24.12 $192.46 $180.74
12/31/2021 $49.28 $46.24 22.97 24.25 $189.83 $179.81
9/30/2021 $47.06 $44.27 24.39 26.42   $178.73 $165.01
6/30/2021 (9.8%) 4297.50 $46.08 $43.35 25.71 28.36   $169.57 $153.72
3/31/2021 3972.89 $47.41 $45.95 26.44 30.99 $150.28 $128.20
12/31/2020 3756.07 $38.18 $31.44 30.69 39.90   $122.37 $94.13
9/30/2020 3363.00 $37.90 $32.98 27.26 34.24   $123.37 $98.22
6/30/2020 3100.29 $26.79 $17.83 24.75 31.24   $125.28 $99.23
3/31/2020 2584.59 $19.50 $11.88 18.64 22.22   $138.63 $116.33
12/31/2019 3230.78 $39.18 $35.53 20.56 23.16   $157.12 $139.47
9/30/2019  2976.74 $39.81 $33.99 19.46 22.40   $152.97 $132.90
6/30/2019 2941.76 $40.14 $34.93 19.04 21.75   $154.54 $135.27
3/31/2019 2834.40 $37.99 $35.02 18.52 21.09   $153.05 $134.39


> eps_year_xts["2020::"]
             [,1]
2020-01-01 116.33
2020-04-01  99.23
2020-07-01  98.22
2020-10-01  94.13
2021-01-01 122.64
2021-04-01 144.14
2021-07-01 153.96
2021-10-01 166.77
2022-01-01 170.06
2022-04-01 176.48
2022-07-01 182.75
2022-10-01 188.97


MacBook-Pro-16:~/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] <- 139.47
eps_year_xts["2019::"][5] <- 116.33
eps_year_xts["2019::"][6] <- 99.23
eps_year_xts["2019::"][7] <- 98.22
eps_year_xts["2019::"][8] <- 94.13
eps_year_xts["2019::"][9] <- 128.20
eps_year_xts["2019::"][10] <- 153.72
eps_year_xts["2019::"][11] <- 165.01
eps_year_xts["2019::"][12] <- 179.81
eps_year_xts["2019::"][13] <- 180.74
eps_year_xts["2019::"][14] <- 185.62
eps_year_xts["2019::"][15] <- 191.96
eps_year_xts["2019::"][16] <- 198.50

2021年7月16日金曜日

dplyr filter group_by summarise

 


 df.melt[1:10,]

            t variable value
1  2020-10-01       10    13
2  2020-10-02       10    18
3  2020-10-03       10    11
4  2020-10-04       10     7
5  2020-10-05       10     5
6  2020-10-06       10    16
7  2020-10-07       10     3
8  2020-10-08       10    12
9  2020-10-09       10    20
10 2020-10-10       10    29

 df.melt[289:299,]

             t variable value
289 2020-10-01       20    60
290 2020-10-02       20    48
291 2020-10-03       20    60
292 2020-10-04       20    31
293 2020-10-05       20    17
294 2020-10-06       20    44
295 2020-10-07       20    28
296 2020-10-08       20    49
297 2020-10-09       20    60
298 2020-10-10       20    64
299 2020-10-11       20    38

dplyr::filter(df.melt,variable>=10 & variable < 21) %>% dplyr::group_by(t) %>% dplyr::summarise(.,sum(value))

# A tibble: 288 x 2
   t          `sum(value)`
   <date>            <dbl>
 1 2020-10-01           73
 2 2020-10-02           66
 3 2020-10-03           71
 4 2020-10-04           38
 5 2020-10-05           22
 6 2020-10-06           60
 7 2020-10-07           31
 8 2020-10-08           61
 9 2020-10-09           80
10 2020-10-10           93
# ... with 278 more rows

 dplyr::filter(df.melt,variable>=10 ) %>% dplyr::group_by(t) %>% dplyr::summarise(.,sum(value))

# A tibble: 289 x 2
   t          `sum(value)`
   <date>            <dbl>
 1 2020-10-01          234
 2 2020-10-02          196
 3 2020-10-03          205
 4 2020-10-04          107
 5 2020-10-05           65
 6 2020-10-06          176
 7 2020-10-07          140
 8 2020-10-08          248
 9 2020-10-09          203
10 2020-10-10          248
# ... with 279 more rows

dplyr::filter(df.melt,variable>=70 ) %>% dplyr::group_by(t) %>% dplyr::summarise(.,sum(value))

# A tibble: 289 x 2
   t          `sum(value)`
   <date>            <dbl>
 1 2020-10-01           31
 2 2020-10-02           20
 3 2020-10-03           21
 4 2020-10-04           13
 5 2020-10-05            6
 6 2020-10-06           20
 7 2020-10-07           22
 8 2020-10-08           25
 9 2020-10-09           17
10 2020-10-10           33
# ... with 279 more rows

(dplyr::filter(df.melt,variable>=70 ) %>% dplyr::group_by(t) %>% dplyr::summarise(.,sum(value)))[,2] / as.vector(dplyr::filter(df.melt,variable>=10 ) %>% dplyr::group_by(t) %>% dplyr::summarise(.,sum(value)))[,2]

    sum(value)
1   0.13247863
2   0.10204082
3   0.10243902
4   0.12149533
5   0.09230769
6   0.11363636
7   0.15714286
8   0.10080645
9   0.08374384
10  0.13306452
<Skip>
282 0.02311436
283 0.04105263
284 0.03094463
285 0.02589641
286 0.03855422
287 0.02872063
288 0.02675841
289 0.02281668

plot(as.xts( (dplyr::filter(df.melt,variable>=70 ) %>% dplyr::group_by(t) %>% dplyr::summarise(.,sum(value)))[,2] / as.vector(dplyr::filter(df.melt,variable>=10 ) %>% dplyr::group_by(t) %>% dplyr::summarise(.,sum(value)))[,2],df.melt$t[1:289]))

OR


plot(as.xts( (dplyr::filter(df.melt,variable>=70 ) %>% dplyr::group_by(t) %>% dplyr::summarise(.,sum(value)))[,2] / as.vector(dplyr::filter(df.melt,variable>=10 ) %>% dplyr::group_by(t) %>% dplyr::summarise(.,sum(value)))[,2],unique(df.melt$t)))




2021年6月27日日曜日

CLIデルタ CLI二次デルタ 月間収益率

 
(1) CLIデルタがプラスかつ二次デルタがマイナスの場合の月間収益率

func <- function(x,y,z){if(x >0 && y <0){return(z) }else(return(NA))}
date <- paste("1970",index(cli_xts) %>% last() %>% substr(.,1,7),sep="::")
i <- 12- length(diff(cli_xts$oecd)[date]) %%12
matrix(c(mapply(func,diff(cli_xts$oecd)[date],  diff(diff(cli_xts$oecd))[date]     ,as.vector(monthlyReturn(GSPC)[date])),rep(NA,i)),nrow=12) %>% t() %>% apply(.,2,mean,na.rm=T) %>% round(.,4)

 [1]  0.0047  0.0100  0.0189  0.0162 -0.0062  0.0019  0.0168  0.0091  0.0047  0.0084  0.0298  0.0187

(2) CLIデルタがプラスかつ二次デルタがプラスの場合の月間収益率

func <- function(x,y,z){if(x >0 && y >0){return(z) }else(return(NA))}
date <- paste("1970",index(cli_xts) %>% last() %>% substr(.,1,7),sep="::")
i <- 12- length(diff(cli_xts$oecd)[date]) %%12
matrix(c(mapply(func,diff(cli_xts$oecd)[date],  diff(diff(cli_xts$oecd))[date]     ,as.vector(monthlyReturn(GSPC)[date])),rep(NA,i)),nrow=12) %>% t() %>% apply(.,2,mean,na.rm=T) %>% round(.,4)


 [1] 0.0258 0.0146 0.0217 0.0420 0.0277 0.0138 0.0247 0.0099 0.0064 0.0166 0.0334 0.0184

(2) CLIデルタがマイナスかつ二次デルタがマイナスの場合の月間収益率

func <- function(x,y,z){if(x <0 && y <0){return(z) }else(return(NA))}
date <- paste("1970",index(cli_xts) %>% last() %>% substr(.,1,7),sep="::")
i <- 12- length(diff(cli_xts$oecd)[date]) %%12
matrix(c(mapply(func,diff(cli_xts$oecd)[date],  diff(diff(cli_xts$oecd))[date]     ,as.vector(monthlyReturn(GSPC)[date])),rep(NA,i)),nrow=12) %>% t() %>% apply(.,2,mean,na.rm=T) %>% round(.,4)


 [1]  0.0038 -0.0189 -0.0051  0.0098 -0.0011  0.0013 -0.0123 -0.0124 -0.0207 -0.0544 -0.0328  0.0082

(2) CLIデルタがマイナスかつ二次デルタがプラスの場合の月間収益率

func <- function(x,y,z){if(x <0 && y >0){return(z) }else(return(NA))}
date <- paste("1970",index(cli_xts) %>% last() %>% substr(.,1,7),sep="::")
i <- 12- length(diff(cli_xts$oecd)[date]) %%12
matrix(c(mapply(func,diff(cli_xts$oecd)[date],  diff(diff(cli_xts$oecd))[date]     ,as.vector(monthlyReturn(GSPC)[date])),rep(NA,i)),nrow=12) %>% t() %>% apply(.,2,mean,na.rm=T) %>% round(.,4)


 [1]  0.0066  0.0017  0.0095 -0.0002 -0.0008 -0.0014  0.0170  0.0015 -0.0138  0.0367  0.0136  0.0117