{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
timetickeropenclosehighlowvolumemoney
02023-08-02 15:00:00603288.XSHG45.8545.8545.8545.85156700.07184695.0
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
indexdateweightdisplay_nametickersectoraggregate_sectorname
015002020-12-310.088神州高铁000008.XSHE机械设备I 运输设备II 铁路设备III 铁路、船舶、航空航天和其他运输设备制造业 城轨铁路 工业工业SZGT
115012020-12-310.344中国宝安000009.XSHE电气设备I 电池II 电池化学品III 综合 工业集团企业 工业工业ZGBA
215022020-12-310.180南玻A000012.XSHE建筑材料I 玻璃制造II 玻璃制造III 非金属矿物制品业 玻璃 原材料原料与能源NBA
315032020-12-310.297深科技000021.XSHE电子I 电子制造II 消费电子零部件及组装III 计算机、通信和其他电子设备制造业 安防设备...信息与通信SKJ
415042020-12-310.030招商港口001872.XSHE交通运输I 航运港口II 港口III 水上运输业 港口 工业工业ZSGK
\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 }