<jupyter_start><jupyter_text>@author: <NAME> | email: <EMAIL> @linkedIn: https://www.linkedin.com/in/carlosbonilla1/"""To-do Notes:Function has a chain assignment warning; I still need to find how to prevent that potential error.<jupyter_code>def investment_pv_table(periods,equipment_and_installation_cost,inventory_investment,operating_cash_flows,
                                       depreciation_period=0,discount_curve=0,marginal_tax_rate=0,
                                       equipment_salvage_value= 0, day_count = 1, interpolate_discount_curve = False):
    #day_count is meant to proxy the length of the "period" the cash flow is received in 
    # If interpolate_discount_curve is true then will use provided discount rates to interpolate a log curve
    
    #Package dependencies
    import pandas as pd

    #Create a dataframe to hold and calclate the relevant data/factors
    df = pd.DataFrame(list(range(periods+1)), columns = ["Period"]) 
    
    df['Net_investment_outlay'] = 0
    df['Net_investment_outlay'].iloc[0] = -inventory_investment-equipment_and_installation_cost
    
    df['Depreciation_Expense'] = equipment_and_installation_cost/depreciation_period
    df['Interest_Expense'] = (operating_cash_flows-df['Depreciation_Expense'])*marginal_tax_rate
    df['After_Tax_Operating_Cash_Flow'] = operating_cash_flows-df['Interest_Expense']#+df['Depreciation_Expense']
    
    df['After_Tax_Operating_Cash_Flow'].iloc[0]=0
    df['Depreciation_Expense'].iloc[0]=0
    
    df['Project_Salvage_Cash_Flow'] = 0
    df['Project_Salvage_Cash_Flow'].iloc[depreciation_period] = equipment_salvage_value+inventory_investment-(marginal_tax_rate*equipment_salvage_value) 
    df['Project_Cash_Flow'] = df['Net_investment_outlay']+df['After_Tax_Operating_Cash_Flow']+df['Project_Salvage_Cash_Flow']
    
    if interpolate_discount_curve == True:
        import numpy as np
        df['Discount_Rate'] = np.geomspace(discount_curve[0], discount_curve[1], num=len(cash_flows))
    else: df['Discount_Rate'] = discount_curve

    #Calculate discount factors
    df['Discount_Factor'] = 1/((1+df['Discount_Rate'])**(df['Period']*day_count))

    #Can loop through the periods and calculate each PV or multiple the cash flow by the discount factor
    df['Project_Cash_Flow_PV']= df['Project_Cash_Flow'] * df['Discount_Factor']
    
    #Economic income is the cash flow plus the change in value, or economic income is the cash flow minus the economic depreciation
    #df['Economic_Income'] = df['PV'].iloc[::-1]-df['Project_Cash_Flow']

    #Return a pandas dataframe 
    return df
investment_pv_table(periods=2,equipment_and_installation_cost=100,inventory_investment=0,operating_cash_flows=50+50,
                    depreciation_period=2,discount_curve=.12,marginal_tax_rate=.3,equipment_salvage_value=0)
npv = investment_pv_table(periods=2,equipment_and_installation_cost=100,inventory_investment=0,operating_cash_flows=50+50,
                    depreciation_period=2,discount_curve=.12,marginal_tax_rate=.3,equipment_salvage_value=0)['Project_Cash_Flow_PV'].sum()
npv<jupyter_output>C:\Users\<NAME>\Anaconda3\lib\site-packages\pandas\core\indexing.py:179: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  self._setitem_with_indexer(indexer, value)
{'fraction_non_alphanumeric': 0.10139453805926786, 'fraction_numerical': 0.014816966879721092, 'mean_word_length': 5.1263345195729535, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '126650', 'license': 'MIT', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1139, 'n_words': 202, 'path': 'NPV Investment Table.ipynb', 'repo_name': 'cbonilla-catalogue/DividendValuationModels', 'size': '3480'}