1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
rootdir <- "T:/Analytics/CLO/"
setwd(rootdir)
options(stringsAsFactors=F)
stripext <- function(name,ext){
sub(paste(".",ext,sep=""),"",name)
}
today <- function(){
as.Date(Sys.time())
}
listcusips <- function(date, flag=""){
clodir <- paste(format(date, "%Y%m%d"), flag, sep="")
cusips <- dir(path=paste(".",clodir,sep="/"), pattern=".report$")
return(stripext(cusips,"report"))
}
readcusip <- function(cusip,date,flag=""){
clodir <- paste(format(date,"%Y%m%d"),flag,sep="")
temp <- read.table(paste(".",clodir,paste(cusip,"report",sep="."),sep="/"),sep="\t",header=T,fill=T)
temp <- temp[temp$Scenario!="Scenario",1:25]
a <-as.matrix(temp$Scenario)
a <- sub("SCENARIO","",as.character(a))
temp <- data.frame(a,temp[,2:25])
tempnames <- colnames(temp)
colnames(temp) <- c("Scenario",tempnames[2:25])
return(temp[order(as.numeric(temp$Scenario)),])
}
readcusip2 <- function(cusip,date){
clodir <- format(date,"%Y%m%d")
temp <- read.table(paste(".",clodir,paste(cusip,"report",sep="."),sep="/"),sep="\t",header=T,fill=T)
temp <- temp[temp$Scenario!="Scenario",1:25]
a <- t(matrix(unlist(strsplit(as.character(temp$Scenario),"_")),2,nrow(temp)))
a[,1] <- sub("SCENARIO","",as.character(a[,1]))
colnames(a) <- c("Scenario","ScenarioType")
temp <- data.frame(a,temp[,2:25])
return(temp[order(as.numeric(temp$Scenario)),])
}
getcusip <- function(cusip,date,colname,scenariotype){
cusipdata <- readcusip2(cusip,date)
as.numeric(cusipdata[cusipdata$ScenarioType==scenariotype,][[colname]])
}
getcusipinfo <- function(cusip,date,scenariotype,infotype,indextype,indextenor){
clodir <- paste(format(date,"%Y%m%d"),"Info",sep="/")
cusipscen <- paste(cusip,scenariotype,sep="_")
temp <- read.table(paste(".",clodir,paste(cusipscen,infotype,sep="."),sep="/"),sep="\t",header=T,fill=T)
return(temp[(temp$IndexType==indextype)&(temp$IndexTenor==indextenor),])
}
A <- c()
for(cusip in cusipsBB){
A <- cbind(A,as.numeric(readcusip(cusip,today())$Price))
}
colnames(A) <- cusipsBB
pricesAAA <- c()
for(cusip in cusipsAAA){
pricesAAA <- rbind(pricesAAA,readcusip(cusip,today())[,c("Price","Duration","Yield","WAL")])
}
pricesAA <- c()
for(cusip in cusipsAA){
pricesAA <- rbind(pricesAA,readcusip(cusip,today())[,c("Price","Duration","Yield","WAL")])
}
pricesA <- c()
for(cusip in cusipsA){
pricesA <- rbind(pricesA,readcusip(cusip,today())[,c("Price","Duration","Yield","WAL")])
}
pricesBBB <- c()
for(cusip in cusipsBBB){
pricesBBB <- rbind(pricesBBB,readcusip(cusip,today())[,c("Price","Duration","Yield","WAL")])
}
pricesBB <- c()
for(cusip in cusipsBB){
pricesBB <- rbind(pricesBB,readcusip(cusip,today())[,c("Price","Duration","Yield","WAL")])
}
pricesNA <- c()
for(cusip in cusipsNA){
pricesNA <- rbind(pricesNA,readcusip(cusip,today())[,c("Price","Duration","Yield","WAL")])
}
|