設為首頁收藏本站

艾歐踢論壇

 找回密碼
 立即註冊

QQ登錄

只需一步,快速開始

搜索
熱搜: 活動 交友 discuz
查看: 337|回復: 0
打印 上一主題 下一主題

make simple watchlist from a running list of tickers with python?

[複製鏈接]
跳轉到指定樓層
樓主
發表於 2023-4-17 08:07:53 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
How to make simple watchlist from a running list of tickers with python?
I am trying to gather tickers that close above the previous day close from a small list of tickers during a specific time period using python?
I am coming up with No data based on my conditions written below but when I look manual I know the conditions are true for ABML on 12-7-21.
I can't seem to figure out what I am missing.
  1. import datetime as dt
  2. import pandas as pd
  3. from pandas_datareader import data as pdr
  4. import yfinance as yf
  5. from tkinter import Tk
  6. from tkinter.filedialog import askopenfilename
  7. import os
  8. from pandas import ExcelWriter

  9. yf.pdr_override()
  10. start = dt.datetime(2021, 11, 30)
  11. now = dt.datetime(2021, 12, 15) # dt.datetime.now()

  12. filePath = ('your file path')

  13. stocklist = pd.read_excel(filePath)
  14. stocklist = stocklist.head()

  15. #*************************************************************************

  16. exportList = pd.DataFrame(columns=['Stock', "Date", "Open"])

  17. for i in stocklist.index:
  18.     stock = str(stocklist["Symbol"][i])
  19.     #RS_Rating = stocklist["RS Rating"][i]

  20. try:
  21.         df = pdr.get_data_yahoo(stock, start, now)

  22.         PreviousClose = df["Close"][-1]
  23.         CurrentClose = df["Close"][0]
  24.         CurrentDate = df["Date"][0]
  25.         CurrentOpen = df["Open"][0]

  26.         # Condition 1: Explain your criteria
  27.         if (PreviousClose < CurrentClose):
  28.             cond_1 = True
  29.         else:
  30.             cond_1 = False
  31.         # Condition 2: Explain your criteria
  32.         if (PreviousClose < CurrentClose):
  33.             cond_2 = True
  34.         else:
  35.             cond_2 = False

  36.         if (cond_1 and cond_2):
  37.             exportList = exportList.append({'Stock': stock, "Date": CurrentDate, "Open": CurrentOpen}, ignore_index=True)

  38. except Exception:
  39.     print("No data on " + stock)


  40. print(exportList)

  41. newFile = os.path.dirname(filePath) + "/ScreenOutput.xlsx"

  42. writer = ExcelWriter(newFile)
  43. exportList.to_excel(writer, "Sheet1")
  44. writer.save()
複製代碼



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 轉播轉播 分享分享 分享淘帖
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

小黑屋|Archiver|手機版|艾歐踢創新工坊    

GMT+8, 2024-5-16 15:20 , Processed in 0.198362 second(s), 18 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表