Skip to content

Commit

Permalink
fix interest #180
Browse files Browse the repository at this point in the history
  • Loading branch information
cortespea committed Jan 9, 2024
1 parent 4e7f16b commit 4489d88
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions biosteam/_tea.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def taxable_and_nontaxable_cashflows(
finance_fraction,
start, years,
lang_factor,
interest_during_construction,
pay_interest_during_construction,
):
# Cash flow data and parameters
# C_FC: Fixed capital
Expand All @@ -187,10 +187,11 @@ def taxable_and_nontaxable_cashflows(
interest = finance_interest
years = finance_years
Loan[:start] = loan = finance_fraction*(C_FC[:start])
if interest_during_construction:
if pay_interest_during_construction:
loan_principal = loan_principal_with_interest(loan, interest)
else:
loan_principal = loan.sum()
LP[:start] = loan * interest
LP[start:start + years] = solve_payment(loan_principal, interest, years)
taxable_cashflow = S - C - D - LP
nontaxable_cashflow = D + Loan - C_FC - C_WC
Expand Down Expand Up @@ -308,7 +309,7 @@ class TEA:
'_startup_schedule', '_operating_days',
'_duration', '_depreciation_key', '_depreciation',
'_years', '_duration', '_start', 'IRR', '_IRR', '_sales',
'_duration_array_cache', 'interest_during_construction')
'_duration_array_cache', 'pay_interest_during_construction')

#: Available depreciation schedules. Defaults include modified
#: accelerated cost recovery system from U.S. IRS publication 946 (MACRS),
Expand Down Expand Up @@ -386,7 +387,7 @@ def __init__(self, system: System, IRR: float, duration: tuple[int, int],
startup_months: float, startup_FOCfrac: float, startup_VOCfrac: float,
startup_salesfrac: float, WC_over_FCI: float, finance_interest: float,
finance_years: int, finance_fraction: float,
interest_during_construction: bool=False):
pay_interest_during_construction: bool=False):
#: System being evaluated.
self.system: System = system

Expand Down Expand Up @@ -431,8 +432,8 @@ def __init__(self, system: System, IRR: float, duration: tuple[int, int],
#: Guess cost for solve_price method
self._sales: float = 0

#: Whether to accumulate interest during construction
self.interest_during_construction = interest_during_construction
#: Whether to pay interest before operation or to accumulate interest during construction
self.pay_interest_during_construction = pay_interest_during_construction

#: For convenience, set a TEA attribute for the system
system._TEA = self
Expand Down Expand Up @@ -745,14 +746,14 @@ def get_cashflow_table(self):
years = self.finance_years
end = start + years
L[:start] = loan = self.finance_fraction*(C_FC[:start])
interest_during_construction = self.interest_during_construction
if interest_during_construction:
pay_interest_during_construction = self.pay_interest_during_construction
if pay_interest_during_construction:
initial_loan_principal = loan_principal_with_interest(loan, interest)
else:
initial_loan_principal = loan.sum()
LP[start:end] = solve_payment(initial_loan_principal, interest, years)
loan_principal = 0
if interest_during_construction:
if pay_interest_during_construction:
for i in range(end):
LI[i] = li = (loan_principal + L[i]) * interest
LPl[i] = loan_principal = loan_principal - LP[i] + li + L[i]
Expand All @@ -764,6 +765,8 @@ def get_cashflow_table(self):
li = (loan_principal + L[i]) * interest
LI[i] = li
LPl[i] = loan_principal = loan_principal - LP[i] + li + L[i]
LI[:start] = L[:start] * interest # Interest still needs to be payed

taxable_cashflow = S - C - D - LP
nontaxable_cashflow = D + L - C_FC - C_WC
else:
Expand Down Expand Up @@ -831,7 +834,7 @@ def _taxable_nontaxable_depreciation_cashflows(self):
self.finance_fraction,
start, years,
self.lang_factor,
self.interest_during_construction,
self.pay_interest_during_construction,
),
D
)
Expand Down

0 comments on commit 4489d88

Please sign in to comment.