-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorra.py
1235 lines (1064 loc) · 55.1 KB
/
corra.py
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Wed July 17 07:54:00 2023
@author: walter wawra
purpose: class that holds attributes of TEA worksheet. Using a dictionary to search for values, display values, and update values
"""
import os
import time
import logging
import pandas as pd
import numpy as np
import numpy_financial as npf
import matplotlib.pyplot as plt
class CORRAClass:
"""
help
Functions
---------
annual_summary_damage_inspection_repair
Parameter
---------
type_of_analysis : string
given by user for specific type_of_analysis Land-Based, Floating Bottom Fixed, etc.
monte_carlo : numpy 3D array
given by the user to change the inspection and repair
show_graphs : boolean
whether the graphs should be shown or not
"""
def annual_summary_damage_inspection_repair(self, type_of_analysis, monte_carlo, show_graphs):
inspection_summary_array = monte_carlo[:, 3, :]
#print("inspection summary array before mean", inspection_summary_array)
inspection_summary_array = np.mean(inspection_summary_array,axis=0)
#print("inspection summary array after mean", inspection_summary_array)
repair_summary_array = monte_carlo[:, 4, :]
repair_summary_array = np.mean(repair_summary_array,axis=0)
#print("repair summary array", repair_summary_array)
net_present = self.update_annual_cash_flow(type_of_analysis, inspection_summary_array, repair_summary_array, show_graphs)
return net_present
"""
Functions
---------
update_dictionary
Parameter
---------
economic_parameters : dictionary
dictionary provided by .cra file
standard_cost_inventory_df : dataframe
dataframe provided by the .cra file
"""
def update_dictionary(self, type_of_analysis, economic_dictionary, standard_cost_inventory_df):
# load excel values
std_cost_inv_df = standard_cost_inventory_df
self.std_cost_inv_df = std_cost_inv_df
self.economic_parameters = economic_dictionary
# get default values
# TODO if one parameter is not present do not worry write it
turbine_size = self.economic_parameters[type_of_analysis]['Turbine size']
turbine_size = float(turbine_size)
num_blades = self.economic_parameters[type_of_analysis]['Number of blades']
num_blades = float(num_blades)
# Rate of return on equity (real) Land-Based
inflation = self.economic_parameters[type_of_analysis]['Inflation']
inflation = float(inflation) / 100
rate_of_rtn_equity_nominal = self.economic_parameters[type_of_analysis]['Rate of return on equity (nominal)']
rate_of_rtn_equity_nominal = float(rate_of_rtn_equity_nominal) / 100
rate_of_return_equity_real = (1+rate_of_rtn_equity_nominal) / (1+inflation) - 1
self.economic_parameters[type_of_analysis]['Rate of return on equity (real)'] = np.round(rate_of_return_equity_real * 100, 15)
# debt interest rate real Land-Based
debt_interest_rate_nominal = self.economic_parameters[type_of_analysis]['Debt interest rate (nominal)']
debt_interest_rate_nominal = float(debt_interest_rate_nominal) / 100
debt_interest_rate_real = (1+debt_interest_rate_nominal) / (1+inflation) - 1
self.economic_parameters[type_of_analysis]['Debt interest rate (real)'] = np.round(debt_interest_rate_real * 100, 15)
# effective tax rate (federal + state) Land-Based
federal_tax = self.economic_parameters[type_of_analysis]['Federal tax rate']
federal_tax = float(federal_tax)/ 100
state_tax = self.economic_parameters[type_of_analysis]['State tax rate']
state_tax = float(state_tax)/ 100
eff_tax_rate_fed_state = federal_tax + (state_tax * (1-federal_tax))
self.economic_parameters[type_of_analysis]['Effective tax rate (federal + state)'] = np.round(eff_tax_rate_fed_state * 100, 15)
# weighted avg cost of capital (nominal)
debt_financing_portion = self.economic_parameters[type_of_analysis]['Debt financing portion']
debt_financing_portion = float(debt_financing_portion)/ 100
# =C11*C12*(1-C21)+(1-C11)*C9
weighted_average_cost_of_capital_nominal = debt_financing_portion * debt_interest_rate_nominal *(1-eff_tax_rate_fed_state) + (1-debt_financing_portion) * rate_of_rtn_equity_nominal
self.economic_parameters[type_of_analysis]['Weighted average cost of capital (nominal)'] = np.round(weighted_average_cost_of_capital_nominal * 100, 15)
# weighted avg cost of capital (real)
weighted_avg_cost_of_capital_nom = weighted_average_cost_of_capital_nominal
weighted_average_cost_of_capital_real = (1+weighted_avg_cost_of_capital_nom) / (1+0.025) - 1
self.economic_parameters[type_of_analysis]['Weighted average cost of capital (real)'] = np.round(weighted_average_cost_of_capital_real * 100, 15)
# updating Capital cost ($/blade)
if type_of_analysis == 'Land-Based':
total_capital_cost_list = std_cost_inv_df.loc[std_cost_inv_df['Project'] == type_of_analysis, '$ per kW'].tolist()
else:
no_hypens_type_of_analysis = type_of_analysis.replace("-", " ")
total_capital_cost_list = std_cost_inv_df.loc[std_cost_inv_df['Project'] == no_hypens_type_of_analysis, '$ per kW'].tolist()
if type_of_analysis == 'Land-Based':
total_capital_cost = total_capital_cost_list[:-1]
else:
total_capital_cost = total_capital_cost_list[:-2]
conversion_mw_to_kw = self.economic_parameters['conversion']['megawatt_to_kilowatts']
conversion_mw_to_kw = int(conversion_mw_to_kw)
capital_cost_per_blade = (sum(total_capital_cost) * turbine_size) * (conversion_mw_to_kw / num_blades)
self.economic_parameters[type_of_analysis]['Capital cost ($/blade)'] = np.round(capital_cost_per_blade, 15)
if type_of_analysis == 'Land-Based':
capital_cost = total_capital_cost_list[-1]
else:
capital_cost = total_capital_cost_list[-2:]
capital_cost = sum(capital_cost)
fixed_o_plus_m_cost_kwh = (capital_cost * turbine_size) * (conversion_mw_to_kw / num_blades)
fixed_o_plus_m_cost_kwh = np.round(fixed_o_plus_m_cost_kwh, 15)
self.economic_parameters[type_of_analysis]['Fixed O+M ($/kW-yr)'] = fixed_o_plus_m_cost_kwh
# annual loan payment
# =-PMT(C13,C23,(C32*(1+C31)*C11))
loan_term_yrs = self.economic_parameters[type_of_analysis]['Loan term (years)']
loan_term_yrs = float(loan_term_yrs)
working_capital_percentage = self.economic_parameters[type_of_analysis]['Working capital']
working_capital_percentage = float(working_capital_percentage)/ 100
pv = capital_cost_per_blade * (1+working_capital_percentage) * debt_financing_portion
annual_loan_payment = npf.pmt(debt_interest_rate_real, loan_term_yrs, pv)
self.economic_parameters[type_of_analysis]['Annual loan payment ($/yr)'] = np.round(annual_loan_payment*-1, 15)
# production kWh/yr
conversion_yr_to_days = self.economic_parameters['conversion']['yr_to_days']
conversion_yr_to_days = int(conversion_yr_to_days)
conversion_day_to_hrs = self.economic_parameters['conversion']['day_to_hrs']
conversion_day_to_hrs = int(conversion_day_to_hrs)
capacity_factor = self.economic_parameters[type_of_analysis]['Capacity factor']
capacity_factor = float(capacity_factor)/ 100
production_kwh_yr = conversion_yr_to_days * conversion_day_to_hrs * capacity_factor * turbine_size * conversion_mw_to_kw / num_blades
self.economic_parameters[type_of_analysis]['Production (kWh/yr)'] = np.round(production_kwh_yr, 15)
# All inclusive opex ($/yr)
# =C39*(C33+C34)+C35
variable_o_plus_m_cost_kwh = self.economic_parameters[type_of_analysis]['Variable O+M ($/kWh)']
variable_o_plus_m_cost_kwh = float(variable_o_plus_m_cost_kwh)
fuel_costs_kwh = self.economic_parameters[type_of_analysis]['Fuel costs ($/kWh)']
fuel_costs_kwh = float(variable_o_plus_m_cost_kwh)
all_inclusive_op_x_cost_yr = production_kwh_yr * (variable_o_plus_m_cost_kwh+fuel_costs_kwh) + fixed_o_plus_m_cost_kwh
all_inclusive_op_x_cost_yr = float(all_inclusive_op_x_cost_yr)
self.economic_parameters[type_of_analysis]['All inclusive opex ($/yr)'] = np.round(all_inclusive_op_x_cost_yr, 15)
"""
Functions
---------
update_annual_cash_flow
Parameter
---------
type_of_analysis : string
gives the type of analysis Land-Based, etc.
inspection_summary_array : numpy array
array of the inspection category
repair_summary_array : numpy array
array of the repair category
show_graphs : boolean
whether graphs should be displayed or not
"""
def update_annual_cash_flow(self, type_of_analysis, inspection_summary_array, repair_summary_array, show_graphs):
# print(self.economic_parameters)
# variables used for equations from dicts
captial_cost_per_blade = self.economic_parameters[type_of_analysis]['Capital cost ($/blade)']
discount_rate_used = self.economic_parameters[type_of_analysis]['Discount rate used']
debt_financing_portion = self.economic_parameters[type_of_analysis]['Debt financing portion']
debt_financing_portion = float(debt_financing_portion) / 100
debt_interest_rate_real = self.economic_parameters[type_of_analysis]['Debt interest rate (real)']
debt_interest_rate_real = float(debt_interest_rate_real)/100
effective_tax_state_fed = self.economic_parameters[type_of_analysis]['Effective tax rate (federal + state)']
effective_tax_state_fed = float(effective_tax_state_fed)/100
weighted_average_cost_of_capital_real = self.economic_parameters[type_of_analysis]['Weighted average cost of capital (real)']
weighted_average_cost_of_capital_real = float(weighted_average_cost_of_capital_real)/100
rate_of_return_on_equity_real = self.economic_parameters[type_of_analysis]['Rate of return on equity (real)']
rate_of_return_on_equity_real = float(rate_of_return_on_equity_real)/100
years_of_operation = self.economic_parameters[type_of_analysis]['Years of operation']
years_of_operation = int(years_of_operation)
self.years_of_operation = years_of_operation
years_of_construction = self.economic_parameters[type_of_analysis]['Years of construction']
years_of_construction = int(years_of_construction)
all_inclusive_opex = self.economic_parameters[type_of_analysis]['All inclusive opex ($/yr)']
all_inclusive_opex = float(all_inclusive_opex)
end_of_life_costs = self.economic_parameters[type_of_analysis]['End of life costs ($/kW)']
end_of_life_costs = float(end_of_life_costs)
losses_forward = self.economic_parameters[type_of_analysis]['Annual losses carried forward']
production_kwh_yr = self.economic_parameters[type_of_analysis]['Production (kWh/yr)']
production_kwh_yr = float(production_kwh_yr)
lcoe = self.economic_parameters['LCOE Breakdown $ per kWh']['Levelized cost of electricity']
lcoe = float(lcoe)
loan_term = self.economic_parameters[type_of_analysis]['Loan term (years)']
loan_term = float(loan_term)
annual_loan_payment = self.economic_parameters[type_of_analysis]['Annual loan payment ($/yr)']
annual_loan_payment = float(annual_loan_payment)
# lists that store analysis
self.equity_spent_years_list = []
for i in range(-5, 1):
year_key = f"Equity spent in year {i}"
equity_spent = self.economic_parameters[type_of_analysis][year_key]
equity_spent = float(equity_spent)/100
self.equity_spent_years_list.append(equity_spent)
self.electricity_sales_list = []
self.operation_and_planned_maintenance_list = []
self.end_of_life_list = []
self.annual_depreciation_list = []
self.depreciation_charge_list = []
self.remaining_value_list = []
self.net_revenue_list = []
self.taxable_income_list = []
self.losses_forward_list = []
self.income_tax_list = []
self.annual_cash_income_list = []
self.fixed_capital_investment_list = []
self.loan_payment_list = []
self.discount_rate_list = []
self.loan_principal_list = []
self.loan_interest_payment_list = []
self.electricity_sales_present_list = []
self.fixed_capital_investment_present_list = []
self.inspection_list = []
self.repair_list = []
self.loan_payment_present_list = []
self.planned_operation_cost_present_list = []
self.inspection_cost_present_list = []
self.repair_cost_present_list = []
self.total_operation_costs_present_list = []
self.end_of_life_present_list = []
self.taxes_present_list = []
self.net_present_list = []
for year in range(years_of_construction, years_of_operation+1):
"""
Updating Financing Category
"""
# print(f"------------------------------Year is {year}---------------------------------------------\n")
# fixed capital investment = -capital cost per blade * (1-debt_financing_portion)*equity_spent_year_minus2
if year < 1:
fixed_capital_investment_value = -captial_cost_per_blade * (1-debt_financing_portion) * self.equity_spent_years_list[year-1]
self.fixed_capital_investment_list.append(fixed_capital_investment_value)
else:
fixed_capital_investment_value = 0.0
self.fixed_capital_investment_list.append(fixed_capital_investment_value)
# print("fci ", fixed_capital_investment_value)
# loan payment = -annual_loan_payment if it is greater than zero otherwise, zero.
if 0 < year <= loan_term:
loan_payment_value = -annual_loan_payment
self.loan_payment_list.append(loan_payment_value)
else:
loan_payment_value = 0.0
self.loan_payment_list.append(loan_payment_value)
# print("loan paymnet ", loan_payment_value)
# loan principal + loan interest payment
if year == years_of_construction:
# loan principal = -capex * debt_financing_portion * equity_spent_year_minus2
loan_principal_value = -captial_cost_per_blade*debt_financing_portion*self.equity_spent_years_list[year-1]
past_years_loan_principal = loan_principal_value
# loan interst payment = debt_interest_rate_real * loan_principal
loan_interest_payment_value = debt_interest_rate_real * loan_principal_value
# update lists
self.loan_principal_list.append(loan_principal_value)
self.loan_interest_payment_list.append(loan_interest_payment_value)
elif years_of_construction < year < 1:
# loan principal
loan_principal_value = -captial_cost_per_blade*debt_financing_portion*self.equity_spent_years_list[year-1]+past_years_loan_principal
past_years_loan_principal = loan_principal_value
# loan interest
loan_interest_payment_value = debt_interest_rate_real * loan_principal_value
# updating lists
self.loan_principal_list.append(loan_principal_value)
self.loan_interest_payment_list.append(loan_interest_payment_value)
elif year == 1:
# loan interest
loan_interest_payment_value = -captial_cost_per_blade * debt_financing_portion * debt_interest_rate_real
self.loan_interest_payment_list.append(loan_interest_payment_value)
# loan prnciplae = past_years_loan_principal - loan_payment + loan_interst_payment
loan_principal_value = past_years_loan_principal - loan_payment_value + loan_interest_payment_value
past_years_loan_principal = loan_principal_value
self.loan_principal_list.append(loan_principal_value)
else:
# loan interest payment
loan_interest_payment_value = past_years_loan_principal * debt_interest_rate_real
# loan principal = past_years_loan_principal - loan_payment + loan_interst_payment
loan_principal_value = past_years_loan_principal-loan_payment_value+loan_interest_payment_value
past_years_loan_principal = loan_principal_value
# updating lists
self.loan_principal_list.append(loan_principal_value)
self.loan_interest_payment_list.append(loan_interest_payment_value)
# print("loan interest payment ", loan_interest_payment_value)
# print("loan principal ",loan_principal_value)
# print("\n------------------------End of Fianancing Category------------------------------------------\n")
"""
Updating Sales Category
"""
if year > 0:
if years_of_operation >= year:
electricity_sales_value = production_kwh_yr * lcoe
self.electricity_sales_list.append(electricity_sales_value)
else:
electricity_sales_value = 0.0
self.electricity_sales_list.append(electricity_sales_value)
else:
electricity_sales_value = 0.0
self.electricity_sales_list.append(electricity_sales_value)
# print("electric ", electricity_sales_value)
# print("\n--------------------------------End of Sales------------------------------------------------\n")
"""
Updating Cost Category
"""
# operation and planned maintenance
if year > 0:
if years_of_operation >= year:
operation_and_planned_maintenance_value = -all_inclusive_opex
self.operation_and_planned_maintenance_list.append(operation_and_planned_maintenance_value)
else:
operation_and_planned_maintenance_value = 0.0
self.operation_and_planned_maintenance_list.append(0.0)
else:
operation_and_planned_maintenance_value = 0.0
self.operation_and_planned_maintenance_list.append(0.0)
# print("operation and planned maintence", operation_and_planned_maintenance_value)
# inspection + repair
if year > 0:
inspection_value = inspection_summary_array[year-1]
repair_value = repair_summary_array[year-1]
self.inspection_list.append(inspection_value)
self.repair_list.append(repair_value)
else:
inspection_value = 0.0
repair_value = 0.0
self.inspection_list.append(inspection_value)
self.repair_list.append(repair_value)
# print("inspection ", inspection_value)
# print("repair ", repair_value)
# end of life
if year > 0:
if years_of_operation == year:
self.end_of_life_list.append(end_of_life_costs)
else:
end_of_life_costs = 0.0
self.end_of_life_list.append(end_of_life_costs)
else:
end_of_life_costs = 0.0
self.end_of_life_list.append(end_of_life_costs)
# print("end of life costs ", end_of_life_costs)
# print("\n--------------------------------------End of Cost Category--------------------------------------\n")
"""
Updating Depreciation Category
"""
# annual depreciation + depreciation charge
annual_depreciation_percentages = [20.0,32.0,19.2,11.52,11.52,5.76]
if 0 < year < len(annual_depreciation_percentages)+1:
# depreciation charge
annual_depreciation_value = annual_depreciation_percentages[year-1]
depreciation_charge_value = -(captial_cost_per_blade * (annual_depreciation_value/100))
# remaining value
if year == 1:
remaining_value = captial_cost_per_blade + depreciation_charge_value
else:
past_remaining_value = remaining_value
remaining_value = past_remaining_value + depreciation_charge_value
# remaining value was super close to zero but not zero
if remaining_value < 1e-5:
remaining_value = 0.0
# updating lists
self.depreciation_charge_list.append(depreciation_charge_value)
self.annual_depreciation_list.append(annual_depreciation_value)
self.remaining_value_list.append(remaining_value)
else:
annual_depreciation_value = 0.0
self.annual_depreciation_list.append(annual_depreciation_value)
depreciation_charge_value = 0.0
self.depreciation_charge_list.append(depreciation_charge_value)
remaining_value = 0.0
self.remaining_value_list.append(remaining_value)
# print("annual depreciation ", annual_depreciation_value)
# print("depreciation charge", depreciation_charge_value)
# print("remaining value ", remaining_value)
# print("\n---------------------------------End of Depreciation Category-------------------------------------------\n")
"""
Taxes Category
"""
# net revenue = electricity sales + o and p maintanence + depreciation charge + loan payment
if year > 0:
net_revenue_value = electricity_sales_value + operation_and_planned_maintenance_value + depreciation_charge_value + loan_payment_value
self.net_revenue_list.append(net_revenue_value)
else:
net_revenue_value = 0.0
self.net_revenue_list.append(net_revenue_value)
# taxable income losses forward and income tax
past_year_net_revenue = net_revenue_value
# losses forward
if losses_forward == 'No':
losses_forward_value = 0.0
self.losses_forward_list.append(losses_forward_value)
else:
if past_year_net_revenue < 0:
losses_forward_value = past_year_net_revenue
self.losses_forward_list.append(past_year_net_revenue)
else:
losses_forward_value = 0.0
self.losses_forward_list.append(losses_forward_value)
# taxable income
if year == 1:
# print(year)
past_year_taxable_income = net_revenue_value
self.taxable_income_list.append(past_year_taxable_income)
else:
past_year_taxable_income = past_year_net_revenue + losses_forward_value
self.taxable_income_list.append(past_year_taxable_income)
# income tax
if past_year_net_revenue + losses_forward_value > 0:
income_tax_value = -effective_tax_state_fed*past_year_taxable_income
self.income_tax_list.append(income_tax_value)
else:
income_tax_value = 0.0
self.income_tax_list.append(income_tax_value)
# print("net revenue ", net_revenue_value)
# print("losses forward ", losses_forward_value)
# print("taxable income ", past_year_taxable_income)
# print("income tax", income_tax_value)
# print("\n----------------------------------End of Taxes Category-------------------------------------\n")
"""
Discounting Category
"""
#annual cash income = electricity sales + loan payment +
# oapm + income tax + inspection + repair + end of life
annual_cash_income_value = electricity_sales_value + loan_payment_value + operation_and_planned_maintenance_value +income_tax_value + inspection_value + repair_value + end_of_life_costs
self.annual_cash_income_list.append(annual_cash_income_value)
# discount factor
# =1/(1+IF(discount_rate="WACC",WACC_real,$E$10))^G65
if discount_rate_used == 'WACC':
discount_factor_value = 1 / (1+weighted_average_cost_of_capital_real) ** year
else:
discount_factor_value = 1 / (1+(7.31707317073174 / 100)) ** year
self.discount_rate_list.append(discount_factor_value)
# print("annual cash income ", annual_cash_income_value)
# print("discount factor ", discount_factor_value)
# print("\n-----------------------------End of Discounting Category--------------------------------\n")
"""
Discounted Present Value
"""
# electricity sales present value = electricity sales * discount rate
electricity_sales_present_value = electricity_sales_value * discount_factor_value
self.electricity_sales_present_list.append(electricity_sales_present_value)
# fixed capital investment + interest = (fixed capital investment + loan interest principal) * discount rate
if year < 1:
fixed_capital_present_value = (fixed_capital_investment_value + loan_interest_payment_value) * discount_factor_value
self.fixed_capital_investment_present_list.append(fixed_capital_present_value)
else:
fixed_capital_present_value = 0.0
self.fixed_capital_investment_present_list.append(fixed_capital_present_value)
# loan payment
loan_payment_present_value = loan_payment_value * discount_factor_value
self.loan_payment_present_list.append(loan_payment_present_value)
# planned operational cost
planned_operation_cost_present_value = operation_and_planned_maintenance_value * discount_factor_value
self.planned_operation_cost_present_list.append(planned_operation_cost_present_value)
# inspection cost = inspection * discount rate
inspection_cost_present_value = inspection_value * discount_factor_value
self.inspection_cost_present_list.append(inspection_cost_present_value)
# repair cost = repair cost * discount rate
repair_cost_present_value = repair_value * discount_factor_value
self.repair_cost_present_list.append(repair_cost_present_value)
# total operation costs = planned operation costs + inspection cost + repair cost
total_operation_costs_present_value = planned_operation_cost_present_value + inspection_cost_present_value +repair_cost_present_value
self.total_operation_costs_present_list.append(total_operation_costs_present_value)
# end of life cost = end of life costs * discount rate
end_of_life_present_value = end_of_life_costs * discount_factor_value
self.end_of_life_present_list.append(end_of_life_present_value)
# taxes = income tax * discount rate
taxes_present_value = income_tax_value * discount_factor_value
self.taxes_present_list.append(taxes_present_value)
# net present value = electricity + (fixed cap + loan payment + planned op cost + inspection + repair) + end of life costs + taxes
if year == -2:
net_present_value = electricity_sales_present_value + (fixed_capital_present_value + loan_payment_present_value + planned_operation_cost_present_value + inspection_cost_present_value + repair_cost_present_value) + end_of_life_present_value + taxes_present_value
past_net_present_value = net_present_value
self.net_present_list.append(net_present_value)
else:
net_present_value = electricity_sales_present_value + ((fixed_capital_present_value + loan_payment_present_value + planned_operation_cost_present_value + inspection_cost_present_value + repair_cost_present_value) + end_of_life_present_value + taxes_present_value) + past_net_present_value
self.net_present_list.append(net_present_value)
past_net_present_value = net_present_value
# print("electricity sales ", electricity_sales_present_value)
# print("fixed capital ",fixed_capital_present_value)
# print("loan payment ", loan_payment_present_value)
# print("planned operational costs ", planned_operation_cost_present_value)
# print("inspection cost ", inspection_cost_present_value)
# print("repair cost ", repair_cost_present_value)
# print("total operational cost ", total_operation_costs_present_value)
# print("end of life costs ", end_of_life_present_value)
# print("taxes ", taxes_present_value)
# print("net present value ", net_present_value)
# print("total insspection + repair costs sum", total_inspection_and_repair_costs_present_sum)
# print("\n---------------------------------End of Discounted Present Value Category-----------------------------------\n")
"""
Discounted Present Value Sum
"""
# electricity sales
self.electricity_sales_present_list_sum = sum(self.electricity_sales_present_list)
# fixed cap
self.fixed_capital_present_list_sum = sum(self.fixed_capital_investment_present_list)
# loan payment
self.loan_payment_present_list_sum = sum(self.loan_payment_present_list)
# planned operational cost
self.planned_operation_cost_present_list_sum = sum(self.planned_operation_cost_present_list)
# inspection cost
self.inspection_cost_present_list_sum = sum(self.inspection_cost_present_list)
# repair cost
self.repair_cost_present_list_sum = sum(self.repair_cost_present_list)
# total operational cost
self.total_operation_costs_present_list_sum = sum(self.total_operation_costs_present_list)
# end of life costs
self.end_of_life_present_list_sum = sum(self.end_of_life_present_list)
# taxes
self.taxes_present_list_sum = sum(self.taxes_present_list)
# net present value = electricity sales sum + fixed cap sum + loan payment sum + planned operational sum + inspection sum +
# repair sum + end of life sum + taxes sum
self.net_present_list_sum = (
self.electricity_sales_present_list_sum + (self.fixed_capital_present_list_sum +
self.loan_payment_present_list_sum + self.planned_operation_cost_present_list_sum +
self.inspection_cost_present_list_sum + self.repair_cost_present_list_sum +
self.end_of_life_present_list_sum + self.taxes_present_list_sum)
)
# total inspection and repair costs = abs value of inspection and repiar sums
total_inspection_and_repair_costs_present_sum = abs(self.inspection_cost_present_list_sum + self.repair_cost_present_list_sum)
# updating LCOE Breakdown $ per kWh
fixed_capital_to_taxes_sum = self.fixed_capital_present_list_sum + self.loan_payment_present_list_sum + self.planned_operation_cost_present_list_sum + self.inspection_cost_present_list_sum + self.repair_cost_present_list_sum + self.end_of_life_present_list_sum + self.taxes_present_list_sum
lcoe_capital_investment = lcoe * self.fixed_capital_present_list_sum / fixed_capital_to_taxes_sum
lcoe_loan = lcoe * self.loan_payment_present_list_sum / fixed_capital_to_taxes_sum
lcoe_operational_costs = lcoe * (self.planned_operation_cost_present_list_sum + self.inspection_cost_present_list_sum + self.repair_cost_present_list_sum) / fixed_capital_to_taxes_sum
lcoe_taxes = lcoe * self.taxes_present_list_sum / fixed_capital_to_taxes_sum
lcoe_end_of_life = abs(lcoe * self.end_of_life_present_list_sum / fixed_capital_to_taxes_sum)
# updating LCOE Breakdown $ per kWh dictionary within economic parameters
self.economic_parameters['LCOE Breakdown $ per kWh']['Capital investment'] = lcoe_capital_investment
self.economic_parameters['LCOE Breakdown $ per kWh']['Loan'] = lcoe_loan
self.economic_parameters['LCOE Breakdown $ per kWh']['Operational costs'] = lcoe_operational_costs
self.economic_parameters['LCOE Breakdown $ per kWh']['Taxes'] = lcoe_taxes
self.economic_parameters['LCOE Breakdown $ per kWh']['End of life costs'] = lcoe_end_of_life
dict_of_lists_to_create_tea_graph = {
'Electricity Sales' : np.array(self.electricity_sales_present_list),
'Capital Investment' : np.array(self.fixed_capital_investment_present_list),
'Taxes' : np.array(self.taxes_present_list),
'Operational Costs' : np.array(self.total_operation_costs_present_list),
'Loan Payment' : np.array(self.loan_payment_present_list),
'End of Life Costs' : np.array(self.end_of_life_present_list),
'Net Present' : np.array(self.net_present_list)
}
if show_graphs:
self.create_techno_economic_analysis_graph(years_of_construction, years_of_operation, dict_of_lists_to_create_tea_graph, self.net_present_list)
self.create_levelized_cost_of_electricity_graph()
return self.net_present_list_sum
"""
Function
--------
calculate_npv_with_discount_rate
Parameters
----------
lcoe : string, dictionary
lceo read in by the users economic_parameters.cra file
type_of_analysis : string
type of analysis given by the user
matrix : numpy array
Matrix given by user via matrix.cra file
show_graphs : boolean
whether the user wishes to see the graphs or not
Return
------
returns the npv with the current lcoe
"""
def calculate_npv_with_discount_rate(self, lcoe, type_of_analysis, matrix):
# Update the economic_parameters dictionary with the provided discount_rate
self.economic_parameters['LCOE Breakdown $ per kWh']['Levelized cost of electricity'] = lcoe
npv = self.annual_summary_damage_inspection_repair(type_of_analysis, matrix, show_graphs=False)
return npv
"""
Function
--------
bisection_method
Parameters
----------
goal : float
the goal is for npv to reach zero
a : float
starts at 0.0 and will narrow down as npv gets closer to zero
b : float
starts at 1.0 and will narrow down as npv gets closer to zero
type_of_analysis : string
give by user what the type of analysis should be
matrix : numpy array
matrix given by users matrix.cra files
show_graphs : boolean
allows user to give an option to show the graphs or not
tolerance : float
gives the tolerance at which point the algo will say the npv is at zero
max_iterations : integer
gives the max number of interations
"""
def bisection_method(self, goal, a, b, type_of_analysis, matrix, tolerance=1e-8, max_iterations=1000):
for _ in range(max_iterations):
c = (a + b) / 2
npv_c = self.calculate_npv_with_discount_rate(c, type_of_analysis, matrix)
if abs(npv_c) - goal < tolerance:
return c
if npv_c * self.calculate_npv_with_discount_rate(a, type_of_analysis, matrix) < 0:
b = c
else:
a = c
return "Unable to Solve LCOE"
"""
Functions
---------
solve_for_lcoe
Parameters
----------
type_of_analysis : string
given by user for specific type_of_analysis Land-Based, Floating Bottom Fixed, etc.
values_to_increase : set
creates of a set of the values to increase
"""
def solve_lcoe(self, type_of_analysis, matrix):
goal = 0
a = 0.0
b = 1.0
self.result_lcoe = self.bisection_method(goal, a, b, type_of_analysis, matrix)
return self.result_lcoe
"""
Function
--------
economic_parameters_plus_or_minus
Parameters
---------
type_of_analysis : string
given by user for specific type_of_analysis Land-Based, Floating Bottom Fixed, etc.
increased_decreased_dict : dictionary
stores in a list the adjusted defualt value
Returns
-------
graph of plus or minus ten percent
"""
def economic_parameters_plus_or_minus(self, type_of_analysis):
increased_decreased_dict = {}
c = 0
for key, value in self.economic_parameters[type_of_analysis].items():
progress = int((c + 1) / len(self.economic_parameters[type_of_analysis]) * 50)
loading_bar = f"[{'=' * progress:<50}] {progress * 2}%"
print(loading_bar, end='\r')
time.sleep(0.1)
c+=1
if key == 'Years of operation' or key == 'Years of construction':
pass
else:
try:
value = float(value)
except:
pass
if isinstance(value, float):
"""
Increasing key's value
"""
value_increased = value
value_increased = value_increased * 1.10
self.economic_parameters[type_of_analysis][key] = value_increased
self.create_file(self.economic_parameters)
economic, standard = self.read_file(type_of_analysis)
self.update_dictionary(type_of_analysis, economic, standard)
matrix = self.read_matrix()
desired_lcoe_increased = self.solve_lcoe(type_of_analysis, matrix[0::])
"""
Decreasing keys value
"""
value_decreased = value * .90
self.economic_parameters[type_of_analysis][key] = value_decreased
self.create_file(self.economic_parameters)
economic, standard = self.read_file(type_of_analysis)
self.update_dictionary(type_of_analysis, economic, standard)
matrix = self.read_matrix()
desired_lcoe_decreased = self.solve_lcoe(type_of_analysis, matrix[0::])
"""
Setting key's value back to default value
"""
self.economic_parameters[type_of_analysis][key] = value
self.create_file(self.economic_parameters)
economic, standard = self.read_file(type_of_analysis)
self.update_dictionary(type_of_analysis, economic, standard)
increased_decreased_dict[key] = [desired_lcoe_increased, desired_lcoe_decreased, desired_lcoe_increased-desired_lcoe_decreased]
self.create_displacement_graph(increased_decreased_dict)
"""
Function
--------
create_displacement_graph
Parameters
----------
increased_decreased_dict : dictionary
stores in a list the adjusted defualt value
center_line : float
the default LCOE
Returns
-------
Shows user a diverging graph where center is the default solved for LCOE. Diverging bars are +/-10% of a default value, solved for LCOE with changed value, and their displacement from the orginally solved LCOE
"""
def create_displacement_graph(self, increased_decreased_dict):
fig, ax = plt.subplots(figsize=(10,6))
center_line = self.result_lcoe
for key, value in increased_decreased_dict.items():
difference = value[0] - center_line
ax.barh(key, difference, left=center_line, color='green')
difference = value[1] - center_line
ax.barh(key, difference, left=center_line, color='purple')
legend_entries = [
plt.Line2D([0], [0], color='green', lw=8, label='+10%'),
plt.Line2D([0], [0], color='purple', lw=8, label='-10%')
]
ax.axvline(x=center_line, color='black', linewidth=1)
ax.set_xlabel("LCOE $ per kW")
ax.set_title("Diverging LCOE Graph")
ax.legend(handles=legend_entries)
ax.invert_yaxis()
plt.tight_layout()
plt.show()
"""
Functions
---------
create_techno_economic_analysis_graph
Parameter
---------
years_of_construction : integer
given by economic_parameters dictionary
years_of_operation : integer
given by economic_parameters dictionary
dict_of_lists_to_create_tea_graph : dictionary, list
gives a list of the dictionarys
net_present_value_present_list : list
gives the net present value list
Returns
-------
Shows user a graph that is the annual summary from years of construction to years of operation
"""
def create_techno_economic_analysis_graph(self, years_of_construction, years_of_operation, dict_of_lists_to_create_tea_graph, net_present_value_present_list):
x_years = list(range(years_of_construction, years_of_operation+1))
width = 0.5
fig, ax = plt.subplots()
upper_sum = max(dict_of_lists_to_create_tea_graph.get('Electricity Sales'))
lower_sum = min(dict_of_lists_to_create_tea_graph.get('Net Present'))
bottom = np.zeros(len(x_years))
bar_colors = ['purple', 'red', 'green', 'gold', 'chocolate', 'cornflowerblue']
# Plotting negative values (Others)
for (label, y), color in zip(dict_of_lists_to_create_tea_graph.items(), bar_colors):
if label != 'Electricity Sales':
ax.bar(x_years, y, width, color=color, label=label, bottom=bottom)
bottom += y
else:
ax.bar(x_years, y, width, color=color, label=label)
ax.axvline(years_of_construction-1, color='black', linestyle='solid')
ax.axhline(color='black', linestyle='solid')
# plt.plot(y_line, linestlye='solid', color='black')
plt.plot(x_years, net_present_value_present_list, linestyle=(0, (1,1)), linewidth=2.5, color='black', label='Net Present Value')
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width*0.8, box.height])
ax.set_title("Techno-Economic Analysis")
ax.legend(loc="center left", bbox_to_anchor=(1,0.5))
plt.xticks(x_years)
plt.xlabel('Years of Operation')
fig.set_size_inches(15,6)
if lower_sum <= -1000000:
upper_limit = np.round(upper_sum/1000000) * 1000000 + 2000000
lower_limit = np.round(lower_sum/1000000) * 1000000 - 2000000
else:
upper_limit = np.round(upper_sum/100000) * 100000 + 100000
lower_limit = np.round(lower_sum/100000) * 100000 - 100000
plt.ylim(lower_limit, upper_limit)
ax.yaxis.set_major_formatter(plt.NullFormatter())
y_ticks = ax.get_yticks()
for tick in y_ticks:
label = self.money_format(tick, None)
color = 'red' if tick < 0 else 'black'
x_coord = ax.get_xlim()[0] - 0.12
ax.text(x_coord, tick, label, ha='right', va='center', color=color)
plt.show(block=False)
"""
Function
--------
money_format
Parameters
----------
x : double
is the y axis values
pos : double
is the x axis values
Returns
-------
Currency formatted values for the y axis of the graph
"""
def money_format(sefl, x, pos):
if x < 0:
formatted = "$({:,.2f})".format(abs(x))
else:
formatted = "${:,.2f}".format(x)
return formatted
"""
Functions
---------
create_levelized_cost_of_electricity_graph
Returns
-------
The Levelized Cost of Electricity ratio break down in a graph
"""
def create_levelized_cost_of_electricity_graph(self):
fig, ax = plt.subplots()
bottom = 0
height_sum = 0.0
bar_colors = [None, 'red', 'chocolate', 'gold', 'green', 'cornflowerblue']
for idx, (label, y) in enumerate(self.economic_parameters['LCOE Breakdown $ per kWh'].items()):
if label != 'Levelized cost of electricity':
ax.bar(np.array(0), np.array(y), width=0.2, color=bar_colors[idx], bottom=bottom, label=label, align='center')
bottom += y
height_sum += y
ax.set_title("Techno-Economic Analysis")
ax.legend(loc="center left", bbox_to_anchor=(1,0.5))
# Hide x-axis ticks and labels
ax.set_xlim(-0.25, 0.25)
ax.set_ylim(0, height_sum+.005)
ax.set_xticks([])
ax.set_xticklabels([])
# Show only y-axis ticks
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('none')
plt.ylabel('Levelized Cost of Electricity\n ($ per kWh)')
plt.tight_layout()
plt.show(block=False)
"""
Functions
---------
create_file
dictionary_lst : list, dictionarys
gives the dictionary list
filepath : string
the file path of the eceonomic parameters
Returns
------
Writes to a .cra file the dictionary held within self.economic_parameters
"""
def create_file(self, dictionary, filepath="economic_parameters.cra"):
with open(filepath, 'w') as f:
for key, nested in dictionary.items():
print(key, file=f)
for subkey, value in nested.items():
print(' {}: {}'.format(subkey, value), file=f)
print(file=f)
"""
Functions
---------
read_file
type_of_analysis : string
the user input of which analysis to run
Returns
-------
reads the economic_parameters and standard_cost_inventory cra files, returns their respective data structures to be used within CORRA
"""
def read_file(self, type_of_analysis):
economic_parameters_dict = {}
current_section = None
for file in ['economic_parameters.cra', 'standard_cost_inventory.cra']:
if file == 'economic_parameters.cra':
with open(file, 'r') as f:
for line in f:
if line:
if current_section is None:
current_section = type_of_analysis
economic_parameters_dict[current_section] = {}
elif not line.startswith(' '):
current_section = line.rstrip()
economic_parameters_dict[current_section] = {}
else:
key, value = map(str.strip, line.split(':', 1))
economic_parameters_dict[current_section][key] = value