日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数据分析实例(股票分析实例)

發布時間:2024/10/8 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据分析实例(股票分析实例) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import numpy as np import pandas as pd import matplotlib.pyplot as plt %matplotlib inline

使用pandas的內建函數DataReader從雅虎財經網站讀取股價數據

import tushare as ts pingan = ts.get_k_data('601318',start='2011-01-01') pingan.head() dateopenclosehighlowvolumecode01234
2011-01-0424.98425.01125.31424.830245626.0601318
2011-01-0524.87024.11024.96224.083427554.0601318
2011-01-0624.14523.11224.14522.611947078.0601318
2011-01-0723.27923.29723.84222.765659013.0601318
2011-01-1023.24822.86623.68822.809282919.0601318
pingan.tail() dateopenclosehighlowvolumecode19992000200120022003
2019-04-0378.4879.8680.1578.37760219.0601318
2019-04-0480.0880.2080.9679.25795626.0601318
2019-04-0880.7080.5982.2580.02916122.0601318
2019-04-0980.4081.1082.0080.37601737.0601318
2019-04-1080.8082.0382.1179.66783620.0601318
pingan['date'] = pd.to_datetime(pingan.date) pingan.set_index('date',inplace = True) pingan.index DatetimeIndex(['2011-01-04', '2011-01-05', '2011-01-06', '2011-01-07','2011-01-10', '2011-01-11', '2011-01-12', '2011-01-13','2011-01-14', '2011-01-17',...'2019-03-27', '2019-03-28', '2019-03-29', '2019-04-01','2019-04-02', '2019-04-03', '2019-04-04', '2019-04-08','2019-04-09', '2019-04-10'],dtype='datetime64[ns]', name='date', length=2004, freq=None) pingan['close'].plot(figsize=(12,8)) <matplotlib.axes._subplots.AxesSubplot at 0x2360fa68e10>

g_yue = pingan['close'].resample('M').ohlc() g_yue openhighlowclosedate2011-01-312011-02-282011-03-312011-04-302011-05-312011-06-302011-07-312011-08-312011-09-302011-10-312011-11-302011-12-312012-01-312012-02-292012-03-312012-04-302012-05-312012-06-302012-07-312012-08-312012-09-302012-10-312012-11-302012-12-312013-01-312013-02-282013-03-312013-04-302013-05-312013-06-30...2016-11-302016-12-312017-01-312017-02-282017-03-312017-04-302017-05-312017-06-302017-07-312017-08-312017-09-302017-10-312017-11-302017-12-312018-01-312018-02-282018-03-312018-04-302018-05-312018-06-302018-07-312018-08-312018-09-302018-10-312018-11-302018-12-312019-01-312019-02-282019-03-312019-04-30
25.01125.01121.24921.842
21.95222.98021.47721.868
22.08423.51221.43321.736
22.51424.12322.51422.954
23.10323.10320.97221.407
21.31021.31019.49521.213
21.15621.60919.53419.724
19.90619.90617.86718.053
18.23118.29414.93514.935
15.08217.22615.08217.208
17.44918.03615.68715.687
16.54116.90114.93515.322
15.08217.39515.06017.057
16.64318.55616.64318.160
18.04018.35216.12316.274
16.79918.40516.75018.111
18.76119.16618.08518.636
18.76120.51818.09420.349
20.50920.57219.49319.793
20.22720.22717.19317.381
17.82918.83317.56018.833
18.61319.01817.09117.423
17.66117.66115.86516.382
16.44920.33816.44920.338
21.15521.65319.95221.653
22.79923.70120.19421.137
20.63420.63418.24518.757
18.40719.26517.87717.877
17.97618.71717.37417.920
17.92917.92915.55815.726
............
33.39335.03132.96434.602
34.68835.26933.01233.745
33.98334.77433.53634.774
33.92635.06933.92634.507
34.44035.25033.90735.250
35.33636.15533.82136.155
36.10743.32735.48842.927
43.78447.58442.54647.251
46.61352.00345.64150.087
52.81254.94047.73853.948
54.08354.68551.56752.616
53.19962.52553.19962.525
62.29276.20362.18567.926
66.15872.77466.15867.985
70.52076.51468.01472.939
73.32873.84362.59365.828
66.96571.97763.44863.448
62.81666.30459.15459.154
59.59162.27258.92160.358
59.88263.99056.26758.000
54.67361.54554.67360.990
59.10962.84256.02062.357
62.10968.50060.60068.500
64.78067.93061.85063.630
64.30067.35062.64063.490
64.99064.99056.10056.100
55.18062.98055.18062.980
63.21073.00063.21070.010
72.39077.10068.70077.100
78.60082.03078.60082.030

100 rows × 4 columns

pingan['close'].loc['2017'].plot(figsize=(12,8)) <matplotlib.axes._subplots.AxesSubplot at 0x23612ba5e10>

shouyi = (pingan['close'][-1] - pingan['close'][0])/pingan['close'][0] shouyi 2.2797569069609374 y_num = pingan.index[-1].year - pingan.index[0].year y_num 8 shouyi**(1/y_num) 1.1085009445718548 pingan['close'].to_period('A') date 2011 25.011 2011 24.110 2011 23.112 2011 23.297 2011 22.866 2011 22.905 2011 23.288 2011 23.283 2011 22.844 2011 21.908 2011 21.974 2011 22.273 2011 21.438 2011 21.714 2011 21.249 2011 21.315 2011 21.504 2011 21.943 2011 21.710 2011 21.842 2011 21.952 2011 21.930 2011 22.224 2011 21.961 2011 22.980 2011 22.695 2011 22.629 2011 22.528 2011 22.492 2011 22.659... 2019 69.980 2019 70.010 2019 72.390 2019 72.580 2019 72.070 2019 72.160 2019 70.290 2019 68.700 2019 68.790 2019 69.250 2019 71.540 2019 72.800 2019 73.850 2019 75.000 2019 75.350 2019 76.550 2019 75.800 2019 74.720 2019 72.290 2019 72.690 2019 74.220 2019 73.400 2019 77.100 2019 78.600 2019 78.960 2019 79.860 2019 80.200 2019 80.590 2019 81.100 2019 82.030 Freq: A-DEC, Name: close, Length: 2004, dtype: float64 pingan['close'].to_period('A').groupby(level = 0).first().plot() <matplotlib.axes._subplots.AxesSubplot at 0x23612bdc748>

pingan['42d'] = pingan['close'].rolling(window=42).mean() pingan['250d'] = pingan['close'].rolling(window=250).mean() pingan[['close','42d','250d']].plot(figsize=(12,8),color = ['y','b','r']) <matplotlib.axes._subplots.AxesSubplot at 0x2360fa38550>

pingan['duishu'] = np.log(pingan['close']/pingan['close'].shift(1)) #shifting 指的是沿著時間軸將數據前移或后移。 pingan[['close','duishu']].plot(subplots = True,figsize=(12,12)) array([<matplotlib.axes._subplots.AxesSubplot object at 0x0000023612FB0CF8>,<matplotlib.axes._subplots.AxesSubplot object at 0x000002361301E978>],dtype=object)

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的数据分析实例(股票分析实例)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。