{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "source": [
    "Please go through the \"building_strategies\" notebook first before you go through this notebook\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Some Prebuilt Reporting ##\n",
    "\n",
    "Lets first build the strategy described in that notebook, add it to a portfolio and run the portfolio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:24.461149Z",
     "start_time": "2020-04-09T01:47:23.243190Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "from types import SimpleNamespace\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import pyqstrat as pq\n",
    "from pyqstrat.notebooks.support.build_example_strategy import build_example_strategy\n",
    "\n",
    "strategy = build_example_strategy(SimpleNamespace(lookback_period = 10, num_std = 2))\n",
    "strategy.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Many objects have functions that return pandas dataframes for ease of use.  Any function that returns a dataframe starts with df_ so its easy to tell which dataframes an object returns.\n",
    "\n",
    "Probably the most common function you will use is df_data on the strategy object.  This returns the market data, indicators, signal values and P&L at each market data bar.  The last column, i is the integer index of that bar, and can be used to query data in other dataframes or objects for that strategy."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:24.507345Z",
     "start_time": "2020-04-09T01:47:24.463651Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>c</th>\n",
       "      <th>h</th>\n",
       "      <th>l</th>\n",
       "      <th>lower_band</th>\n",
       "      <th>o</th>\n",
       "      <th>sma</th>\n",
       "      <th>upper_band</th>\n",
       "      <th>bb_signal</th>\n",
       "      <th>position</th>\n",
       "      <th>unrealized</th>\n",
       "      <th>realized</th>\n",
       "      <th>commission</th>\n",
       "      <th>fee</th>\n",
       "      <th>net_pnl</th>\n",
       "      <th>equity</th>\n",
       "      <th>i</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>550</td>\n",
       "      <td>2019-02-13 10:45:00</td>\n",
       "      <td>113.74</td>\n",
       "      <td>113.98</td>\n",
       "      <td>113.72</td>\n",
       "      <td>113.317057</td>\n",
       "      <td>113.95</td>\n",
       "      <td>113.93401</td>\n",
       "      <td>114.550963</td>\n",
       "      <td>1</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>551</td>\n",
       "      <td>2019-02-13 11:00:00</td>\n",
       "      <td>113.9</td>\n",
       "      <td>113.905</td>\n",
       "      <td>113.68</td>\n",
       "      <td>113.32596</td>\n",
       "      <td>113.75</td>\n",
       "      <td>113.94001</td>\n",
       "      <td>114.55406</td>\n",
       "      <td>-1</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>552</td>\n",
       "      <td>2019-02-13 11:15:00</td>\n",
       "      <td>113.99</td>\n",
       "      <td>114.045</td>\n",
       "      <td>113.87</td>\n",
       "      <td>113.367005</td>\n",
       "      <td>113.87</td>\n",
       "      <td>113.96501</td>\n",
       "      <td>114.563015</td>\n",
       "      <td>1</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>553</td>\n",
       "      <td>2019-02-13 11:30:00</td>\n",
       "      <td>114.04</td>\n",
       "      <td>114.13</td>\n",
       "      <td>113.935</td>\n",
       "      <td>113.394339</td>\n",
       "      <td>113.98</td>\n",
       "      <td>113.986</td>\n",
       "      <td>114.577661</td>\n",
       "      <td>1</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>553</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>554</td>\n",
       "      <td>2019-02-13 11:45:00</td>\n",
       "      <td>114.04</td>\n",
       "      <td>114.04</td>\n",
       "      <td>113.85</td>\n",
       "      <td>113.539625</td>\n",
       "      <td>114.04</td>\n",
       "      <td>114.037</td>\n",
       "      <td>114.534375</td>\n",
       "      <td>1</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>554</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>555</td>\n",
       "      <td>2019-02-13 12:00:00</td>\n",
       "      <td>113.98</td>\n",
       "      <td>114.01</td>\n",
       "      <td>113.92</td>\n",
       "      <td>113.594123</td>\n",
       "      <td>113.9949</td>\n",
       "      <td>114.058</td>\n",
       "      <td>114.521877</td>\n",
       "      <td>-1</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>555</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>556</td>\n",
       "      <td>2019-02-13 12:15:00</td>\n",
       "      <td>113.86</td>\n",
       "      <td>114</td>\n",
       "      <td>113.81</td>\n",
       "      <td>113.724008</td>\n",
       "      <td>114</td>\n",
       "      <td>113.982</td>\n",
       "      <td>114.239992</td>\n",
       "      <td>1</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>557</td>\n",
       "      <td>2019-02-13 12:30:00</td>\n",
       "      <td>113.87</td>\n",
       "      <td>113.87</td>\n",
       "      <td>113.79</td>\n",
       "      <td>113.730101</td>\n",
       "      <td>113.85</td>\n",
       "      <td>113.95</td>\n",
       "      <td>114.169899</td>\n",
       "      <td>-1</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>557</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>558</td>\n",
       "      <td>2019-02-13 12:45:00</td>\n",
       "      <td>113.81</td>\n",
       "      <td>113.89</td>\n",
       "      <td>113.77</td>\n",
       "      <td>113.719122</td>\n",
       "      <td>113.865</td>\n",
       "      <td>113.919</td>\n",
       "      <td>114.118878</td>\n",
       "      <td>-1</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>559</td>\n",
       "      <td>2019-02-13 13:00:00</td>\n",
       "      <td>113.86</td>\n",
       "      <td>113.86</td>\n",
       "      <td>113.79</td>\n",
       "      <td>113.708235</td>\n",
       "      <td>113.8</td>\n",
       "      <td>113.909</td>\n",
       "      <td>114.109765</td>\n",
       "      <td>-1</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>nan</td>\n",
       "      <td>559</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              timestamp      c       h       l  lower_band        o       sma  \\\n",
       "550 2019-02-13 10:45:00 113.74  113.98  113.72  113.317057   113.95 113.93401   \n",
       "551 2019-02-13 11:00:00  113.9 113.905  113.68   113.32596   113.75 113.94001   \n",
       "552 2019-02-13 11:15:00 113.99 114.045  113.87  113.367005   113.87 113.96501   \n",
       "553 2019-02-13 11:30:00 114.04  114.13 113.935  113.394339   113.98   113.986   \n",
       "554 2019-02-13 11:45:00 114.04  114.04  113.85  113.539625   114.04   114.037   \n",
       "555 2019-02-13 12:00:00 113.98  114.01  113.92  113.594123 113.9949   114.058   \n",
       "556 2019-02-13 12:15:00 113.86     114  113.81  113.724008      114   113.982   \n",
       "557 2019-02-13 12:30:00 113.87  113.87  113.79  113.730101   113.85    113.95   \n",
       "558 2019-02-13 12:45:00 113.81  113.89  113.77  113.719122  113.865   113.919   \n",
       "559 2019-02-13 13:00:00 113.86  113.86  113.79  113.708235    113.8   113.909   \n",
       "\n",
       "     upper_band  bb_signal  position  unrealized  realized  commission  fee  \\\n",
       "550  114.550963          1       nan         nan       nan         nan  nan   \n",
       "551   114.55406         -1       nan         nan       nan         nan  nan   \n",
       "552  114.563015          1       nan         nan       nan         nan  nan   \n",
       "553  114.577661          1       nan         nan       nan         nan  nan   \n",
       "554  114.534375          1       nan         nan       nan         nan  nan   \n",
       "555  114.521877         -1       nan         nan       nan         nan  nan   \n",
       "556  114.239992          1       nan         nan       nan         nan  nan   \n",
       "557  114.169899         -1       nan         nan       nan         nan  nan   \n",
       "558  114.118878         -1       nan         nan       nan         nan  nan   \n",
       "559  114.109765         -1       nan         nan       nan         nan  nan   \n",
       "\n",
       "     net_pnl  equity    i  \n",
       "550      nan     nan  550  \n",
       "551      nan     nan  551  \n",
       "552      nan     nan  552  \n",
       "553      nan     nan  553  \n",
       "554      nan     nan  554  \n",
       "555      nan     nan  555  \n",
       "556      nan     nan  556  \n",
       "557      nan     nan  557  \n",
       "558      nan     nan  558  \n",
       "559      nan     nan  559  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "strategy.df_data().iloc[550:560]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also look at just the PNL or just the marketdata by themselves."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:24.528631Z",
     "start_time": "2020-04-09T01:47:24.509731Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>position</th>\n",
       "      <th>unrealized</th>\n",
       "      <th>realized</th>\n",
       "      <th>commission</th>\n",
       "      <th>fee</th>\n",
       "      <th>net_pnl</th>\n",
       "      <th>equity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>2019-01-14 15:00:00</td>\n",
       "      <td>930</td>\n",
       "      <td>51.15</td>\n",
       "      <td>-144.305</td>\n",
       "      <td>4650</td>\n",
       "      <td>0</td>\n",
       "      <td>-4743.155</td>\n",
       "      <td>995256.845</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2019-01-15 15:00:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>720.595</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>720.595</td>\n",
       "      <td>1000720.59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>2019-01-16 15:00:00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>215.01495</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>215.01495</td>\n",
       "      <td>1000215.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>2019-01-17 15:00:00</td>\n",
       "      <td>917</td>\n",
       "      <td>-128.38</td>\n",
       "      <td>459.50495</td>\n",
       "      <td>4585</td>\n",
       "      <td>0</td>\n",
       "      <td>-4253.87505</td>\n",
       "      <td>995746.125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>2019-01-18 15:00:00</td>\n",
       "      <td>917</td>\n",
       "      <td>747.355</td>\n",
       "      <td>459.50495</td>\n",
       "      <td>4585</td>\n",
       "      <td>0</td>\n",
       "      <td>-3378.14005</td>\n",
       "      <td>996621.86</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            timestamp  position  unrealized  realized  commission  fee  \\\n",
       "0 2019-01-14 15:00:00       930       51.15  -144.305        4650    0   \n",
       "1 2019-01-15 15:00:00         0           0   720.595           0    0   \n",
       "2 2019-01-16 15:00:00         0           0 215.01495           0    0   \n",
       "3 2019-01-17 15:00:00       917     -128.38 459.50495        4585    0   \n",
       "4 2019-01-18 15:00:00       917     747.355 459.50495        4585    0   \n",
       "\n",
       "      net_pnl     equity  \n",
       "0   -4743.155 995256.845  \n",
       "1     720.595 1000720.59  \n",
       "2   215.01495 1000215.01  \n",
       "3 -4253.87505 995746.125  \n",
       "4 -3378.14005  996621.86  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "strategy.df_pnl().head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can look at orders and trades that were created during this run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:24.544141Z",
     "start_time": "2020-04-09T01:47:24.531253Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>symbol</th>\n",
       "      <th>type</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>qty</th>\n",
       "      <th>reason_code</th>\n",
       "      <th>order_props</th>\n",
       "      <th>contract_props</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>PEP</td>\n",
       "      <td>StopLimitOrder</td>\n",
       "      <td>2019-01-14 09:45:00</td>\n",
       "      <td>931</td>\n",
       "      <td>enter long</td>\n",
       "      <td>{'trigger_price': 107.38, 'limit_price': nan}</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>PEP</td>\n",
       "      <td>MarketOrder</td>\n",
       "      <td>2019-01-14 12:15:00</td>\n",
       "      <td>-931</td>\n",
       "      <td>exit long</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>PEP</td>\n",
       "      <td>StopLimitOrder</td>\n",
       "      <td>2019-01-14 13:45:00</td>\n",
       "      <td>930</td>\n",
       "      <td>enter long</td>\n",
       "      <td>{'trigger_price': 107.56, 'limit_price': nan}</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>PEP</td>\n",
       "      <td>MarketOrder</td>\n",
       "      <td>2019-01-15 13:30:00</td>\n",
       "      <td>-930</td>\n",
       "      <td>exit long</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>PEP</td>\n",
       "      <td>StopLimitOrder</td>\n",
       "      <td>2019-01-15 15:30:00</td>\n",
       "      <td>920</td>\n",
       "      <td>enter long</td>\n",
       "      <td>{'trigger_price': 108.755, 'limit_price': nan}</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  symbol            type           timestamp  qty reason_code  \\\n",
       "0    PEP  StopLimitOrder 2019-01-14 09:45:00  931  enter long   \n",
       "1    PEP     MarketOrder 2019-01-14 12:15:00 -931   exit long   \n",
       "2    PEP  StopLimitOrder 2019-01-14 13:45:00  930  enter long   \n",
       "3    PEP     MarketOrder 2019-01-15 13:30:00 -930   exit long   \n",
       "4    PEP  StopLimitOrder 2019-01-15 15:30:00  920  enter long   \n",
       "\n",
       "                                      order_props contract_props  \n",
       "0   {'trigger_price': 107.38, 'limit_price': nan}                 \n",
       "1                                                                 \n",
       "2   {'trigger_price': 107.56, 'limit_price': nan}                 \n",
       "3                                                                 \n",
       "4  {'trigger_price': 108.755, 'limit_price': nan}                 "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "strategy.df_orders().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:24.564559Z",
     "start_time": "2020-04-09T01:47:24.546561Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>symbol</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>qty</th>\n",
       "      <th>price</th>\n",
       "      <th>fee</th>\n",
       "      <th>commission</th>\n",
       "      <th>order_date</th>\n",
       "      <th>order_qty</th>\n",
       "      <th>reason_code</th>\n",
       "      <th>order_props</th>\n",
       "      <th>contract_props</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>PEP</td>\n",
       "      <td>2019-01-14 10:00:00</td>\n",
       "      <td>931</td>\n",
       "      <td>107.48</td>\n",
       "      <td>0</td>\n",
       "      <td>4655</td>\n",
       "      <td>2019-01-14 09:45:00</td>\n",
       "      <td>931</td>\n",
       "      <td>enter long</td>\n",
       "      <td>{'trigger_price': 107.38, 'limit_price': nan}</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>PEP</td>\n",
       "      <td>2019-01-14 12:30:00</td>\n",
       "      <td>-931</td>\n",
       "      <td>107.325</td>\n",
       "      <td>0</td>\n",
       "      <td>-4655</td>\n",
       "      <td>2019-01-14 12:15:00</td>\n",
       "      <td>-931</td>\n",
       "      <td>exit long</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>PEP</td>\n",
       "      <td>2019-01-14 14:00:00</td>\n",
       "      <td>930</td>\n",
       "      <td>107.575</td>\n",
       "      <td>0</td>\n",
       "      <td>4650</td>\n",
       "      <td>2019-01-14 13:45:00</td>\n",
       "      <td>930</td>\n",
       "      <td>enter long</td>\n",
       "      <td>{'trigger_price': 107.56, 'limit_price': nan}</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>PEP</td>\n",
       "      <td>2019-01-15 13:45:00</td>\n",
       "      <td>-930</td>\n",
       "      <td>108.505</td>\n",
       "      <td>0</td>\n",
       "      <td>-4650</td>\n",
       "      <td>2019-01-15 13:30:00</td>\n",
       "      <td>-930</td>\n",
       "      <td>exit long</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>PEP</td>\n",
       "      <td>2019-01-15 15:45:00</td>\n",
       "      <td>920</td>\n",
       "      <td>108.8225</td>\n",
       "      <td>0</td>\n",
       "      <td>4600</td>\n",
       "      <td>2019-01-15 15:30:00</td>\n",
       "      <td>920</td>\n",
       "      <td>enter long</td>\n",
       "      <td>{'trigger_price': 108.755, 'limit_price': nan}</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  symbol           timestamp  qty    price  fee  commission  \\\n",
       "0    PEP 2019-01-14 10:00:00  931   107.48    0        4655   \n",
       "1    PEP 2019-01-14 12:30:00 -931  107.325    0       -4655   \n",
       "2    PEP 2019-01-14 14:00:00  930  107.575    0        4650   \n",
       "3    PEP 2019-01-15 13:45:00 -930  108.505    0       -4650   \n",
       "4    PEP 2019-01-15 15:45:00  920 108.8225    0        4600   \n",
       "\n",
       "           order_date  order_qty reason_code  \\\n",
       "0 2019-01-14 09:45:00        931  enter long   \n",
       "1 2019-01-14 12:15:00       -931   exit long   \n",
       "2 2019-01-14 13:45:00        930  enter long   \n",
       "3 2019-01-15 13:30:00       -930   exit long   \n",
       "4 2019-01-15 15:30:00        920  enter long   \n",
       "\n",
       "                                      order_props contract_props  \n",
       "0   {'trigger_price': 107.38, 'limit_price': nan}                 \n",
       "1                                                                 \n",
       "2   {'trigger_price': 107.56, 'limit_price': nan}                 \n",
       "3                                                                 \n",
       "4  {'trigger_price': 108.755, 'limit_price': nan}                 "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "strategy.df_trades().head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-10T21:09:59.531818Z",
     "start_time": "2018-08-10T21:09:59.499471Z"
    }
   },
   "source": [
    "You can also look at the returns at the portfolio level (i.e. summing up several strategies)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:24.595577Z",
     "start_time": "2020-04-09T01:47:24.567128Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>net_pnl</th>\n",
       "      <th>equity</th>\n",
       "      <th>ret</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>2019-01-14</td>\n",
       "      <td>-4743.155</td>\n",
       "      <td>995256.845</td>\n",
       "      <td>nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2019-01-15</td>\n",
       "      <td>720.595</td>\n",
       "      <td>1000720.59</td>\n",
       "      <td>0.00548978892</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>2019-01-16</td>\n",
       "      <td>215.01495</td>\n",
       "      <td>1000215.01</td>\n",
       "      <td>-0.000505215994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>2019-01-17</td>\n",
       "      <td>-4253.87505</td>\n",
       "      <td>995746.125</td>\n",
       "      <td>-0.00446792933</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>2019-01-18</td>\n",
       "      <td>-3378.14005</td>\n",
       "      <td>996621.86</td>\n",
       "      <td>0.000879476182</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   timestamp     net_pnl     equity             ret\n",
       "0 2019-01-14   -4743.155 995256.845             nan\n",
       "1 2019-01-15     720.595 1000720.59   0.00548978892\n",
       "2 2019-01-16   215.01495 1000215.01 -0.000505215994\n",
       "3 2019-01-17 -4253.87505 995746.125  -0.00446792933\n",
       "4 2019-01-18 -3378.14005  996621.86  0.000879476182"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "strategy.df_returns().head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also get data as native Python objects as opposed to pandas dataframes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:24.605499Z",
     "start_time": "2020-04-09T01:47:24.598412Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[PEP 2019-01-15 13:45:00 qty: -930.0 prc: 108.505 commission: -4650 order: PEP 2019-01-15 13:30:00 qty: -930.0 exit long filled,\n",
       " PEP 2019-01-15 15:45:00 qty: 920.0 prc: 108.822 commission: 4600 order: PEP 2019-01-15 15:30:00 qty: 920.0 trigger_prc: 108.755 limit_prc: nan enter long namespace(limit_price=nan, trigger_price=108.755) filled,\n",
       " PEP 2019-01-16 10:15:00 qty: -920.0 prc: 108.458 commission: -4600 order: PEP 2019-01-16 10:00:00 qty: -920.0 exit long filled,\n",
       " PEP 2019-01-16 11:30:00 qty: -927.0 prc: 107.902 commission: -4635 order: PEP 2019-01-16 11:15:00 qty: -927.0 trigger_prc: 107.91 limit_prc: nan enter short namespace(limit_price=nan, trigger_price=107.91) filled,\n",
       " PEP 2019-01-16 13:30:00 qty: 927.0 prc: 108.085 commission: 4635 order: PEP 2019-01-16 13:15:00 qty: 927.0 exit short filled,\n",
       " PEP 2019-01-17 09:45:00 qty: 923.0 prc: 108.5 commission: 4615 order: PEP 2019-01-16 16:00:00 qty: 923.0 trigger_prc: 108.33 limit_prc: nan enter long namespace(limit_price=nan, trigger_price=108.33) filled,\n",
       " PEP 2019-01-17 12:30:00 qty: -923.0 prc: 108.73 commission: -4615 order: PEP 2019-01-17 12:15:00 qty: -923.0 exit long filled,\n",
       " PEP 2019-01-17 12:45:00 qty: -920.0 prc: 108.74 commission: -4600 order: PEP 2019-01-17 12:30:00 qty: -920.0 trigger_prc: 108.76 limit_prc: nan enter short namespace(limit_price=nan, trigger_price=108.76) filled,\n",
       " PEP 2019-01-17 14:30:00 qty: 920.0 prc: 108.705 commission: 4600 order: PEP 2019-01-17 14:15:00 qty: 920.0 exit short filled,\n",
       " PEP 2019-01-17 15:00:00 qty: 917.0 prc: 109.3 commission: 4585 order: PEP 2019-01-17 14:45:00 qty: 917.0 trigger_prc: 109.16 limit_prc: nan enter long namespace(limit_price=nan, trigger_price=109.16) filled]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "strategy.trades(start_date = '2019-01-15', end_date = '2019-01-20')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Adding your Own Metrics ##\n",
    "\n",
    "Each strategy may have metrics that you want to measure that are specific to that strategy.  To add these, you can use the Evaluator object which can make things easier.\n",
    "\n",
    "To evaluate a strategy we use the evaluate returns function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:24.666134Z",
     "start_time": "2020-04-09T01:47:24.611420Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>gmean</th>\n",
       "      <th>amean</th>\n",
       "      <th>std</th>\n",
       "      <th>shrp</th>\n",
       "      <th>srt</th>\n",
       "      <th>k</th>\n",
       "      <th>calmar</th>\n",
       "      <th>mar</th>\n",
       "      <th>mdd_pct</th>\n",
       "      <th>mdd_dates</th>\n",
       "      <th>dd_3y_pct</th>\n",
       "      <th>dd_3y_timestamps</th>\n",
       "      <th>up_dwn</th>\n",
       "      <th>2019</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td></td>\n",
       "      <td>-0.05588</td>\n",
       "      <td>-0.05525</td>\n",
       "      <td>0.004225</td>\n",
       "      <td>-0.8238</td>\n",
       "      <td>-1.385</td>\n",
       "      <td>4.845</td>\n",
       "      <td>-3.432</td>\n",
       "      <td>-3.432</td>\n",
       "      <td>0.0161</td>\n",
       "      <td>2019-01-22/2019-02-26</td>\n",
       "      <td>0.0161</td>\n",
       "      <td>2019-01-22/2019-02-26</td>\n",
       "      <td>10/19/0.345</td>\n",
       "      <td>-0.05588</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     gmean     amean       std     shrp     srt      k  calmar     mar  \\\n",
       "  -0.05588  -0.05525  0.004225  -0.8238  -1.385  4.845  -3.432  -3.432   \n",
       "\n",
       " mdd_pct              mdd_dates dd_3y_pct       dd_3y_timestamps       up_dwn  \\\n",
       "  0.0161  2019-01-22/2019-02-26    0.0161  2019-01-22/2019-02-26  10/19/0.345   \n",
       "\n",
       "      2019  \n",
       "  -0.05588  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "strategy.evaluate_returns(plot = False);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What if we want to add some more metrics to this.  For example, lets say we want to add a metric that looks at how many long trades we had versus short trades.  We can do this using an Evaluator object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:24.676289Z",
     "start_time": "2020-04-09T01:47:24.669493Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Long Trades: 29 Short Trades: 20\n"
     ]
    }
   ],
   "source": [
    "def compute_num_long_trades(trades):\n",
    "    return len([trade for trade in trades if trade.order.reason_code == pq.ReasonCode.ENTER_LONG])\n",
    "\n",
    "def compute_num_short_trades(trades):\n",
    "    return len([trade for trade in trades if trade.order.reason_code == pq.ReasonCode.ENTER_SHORT])\n",
    "\n",
    "evaluator = pq.Evaluator(initial_metrics = {'trades' : strategy.trades()})\n",
    "\n",
    "evaluator.add_metric('num_long_trades', compute_num_long_trades, dependencies = ['trades'])\n",
    "evaluator.add_metric('num_short_trades', compute_num_short_trades, dependencies = ['trades'])\n",
    "\n",
    "evaluator.compute()\n",
    "\n",
    "print('Long Trades: {} Short Trades: {}'.format(evaluator.metric('num_long_trades'), evaluator.metric('num_short_trades')))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-10T21:35:46.005492Z",
     "start_time": "2018-08-10T21:35:46.002539Z"
    }
   },
   "source": [
    "The Evaluator takes care of dependency management so that if you want to compute a metric that relies on other metrics, it will compute the metrics in the right order.\n",
    "\n",
    "Lets compute Maximum Adverse Execution for each trade.  MAE tells you the maximum loss each trade in its lifetime.  It's useful for figuring out where to put trailing stops. For example, if most of your profitable trades had a maximum loss during their life up to 5% but many losing trades had losses of 50% and 60%, it might make sense to place a trailing stop around 6% or 7% so you don't get stopped out of your profitable trades but get out of the losing ones quickly.  See Jaekle and Tomasini, page 66 for details\n",
    "\n",
    "To do this we first have to first pair up entry and exit trades into a single \"round-trip\" trade."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:24.694141Z",
     "start_time": "2020-04-09T01:47:24.678420Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "import collections\n",
    "\n",
    "trades = strategy.trades()\n",
    "\n",
    "entry_trades = [trade for trade in trades if trade.order.reason_code == pq.ReasonCode.ENTER_LONG]\n",
    "exit_trades = [trade for trade in trades if trade.order.reason_code == pq.ReasonCode.EXIT_LONG]\n",
    "\n",
    "def compute_mae(entry_trades, exit_trades, c, timestamps):\n",
    "    mae = np.empty(len(exit_trades)) * np.nan\n",
    "    \n",
    "    round_trip_pnl = np.empty(len(exit_trades)) * np.nan\n",
    "\n",
    "    for i, exit in enumerate(exit_trades):\n",
    "        #if i == len(exit_trades): break\n",
    "        entry = entry_trades[i]\n",
    "        _round_trip_pnl = entry.qty * (exit.price - entry.price)\n",
    "        running_price = c[(timestamps >= entry.timestamp) & (timestamps <= exit.timestamp)]\n",
    "        running_pnl = entry.qty * (running_price - entry.price)\n",
    "        _mae = -1 * min(_round_trip_pnl, np.min(running_pnl))\n",
    "        _mae = _mae / entry.price # Get mae in % terms\n",
    "        _mae = max(0, _mae) # If we have no drawdown for this trade, set it to 0\n",
    "        mae[i] = _mae\n",
    "        round_trip_pnl[i] = _round_trip_pnl / entry.price # Also store round trip pnl for this trade since we will have to plot it\n",
    "    return mae, round_trip_pnl\n",
    "        \n",
    "def get_trades(trades, entry):\n",
    "    rc = [pq.ReasonCode.ENTER_LONG, pq.ReasonCode.ENTER_SHORT] if entry else [pq.ReasonCode.EXIT_LONG, pq.ReasonCode.EXIT_SHORT]\n",
    "    return [trade for trade in trades if trade.order.reason_code in rc]\n",
    "\n",
    "contract_group = strategy.contract_groups[0]\n",
    "\n",
    "evaluator = pq.Evaluator(initial_metrics = {'trades' : strategy.trades(),\n",
    "                                            'c' : strategy.indicator_values[contract_group].c,\n",
    "                                            'timestamps' : strategy.timestamps})\n",
    "evaluator.add_metric('entry_trades', lambda trades : get_trades(trades, True), dependencies=['trades'])\n",
    "evaluator.add_metric('exit_trades', lambda trades : get_trades(trades, False), dependencies=['trades'])\n",
    "evaluator.add_metric('mae', compute_mae, dependencies=['entry_trades', 'exit_trades', 'c', 'timestamps'])\n",
    "\n",
    "evaluator.compute()\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We could have easily done the same computation without using the Evaluator.  The main advantage of using the Evaluator is that you can reuse other metrics you are dependent on without having to recompute them each time, i.e it provides a local cache of metrics."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-10T22:14:20.705460Z",
     "start_time": "2018-08-10T22:14:20.700666Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "source": [
    "## Plotting ##\n",
    "\n",
    "Now that we have maximum adverse execution, lets plot it.\n",
    "\n",
    "pyqstrat plots are built on top of matplotlib.  Each pyqstrat Plot object contains a list of Subplot objects which in turn each contain a list of the data you want to plot in that subplot.\n",
    "\n",
    "In this case, we want to plot round trip PNL for each trade versus its max drawdown (MAE).  The goal is to find out where to set a stop loss so we keep most of the winning trades while limiting our losses from the biggest losing trades.  Since we want to look at the effect of setting a stop loss on both winning and losing trades, we flip the sign of the round trip pnl on the losing trades and mark them in a different color to show the negative P&L."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:24.934968Z",
     "start_time": "2020-04-09T01:47:24.696670Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 576x432 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 35420 characters]\n",
      "text/plain": [
       "<Figure size 1080x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "mae = evaluator.metric('mae')[0]\n",
    "round_trip_pnl = evaluator.metric('mae')[1]\n",
    "\n",
    "# Separate out positive trades from negative trades\n",
    "round_trip_profit = round_trip_pnl[round_trip_pnl >= 0]\n",
    "mae_profit = mae[round_trip_pnl >= 0]\n",
    "\n",
    "round_trip_loss = round_trip_pnl[round_trip_pnl <= 0]\n",
    "mae_loss = mae[round_trip_pnl <= 0]\n",
    "\n",
    "subplot = pq.Subplot([\n",
    "    pq.XYData('Profitable Trade', mae_profit, round_trip_profit, display_attributes = pq.ScatterPlotAttributes(marker = '^', marker_color = 'green')),\n",
    "    pq.XYData('Losing Trade', mae_loss, -1 * round_trip_loss, display_attributes = pq.ScatterPlotAttributes(marker = 'v', marker_color = 'red'))],\n",
    "    horizontal_lines = [pq.HorizontalLine(y = 0, color = 'black')],\n",
    "    vertical_lines = [pq.VerticalLine(x = 0, color = 'black')],\n",
    "    xlabel = 'Drawdown in %', ylabel = 'Profit / Loss in %')\n",
    "\n",
    "plot = pq.Plot([subplot])\n",
    "plot.draw();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "It looks like a good place to put a stop loss so we keep most of the winning trades but don't take big losses might be around 4%.  The next step would be to re-test the system with this stop loss inserted.  Lets plot the same data with a line showing the stop loss."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-09T01:47:25.165848Z",
     "start_time": "2020-04-09T01:47:24.937511Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 39212 characters]\n",
      "text/plain": [
       "<Figure size 1080x576 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "subplot = pq.Subplot([\n",
    "    pq.XYData('Profitable Trade', mae_profit, round_trip_profit, display_attributes = pq.ScatterPlotAttributes(marker = '^', marker_color = 'green')),\n",
    "    pq.XYData('Losing Trade', mae_loss, -1 * round_trip_loss, display_attributes = pq.ScatterPlotAttributes(marker = 'v', marker_color = 'red'))],\n",
    "    horizontal_lines = [pq.HorizontalLine(y = 0, color = 'black')],\n",
    "    vertical_lines = [pq.VerticalLine(x = 0, color = 'black'), pq.VerticalLine(name = 'Stop Loss', x = 4, color = 'blue')],\n",
    "    xlabel = 'Drawdown in %', ylabel = 'Profit / Loss in %')\n",
    "\n",
    "plot = pq.Plot([subplot])\n",
    "plot.draw();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are several different kinds of subplots, including 3d subplots that you can include in the same plot.  See the code of the plot function in the Strategy class or the Evaluator class for eamples."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
