{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pipeline\n",
"import settings\n",
"from sqlalchemy import create_engine\n",
"import pandas as pd\n",
"import datetime as dt\n",
"import api\n",
"db_url = 'sqlite:///instance/local.db'"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"auth success \n"
]
}
],
"source": [
"pipeline.update_stocks_details_to_db()"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 147,
"metadata": {},
"outputs": [],
"source": [
"## calculate weight for benchmark and portfolio \n",
"with create_engine(db_url).connect() as conn:\n",
" p_profile = pd.read_sql('portfolio_profile', con=conn)\n",
" b_profile = pd.read_sql('benchmark_profile', con=conn)"
]
},
{
"cell_type": "code",
"execution_count": 167,
"metadata": {},
"outputs": [],
"source": [
"date = dt.datetime(2023, 8, 2, 15, 0,0)\n"
]
},
{
"cell_type": "code",
"execution_count": 168,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" time | \n",
" ticker | \n",
" open | \n",
" close | \n",
" high | \n",
" low | \n",
" volume | \n",
" money | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 2023-08-02 15:00:00 | \n",
" 603288.XSHG | \n",
" 45.85 | \n",
" 45.85 | \n",
" 45.85 | \n",
" 45.85 | \n",
" 156700.0 | \n",
" 7184695.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" time ticker open close high low volume \\\n",
"0 2023-08-02 15:00:00 603288.XSHG 45.85 45.85 45.85 45.85 156700.0 \n",
"\n",
" money \n",
"0 7184695.0 "
]
},
"execution_count": 168,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"api.fetch_stocks_price(security=['603288.XSHG'],end_date=date,count=1, frequency='minute')"
]
},
{
"cell_type": "code",
"execution_count": 151,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2023-08-02 21:20:02')"
]
},
"execution_count": 151,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"date = dt.datetime(2023, 8, 2)\n",
"p_profile.iloc[0].date"
]
},
{
"cell_type": "code",
"execution_count": 149,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" index | \n",
" date | \n",
" weight | \n",
" display_name | \n",
" ticker | \n",
" sector | \n",
" aggregate_sector | \n",
" name | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1500 | \n",
" 2020-12-31 | \n",
" 0.088 | \n",
" 神州高铁 | \n",
" 000008.XSHE | \n",
" 机械设备I 运输设备II 铁路设备III 铁路、船舶、航空航天和其他运输设备制造业 城轨铁路 工业 | \n",
" 工业 | \n",
" SZGT | \n",
"
\n",
" \n",
" 1 | \n",
" 1501 | \n",
" 2020-12-31 | \n",
" 0.344 | \n",
" 中国宝安 | \n",
" 000009.XSHE | \n",
" 电气设备I 电池II 电池化学品III 综合 工业集团企业 工业 | \n",
" 工业 | \n",
" ZGBA | \n",
"
\n",
" \n",
" 2 | \n",
" 1502 | \n",
" 2020-12-31 | \n",
" 0.180 | \n",
" 南玻A | \n",
" 000012.XSHE | \n",
" 建筑材料I 玻璃制造II 玻璃制造III 非金属矿物制品业 玻璃 原材料 | \n",
" 原料与能源 | \n",
" NBA | \n",
"
\n",
" \n",
" 3 | \n",
" 1503 | \n",
" 2020-12-31 | \n",
" 0.297 | \n",
" 深科技 | \n",
" 000021.XSHE | \n",
" 电子I 电子制造II 消费电子零部件及组装III 计算机、通信和其他电子设备制造业 安防设备... | \n",
" 信息与通信 | \n",
" SKJ | \n",
"
\n",
" \n",
" 4 | \n",
" 1504 | \n",
" 2020-12-31 | \n",
" 0.030 | \n",
" 招商港口 | \n",
" 001872.XSHE | \n",
" 交通运输I 航运港口II 港口III 水上运输业 港口 工业 | \n",
" 工业 | \n",
" ZSGK | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" index date weight display_name ticker \\\n",
"0 1500 2020-12-31 0.088 神州高铁 000008.XSHE \n",
"1 1501 2020-12-31 0.344 中国宝安 000009.XSHE \n",
"2 1502 2020-12-31 0.180 南玻A 000012.XSHE \n",
"3 1503 2020-12-31 0.297 深科技 000021.XSHE \n",
"4 1504 2020-12-31 0.030 招商港口 001872.XSHE \n",
"\n",
" sector aggregate_sector name \n",
"0 机械设备I 运输设备II 铁路设备III 铁路、船舶、航空航天和其他运输设备制造业 城轨铁路 工业 工业 SZGT \n",
"1 电气设备I 电池II 电池化学品III 综合 工业集团企业 工业 工业 ZGBA \n",
"2 建筑材料I 玻璃制造II 玻璃制造III 非金属矿物制品业 玻璃 原材料 原料与能源 NBA \n",
"3 电子I 电子制造II 消费电子零部件及组装III 计算机、通信和其他电子设备制造业 安防设备... 信息与通信 SKJ \n",
"4 交通运输I 航运港口II 港口III 水上运输业 港口 工业 工业 ZSGK "
]
},
"execution_count": 149,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b_profile.head()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "risk-dashboard",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}