Python学习——ARIMA模型使用之COVID-19 Stock Market Analysis

ARIMA模型使用之COVID-19 Stock Market Analysis

以下数据分析的目的是了解新冠肺炎发生前后美国股票市场的变化。 以下探索的主要目的是回答指导性问题:
“新冠肺炎股市崩盘对标准普尔500指数中的公司有何影响?” 在这里,我们将假设一个投资者的立场,并进行彻底的分析。

学习目标:

  1. 使用统计和金融分析的方法来推动一个更强大、更量化的分析方法。
  2. 获得使用Python 3库进行数据操作和数据可视化的经验。
  3. 熟悉股票市场分析的方法
import pandas as pd
import pandas_datareader as web
import datetime
import matplotlib.pyplot as plt
%matplotlib inline

为了更好地分析标准普尔500指数,我将使用我随机选择的三家公司的股票数据:特斯拉、苹果和迪士尼。这三家公司分别对应了不同的行业,新能源汽车,电子行业和旅游行业 在我看来,这三家公司是美国市场中中不同行业的一个很好的可视化——它们都可能受到不同于COVID-19的影响。而且这三家公司都具备全球性的产业链或者在不同的国家进行着旅游经营,通过研究分析它们在疫情期间的股价变化,有助于我们对于疫情时代下的世界变化有更深刻的理解

我们选取了疫情开始的2020年2月20日作为时间的起点,选取了2021年2月20日作为终点

start = datetime.datetime(2020, 2, 20)
end = datetime.datetime(2021, 2, 20)

我们选取了pandas_datareader作为读取数据的工具包,这是一个比较完整的数据读取提供了很详细的数据读取工具,其中包括了yahoo财经的数据,以下为读取数据的接口,以下读取了各个股票的K线数据

tesla  = web.DataReader("TSLA",'yahoo',start,end)
Apple   = web.DataReader("AAPL",'yahoo',start,end)
disney = web.DataReader("DIS",'yahoo',start,end)

并进行本地化的数据保存

tesla.to_csv('Tesla_Stock.csv')
Apple.to_csv('Apple_Stock.csv')
disney.to_csv('Disney_Stock.csv')

以代表科技&电子行业的苹果公司为例,我们进行数据的可视化展示,如下所示,我们展示了苹果公司每日的最高价,最低价,开盘,收盘,成交量和复权的收盘价信息

Apple.head()
High Low Open Close Volume Adj Close
Date
2020-02-19 81.142502 80.000000 80.000000 80.904999 93984000.0 80.146545
2020-02-20 81.162498 79.552498 80.657501 80.074997 100566000.0 79.324333
2020-02-21 80.112503 77.625000 79.654999 78.262497 129554000.0 77.528809
2020-02-24 76.044998 72.307503 74.315002 74.544998 222195200.0 73.846161
2020-02-25 75.632500 71.532501 75.237503 72.019997 230673600.0 71.344841

为了便于进一步分析股票价格的变化,我们使用可视化工具matplotlib选取Apple为例进行数据的可视化,从下图可以看出,在2020年3月-2020年5月期间,苹果的股票价格出现了一个比较大的回撤,但是后续在美国政府的一系列政策激励中不断走高,其次伴随着中国疫情的好转,作为苹果公司的重要生产国,苹果公司没有受到严重的影响

import matplotlib.pyplot as plt   # Import matplotlib
# This line is necessary for the plot to appear in a Jupyter notebook
%matplotlib inline
 
# Control the default size of figures in this Jupyter notebook
%pylab inline
 
pylab.rcParams['figure.figsize'] = (15, 9)   # Change the size of plots
 
Apple["Adj Close"].plot(grid = True) # Plot the adjusted closing price of AAPL
Populating the interactive namespace from numpy and matplotlib






[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-d3lCOUwM-1626417736634)(output_13_2.png)]

为了更详细的展示所有的数据情况,我们使用了matplotlib中的finance模块,其中有蜡烛图的工具,可以比较详细的画出k线的变化情况

 from mplfinance.original_flavor import candlestick_ohlc
import matplotlib.dates as mpdates
    
fig, ax = plt.subplots()
Apple['Date'] = Apple.index.map(mpdates.date2num)
df = Apple[['Date','Open', 'High', 'Low', 'Close', 'Volume']]
candlestick_ohlc(ax, df.values, width=.6, colorup = 'red', colordown = 'green', )
([,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ],
 [,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ])

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cPzbwp0E-1626417736636)(output_15_1.png)]

为了进一步进行数据预测,我们选取了statsmodels其中的arima模型模型进行股价预测。ARIMA模型(英语:Autoregressive Integrated Moving Average model),差分整合移动平均自回归模型,又称整合移动平均自回归模型(移动也可称作滑动),时间序列预测分析方法之一。ARIMA(p,d,q)中,AR是"自回归",p为自回归项数;MA为"滑动平均",q为滑动平均项数,d为使之成为平稳序列所做的差分次数(阶数)。
从上图可以看出,数据波动比较大,而时间序列模型要求数据平缓,满足平稳性的要求。因此需要对数据进行差分处理。

