-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_prices.py
More file actions
49 lines (44 loc) · 1.86 KB
/
Copy pathget_prices.py
File metadata and controls
49 lines (44 loc) · 1.86 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Get latest stock prices for PK review"""
import sys
sys.path.insert(0, 'd:/trandingagent/deer-flow/skills/custom/factor-analysis')
import akshare as ak
import pandas as pd
# All 20 stocks
stocks = [
# AI portfolio (8)
("600000", "浦发银行"), ("601800", "中国交建"), ("000877", "天山股份"),
("601186", "中国铁建"), ("600373", "中文传媒"), ("600997", "开滦股份"),
("601686", "友发集团"), ("601166", "兴业银行"),
# User portfolio (9)
("002050", "三花智控"), ("002938", "鹏鼎控股"), ("600584", "长电科技"),
("688820", "盛合晶微"), ("688212", "澳华内镜"), ("003031", "中瓷电子"),
("600941", "中国移动"), ("600406", "国电南瑞"),
]
print("=" * 80)
print("📊 20只股票最新价格查询")
print("=" * 80)
print(f"\n{'股票':<10} {'代码':<8} {'最新价':>10} {'日期':<12}")
print("-" * 42)
results = {}
for ticker, name in stocks:
try:
df = ak.stock_zh_a_hist(symbol=ticker, period="daily", start_date="20260515", end_date="20260519")
if not df.empty:
df = df.sort_values("日期")
last = df.iloc[-1]
price = last["收盘"]
date = last["日期"]
results[ticker] = {"name": name, "price": price, "date": date}
print(f"{name:<10} {ticker:<8} {price:>10.2f} {date:<12}")
else:
print(f"{name:<10} {ticker:<8} {'无数据':>10} {'N/A':<12}")
except Exception as e:
print(f"{name:<10} {ticker:<8} {'错误':>10} {str(e)[:20]:<12}")
print(f"\n共查询 {len(results)} 只股票")
if results:
print(f"数据最新日期: {max(v['date'] for v in results.values())}")
# Save for calculation
import json
with open("d:/trandingagent/latest_prices.json", "w", encoding="utf-8") as f:
json.dump(results, f, ensure_ascii=False, indent=2)
print("\n价格已保存到 latest_prices.json")