股票价格的插值

时间:2018-01-14 16:36:20

标签: python-3.x

我一直在努力使用这个代码来对AAPL的30天股票调整收盘价进行二次插值。运行代码后,我收到了错误消息。 可能是什么问题呢?我试过操纵数据没有成功。

  

ValueError:沿着插值轴,x和y数组的长度必须相等。

from pandas_datareader import data
import matplotlib.pyplot as plt
import pandas as pd
import googlefinance
import numpy as np
import scipy.interpolate as interp1d
from scipy.interpolate import interp1d


ticker = ['AAPL','SPY']
data_source = 'google'
start_date = '2017-11-15'
end_date = '2017-12-15'

panel_data=data.DataReader(ticker,data_source,start_date,end_date)
adj_close = panel_data.loc['Close']


end = np.shape(adj_close)[0]
adj_x = np.linspace(0, end, end, endpoint=True)

# Interpolating points in the entire function.
interp_Linear = interp1d(adj_x, adj_close, kind='linear')
interp_adjclose = interp_Linear(adj_x)

# Plotting the interpolation.
plt.figure()
plt.plot(adj_x, adj_close, 'ro', adj_x, interp_adjclose, 'k--')
plt.xlabel('Days')
plt.ylabel('Adjusted Close Price')
plt.show()

1 个答案:

答案 0 :(得分:0)

我解决了类似的任务,而不是你的'adj_close',我将它转换为numpy.array(adj_close).ravel()。然后它对我有用。我之前遇到了同样的错误。

相关问题