diff --git a/.idea/csv-editor.xml b/.idea/csv-editor.xml
deleted file mode 100644
index af8e228..0000000
--- a/.idea/csv-editor.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/data_source_mapping.xml b/.idea/data_source_mapping.xml
new file mode 100644
index 0000000..c96c85c
--- /dev/null
+++ b/.idea/data_source_mapping.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/db-forest-config.xml b/.idea/db-forest-config.xml
new file mode 100644
index 0000000..454b8f6
--- /dev/null
+++ b/.idea/db-forest-config.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/data.py b/data.py
new file mode 100644
index 0000000..a4dfe27
--- /dev/null
+++ b/data.py
@@ -0,0 +1,136 @@
+from datetime import date, datetime, timedelta
+from time import sleep
+
+from sqlalchemy import Column, Double, Integer, String, create_engine
+from sqlalchemy.orm import DeclarativeBase, Session
+from tushare import pro_api
+
+TUSHARE_API_KEY = '64ebff4fa679167600b905ee45dd88e76f3963c0ff39157f3f085f0e'
+
+
+class Base(DeclarativeBase):
+ pass
+
+
+class Stock(Base):
+ __tablename__ = 'stock'
+
+ code = Column(String, primary_key=True, comment="代码")
+ name = Column(String, comment="名称")
+ fullname = Column(String, comment="全名")
+ market = Column(String, comment="市场")
+ exchange = Column(String, comment="交易所")
+ industry = Column(String, comment="行业")
+ list_date = Column(String, comment="上市日期")
+
+
+class Daily(Base):
+ __tablename__ = 'daily'
+
+ code = Column(String, primary_key=True)
+ trade_date = Column(String, primary_key=True)
+ open = Column(Double)
+ close = Column(Double)
+ high = Column(Double)
+ low = Column(Double)
+ previous_close = Column(Double)
+ turnover = Column(Double)
+ volume = Column(Integer)
+ price_change_amount = Column(Double)
+ factor = Column(Double)
+
+
+def main():
+ print("开始更新数据")
+
+ engine = create_engine(f"sqlite:////Users/lanyuanxiaoyao/Documents/leopard_data/leopard.sqlite")
+ try:
+ Stock.metadata.create_all(engine, checkfirst=True)
+ Daily.metadata.create_all(engine, checkfirst=True)
+ pro = pro_api(TUSHARE_API_KEY)
+ # with engine.connect() as connection:
+ # stocks = pro.stock_basic(list_status="L", market="主板", fields="ts_code,name,fullname,market,exchange,industry,list_date")
+ # for row in stocks.itertuples():
+ # stmt = insert(Stock).values(
+ # code=row.ts_code,
+ # name=row.name,
+ # fullname=row.fullname,
+ # market=row.market,
+ # exchange=row.exchange,
+ # industry=row.industry,
+ # list_date=row.list_date,
+ # )
+ # stmt = stmt.on_conflict_do_update(
+ # index_elements=["code"],
+ # set_={
+ # "name": stmt.excluded.name,
+ # "fullname": stmt.excluded.fullname,
+ # "market": stmt.excluded.market,
+ # "exchange": stmt.excluded.exchange,
+ # "industry": stmt.excluded.industry,
+ # "list_date": stmt.excluded.list_date,
+ # },
+ # )
+ # print(stmt)
+ # connection.execute(stmt)
+ # connection.commit()
+ #
+ # print("清理行情数据")
+ # connection.execute(text("delete from daily where code not in (select distinct code from stock)"))
+ # connection.commit()
+ #
+ # print("清理财务数据")
+ # connection.execute(text("delete from finance_indicator where code not in (select distinct code from stock)"))
+ # connection.commit()
+
+ with Session(engine) as session:
+ stock_codes = [row[0] for row in session.query(Stock.code).all()]
+
+ latest_date = session.query(Daily.trade_date).order_by(Daily.trade_date.desc()).first()
+ if latest_date is None:
+ latest_date = '1990-12-19'
+ else:
+ latest_date = latest_date.trade_date
+ latest_date = datetime.strptime(latest_date, '%Y-%m-%d').date()
+ current_date = date.today() - timedelta(days=1)
+ delta = (current_date - latest_date).days
+ print(f"最新数据日期:{latest_date},当前日期:{current_date},待更新天数:{delta}")
+ if delta > 0:
+ update_dates = []
+ for i in range(delta):
+ latest_date = latest_date + timedelta(days=1)
+ update_dates.append(latest_date.strftime('%Y%m%d'))
+ for target_date in update_dates:
+ print(f"正在采集:{target_date}")
+ dailies = pro.daily(trade_date=target_date)
+ dailies.set_index("ts_code", inplace=True)
+ factors = pro.adj_factor(trade_date=target_date)
+ factors.set_index("ts_code", inplace=True)
+ results = dailies.join(factors, lsuffix="_daily", rsuffix="_factor", how="left")
+ rows = []
+ for row in results.itertuples():
+ if row.Index in stock_codes:
+ rows.append(
+ Daily(
+ code=row.Index,
+ trade_date=datetime.strptime(target_date, '%Y%m%d').strftime("%Y-%m-%d"),
+ open=row.open,
+ close=row.close,
+ high=row.high,
+ low=row.low,
+ previous_close=row.pre_close,
+ turnover=row.amount,
+ volume=row.vol,
+ price_change_amount=row.pct_chg,
+ factor=row.adj_factor,
+ )
+ )
+ session.add_all(rows)
+ session.commit()
+ sleep(1)
+ finally:
+ engine.dispose()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/notebook/datasource/data.ipynb b/notebook/datasource/data.ipynb
new file mode 100644
index 0000000..a872a0a
--- /dev/null
+++ b/notebook/datasource/data.ipynb
@@ -0,0 +1,1300 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "id": "initial_id",
+ "metadata": {
+ "collapsed": true,
+ "ExecuteTime": {
+ "end_time": "2026-01-30T06:48:44.912513Z",
+ "start_time": "2026-01-30T06:48:44.785729Z"
+ }
+ },
+ "source": [
+ "import baostock as bs\n",
+ "import pandas as pd\n",
+ "\n",
+ "lg = bs.login()"
+ ],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "login success!\n"
+ ]
+ }
+ ],
+ "execution_count": 27
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2026-01-30T06:48:59.682551Z",
+ "start_time": "2026-01-30T06:48:59.515016Z"
+ }
+ },
+ "cell_type": "code",
+ "source": [
+ "rs = bs.query_history_k_data_plus(\n",
+ " \"sz.000001\",\n",
+ " \"date,code,open,high,low,close,preClose,volume,amount,turn,pctChg\",\n",
+ " start_date=\"1991-1-1\",\n",
+ " end_date=\"1992-1-1\",\n",
+ " adjustflag=\"1\",\n",
+ ")\n",
+ "data_list = []\n",
+ "while (rs.error_code == '0') & rs.next():\n",
+ " data_list.append(rs.get_row_data())\n",
+ "\n",
+ "df = pd.DataFrame(data_list, columns=rs.fields)\n",
+ "# df[\"code\"] = df.apply(lambda row: \".\".join(row[\"code\"].split(\".\")[::-1]).upper(), axis=1)\n",
+ "df"
+ ],
+ "id": "ed40fa92230584dc",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ " date code open high low \\\n",
+ "0 1991-04-03 sz.000001 49.0000000000 49.0000000000 49.0000000000 \n",
+ "1 1991-04-04 sz.000001 48.7600000000 48.7600000000 48.7600000000 \n",
+ "2 1991-04-05 sz.000001 48.5200000000 48.5200000000 48.5200000000 \n",
+ "3 1991-04-08 sz.000001 48.0400000000 48.0400000000 48.0400000000 \n",
+ "4 1991-04-09 sz.000001 47.8000000000 47.8000000000 47.8000000000 \n",
+ ".. ... ... ... ... ... \n",
+ "187 1991-12-25 sz.000001 42.5415391500 43.7820300000 42.4685691000 \n",
+ "188 1991-12-26 sz.000001 42.7604493000 42.7604493000 40.8632280000 \n",
+ "189 1991-12-27 sz.000001 40.8632280000 41.5929285000 40.8632280000 \n",
+ "190 1991-12-30 sz.000001 42.7604493000 42.9063894000 42.0307488000 \n",
+ "191 1991-12-31 sz.000001 42.0307488000 42.8334193500 42.0307488000 \n",
+ "\n",
+ " close preClose volume amount turn pctChg \n",
+ "0 49.0000000000 40.0000000000 100 4900.0000 0.000270 22.500000 \n",
+ "1 48.7600000000 49.0000000000 300 14628.0000 0.000809 -0.489799 \n",
+ "2 48.5200000000 48.7600000000 200 9704.0000 0.000539 -0.492202 \n",
+ "3 48.0400000000 48.2800000000 200 9608.0000 0.000539 -0.497100 \n",
+ "4 47.8000000000 48.0400000000 400 19120.0000 0.001078 -0.499587 \n",
+ ".. ... ... ... ... ... ... \n",
+ "187 42.7604493000 42.3955990500 226900 6702870.0000 0.470454 0.860585 \n",
+ "188 40.8632280000 42.7604493000 191800 5509610.0000 0.397678 -4.436858 \n",
+ "189 41.5199584500 40.8632280000 210500 5935400.0000 0.436450 1.607146 \n",
+ "190 42.0307488000 42.6874792500 105900 3093085.0000 0.219573 -1.538462 \n",
+ "191 42.8334193500 42.0307488000 75900 2203915.0000 0.152534 1.909726 \n",
+ "\n",
+ "[192 rows x 11 columns]"
+ ],
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " date | \n",
+ " code | \n",
+ " open | \n",
+ " high | \n",
+ " low | \n",
+ " close | \n",
+ " preClose | \n",
+ " volume | \n",
+ " amount | \n",
+ " turn | \n",
+ " pctChg | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1991-04-03 | \n",
+ " sz.000001 | \n",
+ " 49.0000000000 | \n",
+ " 49.0000000000 | \n",
+ " 49.0000000000 | \n",
+ " 49.0000000000 | \n",
+ " 40.0000000000 | \n",
+ " 100 | \n",
+ " 4900.0000 | \n",
+ " 0.000270 | \n",
+ " 22.500000 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 1991-04-04 | \n",
+ " sz.000001 | \n",
+ " 48.7600000000 | \n",
+ " 48.7600000000 | \n",
+ " 48.7600000000 | \n",
+ " 48.7600000000 | \n",
+ " 49.0000000000 | \n",
+ " 300 | \n",
+ " 14628.0000 | \n",
+ " 0.000809 | \n",
+ " -0.489799 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 1991-04-05 | \n",
+ " sz.000001 | \n",
+ " 48.5200000000 | \n",
+ " 48.5200000000 | \n",
+ " 48.5200000000 | \n",
+ " 48.5200000000 | \n",
+ " 48.7600000000 | \n",
+ " 200 | \n",
+ " 9704.0000 | \n",
+ " 0.000539 | \n",
+ " -0.492202 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 1991-04-08 | \n",
+ " sz.000001 | \n",
+ " 48.0400000000 | \n",
+ " 48.0400000000 | \n",
+ " 48.0400000000 | \n",
+ " 48.0400000000 | \n",
+ " 48.2800000000 | \n",
+ " 200 | \n",
+ " 9608.0000 | \n",
+ " 0.000539 | \n",
+ " -0.497100 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 1991-04-09 | \n",
+ " sz.000001 | \n",
+ " 47.8000000000 | \n",
+ " 47.8000000000 | \n",
+ " 47.8000000000 | \n",
+ " 47.8000000000 | \n",
+ " 48.0400000000 | \n",
+ " 400 | \n",
+ " 19120.0000 | \n",
+ " 0.001078 | \n",
+ " -0.499587 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 187 | \n",
+ " 1991-12-25 | \n",
+ " sz.000001 | \n",
+ " 42.5415391500 | \n",
+ " 43.7820300000 | \n",
+ " 42.4685691000 | \n",
+ " 42.7604493000 | \n",
+ " 42.3955990500 | \n",
+ " 226900 | \n",
+ " 6702870.0000 | \n",
+ " 0.470454 | \n",
+ " 0.860585 | \n",
+ "
\n",
+ " \n",
+ " | 188 | \n",
+ " 1991-12-26 | \n",
+ " sz.000001 | \n",
+ " 42.7604493000 | \n",
+ " 42.7604493000 | \n",
+ " 40.8632280000 | \n",
+ " 40.8632280000 | \n",
+ " 42.7604493000 | \n",
+ " 191800 | \n",
+ " 5509610.0000 | \n",
+ " 0.397678 | \n",
+ " -4.436858 | \n",
+ "
\n",
+ " \n",
+ " | 189 | \n",
+ " 1991-12-27 | \n",
+ " sz.000001 | \n",
+ " 40.8632280000 | \n",
+ " 41.5929285000 | \n",
+ " 40.8632280000 | \n",
+ " 41.5199584500 | \n",
+ " 40.8632280000 | \n",
+ " 210500 | \n",
+ " 5935400.0000 | \n",
+ " 0.436450 | \n",
+ " 1.607146 | \n",
+ "
\n",
+ " \n",
+ " | 190 | \n",
+ " 1991-12-30 | \n",
+ " sz.000001 | \n",
+ " 42.7604493000 | \n",
+ " 42.9063894000 | \n",
+ " 42.0307488000 | \n",
+ " 42.0307488000 | \n",
+ " 42.6874792500 | \n",
+ " 105900 | \n",
+ " 3093085.0000 | \n",
+ " 0.219573 | \n",
+ " -1.538462 | \n",
+ "
\n",
+ " \n",
+ " | 191 | \n",
+ " 1991-12-31 | \n",
+ " sz.000001 | \n",
+ " 42.0307488000 | \n",
+ " 42.8334193500 | \n",
+ " 42.0307488000 | \n",
+ " 42.8334193500 | \n",
+ " 42.0307488000 | \n",
+ " 75900 | \n",
+ " 2203915.0000 | \n",
+ " 0.152534 | \n",
+ " 1.909726 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
192 rows × 11 columns
\n",
+ "
"
+ ]
+ },
+ "execution_count": 30,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "execution_count": 30
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2026-01-30T06:51:04.154374Z",
+ "start_time": "2026-01-30T06:51:04.096340Z"
+ }
+ },
+ "cell_type": "code",
+ "source": [
+ "for year in range(1990, 2025):\n",
+ " print(year)"
+ ],
+ "id": "cbb28b1f4857259e",
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "1990\n",
+ "1991\n",
+ "1992\n",
+ "1993\n",
+ "1994\n",
+ "1995\n",
+ "1996\n",
+ "1997\n",
+ "1998\n",
+ "1999\n",
+ "2000\n",
+ "2001\n",
+ "2002\n",
+ "2003\n",
+ "2004\n",
+ "2005\n",
+ "2006\n",
+ "2007\n",
+ "2008\n",
+ "2009\n",
+ "2010\n",
+ "2011\n",
+ "2012\n",
+ "2013\n",
+ "2014\n",
+ "2015\n",
+ "2016\n",
+ "2017\n",
+ "2018\n",
+ "2019\n",
+ "2020\n",
+ "2021\n",
+ "2022\n",
+ "2023\n",
+ "2024\n"
+ ]
+ }
+ ],
+ "execution_count": 31
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2026-01-30T02:30:18.416075Z",
+ "start_time": "2026-01-30T02:30:18.255416Z"
+ }
+ },
+ "cell_type": "code",
+ "source": [
+ "rs = bs.query_stock_basic(code=\"sz.000001\")\n",
+ "data_list = []\n",
+ "while (rs.error_code == '0') & rs.next():\n",
+ " data_list.append(rs.get_row_data())\n",
+ "df = pd.DataFrame(data_list, columns=rs.fields)\n",
+ "df"
+ ],
+ "id": "3eb9e1033b4360ed",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ " code code_name ipoDate outDate type status\n",
+ "0 sz.000001 平安银行 1991-04-03 1 1"
+ ],
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " code | \n",
+ " code_name | \n",
+ " ipoDate | \n",
+ " outDate | \n",
+ " type | \n",
+ " status | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " sz.000001 | \n",
+ " 平安银行 | \n",
+ " 1991-04-03 | \n",
+ " | \n",
+ " 1 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "execution_count": 8
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2026-01-30T02:17:09.614916Z",
+ "start_time": "2026-01-30T02:16:48.773160Z"
+ }
+ },
+ "cell_type": "code",
+ "source": [
+ "import adata\n",
+ "\n",
+ "adata.stock.info.all_code()"
+ ],
+ "id": "93a1d7caffc916c",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ " stock_code short_name exchange list_date\n",
+ "0 000001 平安银行 SZ 1991-04-03\n",
+ "1 000002 万科A SZ 1991-01-29\n",
+ "2 000003 PT金田A SZ NaN\n",
+ "3 000004 *ST国华 SZ 1990-12-01\n",
+ "4 000005 ST星源 SZ 1990-12-10\n",
+ "... ... ... ... ...\n",
+ "5759 920978 开特股份 BJ 2023-09-28\n",
+ "5760 920981 晶赛科技 BJ 2021-11-15\n",
+ "5761 920982 锦波生物 BJ 2023-07-20\n",
+ "5762 920985 海泰新能 BJ 2022-08-08\n",
+ "5763 920992 中科美菱 BJ 2022-10-18\n",
+ "\n",
+ "[5764 rows x 4 columns]"
+ ],
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " stock_code | \n",
+ " short_name | \n",
+ " exchange | \n",
+ " list_date | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 000001 | \n",
+ " 平安银行 | \n",
+ " SZ | \n",
+ " 1991-04-03 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 000002 | \n",
+ " 万科A | \n",
+ " SZ | \n",
+ " 1991-01-29 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 000003 | \n",
+ " PT金田A | \n",
+ " SZ | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 000004 | \n",
+ " *ST国华 | \n",
+ " SZ | \n",
+ " 1990-12-01 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 000005 | \n",
+ " ST星源 | \n",
+ " SZ | \n",
+ " 1990-12-10 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 5759 | \n",
+ " 920978 | \n",
+ " 开特股份 | \n",
+ " BJ | \n",
+ " 2023-09-28 | \n",
+ "
\n",
+ " \n",
+ " | 5760 | \n",
+ " 920981 | \n",
+ " 晶赛科技 | \n",
+ " BJ | \n",
+ " 2021-11-15 | \n",
+ "
\n",
+ " \n",
+ " | 5761 | \n",
+ " 920982 | \n",
+ " 锦波生物 | \n",
+ " BJ | \n",
+ " 2023-07-20 | \n",
+ "
\n",
+ " \n",
+ " | 5762 | \n",
+ " 920985 | \n",
+ " 海泰新能 | \n",
+ " BJ | \n",
+ " 2022-08-08 | \n",
+ "
\n",
+ " \n",
+ " | 5763 | \n",
+ " 920992 | \n",
+ " 中科美菱 | \n",
+ " BJ | \n",
+ " 2022-10-18 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
5764 rows × 4 columns
\n",
+ "
"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "execution_count": 2
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2026-01-30T02:23:11.398502Z",
+ "start_time": "2026-01-30T02:23:11.257663Z"
+ }
+ },
+ "cell_type": "code",
+ "source": "adata.stock.market.get_market(stock_code='000001', start_date='2025-01-01', end_date='2025-12-31', adjust_type=0)",
+ "id": "c716caf5e7157b4f",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ " stock_code trade_time trade_date open close high low \\\n",
+ "0 000001 2025-01-02 00:00:00 2025-01-02 11.73 11.43 11.77 11.39 \n",
+ "1 000001 2025-01-03 00:00:00 2025-01-03 11.44 11.38 11.54 11.36 \n",
+ "2 000001 2025-01-06 00:00:00 2025-01-06 11.38 11.44 11.48 11.22 \n",
+ "3 000001 2025-01-07 00:00:00 2025-01-07 11.42 11.51 11.53 11.37 \n",
+ "4 000001 2025-01-08 00:00:00 2025-01-08 11.50 11.50 11.63 11.40 \n",
+ ".. ... ... ... ... ... ... ... \n",
+ "238 000001 2025-12-25 00:00:00 2025-12-25 11.54 11.56 11.62 11.52 \n",
+ "239 000001 2025-12-26 00:00:00 2025-12-26 11.56 11.54 11.59 11.53 \n",
+ "240 000001 2025-12-29 00:00:00 2025-12-29 11.54 11.56 11.62 11.50 \n",
+ "241 000001 2025-12-30 00:00:00 2025-12-30 11.53 11.48 11.56 11.45 \n",
+ "242 000001 2025-12-31 00:00:00 2025-12-31 11.48 11.41 11.49 11.40 \n",
+ "\n",
+ " volume amount change_pct change turnover_ratio pre_close \n",
+ "0 181959700 2.102923e+09 -2.31 -0.27 0.94 11.70 \n",
+ "1 115468000 1.320521e+09 -0.44 -0.05 0.60 11.43 \n",
+ "2 108553600 1.234306e+09 0.53 0.06 0.56 11.38 \n",
+ "3 74786300 8.583290e+08 0.61 0.07 0.39 11.44 \n",
+ "4 106238600 1.223599e+09 -0.09 -0.01 0.55 11.51 \n",
+ ".. ... ... ... ... ... ... \n",
+ "238 54745500 6.337726e+08 0.17 0.02 0.28 11.54 \n",
+ "239 43634000 5.040793e+08 -0.17 -0.02 0.22 11.56 \n",
+ "240 64829500 7.490830e+08 0.17 0.02 0.33 11.54 \n",
+ "241 58258400 6.694093e+08 -0.69 -0.08 0.30 11.56 \n",
+ "242 59062000 6.754574e+08 -0.61 -0.07 0.30 11.48 \n",
+ "\n",
+ "[243 rows x 13 columns]"
+ ],
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " stock_code | \n",
+ " trade_time | \n",
+ " trade_date | \n",
+ " open | \n",
+ " close | \n",
+ " high | \n",
+ " low | \n",
+ " volume | \n",
+ " amount | \n",
+ " change_pct | \n",
+ " change | \n",
+ " turnover_ratio | \n",
+ " pre_close | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 000001 | \n",
+ " 2025-01-02 00:00:00 | \n",
+ " 2025-01-02 | \n",
+ " 11.73 | \n",
+ " 11.43 | \n",
+ " 11.77 | \n",
+ " 11.39 | \n",
+ " 181959700 | \n",
+ " 2.102923e+09 | \n",
+ " -2.31 | \n",
+ " -0.27 | \n",
+ " 0.94 | \n",
+ " 11.70 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 000001 | \n",
+ " 2025-01-03 00:00:00 | \n",
+ " 2025-01-03 | \n",
+ " 11.44 | \n",
+ " 11.38 | \n",
+ " 11.54 | \n",
+ " 11.36 | \n",
+ " 115468000 | \n",
+ " 1.320521e+09 | \n",
+ " -0.44 | \n",
+ " -0.05 | \n",
+ " 0.60 | \n",
+ " 11.43 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 000001 | \n",
+ " 2025-01-06 00:00:00 | \n",
+ " 2025-01-06 | \n",
+ " 11.38 | \n",
+ " 11.44 | \n",
+ " 11.48 | \n",
+ " 11.22 | \n",
+ " 108553600 | \n",
+ " 1.234306e+09 | \n",
+ " 0.53 | \n",
+ " 0.06 | \n",
+ " 0.56 | \n",
+ " 11.38 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 000001 | \n",
+ " 2025-01-07 00:00:00 | \n",
+ " 2025-01-07 | \n",
+ " 11.42 | \n",
+ " 11.51 | \n",
+ " 11.53 | \n",
+ " 11.37 | \n",
+ " 74786300 | \n",
+ " 8.583290e+08 | \n",
+ " 0.61 | \n",
+ " 0.07 | \n",
+ " 0.39 | \n",
+ " 11.44 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 000001 | \n",
+ " 2025-01-08 00:00:00 | \n",
+ " 2025-01-08 | \n",
+ " 11.50 | \n",
+ " 11.50 | \n",
+ " 11.63 | \n",
+ " 11.40 | \n",
+ " 106238600 | \n",
+ " 1.223599e+09 | \n",
+ " -0.09 | \n",
+ " -0.01 | \n",
+ " 0.55 | \n",
+ " 11.51 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 238 | \n",
+ " 000001 | \n",
+ " 2025-12-25 00:00:00 | \n",
+ " 2025-12-25 | \n",
+ " 11.54 | \n",
+ " 11.56 | \n",
+ " 11.62 | \n",
+ " 11.52 | \n",
+ " 54745500 | \n",
+ " 6.337726e+08 | \n",
+ " 0.17 | \n",
+ " 0.02 | \n",
+ " 0.28 | \n",
+ " 11.54 | \n",
+ "
\n",
+ " \n",
+ " | 239 | \n",
+ " 000001 | \n",
+ " 2025-12-26 00:00:00 | \n",
+ " 2025-12-26 | \n",
+ " 11.56 | \n",
+ " 11.54 | \n",
+ " 11.59 | \n",
+ " 11.53 | \n",
+ " 43634000 | \n",
+ " 5.040793e+08 | \n",
+ " -0.17 | \n",
+ " -0.02 | \n",
+ " 0.22 | \n",
+ " 11.56 | \n",
+ "
\n",
+ " \n",
+ " | 240 | \n",
+ " 000001 | \n",
+ " 2025-12-29 00:00:00 | \n",
+ " 2025-12-29 | \n",
+ " 11.54 | \n",
+ " 11.56 | \n",
+ " 11.62 | \n",
+ " 11.50 | \n",
+ " 64829500 | \n",
+ " 7.490830e+08 | \n",
+ " 0.17 | \n",
+ " 0.02 | \n",
+ " 0.33 | \n",
+ " 11.54 | \n",
+ "
\n",
+ " \n",
+ " | 241 | \n",
+ " 000001 | \n",
+ " 2025-12-30 00:00:00 | \n",
+ " 2025-12-30 | \n",
+ " 11.53 | \n",
+ " 11.48 | \n",
+ " 11.56 | \n",
+ " 11.45 | \n",
+ " 58258400 | \n",
+ " 6.694093e+08 | \n",
+ " -0.69 | \n",
+ " -0.08 | \n",
+ " 0.30 | \n",
+ " 11.56 | \n",
+ "
\n",
+ " \n",
+ " | 242 | \n",
+ " 000001 | \n",
+ " 2025-12-31 00:00:00 | \n",
+ " 2025-12-31 | \n",
+ " 11.48 | \n",
+ " 11.41 | \n",
+ " 11.49 | \n",
+ " 11.40 | \n",
+ " 59062000 | \n",
+ " 6.754574e+08 | \n",
+ " -0.61 | \n",
+ " -0.07 | \n",
+ " 0.30 | \n",
+ " 11.48 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
243 rows × 13 columns
\n",
+ "
"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "execution_count": 6
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2026-01-30T07:20:29.946256Z",
+ "start_time": "2026-01-30T07:20:29.785116Z"
+ }
+ },
+ "cell_type": "code",
+ "source": [
+ "import akshare as ak\n",
+ "\n",
+ "ak.stock_individual_info_em(symbol='600000')"
+ ],
+ "id": "f7667bf80cc8c02",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ " item value\n",
+ "0 最新 10.04\n",
+ "1 股票代码 600000\n",
+ "2 股票简称 浦发银行\n",
+ "3 总股本 33305838300.0\n",
+ "4 流通股 33305838300.0\n",
+ "5 总市值 334390616532.0\n",
+ "6 流通市值 334390616532.0\n",
+ "7 行业 银行\n",
+ "8 上市时间 19991110"
+ ],
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " item | \n",
+ " value | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 最新 | \n",
+ " 10.04 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 股票代码 | \n",
+ " 600000 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 股票简称 | \n",
+ " 浦发银行 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 总股本 | \n",
+ " 33305838300.0 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 流通股 | \n",
+ " 33305838300.0 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " 总市值 | \n",
+ " 334390616532.0 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " 流通市值 | \n",
+ " 334390616532.0 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " 行业 | \n",
+ " 银行 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " 上市时间 | \n",
+ " 19991110 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ]
+ },
+ "execution_count": 38,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "execution_count": 38
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2026-01-30T07:23:53.711254Z",
+ "start_time": "2026-01-30T07:23:53.490571Z"
+ }
+ },
+ "cell_type": "code",
+ "source": "ak.stock_individual_basic_info_xq(symbol='SH600005')",
+ "id": "d58638d8a8b269e7",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ " item \\\n",
+ "0 org_id \n",
+ "1 org_name_cn \n",
+ "2 org_short_name_cn \n",
+ "3 org_name_en \n",
+ "4 org_short_name_en \n",
+ "5 main_operation_business \n",
+ "6 operating_scope \n",
+ "7 district_encode \n",
+ "8 org_cn_introduction \n",
+ "9 legal_representative \n",
+ "10 general_manager \n",
+ "11 secretary \n",
+ "12 established_date \n",
+ "13 reg_asset \n",
+ "14 staff_num \n",
+ "15 telephone \n",
+ "16 postcode \n",
+ "17 fax \n",
+ "18 email \n",
+ "19 org_website \n",
+ "20 reg_address_cn \n",
+ "21 reg_address_en \n",
+ "22 office_address_cn \n",
+ "23 office_address_en \n",
+ "24 currency_encode \n",
+ "25 currency \n",
+ "26 listed_date \n",
+ "27 provincial_name \n",
+ "28 actual_controller \n",
+ "29 classi_name \n",
+ "30 pre_name_cn \n",
+ "31 chairman \n",
+ "32 executives_nums \n",
+ "33 actual_issue_vol \n",
+ "34 issue_price \n",
+ "35 actual_rc_net_amt \n",
+ "36 pe_after_issuing \n",
+ "37 online_success_rate_of_issue \n",
+ "38 affiliate_industry \n",
+ "\n",
+ " value \n",
+ "0 02600005 \n",
+ "1 武汉钢铁股份有限公司 \n",
+ "2 武钢股份 \n",
+ "3 Wuhan Iron And Steel Company Limited \n",
+ "4 WISCO,Ltd. \n",
+ "5 冶金产品及副产品、钢铁延伸产品制造及冶金产品的技术开发 \n",
+ "6 冶金产品及副产品、钢铁延伸产品制造;冶金产品的技术开发;钢铁及副产品的销售;货物进出口、... \n",
+ "7 420107 \n",
+ "8 武汉钢铁股份有限公司是由武汉钢铁集团公司控股的、国内第二大钢铁上市公司.是一家主要经营钢铁生... \n",
+ "9 马国强 \n",
+ "10 邹继新 \n",
+ "11 李海涛 \n",
+ "12 878832000000 \n",
+ "13 10093780000.0 \n",
+ "14 27328 \n",
+ "15 86-27-86217195 \n",
+ "16 430083 \n",
+ "17 86-27-86217296 \n",
+ "18 wiscl@wisco.com.cn \n",
+ "19 www.wisco.com.cn \n",
+ "20 湖北省武汉市青山区厂前街(青山区股份公司机关) \n",
+ "21 None \n",
+ "22 湖北省武汉市青山区厂前武钢2号门 \n",
+ "23 None \n",
+ "24 019001 \n",
+ "25 CNY \n",
+ "26 933609600000 \n",
+ "27 湖北省 \n",
+ "28 国务院国有资产监督管理委员会 (52.76%) \n",
+ "29 央企国资控股 \n",
+ "30 None \n",
+ "31 邹继新 \n",
+ "32 5 \n",
+ "33 320000000.0 \n",
+ "34 4.3 \n",
+ "35 1349051600.0 \n",
+ "36 14.1 \n",
+ "37 4.923 \n",
+ "38 None "
+ ],
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " item | \n",
+ " value | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " org_id | \n",
+ " 02600005 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " org_name_cn | \n",
+ " 武汉钢铁股份有限公司 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " org_short_name_cn | \n",
+ " 武钢股份 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " org_name_en | \n",
+ " Wuhan Iron And Steel Company Limited | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " org_short_name_en | \n",
+ " WISCO,Ltd. | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " main_operation_business | \n",
+ " 冶金产品及副产品、钢铁延伸产品制造及冶金产品的技术开发 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " operating_scope | \n",
+ " 冶金产品及副产品、钢铁延伸产品制造;冶金产品的技术开发;钢铁及副产品的销售;货物进出口、... | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " district_encode | \n",
+ " 420107 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " org_cn_introduction | \n",
+ " 武汉钢铁股份有限公司是由武汉钢铁集团公司控股的、国内第二大钢铁上市公司.是一家主要经营钢铁生... | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " legal_representative | \n",
+ " 马国强 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " general_manager | \n",
+ " 邹继新 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " secretary | \n",
+ " 李海涛 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " established_date | \n",
+ " 878832000000 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " reg_asset | \n",
+ " 10093780000.0 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " staff_num | \n",
+ " 27328 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " telephone | \n",
+ " 86-27-86217195 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " postcode | \n",
+ " 430083 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " fax | \n",
+ " 86-27-86217296 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " email | \n",
+ " wiscl@wisco.com.cn | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " org_website | \n",
+ " www.wisco.com.cn | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " reg_address_cn | \n",
+ " 湖北省武汉市青山区厂前街(青山区股份公司机关) | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " reg_address_en | \n",
+ " None | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " office_address_cn | \n",
+ " 湖北省武汉市青山区厂前武钢2号门 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " office_address_en | \n",
+ " None | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " currency_encode | \n",
+ " 019001 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " currency | \n",
+ " CNY | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " listed_date | \n",
+ " 933609600000 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " provincial_name | \n",
+ " 湖北省 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " actual_controller | \n",
+ " 国务院国有资产监督管理委员会 (52.76%) | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " classi_name | \n",
+ " 央企国资控股 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " pre_name_cn | \n",
+ " None | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " chairman | \n",
+ " 邹继新 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " executives_nums | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " actual_issue_vol | \n",
+ " 320000000.0 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " issue_price | \n",
+ " 4.3 | \n",
+ "
\n",
+ " \n",
+ " | 35 | \n",
+ " actual_rc_net_amt | \n",
+ " 1349051600.0 | \n",
+ "
\n",
+ " \n",
+ " | 36 | \n",
+ " pe_after_issuing | \n",
+ " 14.1 | \n",
+ "
\n",
+ " \n",
+ " | 37 | \n",
+ " online_success_rate_of_issue | \n",
+ " 4.923 | \n",
+ "
\n",
+ " \n",
+ " | 38 | \n",
+ " affiliate_industry | \n",
+ " None | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ]
+ },
+ "execution_count": 41,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "execution_count": 41
+ },
+ {
+ "metadata": {},
+ "cell_type": "code",
+ "outputs": [],
+ "execution_count": null,
+ "source": "",
+ "id": "f624320cab54d22"
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 2
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython2",
+ "version": "2.7.6"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/notebook/datasource/data_old.ipynb b/notebook/datasource/data_old.ipynb
index 0c8dad1..b65522a 100644
--- a/notebook/datasource/data_old.ipynb
+++ b/notebook/datasource/data_old.ipynb
@@ -3,8 +3,8 @@
{
"metadata": {
"ExecuteTime": {
- "end_time": "2026-01-29T10:09:22.171634Z",
- "start_time": "2026-01-29T08:27:03.148937Z"
+ "end_time": "2026-01-30T05:41:51.291397Z",
+ "start_time": "2026-01-30T04:34:22.917761Z"
}
},
"cell_type": "code",
@@ -13,6 +13,7 @@
"\n",
"import pandas as pd\n",
"import sqlalchemy\n",
+ "from sqlalchemy import text\n",
"from sqlalchemy.orm import DeclarativeBase, Session\n",
"\n",
"postgresql_engin = sqlalchemy.create_engine(\n",
@@ -29,7 +30,7 @@
" __tablename__ = 'daily'\n",
"\n",
" code = sqlalchemy.Column(sqlalchemy.String, primary_key=True)\n",
- " trade_date = sqlalchemy.Column(sqlalchemy.Date)\n",
+ " trade_date = sqlalchemy.Column(sqlalchemy.Date, primary_key=True)\n",
" open = sqlalchemy.Column(sqlalchemy.Double)\n",
" close = sqlalchemy.Column(sqlalchemy.Double)\n",
" high = sqlalchemy.Column(sqlalchemy.Double)\n",
@@ -42,47 +43,52 @@
"\n",
"\n",
"try:\n",
- " stock_df = pd.read_sql_table(\"stock\", sqlite_engine)\n",
- " for index, code in enumerate(stock_df[\"code\"]):\n",
- " print(code)\n",
- " daily_df = pd.read_sql(\n",
- " f\"\"\"\n",
- " select code,\n",
- " trade_date,\n",
- " open,\n",
- " close,\n",
- " high,\n",
- " low,\n",
- " previous_close,\n",
- " turnover,\n",
- " volume,\n",
- " price_change_amount,\n",
- " factor\n",
- " from leopard_daily d\n",
- " left join leopard_stock s on d.stock_id = s.id\n",
- " where s.code = '{code}'\n",
- " \"\"\",\n",
- " postgresql_engin\n",
- " )\n",
- " with Session(sqlite_engine) as session:\n",
- " for _, row in daily_df.iterrows():\n",
- " session.add(\n",
- " Daily(\n",
- " code=row[\"code\"],\n",
- " trade_date=row[\"trade_date\"],\n",
- " open=row[\"open\"],\n",
- " close=row[\"close\"],\n",
- " high=row[\"high\"],\n",
- " low=row[\"low\"],\n",
- " previous_close=row[\"previous_close\"],\n",
- " turnover=row[\"turnover\"],\n",
- " volume=row[\"volume\"],\n",
- " price_change_amount=row[\"price_change_amount\"],\n",
- " factor=row[\"factor\"]\n",
+ " with Session(postgresql_engin) as pg_session:\n",
+ " results = pg_session.execute(text(\"select distinct trade_date from leopard_daily\")).fetchall()\n",
+ " results = list(map(lambda x: x[0].strftime(\"%Y-%m-%d\"), results))\n",
+ " dates = [results[i: i + 30] for i in range(0, len(results), 30)]\n",
+ "\n",
+ " for index, date in enumerate(dates):\n",
+ " print(date)\n",
+ " daily_df = pd.read_sql(\n",
+ " f\"\"\"\n",
+ " select code,\n",
+ " trade_date,\n",
+ " open,\n",
+ " close,\n",
+ " high,\n",
+ " low,\n",
+ " previous_close,\n",
+ " turnover,\n",
+ " volume,\n",
+ " price_change_amount,\n",
+ " factor\n",
+ " from leopard_daily d\n",
+ " left join leopard_stock s on d.stock_id = s.id\n",
+ " where d.trade_date in ('{\"','\".join(date)}')\n",
+ " \"\"\",\n",
+ " postgresql_engin\n",
+ " )\n",
+ " with Session(sqlite_engine) as session:\n",
+ " rows = []\n",
+ " for _, row in daily_df.iterrows():\n",
+ " rows.append(\n",
+ " Daily(\n",
+ " code=row[\"code\"],\n",
+ " trade_date=row[\"trade_date\"],\n",
+ " open=row[\"open\"],\n",
+ " close=row[\"close\"],\n",
+ " high=row[\"high\"],\n",
+ " low=row[\"low\"],\n",
+ " previous_close=row[\"previous_close\"],\n",
+ " turnover=row[\"turnover\"],\n",
+ " volume=row[\"volume\"],\n",
+ " price_change_amount=row[\"price_change_amount\"],\n",
+ " factor=row[\"factor\"]\n",
+ " )\n",
" )\n",
- " )\n",
- " session.flush()\n",
- " session.commit()\n",
+ " session.add_all(rows)\n",
+ " session.commit()\n",
"finally:\n",
" postgresql_engin.dispose()\n",
" sqlite_engine.dispose()"
@@ -90,28 +96,339 @@
"id": "48821306efc640a1",
"outputs": [
{
- "ename": "KeyboardInterrupt",
- "evalue": "",
- "output_type": "error",
- "traceback": [
- "\u001B[31m---------------------------------------------------------------------------\u001B[39m",
- "\u001B[31mKeyboardInterrupt\u001B[39m Traceback (most recent call last)",
- "\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[26]\u001B[39m\u001B[32m, line 37\u001B[39m\n\u001B[32m 35\u001B[39m \u001B[38;5;28;01mfor\u001B[39;00m index, code \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28menumerate\u001B[39m(stock_df[\u001B[33m\"\u001B[39m\u001B[33mcode\u001B[39m\u001B[33m\"\u001B[39m]):\n\u001B[32m 36\u001B[39m \u001B[38;5;28mprint\u001B[39m(code)\n\u001B[32m---> \u001B[39m\u001B[32m37\u001B[39m daily_df = \u001B[43mpd\u001B[49m\u001B[43m.\u001B[49m\u001B[43mread_sql\u001B[49m\u001B[43m(\u001B[49m\n\u001B[32m 38\u001B[39m \u001B[43m \u001B[49m\u001B[33;43mf\u001B[39;49m\u001B[33;43m\"\"\"\u001B[39;49m\n\u001B[32m 39\u001B[39m \u001B[33;43m select code,\u001B[39;49m\n\u001B[32m 40\u001B[39m \u001B[33;43m trade_date,\u001B[39;49m\n\u001B[32m 41\u001B[39m \u001B[33;43m open,\u001B[39;49m\n\u001B[32m 42\u001B[39m \u001B[33;43m close,\u001B[39;49m\n\u001B[32m 43\u001B[39m \u001B[33;43m high,\u001B[39;49m\n\u001B[32m 44\u001B[39m \u001B[33;43m low,\u001B[39;49m\n\u001B[32m 45\u001B[39m \u001B[33;43m previous_close,\u001B[39;49m\n\u001B[32m 46\u001B[39m \u001B[33;43m turnover,\u001B[39;49m\n\u001B[32m 47\u001B[39m \u001B[33;43m volume,\u001B[39;49m\n\u001B[32m 48\u001B[39m \u001B[33;43m price_change_amount,\u001B[39;49m\n\u001B[32m 49\u001B[39m \u001B[33;43m factor\u001B[39;49m\n\u001B[32m 50\u001B[39m \u001B[33;43m from leopard_daily d\u001B[39;49m\n\u001B[32m 51\u001B[39m \u001B[33;43m left join leopard_stock s on d.stock_id = s.id\u001B[39;49m\n\u001B[32m 52\u001B[39m \u001B[33;43m where s.code = \u001B[39;49m\u001B[33;43m'\u001B[39;49m\u001B[38;5;132;43;01m{\u001B[39;49;00m\u001B[43mcode\u001B[49m\u001B[38;5;132;43;01m}\u001B[39;49;00m\u001B[33;43m'\u001B[39;49m\n\u001B[32m 53\u001B[39m \u001B[33;43m \u001B[39;49m\u001B[33;43m\"\"\"\u001B[39;49m\u001B[43m,\u001B[49m\n\u001B[32m 54\u001B[39m \u001B[43m \u001B[49m\u001B[43mpostgresql_engin\u001B[49m\n\u001B[32m 55\u001B[39m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m 56\u001B[39m \u001B[38;5;28;01mwith\u001B[39;00m Session(sqlite_engine) \u001B[38;5;28;01mas\u001B[39;00m session:\n\u001B[32m 57\u001B[39m \u001B[38;5;28;01mfor\u001B[39;00m _, row \u001B[38;5;129;01min\u001B[39;00m daily_df.iterrows():\n",
- "\u001B[36mFile \u001B[39m\u001B[32m~/Project/leopard_analysis/.venv/lib/python3.14/site-packages/pandas/io/sql.py:736\u001B[39m, in \u001B[36mread_sql\u001B[39m\u001B[34m(sql, con, index_col, coerce_float, params, parse_dates, columns, chunksize, dtype_backend, dtype)\u001B[39m\n\u001B[32m 726\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m pandas_sql.read_table(\n\u001B[32m 727\u001B[39m sql,\n\u001B[32m 728\u001B[39m index_col=index_col,\n\u001B[32m (...)\u001B[39m\u001B[32m 733\u001B[39m dtype_backend=dtype_backend,\n\u001B[32m 734\u001B[39m )\n\u001B[32m 735\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[32m--> \u001B[39m\u001B[32m736\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mpandas_sql\u001B[49m\u001B[43m.\u001B[49m\u001B[43mread_query\u001B[49m\u001B[43m(\u001B[49m\n\u001B[32m 737\u001B[39m \u001B[43m \u001B[49m\u001B[43msql\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 738\u001B[39m \u001B[43m \u001B[49m\u001B[43mindex_col\u001B[49m\u001B[43m=\u001B[49m\u001B[43mindex_col\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 739\u001B[39m \u001B[43m \u001B[49m\u001B[43mparams\u001B[49m\u001B[43m=\u001B[49m\u001B[43mparams\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 740\u001B[39m \u001B[43m \u001B[49m\u001B[43mcoerce_float\u001B[49m\u001B[43m=\u001B[49m\u001B[43mcoerce_float\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 741\u001B[39m \u001B[43m \u001B[49m\u001B[43mparse_dates\u001B[49m\u001B[43m=\u001B[49m\u001B[43mparse_dates\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 742\u001B[39m \u001B[43m \u001B[49m\u001B[43mchunksize\u001B[49m\u001B[43m=\u001B[49m\u001B[43mchunksize\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 743\u001B[39m \u001B[43m \u001B[49m\u001B[43mdtype_backend\u001B[49m\u001B[43m=\u001B[49m\u001B[43mdtype_backend\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 744\u001B[39m \u001B[43m \u001B[49m\u001B[43mdtype\u001B[49m\u001B[43m=\u001B[49m\u001B[43mdtype\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 745\u001B[39m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n",
- "\u001B[36mFile \u001B[39m\u001B[32m~/Project/leopard_analysis/.venv/lib/python3.14/site-packages/pandas/io/sql.py:1848\u001B[39m, in \u001B[36mSQLDatabase.read_query\u001B[39m\u001B[34m(self, sql, index_col, coerce_float, parse_dates, params, chunksize, dtype, dtype_backend)\u001B[39m\n\u001B[32m 1791\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mread_query\u001B[39m(\n\u001B[32m 1792\u001B[39m \u001B[38;5;28mself\u001B[39m,\n\u001B[32m 1793\u001B[39m sql: \u001B[38;5;28mstr\u001B[39m,\n\u001B[32m (...)\u001B[39m\u001B[32m 1800\u001B[39m dtype_backend: DtypeBackend | Literal[\u001B[33m\"\u001B[39m\u001B[33mnumpy\u001B[39m\u001B[33m\"\u001B[39m] = \u001B[33m\"\u001B[39m\u001B[33mnumpy\u001B[39m\u001B[33m\"\u001B[39m,\n\u001B[32m 1801\u001B[39m ) -> DataFrame | Iterator[DataFrame]:\n\u001B[32m 1802\u001B[39m \u001B[38;5;250m \u001B[39m\u001B[33;03m\"\"\"\u001B[39;00m\n\u001B[32m 1803\u001B[39m \u001B[33;03m Read SQL query into a DataFrame.\u001B[39;00m\n\u001B[32m 1804\u001B[39m \n\u001B[32m (...)\u001B[39m\u001B[32m 1846\u001B[39m \n\u001B[32m 1847\u001B[39m \u001B[33;03m \"\"\"\u001B[39;00m\n\u001B[32m-> \u001B[39m\u001B[32m1848\u001B[39m result = \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mexecute\u001B[49m\u001B[43m(\u001B[49m\u001B[43msql\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mparams\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m 1849\u001B[39m columns = result.keys()\n\u001B[32m 1851\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m chunksize \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n",
- "\u001B[36mFile \u001B[39m\u001B[32m~/Project/leopard_analysis/.venv/lib/python3.14/site-packages/pandas/io/sql.py:1671\u001B[39m, in \u001B[36mSQLDatabase.execute\u001B[39m\u001B[34m(self, sql, params)\u001B[39m\n\u001B[32m 1669\u001B[39m args = [] \u001B[38;5;28;01mif\u001B[39;00m params \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;28;01melse\u001B[39;00m [params]\n\u001B[32m 1670\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(sql, \u001B[38;5;28mstr\u001B[39m):\n\u001B[32m-> \u001B[39m\u001B[32m1671\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mcon\u001B[49m\u001B[43m.\u001B[49m\u001B[43mexec_driver_sql\u001B[49m\u001B[43m(\u001B[49m\u001B[43msql\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43m*\u001B[49m\u001B[43margs\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m 1672\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m.con.execute(sql, *args)\n",
- "\u001B[36mFile \u001B[39m\u001B[32m~/Project/leopard_analysis/.venv/lib/python3.14/site-packages/sqlalchemy/engine/base.py:1779\u001B[39m, in \u001B[36mConnection.exec_driver_sql\u001B[39m\u001B[34m(self, statement, parameters, execution_options)\u001B[39m\n\u001B[32m 1774\u001B[39m execution_options = \u001B[38;5;28mself\u001B[39m._execution_options.merge_with(\n\u001B[32m 1775\u001B[39m execution_options\n\u001B[32m 1776\u001B[39m )\n\u001B[32m 1778\u001B[39m dialect = \u001B[38;5;28mself\u001B[39m.dialect\n\u001B[32m-> \u001B[39m\u001B[32m1779\u001B[39m ret = \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_execute_context\u001B[49m\u001B[43m(\u001B[49m\n\u001B[32m 1780\u001B[39m \u001B[43m \u001B[49m\u001B[43mdialect\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1781\u001B[39m \u001B[43m \u001B[49m\u001B[43mdialect\u001B[49m\u001B[43m.\u001B[49m\u001B[43mexecution_ctx_cls\u001B[49m\u001B[43m.\u001B[49m\u001B[43m_init_statement\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1782\u001B[39m \u001B[43m \u001B[49m\u001B[43mstatement\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1783\u001B[39m \u001B[43m \u001B[49m\u001B[38;5;28;43;01mNone\u001B[39;49;00m\u001B[43m,\u001B[49m\n\u001B[32m 1784\u001B[39m \u001B[43m \u001B[49m\u001B[43mexecution_options\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1785\u001B[39m \u001B[43m \u001B[49m\u001B[43mstatement\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1786\u001B[39m \u001B[43m \u001B[49m\u001B[43mdistilled_parameters\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m 1787\u001B[39m \u001B[43m\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m 1789\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m ret\n",
- "\u001B[36mFile \u001B[39m\u001B[32m~/Project/leopard_analysis/.venv/lib/python3.14/site-packages/sqlalchemy/engine/base.py:1846\u001B[39m, in \u001B[36mConnection._execute_context\u001B[39m\u001B[34m(self, dialect, constructor, statement, parameters, execution_options, *args, **kw)\u001B[39m\n\u001B[32m 1844\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m._exec_insertmany_context(dialect, context)\n\u001B[32m 1845\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[32m-> \u001B[39m\u001B[32m1846\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_exec_single_context\u001B[49m\u001B[43m(\u001B[49m\n\u001B[32m 1847\u001B[39m \u001B[43m \u001B[49m\u001B[43mdialect\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcontext\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mstatement\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mparameters\u001B[49m\n\u001B[32m 1848\u001B[39m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n",
- "\u001B[36mFile \u001B[39m\u001B[32m~/Project/leopard_analysis/.venv/lib/python3.14/site-packages/sqlalchemy/engine/base.py:1986\u001B[39m, in \u001B[36mConnection._exec_single_context\u001B[39m\u001B[34m(self, dialect, context, statement, parameters)\u001B[39m\n\u001B[32m 1983\u001B[39m result = context._setup_result_proxy()\n\u001B[32m 1985\u001B[39m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mBaseException\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m e:\n\u001B[32m-> \u001B[39m\u001B[32m1986\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_handle_dbapi_exception\u001B[49m\u001B[43m(\u001B[49m\n\u001B[32m 1987\u001B[39m \u001B[43m \u001B[49m\u001B[43me\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mstr_statement\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43meffective_parameters\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcursor\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcontext\u001B[49m\n\u001B[32m 1988\u001B[39m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m 1990\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m result\n",
- "\u001B[36mFile \u001B[39m\u001B[32m~/Project/leopard_analysis/.venv/lib/python3.14/site-packages/sqlalchemy/engine/base.py:2366\u001B[39m, in \u001B[36mConnection._handle_dbapi_exception\u001B[39m\u001B[34m(self, e, statement, parameters, cursor, context, is_sub_exec)\u001B[39m\n\u001B[32m 2364\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[32m 2365\u001B[39m \u001B[38;5;28;01massert\u001B[39;00m exc_info[\u001B[32m1\u001B[39m] \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m\n\u001B[32m-> \u001B[39m\u001B[32m2366\u001B[39m \u001B[38;5;28;01mraise\u001B[39;00m exc_info[\u001B[32m1\u001B[39m].with_traceback(exc_info[\u001B[32m2\u001B[39m])\n\u001B[32m 2367\u001B[39m \u001B[38;5;28;01mfinally\u001B[39;00m:\n\u001B[32m 2368\u001B[39m \u001B[38;5;28;01mdel\u001B[39;00m \u001B[38;5;28mself\u001B[39m._reentrant_error\n",
- "\u001B[36mFile \u001B[39m\u001B[32m~/Project/leopard_analysis/.venv/lib/python3.14/site-packages/sqlalchemy/engine/base.py:1967\u001B[39m, in \u001B[36mConnection._exec_single_context\u001B[39m\u001B[34m(self, dialect, context, statement, parameters)\u001B[39m\n\u001B[32m 1965\u001B[39m \u001B[38;5;28;01mbreak\u001B[39;00m\n\u001B[32m 1966\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m evt_handled:\n\u001B[32m-> \u001B[39m\u001B[32m1967\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mdialect\u001B[49m\u001B[43m.\u001B[49m\u001B[43mdo_execute\u001B[49m\u001B[43m(\u001B[49m\n\u001B[32m 1968\u001B[39m \u001B[43m \u001B[49m\u001B[43mcursor\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mstr_statement\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43meffective_parameters\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcontext\u001B[49m\n\u001B[32m 1969\u001B[39m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m 1971\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m._has_events \u001B[38;5;129;01mor\u001B[39;00m \u001B[38;5;28mself\u001B[39m.engine._has_events:\n\u001B[32m 1972\u001B[39m \u001B[38;5;28mself\u001B[39m.dispatch.after_cursor_execute(\n\u001B[32m 1973\u001B[39m \u001B[38;5;28mself\u001B[39m,\n\u001B[32m 1974\u001B[39m cursor,\n\u001B[32m (...)\u001B[39m\u001B[32m 1978\u001B[39m context.executemany,\n\u001B[32m 1979\u001B[39m )\n",
- "\u001B[36mFile \u001B[39m\u001B[32m~/Project/leopard_analysis/.venv/lib/python3.14/site-packages/sqlalchemy/engine/default.py:952\u001B[39m, in \u001B[36mDefaultDialect.do_execute\u001B[39m\u001B[34m(self, cursor, statement, parameters, context)\u001B[39m\n\u001B[32m 951\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mdo_execute\u001B[39m(\u001B[38;5;28mself\u001B[39m, cursor, statement, parameters, context=\u001B[38;5;28;01mNone\u001B[39;00m):\n\u001B[32m--> \u001B[39m\u001B[32m952\u001B[39m \u001B[43mcursor\u001B[49m\u001B[43m.\u001B[49m\u001B[43mexecute\u001B[49m\u001B[43m(\u001B[49m\u001B[43mstatement\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mparameters\u001B[49m\u001B[43m)\u001B[49m\n",
- "\u001B[36mFile \u001B[39m\u001B[32m~/.local/share/uv/python/cpython-3.14.2-macos-x86_64-none/lib/python3.14/encodings/utf_8.py:15\u001B[39m, in \u001B[36mdecode\u001B[39m\u001B[34m(input, errors)\u001B[39m\n\u001B[32m 11\u001B[39m \u001B[38;5;66;03m### Codec APIs\u001B[39;00m\n\u001B[32m 13\u001B[39m encode = codecs.utf_8_encode\n\u001B[32m---> \u001B[39m\u001B[32m15\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mdecode\u001B[39m(\u001B[38;5;28minput\u001B[39m, errors=\u001B[33m'\u001B[39m\u001B[33mstrict\u001B[39m\u001B[33m'\u001B[39m):\n\u001B[32m 16\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m codecs.utf_8_decode(\u001B[38;5;28minput\u001B[39m, errors, \u001B[38;5;28;01mTrue\u001B[39;00m)\n\u001B[32m 18\u001B[39m \u001B[38;5;28;01mclass\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mIncrementalEncoder\u001B[39;00m(codecs.IncrementalEncoder):\n",
- "\u001B[31mKeyboardInterrupt\u001B[39m: "
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "['2025-12-25', '2025-12-26', '2025-12-29', '2025-12-30', '2025-12-31', '2026-01-05', '2026-01-06', '2026-01-07', '2026-01-08', '2026-01-09']\n"
]
}
],
- "execution_count": 26
+ "execution_count": 22
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2026-01-30T09:24:09.859231Z",
+ "start_time": "2026-01-30T09:24:09.746912Z"
+ }
+ },
+ "cell_type": "code",
+ "source": [
+ "import tushare as ts\n",
+ "\n",
+ "pro = ts.pro_api(\"64ebff4fa679167600b905ee45dd88e76f3963c0ff39157f3f085f0e\")\n",
+ "# stocks = pro.stock_basic(ts_code=\"600200.SH\", list_status=\"D\", fields=\"ts_code,name,fullname,market,exchange,industry,list_date,delist_date\")\n",
+ "# stocks"
+ ],
+ "id": "ed58a1faaf2cdb8e",
+ "outputs": [],
+ "execution_count": 34
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2026-01-30T07:14:29.897120Z",
+ "start_time": "2026-01-30T07:14:29.664124Z"
+ }
+ },
+ "cell_type": "code",
+ "source": "# stocks.to_csv(\"dlist.csv\")",
+ "id": "3c8c0a38d6b2992e",
+ "outputs": [],
+ "execution_count": 24
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2026-01-30T09:46:34.808300Z",
+ "start_time": "2026-01-30T09:46:34.129412Z"
+ }
+ },
+ "cell_type": "code",
+ "source": [
+ "daily_df = pro.daily(trade_date=\"20251231\")\n",
+ "daily_df.set_index(\"ts_code\", inplace=True)\n",
+ "factor_df = pro.adj_factor(trade_date=\"20251231\")\n",
+ "factor_df.set_index(\"ts_code\", inplace=True)"
+ ],
+ "id": "c052a945869aa329",
+ "outputs": [],
+ "execution_count": 50
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2026-01-30T09:46:36.697015Z",
+ "start_time": "2026-01-30T09:46:36.642975Z"
+ }
+ },
+ "cell_type": "code",
+ "source": [
+ "result_df = daily_df.join(factor_df, lsuffix=\"_daily\", rsuffix=\"_factor\", how=\"left\")\n",
+ "result_df\n",
+ "# factor_df"
+ ],
+ "id": "d61ee80d2cd9f06b",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ " trade_date_daily open high low close pre_close change \\\n",
+ "ts_code \n",
+ "000001.SZ 20251231 11.48 11.49 11.40 11.41 11.48 -0.07 \n",
+ "000002.SZ 20251231 4.66 4.68 4.62 4.65 4.62 0.03 \n",
+ "000004.SZ 20251231 11.30 11.35 11.07 11.08 11.27 -0.19 \n",
+ "000006.SZ 20251231 9.95 10.03 9.69 9.95 9.86 0.09 \n",
+ "000007.SZ 20251231 11.72 11.75 11.28 11.44 11.62 -0.18 \n",
+ "... ... ... ... ... ... ... ... \n",
+ "920978.BJ 20251231 37.64 38.39 36.88 36.90 37.78 -0.88 \n",
+ "920981.BJ 20251231 32.20 32.29 31.75 31.96 32.07 -0.11 \n",
+ "920982.BJ 20251231 233.00 238.49 232.10 233.70 234.80 -1.10 \n",
+ "920985.BJ 20251231 7.32 7.35 7.17 7.19 7.30 -0.11 \n",
+ "920992.BJ 20251231 17.33 17.60 17.29 17.39 17.38 0.01 \n",
+ "\n",
+ " pct_chg vol amount trade_date_factor adj_factor \n",
+ "ts_code \n",
+ "000001.SZ -0.6098 590620.37 675457.357 20251231 134.5794 \n",
+ "000002.SZ 0.6494 1075561.25 499883.113 20251231 181.7040 \n",
+ "000004.SZ -1.6859 18056.00 20248.567 20251231 4.0640 \n",
+ "000006.SZ 0.9128 270369.08 267758.676 20251231 39.7400 \n",
+ "000007.SZ -1.5491 80556.00 92109.366 20251231 8.2840 \n",
+ "... ... ... ... ... ... \n",
+ "920978.BJ -2.3293 33945.04 126954.937 20251231 1.2885 \n",
+ "920981.BJ -0.3430 8237.16 26301.206 20251231 1.4343 \n",
+ "920982.BJ -0.4685 5210.09 122452.646 20251231 4.2831 \n",
+ "920985.BJ -1.5068 35174.30 25350.257 20251231 1.6280 \n",
+ "920992.BJ 0.0575 6991.87 12193.445 20251231 1.4932 \n",
+ "\n",
+ "[5458 rows x 12 columns]"
+ ],
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " trade_date_daily | \n",
+ " open | \n",
+ " high | \n",
+ " low | \n",
+ " close | \n",
+ " pre_close | \n",
+ " change | \n",
+ " pct_chg | \n",
+ " vol | \n",
+ " amount | \n",
+ " trade_date_factor | \n",
+ " adj_factor | \n",
+ "
\n",
+ " \n",
+ " | ts_code | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 000001.SZ | \n",
+ " 20251231 | \n",
+ " 11.48 | \n",
+ " 11.49 | \n",
+ " 11.40 | \n",
+ " 11.41 | \n",
+ " 11.48 | \n",
+ " -0.07 | \n",
+ " -0.6098 | \n",
+ " 590620.37 | \n",
+ " 675457.357 | \n",
+ " 20251231 | \n",
+ " 134.5794 | \n",
+ "
\n",
+ " \n",
+ " | 000002.SZ | \n",
+ " 20251231 | \n",
+ " 4.66 | \n",
+ " 4.68 | \n",
+ " 4.62 | \n",
+ " 4.65 | \n",
+ " 4.62 | \n",
+ " 0.03 | \n",
+ " 0.6494 | \n",
+ " 1075561.25 | \n",
+ " 499883.113 | \n",
+ " 20251231 | \n",
+ " 181.7040 | \n",
+ "
\n",
+ " \n",
+ " | 000004.SZ | \n",
+ " 20251231 | \n",
+ " 11.30 | \n",
+ " 11.35 | \n",
+ " 11.07 | \n",
+ " 11.08 | \n",
+ " 11.27 | \n",
+ " -0.19 | \n",
+ " -1.6859 | \n",
+ " 18056.00 | \n",
+ " 20248.567 | \n",
+ " 20251231 | \n",
+ " 4.0640 | \n",
+ "
\n",
+ " \n",
+ " | 000006.SZ | \n",
+ " 20251231 | \n",
+ " 9.95 | \n",
+ " 10.03 | \n",
+ " 9.69 | \n",
+ " 9.95 | \n",
+ " 9.86 | \n",
+ " 0.09 | \n",
+ " 0.9128 | \n",
+ " 270369.08 | \n",
+ " 267758.676 | \n",
+ " 20251231 | \n",
+ " 39.7400 | \n",
+ "
\n",
+ " \n",
+ " | 000007.SZ | \n",
+ " 20251231 | \n",
+ " 11.72 | \n",
+ " 11.75 | \n",
+ " 11.28 | \n",
+ " 11.44 | \n",
+ " 11.62 | \n",
+ " -0.18 | \n",
+ " -1.5491 | \n",
+ " 80556.00 | \n",
+ " 92109.366 | \n",
+ " 20251231 | \n",
+ " 8.2840 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 920978.BJ | \n",
+ " 20251231 | \n",
+ " 37.64 | \n",
+ " 38.39 | \n",
+ " 36.88 | \n",
+ " 36.90 | \n",
+ " 37.78 | \n",
+ " -0.88 | \n",
+ " -2.3293 | \n",
+ " 33945.04 | \n",
+ " 126954.937 | \n",
+ " 20251231 | \n",
+ " 1.2885 | \n",
+ "
\n",
+ " \n",
+ " | 920981.BJ | \n",
+ " 20251231 | \n",
+ " 32.20 | \n",
+ " 32.29 | \n",
+ " 31.75 | \n",
+ " 31.96 | \n",
+ " 32.07 | \n",
+ " -0.11 | \n",
+ " -0.3430 | \n",
+ " 8237.16 | \n",
+ " 26301.206 | \n",
+ " 20251231 | \n",
+ " 1.4343 | \n",
+ "
\n",
+ " \n",
+ " | 920982.BJ | \n",
+ " 20251231 | \n",
+ " 233.00 | \n",
+ " 238.49 | \n",
+ " 232.10 | \n",
+ " 233.70 | \n",
+ " 234.80 | \n",
+ " -1.10 | \n",
+ " -0.4685 | \n",
+ " 5210.09 | \n",
+ " 122452.646 | \n",
+ " 20251231 | \n",
+ " 4.2831 | \n",
+ "
\n",
+ " \n",
+ " | 920985.BJ | \n",
+ " 20251231 | \n",
+ " 7.32 | \n",
+ " 7.35 | \n",
+ " 7.17 | \n",
+ " 7.19 | \n",
+ " 7.30 | \n",
+ " -0.11 | \n",
+ " -1.5068 | \n",
+ " 35174.30 | \n",
+ " 25350.257 | \n",
+ " 20251231 | \n",
+ " 1.6280 | \n",
+ "
\n",
+ " \n",
+ " | 920992.BJ | \n",
+ " 20251231 | \n",
+ " 17.33 | \n",
+ " 17.60 | \n",
+ " 17.29 | \n",
+ " 17.39 | \n",
+ " 17.38 | \n",
+ " 0.01 | \n",
+ " 0.0575 | \n",
+ " 6991.87 | \n",
+ " 12193.445 | \n",
+ " 20251231 | \n",
+ " 1.4932 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
5458 rows × 12 columns
\n",
+ "
"
+ ]
+ },
+ "execution_count": 51,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "execution_count": 51
}
],
"metadata": {
diff --git a/notebook/sqlalchemy.ipynb b/notebook/sqlalchemy.ipynb
new file mode 100644
index 0000000..2eae745
--- /dev/null
+++ b/notebook/sqlalchemy.ipynb
@@ -0,0 +1,82 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "id": "initial_id",
+ "metadata": {
+ "collapsed": true,
+ "ExecuteTime": {
+ "end_time": "2026-01-30T01:34:39.234530Z",
+ "start_time": "2026-01-30T01:34:39.002346Z"
+ }
+ },
+ "source": [
+ "from sqlalchemy import Column, Date, Double, Integer, String, create_engine\n",
+ "from sqlalchemy.orm import DeclarativeBase, Session\n",
+ "\n",
+ "engine = create_engine(f\"sqlite:////Users/lanyuanxiaoyao/Documents/leopard_data/leopard.sqlite\")\n",
+ "\n",
+ "\n",
+ "class Base(DeclarativeBase):\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "class Daily(Base):\n",
+ " __tablename__ = 'daily'\n",
+ "\n",
+ " code = Column(String, nullable=False, primary_key=True)\n",
+ " trade_date = Column(Date, primary_key=True)\n",
+ " open = Column(Double)\n",
+ " close = Column(Double)\n",
+ " high = Column(Double)\n",
+ " low = Column(Double)\n",
+ " previous_close = Column(Double)\n",
+ " turnover = Column(Double)\n",
+ " volume = Column(Integer)\n",
+ " price_change_amount = Column(Double)\n",
+ " factor = Column(Double)\n",
+ "\n",
+ " def __repr__(self):\n",
+ " return f\"\"\n",
+ "\n",
+ "\n",
+ "Base.metadata.create_all(engine, checkfirst=True)\n",
+ "\n",
+ "with Session(engine) as session:\n",
+ " result = session.query(Daily).filter(Daily.code.in_([\"000001.SZ\"])).all()\n",
+ " print(result)"
+ ],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,