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)
结论:股市的诈骗,远远不及算法!