Logarithmic returns in pandas dataframe

后端 未结 5 1216
悲&欢浪女
悲&欢浪女 2020-12-07 15:45

Python pandas has a pct_change function which I use to calculate the returns for stock prices in a dataframe:

ndf[\'Return\']= ndf[\'TypicalPrice\'].pct_chan         


        
5条回答
  •  无人及你
    2020-12-07 16:16

    Log returns are simply the natural log of 1 plus the arithmetic return. So how about this?

    df['pct_change'] = df.price.pct_change()
    df['log_return'] = np.log(1 + df.pct_change)
    

提交回复
热议问题