#!/usr/bin/env python
# coding: utf-8
import pandas as pd
import numpy as np
from sklearn.neural_network import MLPRegressor
import matplotlib.pyplot as plt
tau = 4
# 确定每月日期 2014-01-01~2016-01-01
dates = get_trading_dates(start_date="2019-11-01", end_date="2021-12-15")
#stock = index_components("000065.XSHE")
x = get_price(["000065.XSHE"], start_date=dates[0], end_date=dates[-1], fields='close')
T = len(x)
features = np.zeros((T - tau, tau))
for i in range(tau):
features[:, i] = x[i: T - tau + i].T
labels = x[tau:].values
#预测N天后股价
N = 7
features = features[:-N]
labels = labels[N:]
lr = MLPRegressor(solver="lbfgs", max_iter = 30000, alpha=0.001, hidden_layer_sizes=(32,16), random_state=1)
lr.fit(features, labels.ravel())
y_pri = lr.predict(features)
cnt = len(y_pri)
plt.plot(np.arange(cnt), y_pri)
plt.plot(np.arange(cnt), labels)
plt.show()
aa = lr.predict([[8.11,8.26,8.31,8.32]])
aa = lr.predict([[7.12,7.21,7.34,7.4]])
aa
基于Ricequant时间序列模型预测股价
最新推荐文章于 2023-03-06 11:43:52 发布