没有合适的资源?快使用搜索试试~ 我知道了~
首页使用python的pandas为你的股票绘制趋势图
资源详情
资源评论
资源推荐
使用使用python的的pandas为你的股票绘制趋势图为你的股票绘制趋势图
主要介绍了通过python为你的股票绘制趋势图,动手写个小程序, 把股票趋势每天早上发到邮箱里,用 python 的 pandas,
matplotlib 写起来很容易, 几十行代码搞定。,需要的朋友可以参考下
前言前言
手里有一点点公司的股票, 拿不准在什么时机抛售, 程序员也没时间天天盯着看,不如动手写个小程序, 把股票趋势每天早上发到邮箱里,
用 python 的 pandas, matplotlib 写起来很容易, 几十行代码搞定。
准备环境准备环境
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
运行命令如下
python stock.py -c CSCO -s 2019-01-01 -e 2019-02-19 -f cisco_stock_trend.png
图表如下图表如下
cisco
weixin_38666232
- 粉丝: 3
- 资源: 923
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0