我正在尝试使用函数(对数周期幂律),代码示例中的输入价格如下所示:
然而,当我尝试导入我拥有的数据时,无论是 csv 还是 txt,它都有问题。实际上,我猜这就是问题所在,因为其余的几乎相同。
代码几乎与pypi.org页面中显示的完全一样 (https://pypi.org/project/lppls/):
data = data_loader.sp500()
time = np.linspace(0, len(data)-1, len(data))
price = np.log(data['Adj Close'].values)
# create Mx2 matrix (expected format for LPPLS observations)
observations = np.array([time, price])
MAX_SEARCHES = 25
lppls_model = lppls.LPPLS(observations=observations)
tc, m, w, a, b, c, c1, c2 = lppls_model.fit(observations, MAX_SEARCHES, minimizer='Nelder-Mead')
# visualize the fit
lppls_model.plot_fit()
唯一的变化是我导入的数据,它一直说“IndexError:数组的索引太多”。
这是我的代码:
retdji = pd.read_csv('mdji.csv')
content = np.array(retdji.transpose())
observations = np.array([time, content])
MAX_SEARCHES = 25
lppls_model = lppls.LPPLS(observations=observations)
# fit the model to the data and get back the params
tc,m,w,a,b,c,c1,c2 = lppls_model.fit(observations, MAX_SEARCHES, minimizer='Nelder-Mead')
# visualize the fit
lppls_model.plot_fit()
那么,如果我的数据采用这种格式,我应该如何操作它才能被模型接受? 提前致谢。