Skip to content

Commit 6fb4d35

Browse files
committed
update effective exchange rate data
1 parent 0cc808a commit 6fb4d35

File tree

6 files changed

+64
-66
lines changed

6 files changed

+64
-66
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: tqr
22
Type: Package
33
Title: Add tq_xx functions to tidyquant package to facilitate economic analyses
4-
Version: 0.0.0.9009
4+
Version: 0.0.0.9010
55
Author: Mitsuo Shiota
66
Maintainer: Mitsuo Shiota <[email protected]>
77
Description: Add utility functions to facilitate economic analyses on

README.Rmd

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Let us see the differences year-over-year.
121121
```{r tq_diff, fig.width=8, fig.height=4}
122122
eer_ts %>%
123123
tq_diff(n = 12) %>%
124-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
124+
pivot_longer(!c(date, symbol), names_to = "area") %>%
125125
filter(symbol == "reer") %>%
126126
filter(area %in% c("Japan", "Euro area", "United States")) %>%
127127
ggplot(aes(x = date, y = value, color = area)) +
@@ -141,7 +141,7 @@ Let us see 6 month moving average movements.
141141
```{r tq_ma, fig.width=8, fig.height=4}
142142
eer_ts %>%
143143
tq_ma(n = 6) %>%
144-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
144+
pivot_longer(!c(date, symbol), names_to = "area") %>%
145145
filter(symbol == "reer") %>%
146146
filter(area %in% c("Japan", "Euro area", "United States")) %>%
147147
ggplot(aes(x = date, y = value, color = area)) +
@@ -161,7 +161,7 @@ Let us see year-over-year growth rates, percents.
161161
```{r tq_gr, fig.width=8, fig.height=4}
162162
eer_ts %>%
163163
tq_gr(n = 12) %>%
164-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
164+
pivot_longer(!c(date, symbol), names_to = "area") %>%
165165
filter(symbol == "reer") %>%
166166
filter(area %in% c("Japan", "Euro area", "United States")) %>%
167167
ggplot(aes(x = date, y = value, color = area)) +
@@ -180,7 +180,7 @@ You can convert from "month" to "quarter".
180180

181181
```{r convert_freq, fig.width=8, fig.height=4}
182182
eer_q <- eer_ts %>%
183-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
183+
pivot_longer(!c(date, symbol), names_to = "area") %>%
184184
group_by(symbol, area) %>%
185185
index_by(quarter = yearquarter(date)) %>%
186186
summarize(value = mean(value))
@@ -206,7 +206,7 @@ Let us get seasonally adjust values. `tq_sa` utilizes [`seasonal` package](https
206206

207207
```{r tq_sa, fig.width=8, fig.height=4}
208208
greece <- eer_ts %>%
209-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
209+
pivot_longer(!c(date, symbol), names_to = "area") %>%
210210
filter(symbol == "deflator", area == "Greece") %>%
211211
mutate(symbol = "original")
212212
@@ -276,8 +276,8 @@ tq_range <- cal_factory(
276276
277277
eer_ts %>%
278278
tq_range() %>%
279-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
280-
pivot_wider(names_from = date, values_from = value) %>%
279+
pivot_longer(!c(date, symbol), names_to = "area") %>%
280+
pivot_wider(names_from = date) %>%
281281
mutate(range = max - min) %>%
282282
filter(symbol == "deflator") %>%
283283
arrange(desc(range))
@@ -307,7 +307,7 @@ tq_acf <- cal_factory(
307307
defl_gr1 %>%
308308
tq_acf() %>%
309309
filter(date == "acf12") %>%
310-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
310+
pivot_longer(!c(date, symbol), names_to = "area") %>%
311311
arrange(desc(value))
312312
313313
@@ -345,7 +345,7 @@ system.time(tq_ma(eer_ts, n = 3))
345345
system.time(tq_rollmean(eer_ts, k = 3, align = "right", fill = NA))
346346
347347
eer_ts_long <- eer_ts %>%
348-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value")
348+
pivot_longer(!c(date, symbol), names_to = "area")
349349
350350
system.time(tq_ma(eer_ts_long, n = 3))
351351
system.time(tq_rollmean(eer_ts_long, k = 3, align = "right", fill = NA))

README.md

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,41 @@ Introduction to tqr package
33
Mitsuo Shiota
44
2019-07-19
55

6-
- [tqr: add-on to tsibble, inspired by
6+
- [tqr: add-on to tsibble, inspired by
77
tidyquant](#tqr-add-on-to-tsibble-inspired-by-tidyquant)
8-
- [Installation](#installation)
9-
- [Libraries](#libraries)
10-
- [Create time aware dataframe of tsibble
8+
- [Installation](#installation)
9+
- [Libraries](#libraries)
10+
- [Create time aware dataframe of tsibble
1111
class](#create-time-aware-dataframe-of-tsibble-class)
12-
- [Insert missing rows, if
12+
- [Insert missing rows, if
1313
necessary](#insert-missing-rows-if-necessary)
14-
- [tq\_diff: calculate
14+
- [tq\_diff: calculate
1515
differences](#tq_diff-calculate-differences)
16-
- [tq\_ma: calculate moving
16+
- [tq\_ma: calculate moving
1717
averages](#tq_ma-calculate-moving-averages)
18-
- [tq\_gr: calculate growth rates](#tq_gr-calculate-growth-rates)
19-
- [Convert to lower frequency](#convert-to-lower-frequency)
20-
- [tq\_sa: calculate seasonally adjusted
18+
- [tq\_gr: calculate growth rates](#tq_gr-calculate-growth-rates)
19+
- [Convert to lower frequency](#convert-to-lower-frequency)
20+
- [tq\_sa: calculate seasonally adjusted
2121
values](#tq_sa-calculate-seasonally-adjusted-values)
22-
- [cal\_factory: function factory for
22+
- [cal\_factory: function factory for
2323
calculation](#cal_factory-function-factory-for-calculation)
24-
- [cal\_factory\_zoo: function factory for calculation utilizing
24+
- [cal\_factory\_zoo: function factory for calculation utilizing
2525
zoo
2626
package](#cal_factory_zoo-function-factory-for-calculation-utilizing-zoo-package)
27-
- [cal\_factory\_ts: function factory for calculation utilizing ts
27+
- [cal\_factory\_ts: function factory for calculation utilizing ts
2828
class](#cal_factory_ts-function-factory-for-calculation-utilizing-ts-class)
29-
- [cal\_factory\_xts: function factory for calculation utilizing
29+
- [cal\_factory\_xts: function factory for calculation utilizing
3030
xts
3131
package](#cal_factory_xts-function-factory-for-calculation-utilizing-xts-package)
3232

3333
<!-- README.md is generated from README.Rmd. Please edit that file -->
34-
3534
<!-- badges: start -->
3635

3736
[![Travis build
3837
status](https://travis-ci.org/mitsuoxv/tqr.svg?branch=master)](https://travis-ci.org/mitsuoxv/tqr)
3938
<!-- badges: end -->
4039

41-
Updated: 2020-12-24
40+
Updated: 2021-03-21
4241

4342
# tqr: add-on to tsibble, inspired by tidyquant
4443

@@ -106,18 +105,19 @@ eer
106105
#> 9 1994-09-30 defla… 123. 132. 108. 85.6 90.8 205. 3690.
107106
#> 10 1994-10-31 defla… 121. 133. 108. 86.2 91.2 201. 3512.
108107
#> # … with 938 more rows, and 53 more variables: Canada <dbl>, Chile <dbl>,
109-
#> # China <dbl>, `Chinese Taipei` <dbl>, Colombia <dbl>, Croatia <dbl>,
110-
#> # Cyprus <dbl>, `Czech Republic` <dbl>, Denmark <dbl>, Estonia <dbl>, `Euro
111-
#> # area` <dbl>, Finland <dbl>, France <dbl>, Germany <dbl>, Greece <dbl>,
112-
#> # `Hong Kong SAR` <dbl>, Hungary <dbl>, Iceland <dbl>, India <dbl>,
108+
#> # China <dbl>, Chinese Taipei <dbl>, Colombia <dbl>, Croatia <dbl>,
109+
#> # Cyprus <dbl>, Czech Republic <dbl>, Denmark <dbl>, Estonia <dbl>,
110+
#> # Euro area <dbl>, Finland <dbl>, France <dbl>, Germany <dbl>, Greece <dbl>,
111+
#> # Hong Kong SAR <dbl>, Hungary <dbl>, Iceland <dbl>, India <dbl>,
113112
#> # Indonesia <dbl>, Ireland <dbl>, Israel <dbl>, Italy <dbl>, Japan <dbl>,
114113
#> # Korea <dbl>, Latvia <dbl>, Lithuania <dbl>, Luxembourg <dbl>,
115-
#> # Malaysia <dbl>, Malta <dbl>, Mexico <dbl>, Netherlands <dbl>, `New
116-
#> # Zealand` <dbl>, Norway <dbl>, Peru <dbl>, Philippines <dbl>, Poland <dbl>,
117-
#> # Portugal <dbl>, Romania <dbl>, Russia <dbl>, `Saudi Arabia` <dbl>,
118-
#> # Singapore <dbl>, Slovakia <dbl>, Slovenia <dbl>, `South Africa` <dbl>,
119-
#> # Spain <dbl>, Sweden <dbl>, Switzerland <dbl>, Thailand <dbl>, Turkey <dbl>,
120-
#> # `United Arab Emirates` <dbl>, `United Kingdom` <dbl>, `United States` <dbl>
114+
#> # Malaysia <dbl>, Malta <dbl>, Mexico <dbl>, Netherlands <dbl>,
115+
#> # New Zealand <dbl>, Norway <dbl>, Peru <dbl>, Philippines <dbl>,
116+
#> # Poland <dbl>, Portugal <dbl>, Romania <dbl>, Russia <dbl>,
117+
#> # Saudi Arabia <dbl>, Singapore <dbl>, Slovakia <dbl>, Slovenia <dbl>,
118+
#> # South Africa <dbl>, Spain <dbl>, Sweden <dbl>, Switzerland <dbl>,
119+
#> # Thailand <dbl>, Turkey <dbl>, United Arab Emirates <dbl>,
120+
#> # United Kingdom <dbl>, United States <dbl>
121121

122122
class(eer)
123123
#> [1] "tbl_df" "tbl" "data.frame"
@@ -226,7 +226,7 @@ Let us see the differences year-over-year.
226226
``` r
227227
eer_ts %>%
228228
tq_diff(n = 12) %>%
229-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
229+
pivot_longer(!c(date, symbol), names_to = "area") %>%
230230
filter(symbol == "reer") %>%
231231
filter(area %in% c("Japan", "Euro area", "United States")) %>%
232232
ggplot(aes(x = date, y = value, color = area)) +
@@ -248,7 +248,7 @@ Let us see 6 month moving average movements.
248248
``` r
249249
eer_ts %>%
250250
tq_ma(n = 6) %>%
251-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
251+
pivot_longer(!c(date, symbol), names_to = "area") %>%
252252
filter(symbol == "reer") %>%
253253
filter(area %in% c("Japan", "Euro area", "United States")) %>%
254254
ggplot(aes(x = date, y = value, color = area)) +
@@ -270,7 +270,7 @@ Let us see year-over-year growth rates, percents.
270270
``` r
271271
eer_ts %>%
272272
tq_gr(n = 12) %>%
273-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
273+
pivot_longer(!c(date, symbol), names_to = "area") %>%
274274
filter(symbol == "reer") %>%
275275
filter(area %in% c("Japan", "Euro area", "United States")) %>%
276276
ggplot(aes(x = date, y = value, color = area)) +
@@ -291,7 +291,7 @@ You can convert from “month” to “quarter”.
291291

292292
``` r
293293
eer_q <- eer_ts %>%
294-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
294+
pivot_longer(!c(date, symbol), names_to = "area") %>%
295295
group_by(symbol, area) %>%
296296
index_by(quarter = yearquarter(date)) %>%
297297
summarize(value = mean(value))
@@ -320,7 +320,7 @@ package](https://www.rdocumentation.org/packages/seasonal/versions/1.7.0).
320320

321321
``` r
322322
greece <- eer_ts %>%
323-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
323+
pivot_longer(!c(date, symbol), names_to = "area") %>%
324324
filter(symbol == "deflator", area == "Greece") %>%
325325
mutate(symbol = "original")
326326

@@ -396,8 +396,8 @@ tq_range <- cal_factory(
396396

397397
eer_ts %>%
398398
tq_range() %>%
399-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
400-
pivot_wider(names_from = date, values_from = value) %>%
399+
pivot_longer(!c(date, symbol), names_to = "area") %>%
400+
pivot_wider(names_from = date) %>%
401401
mutate(range = max - min) %>%
402402
filter(symbol == "deflator") %>%
403403
arrange(desc(range))
@@ -444,21 +444,21 @@ tq_acf <- cal_factory(
444444
defl_gr1 %>%
445445
tq_acf() %>%
446446
filter(date == "acf12") %>%
447-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value") %>%
447+
pivot_longer(!c(date, symbol), names_to = "area") %>%
448448
arrange(desc(value))
449449
#> # A tibble: 60 x 4
450450
#> date symbol area value
451451
#> <chr> <chr> <chr> <dbl[,1,1]>
452-
#> 1 acf12 deflator Greece 0.891
453-
#> 2 acf12 deflator Luxembourg 0.831
454-
#> 3 acf12 deflator Spain 0.802
455-
#> 4 acf12 deflator Euro area 0.779
456-
#> 5 acf12 deflator Netherlands 0.744
457-
#> 6 acf12 deflator Portugal 0.714
458-
#> 7 acf12 deflator Germany 0.672
459-
#> 8 acf12 deflator Czech Republic 0.667
460-
#> 9 acf12 deflator France 0.667
461-
#> 10 acf12 deflator Colombia 0.655
452+
#> 1 acf12 deflator Greece 0.891
453+
#> 2 acf12 deflator Luxembourg 0.831
454+
#> 3 acf12 deflator Spain 0.802
455+
#> 4 acf12 deflator Euro area 0.779
456+
#> 5 acf12 deflator Netherlands 0.744
457+
#> 6 acf12 deflator Portugal 0.714
458+
#> 7 acf12 deflator Germany 0.672
459+
#> 8 acf12 deflator Czech Republic 0.667
460+
#> 9 acf12 deflator France 0.667
461+
#> 10 acf12 deflator Colombia 0.655
462462
#> # … with 50 more rows
463463
```
464464

@@ -497,20 +497,20 @@ choose, instead consider to spread to wide format.
497497
``` r
498498
system.time(tq_ma(eer_ts, n = 3))
499499
#> user system elapsed
500-
#> 0.248 0.000 0.248
500+
#> 0.246 0.001 0.247
501501
system.time(tq_rollmean(eer_ts, k = 3, align = "right", fill = NA))
502502
#> user system elapsed
503-
#> 0.472 0.000 0.471
503+
#> 0.465 0.003 0.469
504504

505505
eer_ts_long <- eer_ts %>%
506-
pivot_longer(!c(date, symbol), names_to = "area", values_to = "value")
506+
pivot_longer(!c(date, symbol), names_to = "area")
507507

508508
system.time(tq_ma(eer_ts_long, n = 3))
509509
#> user system elapsed
510-
#> 0.763 0.003 0.768
510+
#> 0.815 0.001 0.816
511511
system.time(tq_rollmean(eer_ts_long, k = 3, align = "right", fill = NA))
512512
#> user system elapsed
513-
#> 1.176 0.001 1.177
513+
#> 1.132 0.003 1.136
514514
```
515515

516516
## cal\_factory\_ts: function factory for calculation utilizing ts class

data-raw/broad.xlsx

9.9 KB
Binary file not shown.

data-raw/eer.R

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ neer$symbol <- "neer"
2626
eer <- bind_rows(reer, neer)
2727

2828
eer <- eer %>%
29-
gather(key = "area", value = "value", -date, -symbol) %>%
30-
spread(key = symbol, value = value) %>%
29+
mutate(date = as.Date(date)) %>%
30+
pivot_longer(!c(date, symbol), names_to = "area") %>%
31+
pivot_wider(names_from = symbol) %>%
3132
mutate(deflator = neer / reer * 100) %>%
32-
gather(key = "symbol", value = "value", -date, -area) %>%
33-
spread(key = area, value = value) %>%
33+
pivot_longer(!c(date, area), names_to = "symbol") %>%
34+
pivot_wider(names_from = area) %>%
3435
arrange(symbol, date)
3536

36-
eer$date <- as.Date(eer$date)
37-
3837
usethis::use_data(eer, overwrite = TRUE)
39-

data/eer.rda

6.44 KB
Binary file not shown.

0 commit comments

Comments
 (0)