简体   繁体   English

RuntimeWarning:exp 中遇到溢出(记录到相对)

[英]RuntimeWarning: overflow encountered in exp (log to relative)

I have this dataframe which is called cum_strategy_asset_log_returns :我有这个 dataframe 称为cum_strategy_asset_log_returns

data = {'Date':  ['Jan', 'Feb', 'Mar'],
        'Log_price': ['0.1', '0.2', '0.3'],
        }

cum_strategy_asset_log_returns= pd.DataFrame (data, columns = ['Date','Log_price'])

print (cum_strategy_asset_log_returns)

What I want to do now is change these log returns into relative returns.我现在要做的就是将这些日志收益更改为相对收益。 This can be done with the following line:这可以通过以下行来完成:

cum_strategy_asset_relative_returns = np.exp(cum_strategy_asset_log_returns) - 1

But I get the following error: RuntimeWarning: overflow encountered in exp但我收到以下错误: RuntimeWarning: overflow encountered in exp

I am coding on a windows so I can't use float128.我在 windows 上编码,所以我不能使用 float128。 I have also looked at other stackoverflow questions but I just can't seem to figure it out... Hopefully you can help me!我还查看了其他 stackoverflow 问题,但我似乎无法弄清楚......希望你能帮助我!

I'm assuming that the data for 'Log_Price' should be float s and not str s.我假设'Log_Price'的数据应该是float而不是str Given that you could do something like:鉴于您可以执行以下操作:

import numpy as np
import pandas as pd


data = {
    'Date':  ['Jan', 'Feb', 'Mar'],
    'Log_price': list(map(float, ['0.1', '0.2', '0.3'])),
}

df = pd.DataFrame.from_dict(data)
df['Relative_returns'] = np.exp(df['Log_price']) - 1
print(df)

output: output:

  Date  Log_price  Relative_returns
0  Jan        0.1          0.105171
1  Feb        0.2          0.221403
2  Mar        0.3          0.349859

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM