# ============================================================================== #
#### MASTER - IRIR / IRSIR ####
# ============================================================================== #
# ------------------------------------------------------------------------------ #
# 1. OPPSETT ####
# ------------------------------------------------------------------------------ #
remove(list = ls())
start.time = Sys.time()
options(scipen = 2000)
# Installer pakker
if (!"Benchmarking" %in% installed.packages()) install.packages("Benchmarking")
if (!"plyr" %in% installed.packages()) install.packages("plyr")
if (!"dplyr" %in% installed.packages()) install.packages("dplyr")
if (!"openxlsx" %in% installed.packages()) install.packages("openxlsx")
if (!"rstudioapi" %in% installed.packages()) install.packages("rstudioapi")
if (!"tidyverse" %in% installed.packages()) install.packages("tidyverse")
if (!"writexl" %in% installed.packages()) install.packages("writexl")
if (!"pxweb" %in% installed.packages()) install.packages("pxweb")
if (!"lifecontingencies" %in% installed.packages()) install.packages("lifecontingencies")
if (!"odbc" %in% installed.packages()) install.packages("odbc")
if (!"RODBC" %in% installed.packages()) install.packages("RODBC")
if (!"lubridate" %in% installed.packages()) install.packages("lubridate")
library(tidyverse)
library(Benchmarking)
library(plyr)
library(dplyr)
library(openxlsx)
library(rstudioapi)
library(writexl)
library(pxweb)
library(lifecontingencies)
library(readxl)
library(odbc)
library(RODBC)
library(lubridate)
# Sett arbeidsmappe til mappen der master-scriptet ligger.
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
# getwd() # Kontrollutskrift
# ------------------------------------------------------------------------------ #
# 2. RESULTATMAPPER ####
# ------------------------------------------------------------------------------ #
results_dir = file.path(getwd(), "Results")
timestamp = format(start.time, "%Y-%m-%d_%H-%M-%S")
run_dir = file.path(results_dir, paste0("Run_", timestamp))
dir.create(run_dir, recursive = TRUE, showWarnings = FALSE)
output_folder = paste0(run_dir, "/")
# ------------------------------------------------------------------------------ #
# 3. KJ??RINGSVALG ####
# ------------------------------------------------------------------------------ #
# Bootstrap:
# 1 = beregn nye bootstrap-estimater
# 0 = bruk siste beregning
BS.new = 1
BS.ite = 10000
# Kj??r IRSIR-beregningen for Statnett/NordLink.
Statnett_calc = FALSE
# SSB-data til IRSIR 02:
# 1 = hent nye SSB-data og lagre dem lokalt
# 0 = bruk sist lagrede SSB-data
UPDATE_SSB_DATA = 0
if (length(UPDATE_SSB_DATA) != 1 ||
!(UPDATE_SSB_DATA %in% c(0, 1))) {
stop("UPDATE_SSB_DATA m?? v??re 0 eller 1.")
}
SSB_CACHE_FILE = "./Data/Cache/IRSiR_SSB_price_data.rds"
# ------------------------------------------------------------------------------ #
# 4. BEREGNINGSTYPE TIL DWH ####
# ------------------------------------------------------------------------------ #
versjon <- data.frame("type" = as.integer(1))
# 0 Annet
# 1 Forel??pig beregning
# 2 Varsel
# 3 Vedtak
# 4 Etter klagebehandling (forel??pig)
# 5 Etter klagebehandling (endelig)
# ------------------------------------------------------------------------------ #
# 5. FORUTSETNINGER ####
# ------------------------------------------------------------------------------ #
# source("./Forutsetninger.R")
# ------------------------------------------------------------------------------ #
# 6. IRIR - INNTEKTSRAMMEBEREGNING ####
# ------------------------------------------------------------------------------ #
source("./R-script/functions_nve.R")
source("./R-script/0_1_Config_Assumptions_Data.R")
source("./R-script/0_2_Merging_Z-variables.R")
write.dat = dat[, c(
"orgn", "y", "comp", "ld_OPEXxS", "ld_sal", "ld_sal.cap", "ld_pens",
"ld_pens.eq", "ld_impl", "ld_391", "ld_elhub", "ld_usla", "rd_OPEXxS",
"rd_sal", "rd_sal.cap", "rd_pens", "rd_pens.eq", "rd_impl", "rd_391",
"rd_elhub", "rd_cga", "rd_usla", "t_OPEXxS", "t_sal", "t_sal.cap",
"t_pens", "t_pens.eq", "t_impl", "t_391", "t_elhub", "ld_bv.sf",
"ld_dep.sf", "ld_bv.gf", "ld_dep.gf", "rd_bv.sf", "rd_dep.sf",
"rd_bv.gf", "rd_dep.gf", "t_bv.sf", "t_dep.sf", "ld_cens", "rd_cens",
"t_cens", "ld_nl", "rd_nl", "ld_sub", "ld_hvoh", "ld_hvug", "ld_hvsc",
"ld_hv", "ld_ss", "rd_wv.ol", "rd_wv.uc", "rd_wv.sc", "rd_wv.ss",
"ldz_salt", "ldz_coast_wind", "ldz_water", "ldz_incline", "ldz_prod",
"ldz_snow_trees", "ldz_forest_broadleaf", "ldz_snowdrift",
"ldz_snow_400", "ldz_wind_99", "ldz_frosthours",
"ldz_forest_mixed_conf", "ldz_mgc", "ap.t_2", "pnl.rc"
)]
csv_file = file.path(run_dir, paste0(Sys.Date(), "_grunnlagsdata.csv"))
xlsx_file = file.path(run_dir, paste0(Sys.Date(), "_grunnlagsdata.xlsx"))
write.csv(write.dat, file = csv_file)
write.xlsx(write.dat, file = xlsx_file, overwrite = TRUE)
source("./R-script/0_3_Calculated_Input_Values.R")
source("./R-script/0_4_Company_Selection.R")
source("./R-script/1_0_DEA.R")
source("./R-script/2_0_GeoCorrection.R")
source("./R-script/3_0_Calibration.R")
source("./R-script/Spec_OOTO-model.R")
source("./R-script/Spec_AvEff-model.R")
source("./R-script/4_0_Revenue_Cap_Calculation.R")
if (Statnett_calc) {
# Oppdater nettapspriser n??r nye prisdata skal brukes.
UPDATE_PRICES = TRUE
# Eksporter annuitetsfiler.
ANNUITIES_EXPORT = TRUE
y.cb = as.numeric(y.cb)
price_reference_year = y.cb
interestrate = 0.03
y_NG_annuities <- seq(y.cb - 6, y.cb, by = 1)
ISS = 1991 # Start??r for investeringsstr??m
system_operator_purchases = 3961511 # Post 440
productivity_requirement = 0.02
productivity_requirement_system_operations = 0.006
# IRSIR
source("./R-script/IRSiR_01_NormGrid.R")
source("./R-script/IRSiR_02_Capex_Annuities.R")
source("./R-script/IRSiR_03_Transmission_Data.R")
source("./R-script/IRSiR_04_Benchmark.R")
source("./R-script/IRSiR_05_RevCap_Statnett.R")
source("./R-script/IRSiR_06_RevCap_NordLink.R")
}
end.time = Sys.time()
calc.time = end.time - start.time
calc.time
source("./R-script/Key_figures.R")
source("./R-script/Print_results.R")
View(RevCap)
