Analyse Apple als wichtige Aktienposition an Fonds UBS Vitainvest 75 World. Der Anteil beträgt rund 1.68%.
In welchem Bereich entwickelt sich die Apple Aktie bis Ende 2020?
Nullhypothese: Die Apple Aktie folgt mindestens dem durchschnittlichen Wachstum der letzten Jahre. Alternativhypothese: Die Apple Aktie erfüllt die Erwartungen der Anleger nicht (H0 wird widerlegt).
Der geschätzte Kurswert bis 2020 beträgt rund 187. Zu Beginn ist die Streuung klein (187 +/- 6.6 bzw. 3.5%). Diese wächst mit zunehmender Zeit und findet ihren Höhepunkt beim letzten Schätzpunkt (Dez 2020) mit 187 +/- 45.5 bzw. 25%.
Die Nullhypothese wird infolge fehlendem Wachstum abgelehnt und es gilt: Die Apple Aktie wird die Erwartungen der Anleger nicht erfüllen.
knitr::opts_chunk$set(fig.width=9, fig.height=6)
library(tidyverse)
library(magrittr)
library(readxl)
library(plotly)
library(lubridate)
library(openintro)
library(tseries)
library(lmtest)
library(forecast)
library(xts)
library(vars)
library(dygraphs)
library(summarytools)# Daten lesen
apple <- read_excel(path = "Data/Prices Nestle and Apple.xlsx", sheet = "Apple")
# .csv Versuch hat Wertproblem auch nicht gelöst
# apple <- read.csv("Data/Prices_Apple.csv", sep=";", header=TRUE)
# Spalten umbennen, Durchschnittswerte per 1. Monatstag berechnen &
# nach Datum aufsteigend sortieren
apple %<>%
rename(datum = Date,
wert = Kurswert) %>%
mutate(monat = month(datum),
jahr = year(datum)) %>%
unite(monat_jahr, monat, jahr) %>%
group_by(monat_jahr) %>%
mutate(wert_monat = mean(wert)) %>%
ungroup() %>%
arrange(datum) %>%
distinct(monat_jahr, .keep_all = T) %>%
dplyr::select(datum, wert_monat)
# Cast zu passendem Zeitformat
apple$datum <- ymd(apple$datum)
# Datenstruktur & statistische Kennzahlen anzeigen
glimpse(apple)## Observations: 433
## Variables: 2
## $ datum <date> 1982-11-12, 1982-12-01, 1983-01-03, 1983-02-01, 19...
## $ wert_monat <dbl> 1.1843825, 1.1359391, 1.1840833, 1.6130900, 1.60219...
summary(apple)## datum wert_monat
## Min. :1982-11-12 Min. : 0.6191
## 1st Qu.:1991-11-01 1st Qu.: 1.6862
## Median :2000-11-01 Median : 2.6965
## Mean :2000-10-31 Mean : 27.1324
## 3rd Qu.:2009-11-02 3rd Qu.: 29.2801
## Max. :2018-11-01 Max. :219.5482
(d <- plot_ly(data = apple, x = ~datum, y = ~wert_monat, type = "scatter", mode = "lines") %>%
layout(title = "Apple Aktie",
xaxis = list(title = "Datum"),
yaxis = list(title = "Kurswert")))Was ist 2001 passiert? iPod wird vorgestellt. Scheinbar nur ein kurzer Erfolg. Ereignis 2007? iPhone wird eingeführt.
Offene Fragen:
# Umwandlung in Zeitreihe
# ts() hat nicht funktioniert!
apple_ts <- ts(apple[,-1], start = 1982, end = 2018, frequency = 12)
dygraph(apple_ts)plot(apple_decomposition <- decompose(apple_ts))# Bessere Übersicht: Zeige eine Saison
plot(apple_decomposition$seasonal[1:12], type = "l", main = "Eine Saison (Jahr)",
xlab = "Monat", ylab = "")# XTS Format für spätere Visualisierung
apple_xts <- xts(x = apple$wert_monat,
order.by = apple$datum,
frequency = 12,
tzone = Sys.getenv("Europe/Berlin"))adf.test(apple_ts)## Warning in adf.test(apple_ts): p-value greater than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: apple_ts
## Dickey-Fuller = 0.84285, Lag order = 7, p-value = 0.99
## alternative hypothesis: stationary
Nullhypothese “Daten sind nicht stationär” wird angenommen, da p-Wert mit 0.99 > 0.05. Folge: Die Renditen müssen berechnet werden.
# Daten vorbereiten
apple_returns <- ts(diff(log(apple_ts)))[-1]
apple_returns_xts <- diff(log(apple_xts))[-1]
# Visuelle Exploration durch Interaktiver Graph
(d_returns <- dygraph(apple_returns_xts, main = "Apple Renditen") %>%
dyRangeSelector() %>%
dyOptions(stackedGraph = TRUE, colors = "green"))# Deskriptive Analyse
(hist_apple_returns <- plot_ly(x = ~as.double(apple_returns), type = "histogram"))(boxplot_apple_return <- plot_ly(y = ~as.double(apple_returns), type = "box"))summary(apple_returns)## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.99012 -0.04810 0.02251 0.01190 0.08180 0.42704
adf.test(apple_returns)## Warning in adf.test(apple_returns): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: apple_returns
## Dickey-Fuller = -8.0946, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary
Nullhypothese “Daten sind nicht stationär” wird verworfen, da p-Wert mit 0.01 < 0.05. Renditen sind somit stationär.
acf(apple_returns)pacf(apple_returns)Ergebnisse mit folgender Entscheidungstabelle interpretieren:
Fazit: ACF fällt nach Lag q abrupt auf Null & PACF geht stetig gegen Null. Folglich wird das Modell MA(q) verwendet.
# Modell Ma(q) erstellen und Signifikanz prüfen
apple_ar <- Arima(apple_ts, c(0,1,1))
coeftest(apple_ar)##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## ma1 0.162591 0.047733 3.4063 0.0006585 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Alle geschätzten Parameter des (AR)IMA-Modells sind statistisch signifikant.
# Prognose durchführen
apple_prediction <- forecast(apple_ar, level=0.95, h=35)
# visuell ansprechender ggplot2 Graph anzeigen
autoplot(apple_prediction)# Zeige Prognose-Punktschätzer
apple_prediction_df <- summary(apple_prediction)##
## Forecast method: ARIMA(0,1,1)
##
## Model Information:
## Series: apple_ts
## ARIMA(0,1,1)
##
## Coefficients:
## ma1
## 0.1626
## s.e. 0.0477
##
## sigma^2 estimated as 11.46: log likelihood=-1139.2
## AIC=2282.4 AICc=2282.42 BIC=2290.53
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.368738 3.376729 1.488186 0.3881103 8.560265 0.1920035
## ACF1
## Training set -0.001594156
##
## Forecasts:
## Point Forecast Lo 95 Hi 95
## Feb 2018 186.806 180.1723 193.4396
## Mar 2018 186.806 176.6333 196.9786
## Apr 2018 186.806 174.0404 199.5715
## May 2018 186.806 171.8916 201.7203
## Jun 2018 186.806 170.0156 203.5963
## Jul 2018 186.806 168.3291 205.2828
## Aug 2018 186.806 166.7842 206.8277
## Sep 2018 186.806 165.3502 208.2617
## Oct 2018 186.806 164.0063 209.6056
## Nov 2018 186.806 162.7372 210.8747
## Dec 2018 186.806 161.5318 212.0801
## Jan 2019 186.806 160.3814 213.2305
## Feb 2019 186.806 159.2790 214.3330
## Mar 2019 186.806 158.2190 215.3929
## Apr 2019 186.806 157.1970 216.4149
## May 2019 186.806 156.2091 217.4028
## Jun 2019 186.806 155.2521 218.3598
## Jul 2019 186.806 154.3233 219.2886
## Aug 2019 186.806 153.4203 220.1916
## Sep 2019 186.806 152.5411 221.0708
## Oct 2019 186.806 151.6839 221.9280
## Nov 2019 186.806 150.8472 222.7647
## Dec 2019 186.806 150.0294 223.5825
## Jan 2020 186.806 149.2295 224.3824
## Feb 2020 186.806 148.4463 225.1657
## Mar 2020 186.806 147.6787 225.9332
## Apr 2020 186.806 146.9259 226.6860
## May 2020 186.806 146.1870 227.4249
## Jun 2020 186.806 145.4613 228.1506
## Jul 2020 186.806 144.7482 228.8637
## Aug 2020 186.806 144.0470 229.5650
## Sep 2020 186.806 143.3570 230.2549
## Oct 2020 186.806 142.6779 230.9340
## Nov 2020 186.806 142.0090 231.6029
## Dec 2020 186.806 141.3500 232.2619
Der geschätzte Kurswert bis 2020 beträgt rund 187. Zu Beginn ist die Streuung klein (187 +/- 6.6 bzw. 3.5%). Diese wächst mit zunehmender Zeit und findet ihren Höhepunkt beim letzten Schätzpunkt (Dez 2020) mit 187 +/- 45.5 bzw. 25%.
Die Nullhypothese wird infolge keinem Wachstum abgelehnt und es gilt: Die Apple Aktie wird die Erwartungen der Anleger nicht erfüllen.
Datenvorbereitung und -verständnis ist die halbe Miete!
Experimentieren mit verschiedenen Ausschnitten der Zeitreihe von heute aus zurück. Auf dessen Basis Ergebnisse evaluieren und verbessertes Modell verwenden.
Versuch Prognose mit dygraph und Holtwinters Modell
hw <- HoltWinters(apple_ts)
p <- predict(hw, n.ahead = 35, prediction.interval = TRUE)
all <- cbind(apple_ts, p)
dygraph(all, "Prognose Apple Aktie bis 2020 auf Basis Daten bis Jan 2018") %>%
dySeries("apple_ts", label = "Actual") %>%
dySeries(c("p.lwr", "p.fit", "p.upr"), label = "Predicted")apple_ts_ab_2015 <- tail(apple_ts, 37)
hw <- HoltWinters(apple_ts_ab_2015)
p <- predict(hw, n.ahead = 35, prediction.interval = TRUE)
all <- cbind(apple_ts_ab_2015, p)
dygraph(all, "Prognose Apple Aktie bis 2020 auf Basis Daten 2015 - Jan 2018") %>%
dySeries("apple_ts_ab_2015", label = "Actual") %>%
dySeries(c("p.lwr", "p.fit", "p.upr"), label = "Predicted")