Code: Alles auswählen
library(PortfolioAnalytics)
library(ROI)
library(ROI.plugin.quadprog)
library(MASS)
library(dplyr)
library(caTools)
library(quantmod)
library(timeSeries)
library(astsa)
library(forecast)
library(ggplot2)
# Get risk-free rate (1 month T-Bond rate) from FRED
rf <- getSymbols('DGS1MO', src = 'FRED', auto.assign = FALSE)
# ticker for SBUX Index
ndx_symbol <- 'MA'
ndx <- getSymbols(ndx_symbol, from = "1980-01-01", auto.assign = FALSE)
str(ndx)
any(is.na(ndx))
dailyReturn
ndx_daily <- to.daily(ndx)
ndx_returns <- Return.calculate(ndx_daily$ndx.Adjusted)
ndx_returns <- ndx_returns[(-1),]
names(ndx_returns) <- 'NDX_daily'
plot.zoo(ndx_returns, main = 'NASDAQ-100 Daily Returns', xlab = 'Date')
chart.Drawdown(ndx_returns, plot.engine = "ggplot2") +
geom_hline(yintercept = -0.2, size = 1) +
theme_minimal() +
theme(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1),
plot.caption = element_text(hjust = 0, lineheight = 0.5)) +
scale_y_continuous(labels = scales::percent)+
ggtitle("Drawdowns of Starbucks, monthly data",
subtitle = "Black line indicates bear markets")