一个简单的股票包
项目描述
股票库
一个简单的库来管理股票数据
示例代码
# library import
from thestockslib import TheStock
# initialization
stock = TheStock('AAPL')
# getting live price
stock.getliveprice()
# getting current Yahoo recommendation
r = stock.getyahoorecommendation()
TheStock.getyahoorecommendationstring(r)
# getting Yahoo performance outlook information (short term, medium term, long term)
stock.getyahooperformanceoutlook()
# getting historical price at July 31st, 2020
stock.gethistoricalprice('2020-07-31')
# adding some mapping to recommendations actions
stock.addactiontoperiod('buy', 7) # when a 'buy' suggestion is received, consider a sell after 7 days
stock.addactiontoperiod('strong buy', 7) # when a 'strong buy' suggestion is received, consider a sell after 7 days
stock.addactiontoperiod('long-term buy', 30) # when a 'long-term buy' suggestion is received, consider a sell after 30 days
# initializing the suggester name
suggestername = 'Cascend'
# simulating purchases by suggester name
purchases = stock.simulatepurchases(suggestername)
print(purchases)
# simulating sells
stock.simulatesells(purchases)
# compute suggester's reliability for 'buy' actions
stock.getsuggestionreliability(suggestername, 'buy')
可用枚举
ConsideredAverage
当请求历史数据时,这Enum用于将要采用的平均方法作为输入传递。以下值是可能的:
OPEN_CLOSE, 将给定股票的开盘价和收盘价之间的平均值视为每日价值HIGH_LOW, 将给定股票当天的高价和低价之间的平均值视为每日价值
可用课程
只有一个TheStock类可用。
支持以下属性:
ticker所考虑的股票行情字符串(例如AAPL)tickerobjectyfinance Ticker对象dateformat要考虑的日期格式(默认为%Y-%m-%d)consideredaverage要考虑的平均计算指标(默认为ConsideredAverage.OPEN_CLOSE)historicaldata当前代码的历史市场数据,根据yfinance数据格式,转换为记录数组
支持以下方法:
-
__init__(self, t, df='%Y-%m-%d', ca=ConsideredAverage.OPEN_CLOSE), 初始化TheStock对象t(str) 是股票代码/符号df(str) 是要考虑的日期格式ca(ConsideredAverage) 是要考虑的平均值
-
addactiontoperiod(a, p),在推荐操作和为该推荐考虑的持续时间之间添加匹配a(str) 是动作标题/名称,与推荐列表映射p(int) 是要考虑的期限,以天为单位
-
convertdatetime(d), 将日期时间对象转换d为字符串,采用df对象初始化期间传递的格式d(datetime) 要转换的日期时间对象
-
getliveprice(round_decimals=2), 返回当前交易品种的当前实时价格round_decimals(int) 考虑四舍五入的小数
-
gethistoricalprice(d, round_decimals=2), 返回当前交易品种在时间的历史价格dd(datetime) 考虑的日期round_decimals(int) 考虑四舍五入的小数
-
simulatepurchases(s), 模拟推荐者购买当前符号ss(str) 要考虑的建议者姓名
-
simulatesells(p), 模拟给定购买的销售p,在针对该购买建议的操作的相关期限到期后p(list) 采购对象清单
-
getsuggestionreliabilitydata(suggester, suggestion, transactionprice=0.0),提供有关给定建议者的可靠性和给定建议的结构化信息suggester(str) 推荐人姓名suggestion(str) 建议行动transactionprice(float) 交易考虑的价格
-
getsuggestionreliability(suggester, suggestion, transactionprice=0.0), 计算给定建议者和给定建议的可靠性suggester(str) 推荐人姓名suggestion(str) 建议行动transactionprice(float) 交易考虑的价格
-
generategraphs(fcast_time, alphavantage_apikey, outputname_pre=''), 为当前符号生成要显示的图形fcast_time(int) 要考虑的预测时间,以天为单位alphavantage_apikey(str) 要使用的AlphaVantage API 密钥outputname_pre(str) 用于生成图形的初步文件名
-
getyahoorecommendation(), 返回当前符号的当前 Yahoo 推荐 -
getyahooperformanceoutlook(), 返回当前交易品种的当前 Yahoo 业绩前景(输出是一个列表,按顺序包含短期、中期、长期结果) -
getcompanynews(finnhub_apikey, fromdate=None), 返回与当前交易品种相关的今日新闻列表finnhub_apikey(str) 要使用的FinnHub API 密钥fromdate(str) 检索新闻时要考虑的开始日期,如果需要检索早于今天的新闻
支持以下静态方法:
-
getrevolutsymbols(), 返回Revolut支持的符号列表 -
combineimages(l, vertical=False, outputfile='output.png'), 将图像列表组合到输出文件l(list) 要组合的输入图像的文件名列表vertical(bool) 组合方式(垂直或水平)outputfile(str) 要生成的输出文件名
-
removeimages(outputname_pre=''), 删除所有生成的图像outputname_pre(str) 用于生成图形的初步文件名
-
getyahoorecommendationstring(r),从表示为的输入值中检索 Yahoo 推荐字符串floatr(float) 推荐值表示为float
去做
- 提高代码可读性
联系人
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。