-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_simulation.jl
53 lines (45 loc) · 2.21 KB
/
run_simulation.jl
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
##### run simulation #####
# initialize result variables
npv_results = DataFrame();
lcoe_results = DataFrame();
# run simulation for all projects
for p in eachindex(pjs)
@info("running simulation for", p, name = pjs[p].name)
# generate random variables
rand_vars = gen_rand_vars(opt_scaling, n, wacc, electricity_price, pjs[p])
# run Monte Carlo simulation
results = investment_simulation(pjs[p], rand_vars)
# normalize NPV to plant capacity [USD/MW]
npv_results.res = vec(results[1] / pjs[p].plant_capacity)
rename!(npv_results,:res => pjs[p].name)
lcoe_results.res = vec(results[2])
rename!(lcoe_results,:res => pjs[p].name)
end
# summary statistics
npv_summary = describe(npv_results, :all)
lcoe_summary = describe(lcoe_results, :all)
# output
CSV.write("$outputpath/mcs-npv_results-$opt_scaling.csv", npv_results);
CSV.write("$outputpath/mcs-npv_summary-$opt_scaling.csv", npv_summary[!,1:8]);
CSV.write("$outputpath/mcs-lcoe_results-$opt_scaling.csv", lcoe_results);
CSV.write("$outputpath/mcs-lcoe_summary-$opt_scaling.csv", lcoe_summary[!,1:8]);
##### sensitivity analysis #####
# initialize results variables
si_npv_results = DataFrame();
si_npv_results.si = ["S", "S", "S", "S", "ST", "ST", "ST", "ST"];
si_npv_results.var = ["wacc", "electricity_price", "loadfactor", "investment", "wacc", "electricity_price", "loadfactor", "investment"];
si_lcoe_results = DataFrame();
si_lcoe_results.si = ["S", "S", "S", "S", "ST", "ST", "ST", "ST"];
si_lcoe_results.var = ["wacc", "electricity_price", "loadfactor", "investment", "wacc", "electricity_price", "loadfactor", "investment"];
# run sensitivity analysis for all projects
for p in eachindex(pjs)
@info("running sensitivity analysis for", p, name = pjs[p].name)
si_results = sensitivity_index(opt_scaling, n, wacc, electricity_price, pjs[p])
si_npv_results.res = vcat(collect(si_results[1]),collect(si_results[2]))
rename!(si_npv_results,:res => pjs[p].name)
si_lcoe_results.res = vcat(collect(si_results[3]),collect(si_results[4]))
rename!(si_lcoe_results,:res => pjs[p].name)
end
#output
CSV.write("$outputpath/si-npv_results-$opt_scaling.csv", si_npv_results);
CSV.write("$outputpath/si-lcoe_results-$opt_scaling.csv", si_lcoe_results);