zoukankan      html  css  js  c++  java
  • 五大股指对比图(周线数据, 规整到起点为1000点的相对值)

    五大股指对比图

    用jupyter notebook工具编写的笔记文档, 看看能不能很好地变成一篇博客保留下来.

    整体看来还不错, 下面是操作步骤.

    1. 在jupyter里把文档导出为md格式. 步骤为: file/download as / markdown, 结果保存为本地的一个zip文档.
    2. 解压缩, 得到.md和内嵌的.png文件.
    3. 用tc打开md文档, copy所有内容
    4. 回到cnblogs的网页里, 添加新随笔(注意:选用markdown编辑器)
    5. 填写标题, 写入摘要等内容.
    6. 粘贴.md的文本内容.
    7. 浏览内容, 找到内嵌图片的位置, 把.png文件从本地拖拽到blog页面内的位置
      • 注意: 如果没有拖拽方式上传图片文件, 则博文内是没有内嵌的图片的, 会很让人失望.
      • (关于markdown里的层次列表项的语法: 用tab进行缩进, 后跟*/+/-都行, 表示缩进的内容为次级列表项目)
    8. 点击保存草稿
    9. 立即查看或者继续编辑博文
    10. 点击发布草稿或者保存草稿/立即查看
    11. ==>最后发布成功.
    # %load ../script/my_import.py
    # my_import.py
    import numpy as np
    import pandas as pd
    from pandas import Series, DataFrame
    import tushare as ts
    from datetime import datetime,timedelta
    import matplotlib.pyplot as plt
    %matplotlib inline
    
    # %load方法和%run方法都无法取代import语句. 
    # 所以深刻理解/使用导入语句是最重要的.    ../script/create_dict.py
    
    import sys
    sys.path.append('C:/Documents and Settings/Administrator/duanqs/script/')
    import dict_indexcode as dic
    import dict_stockcode as dsc
    # reload(dsc)
    
    # python怎么import指定文件夹下的模块(自定义的模块)?
    # 简答: sys.path.append(自定义模块的路径)
    
    # reload()函数将以前导入过的模块再加载一次。
    # 重新加载(reload)包括最初导入模块时的分析过程和初始化过程。
    # 这样就允许在不退出解释器的情况下重新加载已更改的Python模块。
    # 在jupyter notebook里的保险的做法是: kernel/restart and clear output(重启并清除输出, 重启内核的快捷键: 0+0)
    
    
    # %pwd
    # print dic.dict_indexcode.items()
    # print dsc.dict_stockcode.items()
    # dsc.dict_stockcode.get(u'天山股份')
    
    def get_indexohlc_weekly(indexname,startdate='2010-06-04'):
        code= dic.dict_indexcode.get(indexname)
        df=ts.get_k_data(code,startdate, ktype='W', index=True)
        
        df2=df.iloc[:,1:7]; df2.index = df.date
        ini_open = df2.open['2010-06-04']
    #     print ini_open
        norm_close = df2.close/ini_open *1000.0; norm_close.name='normC'+'.'+indexname
        df = pd.concat([df2, norm_close], axis=1)
        return df
    # 000001 000300 399001 399005 399006
    # 历史数据最短, 周线的 起始日期: 2010/6/4
    
    def get_5index_weekly():
        df0001=get_indexohlc_weekly(u'上证指数')  
        df0300=get_indexohlc_weekly(u'沪深300')  
        
        df3001=get_indexohlc_weekly(u'深证成指')  
        df3005=get_indexohlc_weekly(u'中小板指')  
        df3006=get_indexohlc_weekly(u'创业板指')
    
        df_5index=df0001.iloc[:, 6]
        df_5index=pd.concat( [df_5index, 
                              df0300.iloc[:, 6],
                              df3001.iloc[:, 6],
                              df3005.iloc[:, 6],
                              df3006.iloc[:, 6]
                              ],axis=1)
    #     df_5index.index.name= 'date'
        return df_5index
    
    df5=get_5index_weekly()
    
    df5.plot(figsize=(12,4))
    # df5['2016'].plot()
    print u'df5的行索引的类型为:', type(df5.index)
    
    df5的行索引的类型为: <class 'pandas.indexes.base.Index'>
    

    png

    df5.head(4)
    
    normC.上证指数 normC.沪深300 normC.深证成指 normC.中小板指 normC.创业板指
    2010-06-04 964.395884 967.925119 974.354062 988.001251 1062.082928
    2010-06-11 970.570285 973.030338 979.340031 1015.556369 1159.764946
    2010-06-18 949.149278 950.916541 953.248579 957.235085 1033.761571
    2010-06-25 964.102818 965.066902 966.475600 969.350218 1050.303377
    df5.tail(5)
    
    normC.上证指数 normC.沪深300 normC.深证成指 normC.中小板指 normC.创业板指
    2016-12-02 1225.076174 1244.632907 1043.737459 1262.989115 2215.202628
    2016-12-09 1220.936995 1232.200510 1031.972179 1258.068591 2170.184444
    2016-12-16 1179.431905 1180.118462 988.467137 1204.935403 2064.997328
    2016-12-23 1174.586498 1166.564504 975.564640 1196.562042 2030.303563
    2016-12-30 1172.127916 1167.439180 973.391587 1191.869865 2027.740544
    
    
  • 相关阅读:
    React同构直出优化总结
    Kubenertes资源分配之Request和Limit解析
    Node Server零基础——开发环境文件自动重载
    Vue组件开发实践之scopedSlot的传递
    【干货合集】Docker快速入门与进阶
    ES6 中的 Set
    十个书写Node.js REST API的最佳实践(上)
    oozie配置安装与原理
    Livy原理详解
    阿里(蚂蚁金服)招聘
  • 原文地址:https://www.cnblogs.com/duan-qs/p/6242744.html
Copyright © 2011-2022 走看看