tidyquant
tidyquant copied to clipboard
tq_transmute(mutate_fun=xts::to.xxx) not return aggregate OHLC data
I suppose it should return OHLC of a period, but the results are the last row of a period. Is this a bug?
df = FANG %>% filter(symbol=='FB') %>% slice(1:40) # FB, Jan/Feb data
tq_transmute(df, select=open:close, mutate_fun=to.monthly)
# date open high low close
# <yearmon> <dbl> <dbl> <dbl> <dbl>
# Jan 2013 29.15 31.47 28.74 30.98
# Feb 2013 26.84 27.30 26.34 27.25
# manually transform to xts then to.monthly get the right data
df %>% select(date, Open=open, High=high, Low=low, Close=close) %>%
tk_xts %>% to.monthly
# ..Open ..High ..Low ..Close
# Jan 2013 27.44 32.51 27.42 30.98
# Feb 2013 31.01 31.02 26.34 27.25
Yep, looks like a bug to me too. I just ran into the same issue. If the data is in an xts form the to.period
function correctly. When using tq_transmute
, the data that is returned is the last record of the period.
+1
Seeing the exact same issue. All the functions of the to.period
family returning OHLC of only the last row of the desired period in tq_transmute
or tq_mutate
Im getting the same problem
Same here I found as workaround https://stackoverflow.com/questions/65873070/converting-daily-data-to-weekly-data-using-r btw it points back to this issue