用于基于AkShare数据的保证金风险监控场景。适用于金融工作中的基础任务单元。
本 Skill 基于 AkShare 提供的 A 股市场公开数据接口构建,核心依赖如下:
stock_margin_detail_sse(date=...)
stock_margin_detail_szse(date=...)
stock_margin_sse(start_date=..., end_date=...)
stock_margin_szse(date=...)
stock_margin_underlying_info_szse(date=...)
stock_zh_a_hist(symbol=..., period="daily", start_date=..., end_date=..., adjust="")
说明:本 Skill 使用 AkShare 对交易所与公开行情数据的封装,不直接连接券商交易系统,不包含账户真实授信额度、个体客户折算率、担保品折扣系数、维持担保比例等专有数据。默认输出适合作为 研究、风控测算、盘前盘后估算,不应替代券商柜台结果。
本 Skill 面向 A 股两融场景,提供以下能力:
akshare_margin_risk_skill/
├── skill.md
└── scripts/
└── calculate_margin_risk.py
pip install akshare pandas numpy
保存为 portfolio.json:
{
"trade_date": "2025-04-11",
"cash": 3000000,
"positions": [
{
"symbol": "600000",
"name": "浦发银行",
"side": "long",
"shares": 300000,
"financed_shares": 150000
},
{
"symbol": "000001",
"name": "平安银行",
"side": "long",
"shares": 200000,
"financed_shares": 50000
},
{
"symbol": "300750",
"name": "宁德时代",
"side": "short",
"shares": 10000
}
],
"assumptions": {
"long_margin_ratio": 1.0,
"short_margin_ratio": 1.0,
"maintenance_margin_ratio": 1.3,
"default_price_shock": -0.05
}
}
python scripts/calculate_margin_risk.py --portfolio portfolio.json
脚本会输出:
也可指定输出文件:
python scripts/calculate_margin_risk.py --portfolio portfolio.json --output result.json
融资头寸
financed_shares 表示通过融资买入形成的数量financed_shares × 收盘价 估算融券头寸
shares 视为融券卖出数量shares × 收盘价 估算融券余额,将作为市场参考字段输出保证金口径
维持担保比例
维持担保比例 = 账户权益 / (融资负债 + 融券负债)适用场景
不适用场景
本 Skill 示例代码采用 MIT License 方式提供。你可以自由使用、修改和分发,但需自行评估其在生产环境中的适用性与合规性。
MIT License
Copyright (c) 2026
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.