Skip to content

tq_get when yahoo finance returns non unique rows #212

@risktoollib

Description

@risktoollib

Most recent day often returns non-unique values which returns a warning. Problem is with the yahoo extract in the first place via quantmod then passed on to tq_get().

Suggest to amend tq_get just before the return(ret) last line to include:

if (identical(get, "stock.prices")) {
    ret <- ret %>%
    dplyr::group_by(symbol, date) %>%
    dplyr::summarise(open = dplyr::last(open),
                     high = dplyr::last(high),
                     low = dplyr::last(low),
                     close = dplyr::last(close),
                     volume = dplyr::last(volume),
                     adjusted = dplyr::last(adjusted)) %>%
        dplyr::ungroup()
    }

At times yahoo finance returns duplicate last day and at other times everything is the same with the exception of volume. Hence the approach above instead of dplyr::distinct().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions