tidyquant icon indicating copy to clipboard operation
tidyquant copied to clipboard

tq_transmute(mutate_fun=xts::to.xxx) not return aggregate OHLC data

Open visitantz opened this issue 5 years ago • 4 comments

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

visitantz avatar Jan 16 '20 00:01 visitantz

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.

pverspeelt avatar Nov 17 '20 10:11 pverspeelt

+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

umairrafique85 avatar Jul 01 '21 11:07 umairrafique85

Im getting the same problem

espher1987 avatar Dec 26 '21 02:12 espher1987

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

ChiBia avatar Dec 27 '21 10:12 ChiBia