stock_predict
时间: 2024-04-14 08:24:21 浏览: 13
股票预测是指通过分析历史数据和市场趋势,来预测未来股票价格的变动趋势。这是一个非常复杂的任务,因为股票市场受到多种因素的影响,包括经济指标、公司业绩、行业发展等等。目前,有许多方法和技术可以用于股票预测,包括基本面分析、技术分析、机器学习等。
基本面分析是通过研究公司的财务报表、行业发展情况、宏观经济指标等来评估股票的价值。技术分析则是通过研究股票的历史价格和交易量等图表数据,来预测未来价格的走势。机器学习方法则是利用大量的历史数据和各种指标,通过建立模型来预测股票价格。
然而,需要注意的是,股票市场具有高度的不确定性和随机性,预测股票价格是一个极具挑战性的任务。即使使用了先进的技术和方法,也不能保证100%准确的预测结果。因此,在进行股票投资时,应该综合考虑多种因素,并做出谨慎的决策。
相关问题
import tensorflow as tf import numpy as np import tkinter as tk from tkinter import filedialog import time import pandas as pd import stock_predict as pred def creat_windows(): win = tk.Tk() # 创建窗口 sw = win.winfo_screenwidth() sh = win.winfo_screenheight() ww, wh = 800, 450 x, y = (sw - ww) / 2, (sh - wh) / 2 win.geometry("%dx%d+%d+%d" % (ww, wh, x, y - 40)) # 居中放置窗口 win.title('LSTM股票预测') # 窗口命名 f_open =open('dataset_2.csv') canvas = tk.Label(win) canvas.pack() var = tk.StringVar() # 创建变量文字 var.set('选择数据集') tk.Label(win, textvariable=var, bg='#C1FFC1', font=('宋体', 21), width=20, height=2).pack() tk.Button(win, text='选择数据集', width=20, height=2, bg='#FF8C00', command=lambda: getdata(var, canvas), font=('圆体', 10)).pack() canvas = tk.Label(win) L1 = tk.Label(win, text="选择你需要的 列(请用空格隔开,从0开始)") L1.pack() E1 = tk.Entry(win, bd=5) E1.pack() button1 = tk.Button(win, text="提交", command=lambda: getLable(E1)) button1.pack() canvas.pack() win.mainloop() def getLable(E1): string = E1.get() print(string) gettraindata(string) def getdata(var, canvas): global file_path file_path = filedialog.askopenfilename() var.set("注,最后一个为label") # 读取文件第一行标签 with open(file_path, 'r', encoding='gb2312') as f: # with open(file_path, 'r', encoding='utf-8') as f: lines = f.readlines() # 读取所有行 data2 = lines[0] print() canvas.configure(text=data2) canvas.text = data2 def gettraindata(string): f_open = open(file_path) df = pd.read_csv(f_open) # 读入股票数据 list = string.split() print(list) x = len(list) index=[] # data = df.iloc[:, [1,2,3]].values # 取第3-10列 (2:10从2开始到9) for i in range(x): q = int(list[i]) index.append(q) global data data = df.iloc[:, index].values print(data) main(data) def main(data): pred.LSTMtest(data) var.set("预测的结果是:" + answer) if __name__ == "__main__": creat_windows()这个代码能实现什么功能
这个代码实现了一个简单的GUI界面,可以让用户选择一个股票数据集,选择需要的列,然后用LSTM模型对这些列进行预测,并在界面上展示预测结果。具体来说,该代码使用了Tkinter库创建了一个窗口,其中包括一个按钮用于选择数据集,一个标签用于展示数据集的列名,以及一个文本框用于让用户输入需要的列。当用户点击提交按钮后,程序会读取用户输入的列号,并使用Pandas库读取该数据集,提取用户选择的列,再使用stock_predict.py文件中的LSTM模型对这些列进行预测,并在界面上展示预测结果。
plt.plot(inv_y,color='red',label='真实值') plt.plot(inv_y_predict,color='green',label='预测值') plt.xlabel('日期') plt.ylabel('收盘价') plt.title(title) plt.legend() plt.show()有14支股票,做一个循环
假设你有14支股票的真实值和预测值,可以将这些数据存储在一个字典中,字典的键为股票名称,值为真实值和预测值对应的列表,如下所示:
```
data = {
'stock1': {
'true_values': [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140],
'predicted_values': [12, 18, 33, 42, 48, 57, 68, 75, 88, 95, 108, 121, 138, 145]
},
'stock2': {
'true_values': [8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112],
'predicted_values': [10, 19, 28, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126]
},
...
}
```
然后,你可以使用for循环遍历字典中的每个股票数据,并绘制对应的真实值和预测值对比图,如下所示:
```
import matplotlib.pyplot as plt
for stock_name, stock_data in data.items():
# 获取真实值和预测值列表
true_values = stock_data['true_values']
predicted_values = stock_data['predicted_values']
# 绘制对比图
title = f'{stock_name} Stock Price Comparison'
plt.plot(true_values, color='red', label='True Values')
plt.plot(predicted_values, color='green', label='Predicted Values')
plt.xlabel('Date')
plt.ylabel('Closing Price')
plt.title(title)
plt.legend()
plt.show()
```
运行以上代码,就可以绘制出14支股票的真实值和预测值对比图。你可以根据实际情况修改代码中的股票数据,以得到你需要的对比图。