from pandas import * import numpy as np import jqdata import matplotlib.pyplot as plt matplotlib.rcParams['axes.unicode_minus']=False # 解决负号显示异常的问题 import pandas as pd from scipy import stats import statsmodels.api as sm
IndexData = get_price('000002.XSHG', start_date='2017-01-01', end_date='2018-01-01', frequency='daily', fields=['close']) # 取得上证指数2016年的收盘价格 IndexData.head()
IndexData['changepct'] ='' for i in range(0,len(IndexData['close'])-1): IndexData.iloc[i, 1] = 100*(IndexData['close'][i+1] - IndexData['close'][i])/IndexData['close'][i] # 计算每日收益率 IndexData['changepct'] = IndexData['changepct'][0:-1] IndexData['closeDif_1'] = IndexData['close'].diff(1) IndexData['closeDif_2'] = IndexData['closeDif_1'].diff(1) IndexData = IndexData[0:-1] # 由于changepct值最后一行缺失,因此去除最后一行 IndexData['changepct'] = float64(IndexData['changepct']) #使changepct数据类型和其他三列保持一致 IndexData.tail()
len(IndexData['changepct']) # 数据量
243
IndexData.plot(subplots=True,figsize=(18,12))
array([Axes(0.125,0.732174;0.775x0.147826), Axes(0.125,0.554783;0.775x0.147826), Axes(0.125,0.377391;0.775x0.147826), Axes(0.125,0.2;0.775x0.147826)], dtype=object)
本社区仅针对特定人员开放
查看需注册登录并通过风险意识测评
5秒后跳转登录页面...
玉兔呈祥:2019年08月23日操盘计划(1)...
玉兔呈祥:2019年07月26日操盘计划(1)...
交易匠人:震荡行情多耐心,黄金早间有望延续...
交易匠人:黄金震荡回踩1708,有波段机会
移动端课程