首先,我们需要先定义一个函数,用于计算项目的净现值(NPV)和内部收益率(IRR)。代码如下:def calculate_npv_irr(initial_investment, lifespan, salvage_value, annual_income, annual_expense, discount_rate): npv = -initial_investment # 初始投资为负值 cash_flows = [] for year in range(1, lifespan+1): income = annual_income * (1 + year/100) # 年收入变化 cash_flow = income - annual_expense cash_flows.append(cash_flow) npv += cash_flow / (1 + discount_rate)**year irr = round(np.irr(cash_flows), 4) return npv, irr
接下来,我们可以使用上述函数进行敏感性分析。对于第一个问题,我们可以改变年收入的值,观察内部收益率的变化情况。代码如下:income_range = range(3000, 4501, 500) # 年收入变化范围discount_rate = 0.1 # 基准收益率for income in income_range: npv, irr = calculate_npv_irr(15000, 10, 0, income, 1000, discount_rate) print(f"年收入为{income}万元时,内部收益率为{round(irr*100, 2)}%")
对于第二个问题,我们可以同时改变初始投资、年收入和寿命三个参数的值,观察净现值的变化情况。代码如下:initial_investment_range = range(12000, 18001, 2000) # 初始投资变化范围lifespan_range = range(8, 13) # 寿命变化范围for initial_investment in initial_investment_range: for lifespan in lifespan_range: npv, irr = calculate_npv_irr(initial_investment, lifespan, 0, 3500, 1000, discount_rate) print(f"初始投资为{initial_investment}万元,寿命为{lifespan}年时,净现值为{round(npv, 2)}万元")
希望以上代码能够对你有所帮助!
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |