到目前为止,我已经建立了一个价格表(如图所示),我想计算各个股票的回报率。 价格数据=pd.read_excel软件(r'\价格数据.xlsx',skiprows=范围(1)
usecols = 'B:SN', index_col = 0)
priceData = priceData.drop(priceData.index[[0,1]])
priceData.index.names = ['Date']
priceData.index = priceData.index.map(pd.to_datetime)
priceData.sort_index()
# To adjust all time series data to start from 1990-01-25 to 2018-09-24
for column in priceData.columns:
if np.isnan(priceData[column].iloc[0]):
priceData = priceData.drop([column],axis=1, inplace=True)
stocks = list(table)
returns = table.apply(lambda x: np.log(x)-np.log(x.shift(1)))
*table是我的数据帧名称。在
我面对的错误信息是:
"TypeError: ("unsupported operand type(s) for /: 'float' and >'datetime.datetime'", 'occurred at index LYB UN Equity')"
我试过:
^{pr2}$但是我遇到了一个新的错误消息:
("'float' object has no attribute 'log'", 'occurred at index LYB UN Equity')
请指教!在
我想出了一个更直观的方法。在
当计算同一数据帧中多个证券的日志回报时,这将起作用。干杯!在
相关问题 更多 >
编程相关推荐