Skip to content

Instantly share code, notes, and snippets.

@yaojenkuo
Created September 2, 2020 10:23
Show Gist options
  • Save yaojenkuo/0fcc0d7aa7ecc9c10d5369dda0cd5c18 to your computer and use it in GitHub Desktop.
Save yaojenkuo/0fcc0d7aa7ecc9c10d5369dda0cd5c18 to your computer and use it in GitHub Desktop.
Getting actual historic prices for split stock.
get_actual_historic_prices <- function(adjusted_prices, split_date_periods, split_ratios) {
n_splits <- length(split_ratios)
#xts_list <- list()
actual_historic_prices <- adjusted_prices[split_date_periods[n_splits + 1]]
for (i in n_splits:1) {
single_xts <- adjusted_prices[split_date_periods[[i]]] / prod(split_ratios[n_splits:i])
#actual_historic_prices <- rbind.xts(actual_historic_prices, single_xts)
actual_historic_prices <- rbind.xts(actual_historic_prices, single_xts)
}
return(actual_historic_prices)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment