library(tidyverse) library(parallel) TS <- read_csv("Data/Curie_Spent_Fuel_Timeline.csv") TOTAL <- read_csv("Data/Curie_Spent_Fuel_Site_Totals.csv") %>% mutate(OP_YEAR=year(Op_Date_Min),CLOSE_YEAR=year(Close_Date_Max))%>% select(Facility,Total_Assemblies,Total_Tons,OP_YEAR,CLOSE_YEAR) ###########Series of functions to calculate the gross consumer surplus from a CIFS for each facility, in each year from 1960 to 2082. #Function to find the net present revenue of a facility,given a discount rate, and the current year, and year the facility will close. This is the sum of discounted costs that WOULD have taken place if the facility was not built VALUE_ADD <- function(r,CURRENT_YEAR,CLOSE_YEAR){ Years_Until_Close <- max(CLOSE_YEAR-CURRENT_YEAR+1,0) VALUES <- (1+r)^-(1:10^6) if(Years_Until_Close==0){return(sum(VALUES))} else{return(sum(VALUES[-1:-Years_Until_Close]))} } #A function to extend the revenues calculations to the closure date of all of the facilities. VALUE_ADD_SINGLE_YEAR <- function(r,CURRENT_YEAR,CLOSE_YEARS){return(sapply(CLOSE_YEARS,function(x){VALUE_ADD(r,CURRENT_YEAR,x)}))} #A function to extend the calculation of the net present revenues of each facility to all years of interest. That is what is the NPV of building the facility in each year, for each facility. NPV_CALC <- function(r,DATA=TOTAL,YEARS=1960:2083){ Facility <- pull(DATA,Facility) RES <- cbind(Facility,do.call(cbind,lapply(YEARS,function(x){VALUE_ADD_SINGLE_YEAR(r,x,DATA$CLOSE_YEAR)}))) colnames(RES) <- c("Facility",YEARS) RES <- as_tibble(RES) %>% pivot_longer(cols=-Facility,names_to="Year",values_to="Revenue") %>% arrange(Year) return(RES) } #A function which returns a list, of net present revenue calculation tables (facility by year) for a range of possible discount rates. This allows for the results to be quickly looked up, when we want to adjust the time value of money. These results will need to be combined with costs to calculate NPV MULTI_DISCOUNT_RATE_NPV <- function(INCREMENT=0.005,DATA=TOTAL,YEARS=1960:2083){ NCORES <- detectCores()-1 RES <- mclapply(seq(0,1,by=INCREMENT),NPV_CALC,mc.cores = NCORES) names(RES) <- 100*seq(0,1,by=INCREMENT) #Name with the discount rate of the given table return(RES) } TOTAL_VALUE_METRICS <- MULTI_DISCOUNT_RATE_NPV(INCREMENT=0.0025) dir.create("./Results",showWarnings=FALSE) saveRDS(TOTAL_VALUE_METRICS,"./Results/Storage_Values_by_Facility_and_Variable_Discounts.Rds")