-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_prices.py
More file actions
25 lines (22 loc) · 1.22 KB
/
Copy pathcheck_prices.py
File metadata and controls
25 lines (22 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import pandas as pd
import os
stocks_dir = 'd:/trandingagent/stocks'
tickers = ['003031', '002938', '002050', '688820', '688212', '600584', '600941', '600373', '600406']
names = ['中瓷电子', '鹏鼎控股', '三花智控', '盛合晶微', '澳华内镜', '长电科技', '中国移动', '中文传媒', '国电南瑞']
print('检查本地CSV文件最新日期...')
print('股票 代码 最新日期 最新价格 前收盘价 涨跌幅')
print('-' * 65)
for ticker, name in zip(tickers, names):
suffix = '.SZ.csv' if ticker.startswith('0') or ticker.startswith('3') else '.SH.csv'
filepath = os.path.join(stocks_dir, ticker + suffix)
try:
df = pd.read_csv(filepath)
df['交易日'] = pd.to_datetime(df['交易日'], format='%Y%m%d')
df = df.sort_values('交易日')
last = df.iloc[-1]
prev = df.iloc[-2] if len(df) > 1 else last
pct = (last['收盘价'] / prev['收盘价'] - 1) * 100
date_str = last['交易日'].strftime('%Y-%m-%d')
print(f'{name:<12} {ticker:<8} {date_str:<12} {last["收盘价"]:>10.2f} {prev["收盘价"]:>10.2f} {pct:>+8.2f}%')
except Exception as e:
print(f'{name:<12} {ticker:<8} Error: {str(e)[:30]}')