{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 加载功能模块\n", "from datetime import datetime\n", "\n", "from vnpy.trader.constant import Interval\n", "\n", "from elite_optionstrategy import BacktestingEngine\n", "\n", "from buy_option_strategy import BuyOptionStrategy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 创建回测引擎\n", "engine = BacktestingEngine()\n", "\n", "engine.set_parameters(\n", " interval=Interval.MINUTE,\n", " start=datetime(2022, 1, 1),\n", " end=datetime(2022, 1, 28),\n", " rate=0,\n", " slippage=0.6 + (16 / 100),\n", ")\n", "\n", "engine.add_strategy(BuyOptionStrategy, {})" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# 历史数据回放\n", "engine.run_backtesting()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 获取引擎内最新交易日的策略对象\n", "strategy = engine.strategy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 获取策略内部对象\n", "portfolio = strategy.get_portfolio(\"IO\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 查看ChainData\n", "chain = portfolio.get_chain_by_level(0)\n", "chain" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "chain.calculate_synthetic()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 查看OptionData\n", "option = chain.get_option_by_level(cp=1, level=0)\n", "option" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.9" }, "vscode": { "interpreter": { "hash": "1b43cb0bd93d5abbadd54afed8252f711d4681fe6223ad6b67ffaee289648f85" } } }, "nbformat": 4, "nbformat_minor": 4 }