Skip to content

Commit

Permalink
add forwarded loses
Browse files Browse the repository at this point in the history
  • Loading branch information
cortespea committed Jan 9, 2024
1 parent 89238e2 commit 78c2fa7
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions biosteam/_tea.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'Sales [MM$]',
'Tax [MM$]',
'Incentives [MM$]',
'Taxed earnings [MM$]',
'Net earnings [MM$]',
'Cash flow [MM$]',
'Discount factor',
Expand Down Expand Up @@ -86,6 +87,17 @@ def solve_payment(loan_principal, interest, years):
fn = f ** years
return loan_principal * interest * fn / (fn - 1)

@njit(cache=True)
def taxable_earnings_with_fowarded_losses(taxable_cashflow): # Forwards losses to later years to reduce future taxes
taxed_earnings = taxable_cashflow.copy()
for i in range(taxed_earnings.size - 1):
x = taxed_earnings[i]
if x < 0:
taxed_earnings[i] = 0
taxed_earnings[i + 1] += x
if taxed_earnings[-1] < 0: taxed_earnings[-1] = 0
return taxed_earnings

@njit(cache=True)
def add_replacement_cost_to_cashflow_array(equipment_installed_cost,
equipment_lifetime,
Expand Down Expand Up @@ -709,6 +721,7 @@ def get_cashflow_table(self):
# S: Sales
# T: Tax
# I: Incentives
# TE: Taxed earnings
# NE: Net earnings
# CF: Cash flow
# DF: Discount factor
Expand All @@ -722,7 +735,7 @@ def get_cashflow_table(self):
VOC = self.VOC
sales = self.sales
length = start + years
C_D, C_FC, C_WC, D, L, LI, LP, LPl, C, S, T, I, NE, CF, DF, NPV, CNPV = data = np.zeros((17, length))
C_D, C_FC, C_WC, D, L, LI, LP, LPl, C, S, T, I, TE, NE, CF, DF, NPV, CNPV = data = np.zeros((18, length))
self._fill_depreciation_array(D, start, years, TDC)
w0 = self._startup_time
w1 = 1. - w0
Expand Down Expand Up @@ -773,6 +786,7 @@ def get_cashflow_table(self):
else:
taxable_cashflow = S - C - D
nontaxable_cashflow = D - C_FC - C_WC
TE[:] = taxable_earnings_with_fowarded_losses(taxable_cashflow)
self._fill_tax_and_incentives(I, taxable_cashflow, nontaxable_cashflow, T, D)
NE[:] = taxable_cashflow + I - T
CF[:] = NE + nontaxable_cashflow
Expand Down Expand Up @@ -841,8 +855,7 @@ def _taxable_nontaxable_depreciation_cashflows(self):
)

def _fill_tax_and_incentives(self, incentives, taxable_cashflow, nontaxable_cashflow, tax, depreciation):
index = taxable_cashflow > 0.
tax[index] = self.income_tax * taxable_cashflow[index]
tax[:] = self.income_tax * taxable_earnings_with_fowarded_losses(taxable_cashflow)

def _net_earnings_and_nontaxable_cashflow_arrays(self):
taxable_cashflow, nontaxable_cashflow, depreciation = self._taxable_nontaxable_depreciation_cashflows()
Expand Down

0 comments on commit 78c2fa7

Please sign in to comment.