This repository has been archived by the owner on Dec 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
/
2_project_input_analysis.R
146 lines (117 loc) · 4.47 KB
/
2_project_input_analysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# This script obtains data, processes the portfolio and saves the files
####################
#### DATA FILES ####
####################
currencies <- get_and_clean_currency_data()
fund_data <- get_and_clean_fund_data()
fin_data <- get_and_clean_fin_data(fund_data)
comp_fin_data <- get_and_clean_company_fin_data()
debt_fin_data <- get_and_clean_debt_fin_data()
revenue_data <- get_and_clean_revenue_data()
average_sector_intensity <- get_average_emission_data(inc_emission_factors)
company_emissions <- get_company_emission_data(inc_emission_factors)
####################
#### PORTFOLIOS ####
####################
portfolio_raw <- read_raw_portfolio_file(project_name)
portfolio <- process_raw_portfolio(
portfolio_raw,
fin_data,
fund_data,
currencies,
grouping_variables
)
# information of coverage and coverage loses for all funds in raw_portfolio
fund_coverage <- get_fund_coverage(
portfolio_raw,
fin_data,
fund_data,
currencies,
grouping_variables
)
# reduce information on fund coverage to a data frame that can be shared with users
fund_coverage_summary <- summarize_fund_coverage(fund_coverage)
# list ISINs of unknown funds in funds. the list includes value_usd to estimate importance of the isin for o
unknown_funds_in_funds <- list_unknown_funds_in_funds(portfolio)
portfolio <- add_revenue_split(has_revenue, portfolio, revenue_data)
portfolio <- create_ald_flag(portfolio, comp_fin_data, debt_fin_data)
eq_portfolio <- create_portfolio_subset(
portfolio,
"Equity"
)
cb_portfolio <- create_portfolio_subset(
portfolio,
"Bonds"
)
portfolio_total <- add_portfolio_flags(portfolio)
portfolio_overview <- portfolio_summary(portfolio_total)
audit_file <- create_audit_file(portfolio_total)
create_audit_chart(audit_file, proc_input_path)
emissions_totals <- calculate_portfolio_emissions(
inc_emission_factors,
audit_file,
fin_data,
comp_fin_data,
average_sector_intensity,
company_emissions
)
################
#### SAVING ####
################
# Todo: add this to a parameter file
file_format_list <- "rda"
if (length(file_format_list) == 0) {
stop("Saving results: No file formats defined")
}
if ("csv" %in% file_format_list) {
if (data_check(portfolio_total)) {
write_csv_file(portfolio_total, file = paste0(proc_input_path, "/", project_name, "_total_portfolio.csv"))
}
if (data_check(eq_portfolio)) {
write_csv_file(eq_portfolio, file = paste0(proc_input_path, "/", project_name, "_equity_portfolio.csv"))
}
if (data_check(cb_portfolio)) {
write_csv_file(cb_portfolio, file = paste0(proc_input_path, "/", project_name, "_bonds_portfolio.csv"))
}
if (data_check(portfolio_overview)) {
write_csv_file(portfolio_overview, file = paste0(proc_input_path, "/", project_name, "_overview_portfolio.csv"))
}
if (data_check(audit_file)) {
write_csv_file(audit_file, file = paste0(proc_input_path, "/", project_name, "_audit_file.csv"))
}
if (data_check(emissions_totals)) {
write_csv_file(emissions_totals, file = paste0(proc_input_path, "/", project_name, "_emissions.csv"))
}
if (data_check(fund_coverage_summary)){
write_csv_file(fund_coverage_summary, file = file.path(proc_input_path_, "fund_coverage_summary.csv"))
}
if (data_check(unknown_funds_in_funds)){
write_csv_file(unknown_funds_in_funds, file = file.path(proc_input_path_, "unknown_funds_in_funds.csv"))
}
}
if ("rds" %in% file_format_list | "rda" %in% file_format_list) {
if (data_check(portfolio_total)) {
write_rds(portfolio_total, paste0(proc_input_path, "/", project_name, "_total_portfolio.rda"))
}
if (data_check(eq_portfolio)) {
write_rds(eq_portfolio, paste0(proc_input_path, "/", project_name, "_equity_portfolio.rda"))
}
if (data_check(cb_portfolio)) {
write_rds(cb_portfolio, paste0(proc_input_path, "/", project_name, "_bonds_portfolio.rda"))
}
if (data_check(portfolio_overview)) {
write_rds(portfolio_overview, paste0(proc_input_path, "/", project_name, "_overview_portfolio.rda"))
}
if (data_check(audit_file)) {
write_rds(audit_file, paste0(proc_input_path, "/", project_name, "_audit_file.rda"))
}
if (data_check(emissions_totals)) {
write_rds(emissions_totals, paste0(proc_input_path, "/", project_name, "_emissions.rda"))
}
if (data_check(fund_coverage_summary)){
write_rds(fund_coverage_summary, file.path(proc_input_path, "fund_coverage_summary.rda"))
}
if (data_check(unknown_funds_in_funds)){
write_rds(unknown_funds_in_funds, file.path(proc_input_path, "unknown_funds_in_funds.rda"))
}
}