我做了一个股票筛选程序,它给出了符合我标准的股票的技术参数,最后,我希望它能打印出符合我标准的股票的简明列表。我尝试使用append函数,但它只打印一个股票,相反,我希望它打印每个股票的股票代码,例如“mmm”,。。。你知道吗
电流输出如下所示。 嗯 尾随市盈率:17.61 股本回报率:54.34% 收入:323.5亿 季度收入增长:-5.00%
def scrape(stock_list, interested, technicals):
for each_stock in stock_list:
technicals = scrape_yahoo(each_stock)
condition_1 = float(technicals.get('Return on Equity',0).replace('%','').replace('N/A','-100')) > 25
condition_2 = float(technicals.get('Trailing P/E',0).replace('N/A','')) > 15
condition_3 = float(technicals.get('Price/Book (mrq)',0)) <15
if (condition_1 and condition_2)==True:
print(each_stock)
SuggestedStocks = []
SuggestedStocks.append(each_stock)
for ind in interested:
print(ind + ": "+ technicals[ind])
print("------")
time.sleep(1) # Use delay to avoid getting flagged as bot
#return technicals
print(SuggestedStocks)
def main():
stock_list = ['MMM', 'ABT', 'ABBV', 'ABMD', 'ACN', 'ATVI', 'ADBE', 'AMD']
interested = ['Trailing P/E', 'Return on Equity', 'Revenue', 'Quarterly Revenue Growth']
technicals = {}
tech = scrape(stock_list, interested, technicals)
print(tech)
main()
它只打印符合我要求的最后一支股票的股票代码标准:ADBE。你知道吗
这是因为您在每个循环中重置建议的股票
SuggestedStocks = []
您应该在循环外初始化它。你知道吗相关问题 更多 >
编程相关推荐