{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "from datetime import datetime\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "from turtleEngine import BacktestingEngine" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "engine = BacktestingEngine()\n", "engine.setPeriod(datetime(2015, 1, 1), datetime(2018, 11, 9))\n", "engine.initPortfolio('setting.csv', 10000000)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "engine.loadData()\n", "engine.runBacktesting()\n", "engine.calculateResult()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "for dt, l in engine.tradeDict.items():\n", " print dt\n", " for trade in l:\n", " print trade.vtSymbol, trade.direction, trade.offset, trade.price, trade.volume" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "for result in engine.resultList:\n", " if result.totalPnl:\n", " print result.date, result.totalPnl" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "l = [result.totalPnl for result in engine.resultList]\n", "equity = np.cumsum(l)\n", "plt.plot(equity)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "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.14" } }, "nbformat": 4, "nbformat_minor": 2 }