作家
登录

用Python做股市数据分析(一)

作者: 来源: 2017-07-07 08:50:15 阅读 我要评论

from numpy and matplotlib 

线段图是可行的,然则每一天的数据至少有四个变量(开市,股票最高价,股票最低价和闭市),我们欲望找到一种不须要我们画四条不合的线就能看到这四个变量走势的可视化办法。一般来说我们应用烛柱图(也称为日本阴阳烛图表)来可视化金融数据,烛柱图最早在18世纪被日本的稻米商人所应用。可以用matplotlib来作图,然则须要费些工夫。

你们可以应用我实现的一个函数更轻易地画烛柱图,它接收pandas的data frame作为数据来源。(法度榜样基于这个例子, 你可以大年夜这里找到相干函数的文档。)

  1. from matplotlib.dates import DateFormatter, WeekdayLocator,\ 
  2.  
  3.     DayLocator, MONDAY 
  4.  
  5. from matplotlib.finance import candlestick_ohlc 
  6.  
  7. def pandas_candlestick_ohlc(dat, stick = "day", otherseries = None): 
  8.  
  9.     ""
  10.  
  11.     :param dat: pandas DataFrame object with datetime64 indexand float columns "Open""High""Low"and "Close", likely created via DataReader from "yahoo" 
  12.  
  13.     :param stick: A string or number indicating the period of time covered by a single candlestick. Valid string inputs include "day""week""month"and "year", ("day" default), and any numeric input indicates the number of trading days included in a period 
  14.  
  15.     :param otherseries: An iterable that will be coerced into a list, containing the columns of dat that hold other series to be plotted as lines 
  16.  
  17.     This will show a Japanese candlestick plot for stock data stored in dat, also plotting other series if passed. 
  18.  
  19.     ""
  20.  
  21.     mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays 
  22.  
  23.     alldays = DayLocator()              # minor ticks on the days 
  24.  
  25.     dayFormatter = DateFormatter('%d')      # e.g., 12 
  26.  
  27.     # Create a new DataFrame which includes OHLC data 

      推荐阅读

      WOT讲师杨钊:人工智能将在不同应用场景逐步落地

    【51CTO.com原创稿件】由51CTO主办的WOTA2017全球立异技巧峰会将于2017年7月21日拉开帷幕。本次峰会,将环绕机>>>详细阅读


    本文标题:用Python做股市数据分析(一)

    地址:http://www.17bianji.com/lsqh/36070.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)