Apple_diff=Apple.diff().dropna() #对数据进行差分,目的使数据平缓,满足平稳性的要求
plt.figure()
plt.plot(Apple_diff)

plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
plt.title('一阶差分')  #注意要设置字体,否则会乱码
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jEXaY97t-1626417736637)(output_17_0.png)]

一阶差分的结果如图4所示,图4可以看出数据基本已经趋于平缓,为了确定一阶差分足以满足需求,再进行ACF和PACF检验,ACF和PACF可以直接调用statemodel里的函数进行求算。

from statsmodels.graphics.tsaplots import plot_acf,plot_pacf

acf=plot_acf(Apple_diff['Close'],lags=20)

plt.title('ACF')

acf.show()

plt.show()

pacf=plot_pacf(Apple_diff['Close'],lags=20)

plt.title('PACF')

pacf.show()

plt.show()
:7: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.
  acf.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-STPPOzoE-1626417736640)(output_19_1.png)]

:15: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.
  pacf.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mCik6rlL-1626417736642)(output_19_3.png)]

由上面的图可以看出,进行一阶差分时,结果已经落在了置信区间内(图中蓝色区域),因此可以确定进行一阶差分是可靠有效的。接下来就可以进行ARIMA模型训练了
参数order=(1,1,1)表示一阶差分,ACF和PACF的取值均为1

对差分后数据进行单位根检验
展示差分后单位根检验结果,返回统计量和p值

from statsmodels.tsa.stattools import adfuller
print(u'原始序列的ADF检验结果为:', adfuller(Apple_diff['Close']))
原始序列的ADF检验结果为: (-18.18428119915623, 2.4284938765818675e-30, 0, 252, {'1%': -3.4565688966099373, '5%': -2.8730786194395455, '10%': -2.5729189953388762}, 1120.8651394879457)

由检验的结果显示,Test Statistic的值是-18.18428119915623,小于Critical Value给出的1%,5%,10%显著性水平下的临界值,同时p-value=2.4284938765818675e-30<0.05,因此拒绝原假设,说明该开盘价序列经一阶差分后是平稳的。
也就是说此时差分后苹果的收盘价序列是平稳白噪声序列。

from statsmodels.tsa.arima_model import ARIMA
data = Apple['Close'].resample("B").fillna(method='ffill')
model=ARIMA(data,order=(1,1,1),freq='B')#训练模型,order表示(p,d,q)

result=model.fit()
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
result.summary()
ARIMA Model Results
Dep. Variable: D.Close No. Observations: 84
Model: ARIMA(1, 1, 1) Log Likelihood -178.587
Method: css-mle S.D. of innovations 2.027
Date: Thu, 15 Jul 2021 AIC 365.173
Time: 21:43:47 BIC 374.897
Sample: 02-23-2021 HQIC 369.082
- 06-18-2021
coef std err z P>|z| [0.025 0.975]
const 0.0587 0.159 0.369 0.712 -0.253 0.370
ar.L1.D.Close 0.1362 0.299 0.455 0.649 -0.450 0.723
ma.L1.D.Close -0.3826 0.270 -1.417 0.157 -0.912 0.147
Roots
Real Imaginary Modulus Frequency
AR.1 7.3425 +0.0000j 7.3425 0.0000
MA.1 2.6140 +0.0000j 2.6140 0.0000

进行模型诊断

result.conf_int()
0 1
const -0.252976 0.370317
ar.L1.D.Close -0.450302 0.722689
ma.L1.D.Close -0.911780 0.146663

上述模型诊断结果中,通过z检验,我们发现P值-0.25,-1大于0.05,即无法拒绝原假设,说明模型诊断不通过,且系数的置信区间包含零,因此不能说在5%的置信水平下,所有系数都是显著的,从而推翻AR(1)模型。

