0

I have a project at uni where I need to use monthly closing price for 10 DAX constituents using yahoo Finance. I tried with a code from my teacher.

I am using R with the quantmod package. The data was downloaded as csv files on my PC

#download my securities
getSymbols(TickersDAX, from=DStart, to=DEnd, warnings=F) 
#ticker list
Ticker_list <- list(BEI.DE,ADS.DE,DBK.DE,DAI.DE,DB1.DE,BMW.DE,ALV.DE,BAYN.DE,CON.DE,BAS.DE,GDAXI)

I received daily prices with not even the full year displayed. What do I need to add to get only monthly closing prices?

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
YSky
  • 13
  • 2
  • Please [add data as shown here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – NelsonGon Jul 06 '19 at 20:36

1 Answers1

0

I am no xts expert but here is an example code to get the latest day in a month from an xts object using lubridate and dplyr:

library(quantmod)
library(lubridate)
library(dplyr)

getSymbols('QQQ')                

df <- tibble(
  date = index(QQQ),
  year = year(date),
  month = month(date)
)

df1 <- df %>% 
  mutate(index = row_number()) %>% 
  group_by(year, month) %>% 
  summarise(index = last(index))

QQQ[df1$index]
eastclintw00d
  • 2,250
  • 1
  • 9
  • 18
  • Oh. Ok I see. I found something else, just that it take more time and write more lines. I used to.monthly for each individually then used merge to get them all together. If I want to calculate a price weighted, value weighted and equally weighted index using these constituents, is there a function within R that I can use? Because afterwords I need to plot the development – YSky Jul 06 '19 at 21:28