ITPub博客

首页 > > > 必看!最简单的Python时间序列预测模型

必看!最简单的Python时间序列预测模型

作者:兔子爱喝奶茶 时间:2019-08-15 15:14:55 0 删除 编辑

获得数据

芝加哥期权交易所波动率指数(CBOE Volatility Index,简称VIX)是衡量标普500指数期权隐含的股市波动预期的常用指标,它是由芝加哥期权交易所(CBOE)实时计算和传播的。

本文设置的标普500指

数(SP500)日期范围是从2011年2月11日到2019年2月11日。我们的目的是使用ANN和LSTM预测波动性标普500指数时间序列。

首先,我们需要导入以下内容到库:

train_sc_df = pd.DataFrame(train_sc, columns=['Y'], index=train.index)
	test_sc_df = pd.DataFrame(test_sc, columns=['Y'], index=test.index)
	

	for s in range(1,2):
	 train_sc_df['X_{}'.format(s)] = train_sc_df['Y'].shift(s)
	 test_sc_df['X_{}'.format(s)] = test_sc_df['Y'].shift(s)
	

	X_train = train_sc_df.dropna().drop('Y', axis=1)
	y_train = train_sc_df.dropna().drop('X_1', axis=1)
	

	X_test = test_sc_df.dropna().drop('Y', axis=1)
	y_test = test_sc_df.dropna().drop('X_1', axis=1)
	

	X_train = X_train.as_matrix()
	y_train = y_train.as_matrix()
	

	X_test = X_test.as_matrix()
	y_test = y_test.as_matrix()
	

	X_train_lmse = X_train.reshape(X_train.shape[0], X_train.shape[1], 1)
	X_test_lmse = X_test.reshape(X_test.shape[0], X_test.shape[1], 1)
	

	print('Train shape: ', X_train_lmse.shape)
	print('Test shape: ', X_test_lmse.shape)

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69918097/viewspace-3122092/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-26

  • 博文量
    1470
  • 访问量
    11228