[英]How to calculate a rolling IRR in python pandas
IIUC,使用expanding
應用irr
:
Python env: pip install numpy-financial
Anaconda env: conda install -c conda-forge numpy-financial
import numpy_financial as npf
df['IRR'] = df['CFs'].expanding(1).agg(npf.irr)
輸出:
>>> df
CFs NAV IRR
0 -100 100 NaN
1 1 101 -0.990000
2 2 103 -0.853490
3 3 106 -0.664270
4 2 108 -0.558468
5 110 0 0.034784
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.