【MIS_231228】使用ARMA预测疫情后某医药股的股价

2023-12-28 15:39:32

import random
import string
from datetime import datetime

def generate_random_string(length=3):
    characters = string.ascii_uppercase
    return ''.join(random.choice(characters) for _ in range(length))

def generate_timestamped_string(separator='_'):
    timestamp = datetime.now().strftime('%y%m%d') # %H%M%S
    random_part = generate_random_string(length=3)
    return random_part+separator+timestamp

timestamped_string = generate_timestamped_string()
print('【{0}】'.format(timestamped_string))

【Talk is cheap】

import warnings
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei'] # 显示中文
plt.rcParams['axes.unicode_minus'] = False # 显示负号
warnings.filterwarnings("ignore")
%matplotlib inline
...
# 绘制ACF和PACF图
plot_acf(df['Close_diff'].dropna())
plt.show()
plot_pacf(df['Close_diff'].dropna())
plt.show()

平衡检验,# 自动输出最佳参数

print("Best ARIMA Model (p, d, q):", best_params)

# 建立ARIMA模型
model = ARIMA(df['Close'], order=(p, d, q))  # p, d, q是根据ACF和PACF图确定的参数
model_fit = model.fit()

...

# 绘制曲线
plt.figure(figsize=(12, 6))
plt.plot(merged_df.index, merged_df['Close'], label='Actual')
plt.plot(merged_df.index, merged_df['Forecast'], label='Forecast')
plt.xlabel('Date')
plt.ylabel('Closing Price')
plt.title('Actual vs Forecasted Closing Price')
plt.legend()
plt.show()

# 输出预测结果的DataFrame
print(forecast_df)

结论:股市的诈骗,远远不及算法!

文章来源:https://blog.csdn.net/baidu_22713341/article/details/135266995
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。