基于Ricequant时间序列模型预测股价

#!/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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值