Created
September 2, 2020 10:23
-
-
Save yaojenkuo/0fcc0d7aa7ecc9c10d5369dda0cd5c18 to your computer and use it in GitHub Desktop.
Getting actual historic prices for split stock.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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