什么是股票指数
股票价格指数为度量和反映股票市场总体价格水平及其变动趋势而编制的股价统计相对数。通常是报告期的股票平均价格或股票市值与选定的基期股票平均价格或股票市值相比,并将两者的比值乘以基期的指数值,即为该报告期的股票价格指数。当股票价格指数上升时,表明股票的平均价格水平上涨;当股票价格指数下跌时,表明股票的平均价格水平下降;是灵敏反映市场所在国(或地区)社会、政治、经济变化状况的晴雨表
有名的股票指数
美国
- 标准普尔500指数 (500家最大的上市公司)
- 道琼斯工业平均指数 (30支在美国市场交易的大型公共股票股价的平均值,但是不能代表美国股市)
- 纳斯达克指数 (指一些在纳斯达克证券交易上市的证券组成的指数,代表了科技股的收益率)
外国
- 英国富时100指数
- 德国的DAX
- 日本的日经255指数
- 中国的上证综合指数
- 摩根士丹利资本国际(MSCI)
代码
外国
import numpy as np
from pandas_datareader import data as wb
import matplotlib.pyplot as plt
import pandas as pd
%matplotlib inline
这里出现小插曲,想读取英国富时100指数^FTSE读取不到
tickers = ['^GSPC','^IXIC','^GDAXI']
ind_data = pd.DataFrame()
for t in tickers:
ind_data[t] = wb.DataReader(t,data_source='iex',start='1997-1-1')['Adj Close']
ind_data.head()
^GSPC | ^IXIC | ^GDAXI | |
---|---|---|---|
Date | |||
1996-12-31 | 740.739990 | 1291.030029 | NaN |
1997-01-02 | 737.010010 | 1280.699951 | 2820.810059 |
1997-01-03 | 748.030029 | 1310.680054 | 2863.260010 |
1997-01-06 | 747.650024 | 1316.400024 | 2890.199951 |
1997-01-07 | 753.229980 | 1327.729980 | 2876.340088 |
ind_data.tail()
^GSPC | ^IXIC | ^GDAXI | |
---|---|---|---|
Date | |||
2019-05-06 | 2932.469971 | 8123.290039 | 12286.879883 |
2019-05-07 | 2884.050049 | 7963.759766 | 12092.740234 |
2019-05-08 | 2879.419922 | 7943.319824 | 12179.929688 |
2019-05-09 | 2870.719971 | 7910.589844 | 11973.919922 |
2019-05-10 | 2881.399902 | 7916.939941 | 12059.830078 |
(ind_data/ind_data.iloc[0]*100).plot(figsize=(15,6))
<matplotlib.axes._subplots.AxesSubplot at 0x220c2a8fa90>
wb.DataReader('^GSPC',data_source='yahoo',start='1997-1-1').head()
High | Low | Open | Close | Volume | Adj Close | |
---|---|---|---|---|---|---|
Date | ||||||
1996-12-31 | 753.950012 | 740.739990 | 753.849976 | 740.739990 | 399760000 | 740.739990 |
1997-01-02 | 742.809998 | 729.549988 | 740.739990 | 737.010010 | 463230000 | 737.010010 |
1997-01-03 | 748.239990 | 737.010010 | 737.010010 | 748.030029 | 452970000 | 748.030029 |
1997-01-06 | 753.309998 | 743.820007 | 748.030029 | 747.650024 | 531350000 | 747.650024 |
1997-01-07 | 753.260010 | 742.179993 | 747.650024 | 753.229980 | 538220000 | 753.229980 |
ind_returns = (ind_data/ind_data.shift(1))-1
ind_returns.head()
^GSPC | ^IXIC | ^GDAXI | |
---|---|---|---|
Date | |||
1996-12-31 | NaN | NaN | NaN |
1997-01-02 | -0.005035 | -0.008001 | NaN |
1997-01-03 | 0.014952 | 0.023409 | 0.015049 |
1997-01-06 | -0.000508 | 0.004364 | 0.009409 |
1997-01-07 | 0.007463 | 0.008607 | -0.004795 |
annual_ind_returns = ind_returns.mean()*250
annual_ind_returns
^GSPC 0.078329
^IXIC 0.111502
^GDAXI 0.078216
dtype: float64
# 美国
tickers = ['PG','^GSPC','^DJI']
data_2 = pd.DataFrame()
for t in tickers:
data_2[t] = wb.DataReader(t,data_source='yahoo',start='2001-1-1')['Adj Close']
data_2.tail()
PG | ^GSPC | ^DJI | |
---|---|---|---|
Date | |||
2019-05-06 | 105.680000 | 2932.469971 | 26438.480469 |
2019-05-07 | 104.699997 | 2884.050049 | 25965.089844 |
2019-05-08 | 105.070000 | 2879.419922 | 25967.330078 |
2019-05-09 | 104.239998 | 2870.719971 | 25828.359375 |
2019-05-10 | 106.010002 | 2881.399902 | 25942.369141 |
(data_2/data_2.iloc[0]*100).plot(figsize=(15,6))
<matplotlib.axes._subplots.AxesSubplot at 0x220c3fb7400>
来源:CSDN
作者:毛利学python
链接:https://blog.csdn.net/weixin_44510615/article/details/90116280