导入sklearn库进行训练
from sklearn.linear_model import LinearRegression reg = LinearRegression() reg.fit(X_train, y_train) X = np.concatenate((X_train, X_test), axis=0) pd.DataFrame(X)
价格预测
用训练后的数据对股价进行预测,并调用matplotlib库将预测结果展示出来:
X = np.concatenate((X_train, X_test), axis=0) dfc['prediction'] = reg.predict(X) dfc['prediction']
dfc['prediction'].plot()
根据预测的结果,估算做单及盈利情况
dfc['position'] = np.sign(dfc['prediction']) np.sign(dfc['prediction'])
dfc['strategy'] = dfc['returns'] * dfc['position'].shift(1) (dfc['strategy'].iloc[split:].cumsum() * 100).plot()
原创文章,作者:朋远方,如若转载,请注明出处:https://caovan.com/09-xianxinghuiguisuanfazaijinrongdeyingyonganli/.html