from statsmodels.tsa.stattools import arma_order_select_ic
arma_order_select_ic(Apple_diff['Close'],max_ar=6,max_ma=4,ic='aic')['aic_min_order'] #AIC确定阶数 
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\tsatools.py:701: RuntimeWarning: overflow encountered in exp
  newparams = ((1-np.exp(-params))/(1+np.exp(-params))).copy()
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\tsatools.py:701: RuntimeWarning: invalid value encountered in true_divide
  newparams = ((1-np.exp(-params))/(1+np.exp(-params))).copy()
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\tsatools.py:702: RuntimeWarning: overflow encountered in exp
  tmp = ((1-np.exp(-params))/(1+np.exp(-params))).copy()
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\tsatools.py:702: RuntimeWarning: invalid value encountered in true_divide
  tmp = ((1-np.exp(-params))/(1+np.exp(-params))).copy()
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\base\model.py:547: HessianInversionWarning: Inverting hessian failed, no bse or cov_params available
  warnings.warn('Inverting hessian failed, no bse or cov_params '
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\base\model.py:566: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
  warnings.warn("Maximum Likelihood optimization failed to "
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\base\model.py:547: HessianInversionWarning: Inverting hessian failed, no bse or cov_params available
  warnings.warn('Inverting hessian failed, no bse or cov_params '
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\base\model.py:547: HessianInversionWarning: Inverting hessian failed, no bse or cov_params available
  warnings.warn('Inverting hessian failed, no bse or cov_params '
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\base\model.py:547: HessianInversionWarning: Inverting hessian failed, no bse or cov_params available
  warnings.warn('Inverting hessian failed, no bse or cov_params '





(4, 4)
model=ARIMA(data,order=(4,1,4),freq='B') 
result=model.fit(disp=-1) 
result.summary()
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\base\model.py:547: HessianInversionWarning: Inverting hessian failed, no bse or cov_params available
  warnings.warn('Inverting hessian failed, no bse or cov_params '
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:472: FutureWarning: 
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been deprecated in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and
statsmodels.tsa.SARIMAX. These will be removed after the 0.12 release.

statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained.

To silence this warning and continue using ARMA and ARIMA until they are
removed, use:

import warnings
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARMA',
                        FutureWarning)
warnings.filterwarnings('ignore', 'statsmodels.tsa.arima_model.ARIMA',
                        FutureWarning)

  warnings.warn(ARIMA_DEPRECATION_WARN, FutureWarning)
C:\Users\sunjifeng\Anaconda3\lib\site-packages\statsmodels\tsa\arima_model.py:1521: RuntimeWarning: invalid value encountered in sqrt
  return np.sqrt(np.diag(-inv(hess)))
ARIMA Model Results
Dep. Variable: D.Close No. Observations: 84
Model: ARIMA(4, 1, 4) Log Likelihood -173.569
Method: css-mle S.D. of innovations 1.824
Date: Thu, 15 Jul 2021 AIC 367.139
Time: 21:49:27 BIC 391.447
Sample: 02-23-2021 HQIC 376.910
- 06-18-2021
coef std err z P>|z| [0.025 0.975]
const 0.0497 0.216 0.230 0.818 -0.373 0.473
ar.L1.D.Close -1.7114 0.094 -18.267 0.000 -1.895 -1.528
ar.L2.D.Close -1.9229 0.120 -16.042 0.000 -2.158 -1.688
ar.L3.D.Close -1.6575 0.110 -15.119 0.000 -1.872 -1.443
ar.L4.D.Close -0.7576 0.084 -9.012 0.000 -0.922 -0.593
ma.L1.D.Close 1.7830 0.080 22.409 0.000 1.627 1.939
ma.L2.D.Close 2.0837 nan nan nan nan nan
ma.L3.D.Close 1.7829 nan nan nan nan nan
ma.L4.D.Close 0.9996 nan nan nan nan nan
Roots
Real Imaginary Modulus Frequency
AR.1 -0.0538 -1.0080j 1.0094 -0.2585
AR.2 -0.0538 +1.0080j 1.0094 0.2585
AR.3 -1.0401 -0.4622j 1.1381 -0.4334
AR.4 -1.0401 +0.4622j 1.1381 0.4334
MA.1 -0.0242 -0.9997j 1.0000 -0.2539
MA.2 -0.0242 +0.9997j 1.0000 0.2539
MA.3 -0.8676 -0.4977j 1.0002 -0.4171
MA.4 -0.8676 +0.4977j 1.0002 0.4171

说明新修正的的模型为ARIMA(4,1,4),紧接着进行相应的诊断上述模型诊断结果中,通过z检验,我们发现所有P值中除截距项之外均小于0.05(说明没有常数项),即拒绝原假设,说明模型诊断通过。为使模型更加精确,我们再进一步用confint()函数计算模型中的系数区间,上述运行结果中,可以看出,除截距项外,所有系数的置信区间都不包含零,因此我们可以说在5%的置信水平下,所有的系数都是显著的,即模型通过检验。

result.conf_int()  #模型诊断
0 1
const -0.373462 0.472793
ar.L1.D.Close -1.895036 -1.527779
ar.L2.D.Close -2.157832 -1.687963
ar.L3.D.Close -1.872333 -1.442596
ar.L4.D.Close -0.922401 -0.592850
ma.L1.D.Close 1.627020 1.938915
ma.L2.D.Close NaN NaN
ma.L3.D.Close NaN NaN
ma.L4.D.Close NaN NaN

最后一步就是利用建立好的result模型来预测走势了

start = datetime.datetime(2021, 2, 21)
end = datetime.datetime(2021, 6, 20)
Apple_pred   = web.DataReader("AAPL",'yahoo',start,end)
len(Apple_pred)
83
plt.figure(figsize=(6,6))

plt.xticks(rotation=45)

plt.plot(pred[0])



plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IUMzg38n-1626417736643)(output_38_0.png)]

plt.figure(figsize=(6,6))

plt.xticks(rotation=45)

plt.plot(Apple_pred['Close'])



plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jjZpQa0Y-1626417736644)(output_39_0.png)]

上图给出的是一个关于苹果公司80日的预测结果,从图中可以看出,模型对苹果公司的股价一直看好,给出了一个持续上涨的态势,但是根据实际情况来看,苹果公司的股价在今年呈现了一个波动的行情,因此后续考虑优化模型可以考虑增加特征以及对模型进行滚动预测的方式

确定股票性质的最好方法之一是分析它的波动率。 一只股票的波动性决定了它的稳定程度,并为投资者描绘了它当前趋势是否可能持续的图景。 它是公司整体实力的有力指标,它不依赖于总体模式或趋势,而是对每日百分比变化的定量分析。
首先,让我们设定冠状病毒感染前后的10个月间隔。

Pre COVID-19 (April 19th, 2019 - Febrary 19th, 2020)

startPre = datetime.datetime(2019, 4, 19)
endPre = datetime.datetime(2020, 2, 19)
teslaPre  = web.DataReader("TSLA",'yahoo',startPre,endPre)
applPre   = web.DataReader("AAPL",'yahoo',startPre,endPre)
disneyPre = web.DataReader("DIS",'yahoo',startPre,endPre)

Post COVID-19 (February 20th, 2020 - December 20th, 2020)

startPost = datetime.datetime(2020, 2, 20)
endPost = datetime.datetime(2021, 2, 20)
teslaPost  = web.DataReader("TSLA",'yahoo',startPost,endPost)
applPost   = web.DataReader("AAPL",'yahoo',startPost,endPost)
disneyPost = web.DataReader("DIS",'yahoo',startPost,endPost)

计算每日百分比变化。

teslaPre['returnsPre']=(teslaPre['Close']/teslaPre['Close'].shift(1)) - 1
applPre['returnsPre']=(applPre['Close']/applPre['Close'].shift(1)) - 1
disneyPre['returnsPre']=(disneyPre['Close']/disneyPre['Close'].shift(1)) - 1
teslaPost['returnsPost']=(teslaPost['Close']/teslaPost['Close'].shift(1)) - 1
applPost['returnsPost']=(applPost['Close']/applPost['Close'].shift(1)) - 1
disneyPost['returnsPost']=(disneyPost['Close']/disneyPost['Close'].shift(1)) - 1

Tesla, Apple, and Disney的波动率

teslaPre['returnsPre'].hist(bins=50,label='Pre-COVID',alpha=0.5, figsize = (16,6))
teslaPost['returnsPost'].hist(bins=50,label='Post-COVID',alpha=0.5)
plt.legend()
plt.title('Tesla')
Text(0.5, 1.0, 'Tesla')

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WH6xiusk-1626417736644)(output_52_1.png)]

