最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用python的pandas為你的股票繪制趨勢圖

 更新時間:2019年06月26日 14:47:34   作者:瓦爾特有范  
這篇文章主要介紹了通過python為你的股票繪制趨勢圖,動手寫個小程序, 把股票趨勢每天早上發(fā)到郵箱里,用 python 的 pandas, matplotlib 寫起來很容易, 幾十行代碼搞定。,需要的朋友可以參考下

前言

手里有一點(diǎn)點(diǎn)公司的股票, 拿不準(zhǔn)在什么時機(jī)拋售, 程序員也沒時間天天盯著看,不如動手寫個小程序, 把股票趨勢每天早上發(fā)到郵箱里,用 python 的 pandas, matplotlib 寫起來很容易, 幾十行代碼搞定。

準(zhǔn)備環(huán)境

python3 -m venv venv
source ./venv/bin/activate
pip install pandas
pip install pandas_datareader
pip install matplotlib

代碼如下

繪制 2019 年到今天2019-02-15 的我司 ( Cisco ) 的股票趨勢 ( open:開盤價, close: 收盤價, high 最高價:, low: 最低價,單位為美元)

$ vi stock.py

import matplotlib.pyplot as plt
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader.data as web
import matplotlib
import time
import matplotlib.pyplot as plt
import argparse
def drawStockTrend(inc, startDate, endDate, pngFile):
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(18.5, 10.5)
df = web.DataReader(name=inc, data_source='iex', start=startDate, end=endDate)
print(df)
plt.style.use('seaborn-whitegrid')
plt.xticks(rotation=30)
plt.plot(df.index, df['open'], label='open', marker='o', linestyle=':', linewidth=1, markersize=3, color='gray')
plt.plot(df.index, df['high'], label='high', marker='o', linestyle=':', linewidth=1, markersize=3, color='green')
plt.plot(df.index, df['low'], label='low', marker='o', linestyle=':', linewidth=1, markersize=3, color='blue')
plt.plot(df.index, df['close'], label='close', marker='o', linestyle='-', linewidth=2, markersize=6, color='red')
for x, y in zip(df.index, df['close']):
plt.text(x, y + 0.3, '%.2f' % y, ha='center', va='bottom', color='red')
plt.legend()
plt.title("%s' stock trend" % company)
plt.show(block=True)
time.sleep(1)
if(not pngFile):
fig.savefig(pngFile)
plt.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-c', action='store', dest='company', help='specify company')
parser.add_argument('-s', action='store', dest='start', help='specify start date')
parser.add_argument('-e', action='store', dest='end', help='specify end date')
parser.add_argument('-f', action='store', dest='file', help='specify the filename')
args = parser.parse_args()
company = 'CSCO'
startDate = '2019-01-01'
endDate = '2019-02-19'
pngFile = None
if(args.company):
company = args.company
if (args.start):
startDate = args.start
if (args.end):
endDate = args.end
if (args.file):
pngFile = args.file
drawStockTrend(company, startDate, endDate, pngFile)
#example
# python stock.py -c GOOGL -s 2019-01-01 -e 2019-02-19 -f google_stock_trend.png
# python stock.py -c CSCO -s 2019-01-01 -e 2019-02-19 -f cisco_stock_trend.png
# python stock.py -c SINA -s 2019-01-01 -e 2019-02-19 -f sina_stock_trend.png
# python stock.py -c BIDU -s 2019-01-01 -e 2019-02-19 -f baidu_stock_trend.png
# python stock.py -c NTES -s 2019-01-01 -e 2019-02-19 -f netease_stock_trend.png

運(yùn)行命令如下

python stock.py -c CSCO -s 2019-01-01 -e 2019-02-19 -f cisco_stock_trend.png

圖表如下

cisco

cisco

看來最近股價漲勢不錯。

再看看其他公司

Google

google

Baidu

baidu

Netease

