# ticker, Date, sell/buy, quantity
# "FAS","2014-01-01","buy", 13888
# "FAS","2016-12-19","sell", 750
x <- vector( "list", length( read.csv( "~/fas.csv") [, 1]))
z <- read.csv( "~/fas.csv")
# ticker Date sell. buy quantity
# 1 FAS 2014-01-01buy 13888
# 2 FAS 2016-12-19 sell 750
#
# >mapply ( my_assign, z$ticker)
#
my_assign <- function( t) {
print ( "0")
output <- as. character( paste( t,"hold", sep ="_"))
# print( c( "1", output))
if ( ! exists( output)) {
assign ( output, c( ), env =. GlobalEnv)
}
output <- as. character( paste( t,"xts ", sep ="_"))
# print( c( "1", output))
if ( ! exists( output)) {
assign ( output, c( ), env =. GlobalEnv)
}
}
#
# mapply(my_hist,z$ticker,z$quantity,z$Date,"2014-01-01")
#
my_hist <- function(t,q,d,s){
l <- seq(as.Date(s),Sys.Date(),by="days")
output <- as. character( paste( t,"hold", sep ="_"))
print ( d)
print(s)
assign ( output, c( get( output),
rep(0,length(l)-length(seq(as.Date(as.character(d)),Sys.Date(),by="days"))),
rep(q,length(seq(as.Date(as.character(d)),Sys.Date(),by="days")))),env=.GlobalEnv)
# as. xts ( rowSums ( matrix( get( output), ncol =length( get( output)) /length( l))), l) * apply. monthly( get( as. character( t)), last) [, 4]
}
my_xts <- function( t) {
output <- as. character( paste( t,"hold", sep ="_"))
assign(as.character(paste(t,"xts",sep="_")),as.xts(rowSums(matrix(get(output),ncol=length(get(output))/length(l))),l) * apply.monthly(get(as.character(t)),last)[,4],env=.GlobalEnv)
}
#
# > ticker_list <- unique( z$ticker)
# [1] "FAS" "SPXL"
# > ticker_list
# [1] "FAS" "SPXL"
#
lapply ( ticker_list, my_xts)
# "FAS","2014-01-01","buy"
# "FAS","2016-12-19","sell"
# ticker Date sell
# 1 FAS 2014-01-01
# 2 FAS 2016-12-19 sell 750
#
# >
#
my_assign <- function
}
}
}
#
# mapply(my_hist,z$ticker,z$quantity,z$Date,"2014-01-01")
#
my_hist <- function(t,q,d,s){
l <- seq(as.Date(s),Sys.Date(),by="days")
rep(0,length(l)-length(seq(as.Date(as.character(d)),Sys.Date(),by="days"))),
rep(q,length(seq(as.Date(as.character(d)),Sys.Date(),by="days")))),env=.GlobalEnv)
# as
}
my_xts <- function
assign(as.character(paste(t,"xts",sep="_")),as.xts(rowSums(matrix(get(output),ncol=length(get(output))/length(l))),l) * apply.monthly(get(as.character(t)),last)[,4],env=.GlobalEnv)
}
#
# > ticker_list <- unique
# [1] "FAS" "SPXL"
# > ticker_list
# [1] "FAS" "SPXL"
#
0 件のコメント:
コメントを投稿