欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用python的pandas為你的股票繪制趨勢(shì)圖

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

前言

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

準(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 ) 的股票趨勢(shì) ( open:開(kāi)盤(pán)價(jià), close: 收盤(pán)價(jià), high 最高價(jià):, low: 最低價(jià),單位為美元)

$ 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

看來(lái)最近股價(jià)漲勢(shì)不錯(cuò)。

再看看其他公司

Google

google

Baidu

baidu

Netease

netease

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

相關(guān)文章

最新評(píng)論