netease

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python實(shí)現(xiàn)動態(tài)創(chuàng)建類的方法分析

    python實(shí)現(xiàn)動態(tài)創(chuàng)建類的方法分析

    這篇文章主要介紹了python實(shí)現(xiàn)動態(tài)創(chuàng)建類的方法,結(jié)合實(shí)例形式分析了Python動態(tài)創(chuàng)建類的原理、實(shí)現(xiàn)方法及相關(guān)操作技巧,需要的朋友可以參考下
    2019-06-06
  • 利用Python改正excel表格數(shù)據(jù)

    利用Python改正excel表格數(shù)據(jù)

    這篇文章主要介紹了利用Python改正excel表格數(shù)據(jù),運(yùn)用面向過程寫的,將每一步都放在了不同的函數(shù)中,下文詳細(xì)過程介紹需要的小伙伴可以參考一下
    2022-06-06
  • Python操作xlwings的實(shí)例詳解

    Python操作xlwings的實(shí)例詳解

    python操作Excel的模塊,網(wǎng)上提到的模塊大致有:xlwings、xlrd、xlwt、openpyxl、pyxll等。本文將通過幾個實(shí)例演示下xlwings的使用,感興趣的可以了解一下
    2022-07-07
  • 使用Python+Matplotlib制作時序動態(tài)圖

    使用Python+Matplotlib制作時序動態(tài)圖

    時序圖是一個二維圖,橫軸表示對象,縱軸表示時間,消息在各對象之間橫向傳遞,依照時間順序縱向排列,可以直觀的描述并發(fā)進(jìn)程,所以本文就使用Python和Matplotlib制作一個簡單的時許動態(tài)圖,感興趣的跟著小編一起來看看吧
    2023-07-07
  • 一文詳解PyQt5中實(shí)現(xiàn)不規(guī)則窗口的顯示

    一文詳解PyQt5中實(shí)現(xiàn)不規(guī)則窗口的顯示

    這篇文章主要為大家詳細(xì)介紹了Python?PyQt5中實(shí)現(xiàn)不規(guī)則窗口的顯示的相關(guān)資料,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,需要的可以參考一下
    2022-12-12
  • 一篇不錯的Python入門教程

    一篇不錯的Python入門教程

    一篇不錯的Python入門教程...
    2007-02-02
  • Python判斷變量名是否合法的方法示例

    Python判斷變量名是否合法的方法示例

    今天小編就為大家分享一篇關(guān)于Python判斷變量名是否合法的方法示例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • Python+flask編寫一個簡單實(shí)用的自動排班系統(tǒng)

    Python+flask編寫一個簡單實(shí)用的自動排班系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了如何基于Python+flask編寫一個簡單實(shí)用的自動排班系統(tǒng),文中的示例代碼講解詳細(xì),有需要的小伙伴可以了解下
    2025-03-03
  • 如何解決cmd運(yùn)行python提示不是內(nèi)部命令

    如何解決cmd運(yùn)行python提示不是內(nèi)部命令

    在本篇文章里小編給大家整理了關(guān)于如何解決cmd運(yùn)行python提示不是內(nèi)部命令的相關(guān)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。
    2020-07-07
  • python正則表達(dá)式抓取成語網(wǎng)站

    python正則表達(dá)式抓取成語網(wǎng)站

    做NLPproject時需要一個成語庫,我需要的是純成語,網(wǎng)上找的都是有詳細(xì)解釋的。于是自己寫了一個爬成語的python程序
    2013-11-11

最新評論

遂平县| 库尔勒市| 常德市| 宜丰县| 瓦房店市| 庆城县| 沽源县| 安化县| 射洪县| 福海县| 建德市| 大化| 蕲春县| 上高县| 大同市| 额尔古纳市| 黎城县| 涡阳县| 香港 | 乌拉特后旗| 庆元县| 磴口县| 纳雍县| 长沙市| 砚山县| 合肥市| 扶风县| 凤凰县| 黔东| 郧西县| 江城| 衢州市| 安西县| 溧阳市| 中西区| 尼玛县| 汤原县| 连州市| 湖口县| 惠州市| 白银市|