> x <- as.data.frame(tapply(read.csv("~/f3.csv")$quantity,read.csv("~/f3.csv")$ticker,sum))
> x
tapply(read.csv("~/f3.csv")$quantity, read.csv("~/f3.csv")$ticker,
FAS 13138
SPXL 21000
YJ2040 2647
YJ7974 100
> colnames(x)[1] <- "shares"
> z <- as.data.frame(tapply(read.csv("~/f3.csv")$quantity,read.csv("~/f3.csv")$ticker,sum))
> colnames(z)[1] <- "shares"
> z2 <- transform(z,ticker=rownames(z))
> z2
shares ticker
FAS 13138 FAS
SPXL 21000 SPXL
YJ2040 2647 YJ2040
YJ7974 100 YJ7974
> my_pf <- transform(z2,total=mapply(function(x,y) x*last(get(as.character(y))[,4]),z2$shares,z2$ticker))
shares ticker total
FAS 13138 FAS 721670.3
SPXL 21000 SPXL 792540.0
YJ2040 2647 YJ2040 49869480.0
YJ7974 100 YJ7974 4202000.0
> my_pf
shares total ticker
FAS 13138 721670.3 FAS
SPXL 21000 792540.0 SPXL
YJ2040 2647 49869480.0 YJ2040
YJ7974 100 4202000.0 YJ7974
> my_pf <- transform(z2,total=mapply(function(x,y) x*last(get(as.character(y))[,4]),z2$shares,z2$ticker))
> my_pf <- transform(my_pf,currency=mapply(function(x) read.csv("~/f3.csv")[grep(x,read.csv("~/f3.csv")$ticker),5][1],my_pf$ticker))
>my_pf
shares ticker total currency
FAS 13138 FAS 721670.3 USD
SPXL 21000 SPXL 792540.0 USD
YJ2040 2647 YJ2040 49869480.0 JPY
YJ7974 100 YJ7974 4202000.0 JPY
> tapply(my_pf$total,my_pf$currency,sum)
JPY USD
54071480 1514210
> x
tapply(read.csv("~/f3.csv")$quantity, read.csv("~/f3.csv")$ticker,
FAS 13138
SPXL 21000
YJ2040 2647
YJ7974 100
> colnames(x)[1] <- "shares"
> z <- as.data.frame(tapply(read.csv("~/f3.csv")$quantity,read.csv("~/f3.csv")$ticker,sum))
> colnames(z)[1] <- "shares"
> z2 <- transform(z,ticker=rownames(z))
> z2
shares ticker
FAS 13138 FAS
SPXL 21000 SPXL
YJ2040 2647 YJ2040
YJ7974 100 YJ7974
> my_pf <- transform(z2,total=mapply(function(x,y) x*last(get(as.character(y))[,4]),z2$shares,z2$ticker))
shares ticker total
FAS 13138 FAS 721670.3
SPXL 21000 SPXL 792540.0
YJ2040 2647 YJ2040 49869480.0
YJ7974 100 YJ7974 4202000.0
> my_pf
shares total ticker
FAS 13138 721670.3 FAS
SPXL 21000 792540.0 SPXL
YJ2040 2647 49869480.0 YJ2040
YJ7974 100 4202000.0 YJ7974
> my_pf <- transform(z2,total=mapply(function(x,y) x*last(get(as.character(y))[,4]),z2$shares,z2$ticker))
> my_pf <- transform(my_pf,currency=mapply(function(x) read.csv("~/f3.csv")[grep(x,read.csv("~/f3.csv")$ticker),5][1],my_pf$ticker))
>my_pf
shares ticker total currency
FAS 13138 FAS 721670.3 USD
SPXL 21000 SPXL 792540.0 USD
YJ2040 2647 YJ2040 49869480.0 JPY
YJ7974 100 YJ7974 4202000.0 JPY
> tapply(my_pf$total,my_pf$currency,sum)
JPY USD
54071480 1514210
0 件のコメント:
コメントを投稿