-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path.Rhistory
512 lines (512 loc) · 11.6 KB
/
.Rhistory
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
if ("text" %in% names(p[[t]])) to.numeric(p[[t]]$text) else NA
}
cy(x[[2984]]$content$properties,"BC_1YEAR")
??to.numeric
?numeric
cy <- function(p,t) {
if ("text" %in% names(p[[t]])) as.numeric(p[[t]]$text) else NA
}
cy(x[[2984]]$content$properties,"BC_1YEAR")
digits=3
cy <- function(p,t) {
if ("text" %in% names(p[[t]]))
round(as.numeric(p[[t]]$text),digits)
else
NA
}
cy(x[[2984]]$content$properties,"BC_1YEAR")
digits=4
cy(x[[2984]]$content$properties,"BC_1YEAR")
cy <- function(p,t) {
if ("text" %in% names(p[[t]]))
round(as.double(p[[t]]$text),digits)
else
NA
}
cy(x[[2984]]$content$properties,"BC_1YEAR")
?round
cy <- function(p,t) {
if ("text" %in% names(p[[t]]))
round(as.double(p[[t]]$text),digits=digits)
else
NA
}
cy(x[[2984]]$content$properties,"BC_1YEAR")
digits=9
cy(x[[2984]]$content$properties,"BC_1YEAR")
cy <- function(p,t) {
if ("text" %in% names(p[[t]]))
signif(as.double(p[[t]]$text),digits=digits)
else
NA
}
cy(x[[2984]]$content$properties,"BC_1YEAR")
cy <- function(p,t) {
if ("text" %in% names(p[[t]]))
# signif(as.double(p[[t]]$text),digits=digits)
signif(p[[t]]$text,digits=digits)
else
NA
}
cy(x[[2984]]$content$properties,"BC_1YEAR")
cy <- function(p,t) {
if ("text" %in% names(p[[t]]))
signif(as.double(p[[t]]$text),digits=digits)
else
NA
}
p
cy <- function(p,t) {
if ("text" %in% names(p[[t]]))
signif(as.double(p[[t]]$text),digits=digits)
else
NA
}
y = ldply(x, function(e) {
p <- e$content$properties
c(cy(p,"BC_1YEAR"),
cy(p,"BC_30YEAR")),
.inform=TRUE)
y = ldply(x, function(e) {
p <- e$content$properties
c(cy(p,"BC_1YEAR"),
cy(p,"BC_30YEAR"))},
.inform=TRUE)
y
head(p)
head(y)
names(x)
names(x$content$properties)
p = x[[1]]$content$properties
names(p)
cy <- function(t,p) {
if ("text" %in% names(p[[t]]))
signif(as.double(p[[t]]$text),digits=digits)
else
NA
}
y = ldply(x, function(e) {
p <- e$content$properties
#c(cy(p,"BC_1YEAR"),
# cy(p,"BC_30YEAR"))
q = sapply(names(p),cy,p)
},
.inform=TRUE)
head(y)
tail(y)
y = ldply(x, function(e) {
p <- e$content$properties
#c(cy(p,"BC_1YEAR"),
# cy(p,"BC_30YEAR"))
q = sapply(names(p),cy,p)
},
.id="NEW_DATE",
.inform=TRUE)
head(y)
tail(y)
p
cy <- function(t,p) {
if ("text" %in% names(p[[t]]))
# signif(as.double(p[[t]]$text),digits=digits)
p[[t]]$text
else
NA
}
y = ldply(x, function(e) {
p <- e$content$properties
q = sapply(names(p),cy,p)
},
.id="NEW_DATE",
.inform=TRUE)
tail(y)
str(y)
tail(y)
y$NEW_DATE
?substring
substring(y$NEW_DATE,1,11)
substring(y$NEW_DATE,1,10)
y = ldply(x, function(e) {
p <- e$content$properties
q = sapply(names(p),cy,p)
},
.id="NEW_DATE",
.inform=TRUE)
y$NEW_DATE = substring(y$NEW_DATE,1,10)
tail(y)
head(y)
y = ldply(x, function(e) {
p <- e$content$properties
q = sapply(names(p),cy,p)
},
.id="NEW_DATE",
.inform=TRUE)
head(y)
ys = sort(y)
keyys = sort(y$NEW_DATE)
head(keyys)
head(y[keys])
head(y[keyys])
head(with(y,NEW_DATE=keyys))
ys = order(y,NEW_DAE)
ys = order(y,NEW_DATE)
ys = order(y,"NEW_DATE")
?order
keyys
y = ldply(x, function(e) {
p <- e$content$properties
q = sapply(names(p),cy,p)
},
.id="NEW_DATE",
.inform=TRUE)
y$NEW_DATE = substring(y$NEW_DATE,1,10)
keys = sort(y$NEW_DATE)
head(keys)
head(y)
head(y[with(y,order(NEW_DATE)),])
rownames(y) <- y$NEW_DATE
head(y)
y = ldply(x, function(e) {
p <- e$content$properties
q = sapply(names(p),cy,p)
},
.id="NEW_DATE",
.inform=TRUE)
y$NEW_DATE = substring(y$NEW_DATE,1,10)
y = y[with(y,order(NEW_DATE)),]
rownames(y) <- y$NEW_DATE
head(y)
y = y[,-1:3]
y = y[,3:10]
head(y)
y = ldply(x, function(e) {
p <- e$content$properties
q = sapply(names(p),cy,p)
},
.id="NEW_DATE",
.inform=TRUE)
y$NEW_DATE = substring(y$NEW_DATE,1,10)
y = y[with(y,order(NEW_DATE)),]
rownames(y) <- y$NEW_DATE
y = y[,3:10]
head(y)
y = ldply(x, function(e) {
p <- e$content$properties
q = sapply(names(p),cy,p)
},
.id="NEW_DATE",
.inform=TRUE)
y$NEW_DATE = substring(y$NEW_DATE,1,10)
y = y[with(y,order(NEW_DATE)),]
rownames(y) <- y$NEW_DATE
y = y[,3:20]
colnames(y)
y = ldply(x, function(e) {
p <- e$content$properties
q = sapply(names(p),cy,p)
},
.id="NEW_DATE",
.inform=TRUE)
y$NEW_DATE = substring(y$NEW_DATE,1,10)
y = y[with(y,order(NEW_DATE)),]
rownames(y) <- y$NEW_DATE
y = y[,3:14]
head(y)
yq = as.double(y)
head(h)
head(y)
as.double("<NA>")
?as.double
as.double(y[,1])
as.double(y[,2])
as.double(y[,3])
as.double(y[,4])
as.double(y[,5])
as.double(y[,6])
as.double(y[,7])
as.double(y[,8])
as.double(y[,9])
as.double(y[,10])
as.double(y[,11])
as.double(y[,12])
as.double(y[,13])
colnames(y)
yq = as.double(y[])
yq = transform(y,as.numeric)
yq
head(yq)
str(yq)
?transform
yq = sapply(y,as.numeric)
head(yq)
rownames(y)
?sapply
yq = sapply(y,as.numeric,simplify=FALSE)
head(yq)
rownames(yq)
yq = vapply(y,as.numeric,"dataframe",simplify=FALSE)
yq = vapply(y,as.numeric,"dataframe")
match.fun("dataframe")
str(y)
yq = vapply(y,as.numeric,"data.frame")
yq = sapply(y,as.numeric,simplify=FALSE)
str(yq)
yq = sapply(y,function(c){y[,c] = as.numeric(y[,c])},simplify=FALSE)
?apply
yq = apply(y,2,function(c){y[,c] = as.numeric(y[,c])})
y[,1]
colnames(y)
ncol(y)
for(i in 1:ncol(y)) y[,i] = as.double(y[,i])
head(y)
str(y)
apply(y,2,function(x) print(x))
yq = apply(y,2,function(x) as.double(x))
head(yq)
str(yq)
yq = data.frame(apply(y,2,function(x) as.double(x)))
head(yq)
str(yq)
y = ldply(x, function(e) {
p <- e$content$properties
q = sapply(names(p),cy,p)
},
.id="NEW_DATE",
.inform=TRUE)
# sort by date
y$NEW_DATE = substring(y$NEW_DATE,1,10)
y = y[with(y,order(NEW_DATE)),]
dates <- y$NEW_DATE
# trim the frame, convert to double, assign row names
y= data.frame(apply(y[,3:14],2,function(x) as.double(x)))
rownames(y) <- dates
head(y)
source('~/git/ustyc/R/yieldcurve.R')
x = xmlParse("bogus")
x
source('~/.active-rstudio-document')
x = getYieldCurve("bogus")
doc <- NULL
doc <- xmlParse(location)
if (doc == NULL) {
warning(paste("Could not parse the location",location))
return(NULL)
}
location
?warning
paste("could not",location)
warning(paste("could not",location))
doc
?is.null
doc <- NULL
doc <- xmlParse(location)
if (is.null(doc)) {
warning(paste("Could not parse the location",location))
return(NULL)
}
?message
source('~/.active-rstudio-document')
x = getYieldCurve()
source('~/.active-rstudio-document')
x = getYieldCurve()
head(x)
head(x,n=1)
head(x,n=2)
colnames(x)
rownames(x)
str(x)
head(x$df)
x$updates
x$updated
updated
head(x$df)
xt = xts(x$df,order.by=rownames(x$df))
require(xts)
xt = xts(x$df,order.by=rownames(x$df))
xt = xts(x$df,order.by=as.Date(rownames(x$df)))
str(xt)
head(xt)
require(lattice)
xyplot.ts(xt)
xyplot.ts(xt,superpose=TRUE)
?xyplot
xyplot.ts(xt,superpose=TRUE,auto.key=list(columns=4))
xyplot.ts(xt,superpose=TRUE,auto.key=list(columns=4),ylab="Yield (%)")
xyplot.ts(xt)
xyplot.ts(xt,scales=list(relation="same"))
xyplot.ts(xt,scales=list(y=list(relation="same")))
xyplot.ts(xt,scales=list(y=list(relation="same")),ylab="Yield (%)")
# xyplot.ts(xt,scales=list(y=list(relation="same")),ylab="Yield (%)")
head(xt)
source('~/.active-rstudio-document')
x = getYieldCurve(year=2014)
base
location <- base
yloc <- mloc <- NULL
year=2014
yloc = ifelse(is.null(year),year,paste("year(NEW_DATE)%20eq%20",year,sep=''))
yloc
mloc = ifelse(is.null(month),year,paste("month(NEW_DATE)%20eq%20",month,sep=''))
month=NULL
mloc = ifelse(is.null(month),year,paste("month(NEW_DATE)%20eq%20",month,sep=''))
parameters <- ""
if (is.null(yloc)==FALSE && is.null(mloc)==FALSE)
parameters = paste("$filter=",mloc,"%20and%20",yloc,sep='')
else {
if (is.null(yloc)==FALSE)
parameters = paste("$filter=",yloc,sep='')
if (is.null(mloc)==FALSE)
parameters = paste("$filter=",mloc,sep='')
}
parameters <- ""
if (is.null(yloc)==FALSE && is.null(mloc)==FALSE)
parameters = paste("$filter=",mloc,"%20and%20",yloc,sep='')
else {
if (is.null(yloc)==FALSE)
parameters = paste("$filter=",yloc,sep='')
if (is.null(mloc)==FALSE)
parameters = paste("$filter=",mloc,sep='')
}
parameters
yloc = ifelse(is.null(year),year,paste("year(NEW_DATE)%20eq%20",year,sep=''))
mloc = ifelse(is.null(month),month,paste("month(NEW_DATE)%20eq%20",month,sep=''))
location <- base
yloc = ifelse(is.null(year),year,paste("year(NEW_DATE)%20eq%20",year,sep=''))
mloc = ifelse(is.null(month),month,paste("month(NEW_DATE)%20eq%20",month,sep=''))
location <- base
yloc = ifelse(is.null(year),NULL,paste("year(NEW_DATE)%20eq%20",year,sep=''))
mloc = ifelse(is.null(month),NULL,paste("month(NEW_DATE)%20eq%20",month,sep=''))
location <- base
yloc <- mloc <- NULL
yloc <- if(is.null(year)==FALSE) paste("year(NEW_DATE)%20eq%20",year,sep='')
mloc <- if(is.null(month)==FALSE) paste("month(NEW_DATE)%20eq%20",month,sep='')
mloc
yloc
parameters <- ""
if (is.null(yloc)==FALSE && is.null(mloc)==FALSE)
parameters = paste("$filter=",mloc,"%20and%20",yloc,sep='')
else {
parameters <- ""
if (is.null(yloc)==FALSE && is.null(mloc)==FALSE) {
parameters = paste("$filter=",mloc,"%20and%20",yloc,sep='')
} else {
if (is.null(yloc)==FALSE)
parameters = paste("$filter=",yloc,sep='')
if (is.null(mloc)==FALSE)
parameters = paste("$filter=",mloc,sep='')
}
parameters
doc <- NULL
doc <- xmlParse(paste(location,parameters,sep=''))
paste(location,parameters,sep='')
parameters <- ""
if (is.null(yloc)==FALSE && is.null(mloc)==FALSE) {
parameters = paste("?$filter=",mloc,"%20and%20",yloc,sep='')
} else {
if (is.null(yloc)==FALSE)
parameters = paste("?$filter=",yloc,sep='')
if (is.null(mloc)==FALSE)
parameters = paste("?$filter=",mloc,sep='')
}
doc <- NULL
doc <- xmlParse(paste(location,parameters,sep=''))
head(doc$df)
doc
if (is.null(doc)) {
warning(paste("Could not parse the location",location))
return(NULL)
}
message("Download and parse complete. Converting to list...")
x <- xmlToList(doc)
message("List conversion complete. Converting to frame...")
# save the updated time
updated = x[[3]]
# truncate first four elements and the last element
x[1:4] <- NULL
x[[length(x)]] <- NULL
cy <- function(t,p) {
if ("text" %in% names(p[[t]]))
p[[t]]$text
else
NA
}
y = ldply(x, function(e) {
p <- e$content$properties
q = sapply(names(p),cy,p)
},
.id="NEW_DATE",
.inform=TRUE)
# sort by date
y$NEW_DATE = substring(y$NEW_DATE,1,10)
y = y[with(y,order(NEW_DATE)),]
dates <- y$NEW_DATE
# trim the columns, convert remainder to double, assign row names
y= data.frame(apply(y[,3:14],2,function(x) as.double(x)))
rownames(y) <- dates
message("Frame conversion complete.")
x = list(updated=updated,df=y)
str(x)
plot(x$df)
xt = xts(x$df,order.by=as.Date(rownames(x$df)))
xyplot.ts(xt,scales=list(y=list(relation="same")),ylab="Yield (%)")
xyplot.ts(xt,superpose=TRUE,auto.key=list(columns=4),ylab="Yield (%)")
source('~/.active-rstudio-document')
x = getYieldCurve(year=2013,month=2)
xt = xts(x$df,order.by=as.Date(rownames(x$df)))
xyplot.ts(xt,superpose=TRUE,auto.key=list(columns=4),ylab="Yield (%)")
x = getYieldCurve(year=2012)
ncol(x)
ncol(x$df)
?ldply
source('~/.active-rstudio-document')
x = getYieldCurve(parallel=TRUE)
require(doParallel)
cluster <- makeCluster(2) # or use detectCores()
registerDoParallel(cluster)
x = getYieldCurve(parallel=TRUE)
parallel
source('~/git/ustyc/R/yieldcurve.R')
cluster <- makeCluster(detectCores()) # or use detectCores()
registerDoParallel(cluster)
x = getYieldCurve(allowParallel=TRUE)
source('~/git/ustyc/R/summary.ustyc.R')
summary(x)
source('~/git/ustyc/R/summary.ustyc.R')
summary(x)
names(x)
nrow(x$df)
#' @export
summary.ustyc <- function(object,...) {
results <- c(nrow(object$df),object$month,object$year,object$updated)
names(results) <- c("rows","month","year","updated")
results
}
str(x)
summary(x)
x$month
x$year
c(nrow(x$df),x$month,x$year,x$updated)
x$query
source('~/.active-rstudio-document')
summary(x)
?install.github
?install_github
require(ustyc)
check()
check()
check()
browseVignettes("ustyc")
install()
browseVignettes(package="ustyc")
browseVignettes(package="ustyc")
check()
check()
check()
check()
setwd("~/git/ustyc")
check()
check()
check()
browseVignettes(package="ustyc")
install()
browseVignettes(package="ustyc")
library(ustyc)