<jupyter_start><jupyter_text>Techno-economic analysis [TEA](../TEA.txt) objects can perform cashflow analysis on a [System](../System.txt) object and arguments for cashflow analysis. These include arguments such as operating days, lang factor, and income tax, as well as arguments for taking into account startup operation, construction schedule, and capital cost financing.  Inhereting from TEA objects Depending on the rigour and flexibility of the techno-economic analysis, different parameters may be needed to calculate total depreciable capital (TDC), fixed capital investment (FCI), and fixed operating cost (FOC). For this reason, the TEA object is left as an *abstract class* with *abstract methods* `_TDC`, `_FCI`, and `_FOC`. Here is an example TEA subclass from the lipidcane biorefinery design for the co-production of ethanol and biodiesel:<jupyter_code>import biosteam as bst

class LipidcaneTEA(bst.TEA):
    """
    Create a LipidcaneTEA object for techno-economic analysis of a biorefinery [1]_.
    
    Parameters
    ----------    
    system : System
        Should contain feed and product streams.
    IRR : float
        Internal rate of return (fraction).
    duration : tuple[int, int]
        Start and end year of venture (e.g. (2018, 2038)).
    depreciation : str
        'MACRS' + number of years (e.g. 'MACRS7').
    operating_days : float
        Number of operating days per year.
    income_tax : float
        Combined federal and state income tax rate (fraction).
    lang_factor : float
        Lang factor for getting fixed capital investment from
        total purchase cost. If no lang factor, estimate capital investment
        using bare module factors.
    startup_schedule : tuple[float]
        Startup investment fractions per year 
        (e.g. (0.5, 0.5) for 50% capital investment in the first year and 50%
        investment in the second).
    WC_over_FCI : float
        Working capital as a fraction of fixed capital investment.
    labor_cost : float
        Total labor cost (USD/yr).
    fringe_benefits : float
        Cost of fringe benefits as a fraction of labor cost.
    property_tax : float
        Fee as a fraction of fixed capital investment.
    property_insurance : float
        Fee as a fraction of fixed capital investment.    
    supplies : float
        Yearly fee as a fraction of labor cost.
    maintenance : float
        Yearly fee as a fraction of fixed capital investment.
    administration : float
        Yearly fee as a fraction of fixed capital investment.

    References
    ----------
    .. [1] <NAME>., <NAME>., & <NAME>. (2016). Techno-economic analysis of biodiesel
        and ethanol co-production from lipid-producing sugarcane. Biofuels, Bioproducts
        and Biorefining, 10(3), 299–315. https://doi.org/10.1002/bbb.1640
    
    """
    
    def __init__(self, system, IRR, duration, depreciation, income_tax,
                 operating_days, lang_factor, construction_schedule, WC_over_FCI,
                 labor_cost, fringe_benefits, property_tax,
                 property_insurance, supplies, maintenance, administration):
        # Huang et. al. does not take into account financing or startup
        # so these parameters are 0 by default
        super().__init__(system, IRR, duration, depreciation, income_tax,
                         operating_days, lang_factor, construction_schedule,
                         startup_months=0, startup_FOCfrac=0, startup_VOCfrac=0,
                         startup_salesfrac=0, finance_interest=0, finance_years=0, 
                         finance_fraction=0, WC_over_FCI=WC_over_FCI)
        self.labor_cost = labor_cost
        self.fringe_benefits = fringe_benefits
        self.property_tax = property_tax
        self.property_insurance = property_insurance
        self.supplies= supplies
        self.maintenance = maintenance
        self.administration = administration
        
    # The abstract _TDC method should take direct permanent investment
    # and return the total depreciable capital. Huang et. al. assume 
    # these values are equal
    def _TDC(self, DPI):
        return DPI
    
    # The abstract _FCI method should take total depreciable capital
    # and return the fixed capital investment. Again, Huang et. al.  
    # assume these values are equal.
    def _FCI(self, TDC):
        return TDC
    
    # The abstract _FOC method should take fixed capital investment
    # and return the fixed operating cost.
    def _FOC(self, FCI):
        return (FCI*(self.property_tax + self.property_insurance
                     + self.maintenance + self.administration)
                + self.labor_cost*(1+self.fringe_benefits+self.supplies))<jupyter_output><empty_output><jupyter_text>Perform cash flow analysis Create a TEA object from a system:<jupyter_code>from biorefineries import lipidcane as lc

lipidcane_tea = LipidcaneTEA(system=lc.lipidcane_sys,
                             IRR=0.15,
                             duration=(2018, 2038),
                             depreciation='MACRS7',
                             income_tax=0.35,
                             operating_days=200,
                             lang_factor=3,
                             construction_schedule=(0.4, 0.6),
                             WC_over_FCI=0.05,
                             labor_cost=2.5e6,
                             fringe_benefits=0.4,
                             property_tax=0.001,
                             property_insurance=0.005,
                             supplies=0.20,
                             maintenance=0.01,
                             administration=0.005)

lipidcane_tea.show() # Print TEA summary at current options
# Ignore the warnings, these are taken care of internally.<jupyter_output>LipidcaneTEA: lipidcane_sys
 NPV: 4.16e+07 USD at 15.0% IRR
 ROI: 0.164 1/yr
 PBP: 5.82 yr<jupyter_text>Retrieve complete cashflow analysis as a DataFrame object:<jupyter_code>lipidcane_tea.get_cashflow_table()<jupyter_output><empty_output><jupyter_text>Find production cost, price, and IRR Find production cost:<jupyter_code>products = [bst.main_flowsheet('ethanol'), bst.main_flowsheet('biodiesel')]
lipidcane_tea.production_cost(products)# USD/yr<jupyter_output><empty_output><jupyter_text>Solve for the price of a stream at the break even point:<jupyter_code>feed = bst.main_flowsheet('lipidcane')
lipidcane_tea.solve_price(feed) # USD/kg<jupyter_output><empty_output><jupyter_text>Solve for the IRR at the break even point:<jupyter_code>lipidcane_tea.IRR = lipidcane_tea.solve_IRR()
lipidcane_tea.show()<jupyter_output>LipidcaneTEA: lipidcane_sys
 NPV: 3.48 USD at 18.0% IRR
 ROI: 0.164 1/yr
 PBP: 5.82 yr<jupyter_text>Note that the cashflow table is created up to date:<jupyter_code>lipidcane_tea.get_cashflow_table()<jupyter_output><empty_output><jupyter_text>System report Save stream tables, utility requirements, itemized costs, TEA results, and a cash flow table:<jupyter_code># Try this on your computer and open excel
lc.lipidcane_sys.save_report('Lipidcane report.xlsx')
# Ignore the warning. The flowsheet is saved on the excel file
# as a really big image and Python thinks it could be a 
# malicious file cause its so big.<jupyter_output>dot: graph is too large for cairo-renderer bitmaps. Scaling by 0.926485 to fit
{'fraction_non_alphanumeric': 0.07191500953418686, 'fraction_numerical': 0.018659765731408335, 'mean_word_length': 2.6899497487437185, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '126750', 'license': 'MIT', 'n_tokens_mistral': 2257, 'n_tokens_neox': 2099, 'n_words': 679, 'path': 'docs/tutorial/Techno-economic_analysis.ipynb', 'repo_name': 'tylerhuntington222/biosteam', 'size': '7347'}