The dataset that I chose is the year-to-date stock prices historical quotes of Apple Inc. The goal is to explore cumulative trends using two time-series metrics: the year-to-date(YTD) average and the 6-day moving average.
df <- read.csv("C:/data/apple_ytd.csv")
df <- df %>%
arrange(date) %>%
mutate(
ytd_avg = round(cummean(close),2),
avg_6days = round(rollmean(close, k = 6, fill = NA, align = "right"),2)
)
A line chart is used to analyze the trend of the year-to-date(YTD) average price and date.
Another line chart used to plot the six-days average price and date.
ggplot(data = df, aes(x = date, y = avg_6days)) + geom_line()
The line chart shows that the YTD average price droped over time, which suggests the stock has been losing value in a long-term perspective and it’s smoother and slower to respond in a overall cumulative trend. The six-days average plot shows the recent trend in a short-term perspective, which suggests more jagged, volatie and quick changes, especially in June.