python - 求解利率以使 NPV 为零 Python
问题描述
到目前为止,我的解决方案(不起作用并卡住)使用 NPV 公式计算每月现金流量并尝试找到贴现率使其为零:
def goal_seek(target,cashflows,_threshold):
threshold = _threshold
lower = -10000
upper = 10000
solve = (lower + upper)/2
while abs(threshold) >= _threshold:
print(f'Threshold is: {threshold}')
print(f'range is: {lower} ---- {solve} ---- {upper}')
if threshold < 0:
upper = solve
solve = (lower + upper)/2
elif threshold > 0:
lower = solve
solve = (lower + upper)/2
threshold = target - numpy.npv(((numpy.sign(solve) * (numpy.abs(solve)+1) ** (1 / 12))-1),cashflows)
print(f'Final result: Threshold: {threshold}....Solved input: {solve}')
return solve
goal_seek(0,[-1,0,0,0,.5],.0001)
实现上面的例子会导致这个二分搜索算法卡在下面
阈值是:0.9767928293785059 范围是:10000.0 ---- 10000.0 ---- 10000
是否有一个简单的 scipy 模块来求解单个变量非线性方程,例如 NPV?
解决方案
我不确定这是否是你想要的。
np.npv()
https://numpy.org/doc/stable/reference/generated/numpy.npv.html
np.irr()
https://numpy.org/doc/stable/reference/generated/numpy.irr.html
推荐阅读
- openstack - 我已经安装了queens(openstack),但它的neutron agent 只支持linuxbridge,我如何通过支持ovs one 来替换它?
- mysql - 用户模型和用户身份验证(Django 和 mysql)
- reactjs - TypeError: Object( ) is not a function when using browser router
- laravel - 获取第一个父母的ID
- struct - C语言的电话簿管理
- python - vscode中的numpy数组不打印小数点?
- directshow - DirectShow 无窗口模式 VMR9 不起作用
- java - 带有 MultiValueMap 的 Spring Cloud Feign 版本 2020.04 问题
- excel - 对一个单元格内的多个换行符分隔行应用 VLOOKUP
- drake - p_WC 与 p_WCa 和 p_WCb