#load packes
library(tidyquant)
library(tidyverse)
Ra <- c("NXPI", "IFX.DE") %>%
tq_get(get = "stock.prices", from = "2026-01-01") %>%
group_by(symbol) %>%
tq_transmute(
select = adjusted,
mutate_fun = periodReturn,
period = "monthly",
col_rename = "Ra"
)
Ra
## # A tibble: 18 × 3
## # Groups: symbol [2]
## symbol date Ra
## <chr> <date> <dbl>
## 1 NXPI 2026-01-30 0.0220
## 2 NXPI 2026-02-27 0.00385
## 3 NXPI 2026-03-31 -0.128
## 4 NXPI 2026-04-30 0.491
## 5 NXPI 2026-05-29 0.0946
## 6 NXPI 2026-06-30 -0.123
## 7 NXPI 2026-07-31 -0.185
## 8 NXPI 2026-08-31 -0.0197
## 9 NXPI 2026-09-21 0.0392
## 10 IFX.DE 2026-01-30 0.0874
## 11 IFX.DE 2026-02-27 0.110
## 12 IFX.DE 2026-03-31 -0.171
## 13 IFX.DE 2026-04-30 0.503
## 14 IFX.DE 2026-05-29 0.420
## 15 IFX.DE 2026-06-30 0.00690
## 16 IFX.DE 2026-07-31 -0.245
## 17 IFX.DE 2026-08-31 -0.0872
## 18 IFX.DE 2026-09-22 0.0682
Rb <- "^IXIC" %>%
tq_get(get = "stock.prices",
from = "2026-01-01") %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "monthly",
col_rename = "Rb")
Rb
## # A tibble: 9 × 2
## date Rb
## <date> <dbl>
## 1 2026-01-30 0.00973
## 2 2026-02-27 -0.0338
## 3 2026-03-31 -0.0475
## 4 2026-04-30 0.153
## 5 2026-05-29 0.0836
## 6 2026-06-30 -0.0281
## 7 2026-07-31 -0.0320
## 8 2026-08-31 0.0393
## 9 2026-09-21 0.0285
RaRb <- left_join(Ra, Rb, by = c("date" = "date"))
RaRb
## # A tibble: 18 × 4
## # Groups: symbol [2]
## symbol date Ra Rb
## <chr> <date> <dbl> <dbl>
## 1 NXPI 2026-01-30 0.0220 0.00973
## 2 NXPI 2026-02-27 0.00385 -0.0338
## 3 NXPI 2026-03-31 -0.128 -0.0475
## 4 NXPI 2026-04-30 0.491 0.153
## 5 NXPI 2026-05-29 0.0946 0.0836
## 6 NXPI 2026-06-30 -0.123 -0.0281
## 7 NXPI 2026-07-31 -0.185 -0.0320
## 8 NXPI 2026-08-31 -0.0197 0.0393
## 9 NXPI 2026-09-21 0.0392 0.0285
## 10 IFX.DE 2026-01-30 0.0874 0.00973
## 11 IFX.DE 2026-02-27 0.110 -0.0338
## 12 IFX.DE 2026-03-31 -0.171 -0.0475
## 13 IFX.DE 2026-04-30 0.503 0.153
## 14 IFX.DE 2026-05-29 0.420 0.0836
## 15 IFX.DE 2026-06-30 0.00690 -0.0281
## 16 IFX.DE 2026-07-31 -0.245 -0.0320
## 17 IFX.DE 2026-08-31 -0.0872 0.0393
## 18 IFX.DE 2026-09-22 0.0682 NA
RaRb_capm <- RaRb %>%
tq_performance(Ra = Ra,
Rb = Rb,
performance_fun = table.CAPM)
RaRb_capm
## # A tibble: 2 × 18
## # Groups: symbol [2]
## symbol ActivePremium Alpha AlphaRobust AnnualizedAlpha Beta `Beta-`
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 NXPI -0.143 -0.0307 -0.0309 -0.312 2.74 0.280
## 2 IFX.DE 0.596 0.0207 0.0208 0.279 3.18 6.91
## # ℹ 11 more variables: `Beta-Robust` <dbl>, `Beta+` <dbl>, `Beta+Robust` <dbl>,
## # BetaRobust <dbl>, Correlation <dbl>, `Correlationp-value` <dbl>,
## # InformationRatio <dbl>, `R-squared` <dbl>, `R-squaredRobust` <dbl>,
## # TrackingError <dbl>, TreynorRatio <dbl>
RaRb_skewness <- RaRb %>%
tq_performance(
Ra = Ra,
performance_fun = skewness
)
RaRb_skewness
## # A tibble: 2 × 2
## # Groups: symbol [2]
## symbol skewness.1
## <chr> <dbl>
## 1 NXPI 1.51
## 2 IFX.DE 0.552
Both stocks have positively skewed returns because their skewness values are above zero. NXPI is more positively skewed (1.51) than IFX.DE (0.552).