applPre['returnsPre'].hist(bins=50,label='Pre-COVID',alpha=0.5, figsize = (16,6))
applPost['returnsPost'].hist(bins=50,label='Post-COVID',alpha=0.5)
plt.legend()
plt.title('appl')
Text(0.5, 1.0, 'appl')

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-EK4IRDjd-1626417736645)(output_53_1.png)]

disneyPre['returnsPre'].hist(bins=50,label='Pre-COVID',alpha=0.5, figsize = (16,6))
disneyPost['returnsPost'].hist(bins=50,label='Post-COVID',alpha=0.5)
plt.legend()
plt.title('Disney')
Text(0.5, 1.0, 'Disney')

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QhpfgEFV-1626417736645)(output_54_1.png)]

波动性是衡量标准偏差的指标。 标准差越大,直方图中的方格越宽,股票的波动性或“不稳定性”就越大。 总的来说,我们可以看到,在这里分析的每一只股票(特斯拉、Apple和迪士尼),都被认为在COVID-19崩溃后比之前有更大的波动。

由此我们可以得出结论,COVID-19通过降低其稳定性影响了每个股票

研究结果和结论总结

根据我们的研究结果,我们可以得出结论,COVID-19崩溃导致股票价格下跌,但也增加了股票波动。 我们可以通过分析股市崩盘前后10个月的每日百分比变化来确定这一点。 我们所确定的是,对于崩盘后的任何股票,其价格的标准差都要大得多。 因此,我们得出结论,COVID-19后,稳定性被削弱。

你可能感兴趣的:(做个人吧)