{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "source": [
    "Bollinger Bands&copy; are used in trend following strategies.  See https://www.bollingerbands.com for more information.\n",
    "\n",
    "We use a moving average of the price of a security, and an upper and lower band around this price.  When the price moves above the upper band, we buy and when the price moves below the lower band we sell."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-03T16:45:21.511071Z",
     "start_time": "2018-08-03T16:45:21.506687Z"
    }
   },
   "source": [
    "First, lets load some data.  We are going to use 15 minute prices for Pepsi stock (symbol PEP) over 1 week"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:09.314446Z",
     "start_time": "2022-08-16T02:38:09.145753Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "import math\n",
    "import datetime\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import scipy.stats\n",
    "import os\n",
    "from types import SimpleNamespace\n",
    "\n",
    "import pyqstrat as pq\n",
    "\n",
    "pq.set_defaults() # Set some display defaults to make dataframes and plots easier to look at\n",
    "\n",
    "try:\n",
    "    file_path = os.path.dirname(os.path.realpath(__file__)) + '/../notebooks/support/pepsi_15_min_prices.csv.gz' # If we are running from unit tests\n",
    "except:\n",
    "    file_path = '../notebooks/support/pepsi_15_min_prices.csv.gz'\n",
    "    \n",
    "prices = pd.read_csv(file_path)\n",
    "prices.date = pd.to_datetime(prices.date)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T20:15:57.458367Z",
     "start_time": "2018-08-06T20:15:57.396777Z"
    }
   },
   "source": [
    "Lets add the Bollinger Band functions.  Let's set the middle band to the 20 bar simple moving average of the close, and the upper and lower bands to 1 standard deviation away from the middle band.  We also a strategy context object that contains any state variables we want to use for this strategy.  The strategy passes this strategy context to functions that it calls so we can pass around any user defined state.  We also create a contract group.  A contract group is useful for futures and options where the underlying instruments expire, but we want to treat them as one virtual instrument in our code."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:09.409643Z",
     "start_time": "2022-08-16T02:38:09.315101Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 432x288 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 128032 characters]\n",
      "text/plain": [
       "<Figure size 1080x576 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "def sma(contract_group, timestamps, indicators, strategy_context): # simple moving average\n",
    "    sma = pd.Series(indicators.c).rolling(window = strategy_context.lookback_period).mean()\n",
    "    return sma.values\n",
    "\n",
    "def band(contract_group, timestamps, indicators, strategy_context, upper):\n",
    "    std = pd.Series(indicators.c).rolling(window = strategy_context.lookback_period).std()\n",
    "    return indicators.sma + strategy_context.num_std * std * (1 if upper else -1)\n",
    "\n",
    "# Each band is 1 standard deviations away from the moving average of price\n",
    "# Lookback period is 20 bars\n",
    "strategy_context = SimpleNamespace(num_std = 1, lookback_period = 20)\n",
    "contract_group = pq.ContractGroup.create('PEP')\n",
    "contract = pq.Contract.create('PEP', contract_group)\n",
    "\n",
    "timestamps = prices.date.values\n",
    "\n",
    "bb_indicators = SimpleNamespace(o = prices.o, h = prices.h, l = prices.l, c = prices.c)\n",
    "\n",
    "sma_values = sma(contract, timestamps, bb_indicators, strategy_context)\n",
    "bb_indicators.sma = sma_values\n",
    "\n",
    "upper_band = lambda contract_group, timestamps, indicators, strategy_context : \\\n",
    "    band(contract_group, timestamps, indicators, strategy_context, upper = True)\n",
    "\n",
    "lower_band = lambda contract_group, timestamps, indicators, strategy_context : \\\n",
    "    band(contract_group, timestamps, indicators, strategy_context, upper = False)\n",
    "\n",
    "upper_band_values = upper_band(contract, timestamps, bb_indicators, strategy_context)\n",
    "lower_band_values = lower_band(contract, timestamps, bb_indicators, strategy_context)\n",
    "\n",
    "indicator_subplot = pq.Subplot(\n",
    "    [pq.TimeSeries('price', timestamps, prices.c, display_attributes=pq.LinePlotAttributes(color = 'blue')), \n",
    "     pq.TimeSeries('sma', timestamps, sma_values, display_attributes=pq.LinePlotAttributes(line_type = 'dotted', color = 'red')),\n",
    "     pq.TimeSeries('upper band', timestamps, upper_band_values, display_attributes=pq.LinePlotAttributes(line_type = 'dashed', color = 'green')),\n",
    "     pq.TimeSeries('lower_band', timestamps, lower_band_values, display_attributes=pq.LinePlotAttributes(line_type = 'dashed', color = 'green'))\n",
    "    ],\n",
    "    ylabel = 'Indicators')\n",
    "plot = pq.Plot(indicator_subplot, title = 'PEP')\n",
    "plot.draw();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The price, bands and the moving average are called \"indicators\" in pyqstrat.  Indicators are the fundamental building blocks of any strategy.\n",
    "\n",
    "Now lets create a signal.  A signal uses marketdata and indicators and tells a strategy when to create orders.  In this case we buy when the price crosses the upper band and exit when the price crosses the moving average.  Similarly, we sell when the price crosses the lower band and exit when it crosses the moving average.  We create 4 different values of the signal, +2, -2, +1, -1 to signal all 4 of these conditions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:09.413657Z",
     "start_time": "2022-08-16T02:38:09.411274Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "def bollinger_band_signal(contract_group, timestamps, indicators, parent_signals, strategy_context):\n",
    "    # Replace nans with 0 so we don't get errors later when comparing nans to floats\n",
    "    upper_band = np.nan_to_num(indicators.upper_band)\n",
    "    lower_band = np.nan_to_num(indicators.lower_band)\n",
    "    sma = np.nan_to_num(indicators.sma)\n",
    "    \n",
    "    signal = np.where(indicators.h > upper_band, 2, 0)\n",
    "    signal = np.where(indicators.l < lower_band, -2, signal)\n",
    "    signal = np.where((indicators.h > sma) & (signal == 0), 1, signal) # price crossed above simple moving avg but not above upper band\n",
    "    signal = np.where((indicators.l < sma) & (signal == 0), -1, signal) # price crossed below simple moving avg but not below lower band\n",
    "    return signal"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's plot the signal in a subplot along with the indicators to check whether it looks reasonable"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:09.535295Z",
     "start_time": "2022-08-16T02:38:09.414537Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 180672 characters]\n",
      "text/plain": [
       "<Figure size 1080x576 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "bb_indicators.upper_band = upper_band_values\n",
    "bb_indicators.lower_band = lower_band_values\n",
    "bb_indicators.sma = sma_values\n",
    "\n",
    "signal = bollinger_band_signal(contract, timestamps, bb_indicators, None,strategy_context)\n",
    "signal_subplot = pq.Subplot([pq.TimeSeries('signal', timestamps, signal)], ylabel = 'Signal')\n",
    "plot = pq.Plot([indicator_subplot, signal_subplot], title = 'BTC', show_date_gaps = False)\n",
    "plot.draw();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-08-06T19:51:47.743290Z",
     "start_time": "2018-08-06T19:51:47.739748Z"
    }
   },
   "source": [
    "This is hard to see clearly so let's look at a smaller date range"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:09.679278Z",
     "start_time": "2022-08-16T02:38:09.536182Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 122172 characters]\n",
      "text/plain": [
       "<Figure size 1080x576 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot = pq.Plot([indicator_subplot, signal_subplot], title = 'PEP', date_range = ('2019-01-14', '2019-01-18'))\n",
    "plot.draw();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This looks good.  The signal behaves as we would expect.\n",
    "\n",
    "The next step is to create a trading rule.  pyqstrat will call a trading rule function when the value of it's associated signal changes value, or when we have live orders in the market that have not been filled.  A trading rule decides whether or not to take action on the signal.  If it decides to take action, it returns a list of one or more orders.  This is also where margin decisions are made, i.e. the trading rule code should calculate how much margin is needed, and not place orders if margin is exceeded.\n",
    "\n",
    "Trading rules are usually path dependent, i.e. they cannot be vectorized like indicators and signals can, since they can depend on current position, risk, or other data which are dependent on previous orders and trades.  \n",
    "\n",
    "Because of this path dependence, pyqstrat calls order rule functions in a loop, once per date.  This is the part of the code (along with market simulation) that you should optimize as much as you can.\n",
    "\n",
    "Lets build the trading rule.  We will risk 10% of our current equity when going long or short.  When entering a position, we use a stop order.  This means the system will only enter if the price crosses the current close during the next bar.  We are trying to avoid a case where we cross a bollinger band in this bar but then price immediately goes the other way in the next bar, in which case we should not enter the trade.  We will ignore margin in this case for simplicity.  If we wanted to check margin, we would add code here that would check if margin would be exceeded (based on broker specific logic), and modify the order qty accordingly.\n",
    "\n",
    "We are using predefined order reason codes when we create orders below.  Reason codes are optional strings that we use to identify why we entered an order and are useful for debugging and for plotting.  You can use an arbitrary string as a reason code.  If you later want to identify those trades in a plot, you will have to provide a mapping between your reason codes and the marker shape, size and color used for that reason code."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:09.683619Z",
     "start_time": "2022-08-16T02:38:09.680036Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "def bollinger_band_trading_rule(contract_group, i, timestamps, indicators, signal, account, strategy_context):\n",
    "    timestamp = timestamps[i]\n",
    "    curr_pos = account.position(contract_group, timestamp)\n",
    "    signal_value = signal[i]\n",
    "    risk_percent = 0.1\n",
    "    close_price = indicators.c[i]\n",
    "    \n",
    "    contract = contract_group.get_contract('PEP')\n",
    "    if contract is None:\n",
    "        contract = pq.Contract.create(symbol = 'PEP', contract_group = contract_group)\n",
    "        \n",
    "    order = None\n",
    "    # if we don't already have a position, check if we should enter a trade\n",
    "    if math.isclose(curr_pos, 0):\n",
    "        if signal_value == 2 or signal_value == -2:\n",
    "            curr_equity = account.equity(timestamp)\n",
    "            order_qty = np.round(curr_equity * risk_percent / close_price * np.sign(signal_value))\n",
    "            trigger_price = close_price\n",
    "            reason_code = pq.ReasonCode.ENTER_LONG if order_qty > 0 else pq.ReasonCode.ENTER_SHORT\n",
    "            order = pq.StopLimitOrder(contract, timestamp, order_qty, trigger_price, reason_code = reason_code)\n",
    "    else: # We have a current position, so check if we should exit\n",
    "        if (curr_pos > 0 and signal_value == -1) or (curr_pos < 0 and signal_value == 1):\n",
    "            order_qty = -curr_pos\n",
    "            reason_code = pq.ReasonCode.EXIT_LONG if order_qty < 0 else pq.ReasonCode.EXIT_SHORT\n",
    "            order = pq.MarketOrder(contract, timestamp, order_qty, reason_code = reason_code)\n",
    "            \n",
    "    if order is not None:\n",
    "        if order_qty > 0: \n",
    "            print(f'Enter: {timestamp.astype(\"M8[m]\")} {order}')\n",
    "        else:\n",
    "            print(f'Exit: {timestamp.astype(\"M8[m]\")} {order}')\n",
    "            \n",
    "    return [order] if order is not None else []"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We need to write one more function, a market simulator.  The market simulator decides whether open orders will be filled, and at what price.  This is where you would add slippage, commissions and fees.  You can add a different market simulator for each symbol, since liquidity and market rules are clearly different when trading an IBM stock on NYSE versus trading a E-mini future on CME.  pyqstrat will call the market simulator on the next bar after you add an order since you obviously cannot get filled using prices you already saw and used to construct your order.  In this simulator we fill buy market orders half way between the open and the high for the current bar, and we fill sells half way between the open and the low. Stop orders are filled halfway between the trigger price and the high or low.  Lets assume commission of $5 per contract and no other fees."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:09.687842Z",
     "start_time": "2022-08-16T02:38:09.684413Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "def market_simulator(orders, i, timestamps, indicators, signals, strategy_context):\n",
    "    trades = []\n",
    "    timestamp = timestamps[i]\n",
    "    \n",
    "    \n",
    "    for order in orders:\n",
    "        cgroup = order.contract.contract_group\n",
    "        ind = indicators[cgroup]\n",
    "        o, h, l, c = ind.o[i], ind.h[i], ind.l[i], ind.c[i]\n",
    "        \n",
    "        trade_price = np.nan\n",
    "        \n",
    "        if isinstance(order, pq.MarketOrder):\n",
    "            trade_price = 0.5 * (o + h) if order.qty > 0 else 0.5 * (o + l)\n",
    "        elif isinstance(order, pq.StopLimitOrder):\n",
    "            if (order.qty > 0 and h > order.trigger_price) or (order.qty < 0 and l < order.trigger_price): # A stop order\n",
    "                trade_price = 0.5 * (order.trigger_price + h) if order.qty > 0 else 0.5 * (order.trigger_price + l)\n",
    "        else:\n",
    "            raise Exception(f'unexpected order type: {order}')\n",
    "            \n",
    "        if np.isnan(trade_price): continue\n",
    "            \n",
    "        trade = pq.Trade(order.contract, order, timestamp, order.qty, trade_price, commission = abs(order.qty) * 5, fee = 0)\n",
    "        print(f'Trade: {timestamp.astype(\"M8[m]\")} {trade}')\n",
    "        order.status = 'filled'\n",
    "                           \n",
    "        trades.append(trade)\n",
    "                           \n",
    "    return trades"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We also need a price function that the strategy calls when it needs to compute P&L, for example when you ask for current equity in trading rule code."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:09.690090Z",
     "start_time": "2022-08-16T02:38:09.688599Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "def get_price(contract, timestamps, i, strategy_context):\n",
    "    return prices.c[i]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now lets create the strategy and run it.\n",
    "\n",
    "**Note that we set the trade_lag argument to 1 so that there is at least one bar between the time we place the order and the time the system creates a trade.**\n",
    "\n",
    "This is good practice, since in practice some time elapses between you getting market data and placing the order and the exchange executing the order.  However, if you only have daily bars, you may want to simulate executing at the same price at which you placed the order, since a one day lag is obviously too long.  In this case you would use the default trade lag, which is 0."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:09.720481Z",
     "start_time": "2022-08-16T02:38:09.692358Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter: 2019-01-14T09:45 PEP 2019-01-14 09:45:00 qty: 931.0 trigger_prc: 107.38 limit_prc: nan enter long namespace(trigger_price=107.38, limit_price=nan) open\n",
      "Trade: 2019-01-14T10:00 PEP 2019-01-14 10:00:00 qty: 931.0 prc: 107.48 commission: 4655 order: PEP 2019-01-14 09:45:00 qty: 931.0 trigger_prc: 107.38 limit_prc: nan enter long namespace(trigger_price=107.38, limit_price=nan) open\n",
      "Exit: 2019-01-14T14:30 PEP 2019-01-14 14:30:00 qty: -931.0 exit long open\n",
      "Trade: 2019-01-14T14:45 PEP 2019-01-14 14:45:00 qty: -931.0 prc: 107.33 commission: 4655 order: PEP 2019-01-14 14:30:00 qty: -931.0 exit long open\n",
      "Enter: 2019-01-14T15:00 PEP 2019-01-14 15:00:00 qty: 920.0 trigger_prc: 107.63 limit_prc: nan enter long namespace(trigger_price=107.63, limit_price=nan) open\n",
      "Trade: 2019-01-14T15:15 PEP 2019-01-14 15:15:00 qty: 920.0 prc: 107.635 commission: 4600 order: PEP 2019-01-14 15:00:00 qty: 920.0 trigger_prc: 107.63 limit_prc: nan enter long namespace(trigger_price=107.63, limit_price=nan) open\n",
      "Exit: 2019-01-15T14:30 PEP 2019-01-15 14:30:00 qty: -920.0 exit long open\n",
      "Trade: 2019-01-15T14:45 PEP 2019-01-15 14:45:00 qty: -920.0 prc: 108.31 commission: 4600 order: PEP 2019-01-15 14:30:00 qty: -920.0 exit long open\n",
      "Exit: 2019-01-15T14:45 PEP 2019-01-15 14:45:00 qty: -906.0 trigger_prc: 108.38 limit_prc: nan enter short namespace(trigger_price=108.38, limit_price=nan) open\n",
      "Trade: 2019-01-15T15:00 PEP 2019-01-15 15:00:00 qty: -906.0 prc: 108.365 commission: 4530 order: PEP 2019-01-15 14:45:00 qty: -906.0 trigger_prc: 108.38 limit_prc: nan enter short namespace(trigger_price=108.38, limit_price=nan) open\n",
      "Enter: 2019-01-15T15:15 PEP 2019-01-15 15:15:00 qty: 906.0 exit short open\n",
      "Trade: 2019-01-15T15:30 PEP 2019-01-15 15:30:00 qty: 906.0 prc: 108.718 commission: 4530 order: PEP 2019-01-15 15:15:00 qty: 906.0 exit short open\n",
      "Enter: 2019-01-15T15:30 PEP 2019-01-15 15:30:00 qty: 894.0 trigger_prc: 108.755 limit_prc: nan enter long namespace(trigger_price=108.755, limit_price=nan) open\n",
      "Trade: 2019-01-15T15:45 PEP 2019-01-15 15:45:00 qty: 894.0 prc: 108.822 commission: 4470 order: PEP 2019-01-15 15:30:00 qty: 894.0 trigger_prc: 108.755 limit_prc: nan enter long namespace(trigger_price=108.755, limit_price=nan) open\n",
      "Exit: 2019-01-16T13:15 PEP 2019-01-16 13:15:00 qty: -894.0 exit long open\n",
      "Trade: 2019-01-16T13:30 PEP 2019-01-16 13:30:00 qty: -894.0 prc: 108.02 commission: 4470 order: PEP 2019-01-16 13:15:00 qty: -894.0 exit long open\n",
      "Enter: 2019-01-16T14:30 PEP 2019-01-16 14:30:00 qty: 888.0 trigger_prc: 108.38 limit_prc: nan enter long namespace(trigger_price=108.38, limit_price=nan) open\n",
      "Trade: 2019-01-16T14:45 PEP 2019-01-16 14:45:00 qty: 888.0 prc: 108.438 commission: 4440 order: PEP 2019-01-16 14:30:00 qty: 888.0 trigger_prc: 108.38 limit_prc: nan enter long namespace(trigger_price=108.38, limit_price=nan) open\n",
      "Exit: 2019-01-17T13:15 PEP 2019-01-17 13:15:00 qty: -888.0 exit long open\n",
      "Trade: 2019-01-17T13:30 PEP 2019-01-17 13:30:00 qty: -888.0 prc: 108.615 commission: 4440 order: PEP 2019-01-17 13:15:00 qty: -888.0 exit long open\n",
      "Exit: 2019-01-17T14:30 PEP 2019-01-17 14:30:00 qty: -877.0 trigger_prc: 108.75 limit_prc: nan enter short namespace(trigger_price=108.75, limit_price=nan) open\n",
      "Trade: 2019-01-17T14:45 PEP 2019-01-17 14:45:00 qty: -877.0 prc: 108.725 commission: 4385 order: PEP 2019-01-17 14:30:00 qty: -877.0 trigger_prc: 108.75 limit_prc: nan enter short namespace(trigger_price=108.75, limit_price=nan) open\n",
      "Enter: 2019-01-17T15:30 PEP 2019-01-17 15:30:00 qty: 877.0 exit short open\n",
      "Trade: 2019-01-17T15:45 PEP 2019-01-17 15:45:00 qty: 877.0 prc: 109.14 commission: 4385 order: PEP 2019-01-17 15:30:00 qty: 877.0 exit short open\n",
      "Enter: 2019-01-17T15:45 PEP 2019-01-17 15:45:00 qty: 867.0 trigger_prc: 109.02 limit_prc: nan enter long namespace(trigger_price=109.02, limit_price=nan) open\n",
      "Trade: 2019-01-17T16:00 PEP 2019-01-17 16:00:00 qty: 867.0 prc: 109.12 commission: 4335 order: PEP 2019-01-17 15:45:00 qty: 867.0 trigger_prc: 109.02 limit_prc: nan enter long namespace(trigger_price=109.02, limit_price=nan) open\n",
      "Exit: 2019-01-24T11:00 PEP 2019-01-24 11:00:00 qty: -867.0 exit long open\n",
      "Trade: 2019-01-24T11:15 PEP 2019-01-24 11:15:00 qty: -867.0 prc: 109.455 commission: 4335 order: PEP 2019-01-24 11:00:00 qty: -867.0 exit long open\n",
      "Exit: 2019-01-24T13:15 PEP 2019-01-24 13:15:00 qty: -860.0 trigger_prc: 108.8866 limit_prc: nan enter short namespace(trigger_price=108.8866, limit_price=nan) open\n",
      "Trade: 2019-01-24T13:30 PEP 2019-01-24 13:30:00 qty: -860.0 prc: 108.813 commission: 4300 order: PEP 2019-01-24 13:15:00 qty: -860.0 trigger_prc: 108.8866 limit_prc: nan enter short namespace(trigger_price=108.8866, limit_price=nan) open\n",
      "Enter: 2019-01-24T14:30 PEP 2019-01-24 14:30:00 qty: 860.0 exit short open\n",
      "Trade: 2019-01-24T14:45 PEP 2019-01-24 14:45:00 qty: 860.0 prc: 109.24 commission: 4300 order: PEP 2019-01-24 14:30:00 qty: 860.0 exit short open\n",
      "Enter: 2019-01-24T15:30 PEP 2019-01-24 15:30:00 qty: 848.0 trigger_prc: 109.355 limit_prc: nan enter long namespace(trigger_price=109.355, limit_price=nan) open\n",
      "Trade: 2019-01-24T15:45 PEP 2019-01-24 15:45:00 qty: 848.0 prc: 109.373 commission: 4240 order: PEP 2019-01-24 15:30:00 qty: 848.0 trigger_prc: 109.355 limit_prc: nan enter long namespace(trigger_price=109.355, limit_price=nan) open\n",
      "Exit: 2019-01-25T12:45 PEP 2019-01-25 12:45:00 qty: -848.0 exit long open\n",
      "Trade: 2019-01-25T13:00 PEP 2019-01-25 13:00:00 qty: -848.0 prc: 109.45 commission: 4240 order: PEP 2019-01-25 12:45:00 qty: -848.0 exit long open\n",
      "Exit: 2019-01-25T13:00 PEP 2019-01-25 13:00:00 qty: -840.0 trigger_prc: 109.42 limit_prc: nan enter short namespace(trigger_price=109.42, limit_price=nan) open\n",
      "Trade: 2019-01-25T13:15 PEP 2019-01-25 13:15:00 qty: -840.0 prc: 109.365 commission: 4200 order: PEP 2019-01-25 13:00:00 qty: -840.0 trigger_prc: 109.42 limit_prc: nan enter short namespace(trigger_price=109.42, limit_price=nan) open\n",
      "Enter: 2019-01-28T14:00 PEP 2019-01-28 14:00:00 qty: 840.0 exit short open\n",
      "Trade: 2019-01-28T14:15 PEP 2019-01-28 14:15:00 qty: 840.0 prc: 108.595 commission: 4200 order: PEP 2019-01-28 14:00:00 qty: 840.0 exit short open\n",
      "Enter: 2019-01-28T14:45 PEP 2019-01-28 14:45:00 qty: 840.0 trigger_prc: 108.51 limit_prc: nan enter long namespace(trigger_price=108.51, limit_price=nan) open\n",
      "Trade: 2019-01-28T15:00 PEP 2019-01-28 15:00:00 qty: 840.0 prc: 108.605 commission: 4200 order: PEP 2019-01-28 14:45:00 qty: 840.0 trigger_prc: 108.51 limit_prc: nan enter long namespace(trigger_price=108.51, limit_price=nan) open\n",
      "Exit: 2019-01-29T13:15 PEP 2019-01-29 13:15:00 qty: -840.0 exit long open\n",
      "Trade: 2019-01-29T13:30 PEP 2019-01-29 13:30:00 qty: -840.0 prc: 108.71 commission: 4200 order: PEP 2019-01-29 13:15:00 qty: -840.0 exit long open\n",
      "Exit: 2019-01-29T14:45 PEP 2019-01-29 14:45:00 qty: -831.0 trigger_prc: 108.68 limit_prc: nan enter short namespace(trigger_price=108.68, limit_price=nan) open\n",
      "Trade: 2019-01-29T15:00 PEP 2019-01-29 15:00:00 qty: -831.0 prc: 108.6 commission: 4155 order: PEP 2019-01-29 14:45:00 qty: -831.0 trigger_prc: 108.68 limit_prc: nan enter short namespace(trigger_price=108.68, limit_price=nan) open\n",
      "Enter: 2019-01-29T15:45 PEP 2019-01-29 15:45:00 qty: 831.0 exit short open\n",
      "Trade: 2019-01-29T16:00 PEP 2019-01-29 16:00:00 qty: 831.0 prc: 108.995 commission: 4155 order: PEP 2019-01-29 15:45:00 qty: 831.0 exit short open\n",
      "Exit: 2019-01-29T16:00 PEP 2019-01-29 16:00:00 qty: -821.0 trigger_prc: 108.99 limit_prc: nan enter short namespace(trigger_price=108.99, limit_price=nan) open\n",
      "Trade: 2019-01-30T09:45 PEP 2019-01-30 09:45:00 qty: -821.0 prc: 108.875 commission: 4105 order: PEP 2019-01-29 16:00:00 qty: -821.0 trigger_prc: 108.99 limit_prc: nan enter short namespace(trigger_price=108.99, limit_price=nan) open\n",
      "Enter: 2019-01-30T13:00 PEP 2019-01-30 13:00:00 qty: 821.0 exit short open\n",
      "Trade: 2019-01-30T13:15 PEP 2019-01-30 13:15:00 qty: 821.0 prc: 110.36 commission: 4105 order: PEP 2019-01-30 13:00:00 qty: 821.0 exit short open\n",
      "Enter: 2019-01-30T14:15 PEP 2019-01-30 14:15:00 qty: 798.0 trigger_prc: 110.96 limit_prc: nan enter long namespace(trigger_price=110.96, limit_price=nan) open\n",
      "Trade: 2019-01-30T14:30 PEP 2019-01-30 14:30:00 qty: 798.0 prc: 110.985 commission: 3990 order: PEP 2019-01-30 14:15:00 qty: 798.0 trigger_prc: 110.96 limit_prc: nan enter long namespace(trigger_price=110.96, limit_price=nan) open\n",
      "Exit: 2019-02-01T11:45 PEP 2019-02-01 11:45:00 qty: -798.0 exit long open\n",
      "Trade: 2019-02-01T12:00 PEP 2019-02-01 12:00:00 qty: -798.0 prc: 112.107 commission: 3990 order: PEP 2019-02-01 11:45:00 qty: -798.0 exit long open\n",
      "Exit: 2019-02-01T12:30 PEP 2019-02-01 12:30:00 qty: -786.0 trigger_prc: 111.71 limit_prc: nan enter short namespace(trigger_price=111.71, limit_price=nan) open\n",
      "Trade: 2019-02-01T12:45 PEP 2019-02-01 12:45:00 qty: -786.0 prc: 111.625 commission: 3930 order: PEP 2019-02-01 12:30:00 qty: -786.0 trigger_prc: 111.71 limit_prc: nan enter short namespace(trigger_price=111.71, limit_price=nan) open\n",
      "Enter: 2019-02-01T14:15 PEP 2019-02-01 14:15:00 qty: 786.0 exit short open\n",
      "Trade: 2019-02-01T14:30 PEP 2019-02-01 14:30:00 qty: 786.0 prc: 112.08 commission: 3930 order: PEP 2019-02-01 14:15:00 qty: 786.0 exit short open\n",
      "Enter: 2019-02-01T15:45 PEP 2019-02-01 15:45:00 qty: 775.0 trigger_prc: 112.21 limit_prc: nan enter long namespace(trigger_price=112.21, limit_price=nan) open\n",
      "Trade: 2019-02-01T16:00 PEP 2019-02-01 16:00:00 qty: 775.0 prc: 112.23 commission: 3875 order: PEP 2019-02-01 15:45:00 qty: 775.0 trigger_prc: 112.21 limit_prc: nan enter long namespace(trigger_price=112.21, limit_price=nan) open\n",
      "Exit: 2019-02-05T14:45 PEP 2019-02-05 14:45:00 qty: -775.0 exit long open\n",
      "Trade: 2019-02-05T15:00 PEP 2019-02-05 15:00:00 qty: -775.0 prc: 112.97 commission: 3875 order: PEP 2019-02-05 14:45:00 qty: -775.0 exit long open\n",
      "Exit: 2019-02-05T16:00 PEP 2019-02-05 16:00:00 qty: -764.0 trigger_prc: 112.9 limit_prc: nan enter short namespace(trigger_price=112.9, limit_price=nan) open\n",
      "Trade: 2019-02-06T09:45 PEP 2019-02-06 09:45:00 qty: -764.0 prc: 112.715 commission: 3820 order: PEP 2019-02-05 16:00:00 qty: -764.0 trigger_prc: 112.9 limit_prc: nan enter short namespace(trigger_price=112.9, limit_price=nan) open\n",
      "Enter: 2019-02-06T10:45 PEP 2019-02-06 10:45:00 qty: 764.0 exit short open\n",
      "Trade: 2019-02-06T11:00 PEP 2019-02-06 11:00:00 qty: 764.0 prc: 112.83 commission: 3820 order: PEP 2019-02-06 10:45:00 qty: 764.0 exit short open\n",
      "Enter: 2019-02-06T13:15 PEP 2019-02-06 13:15:00 qty: 756.0 trigger_prc: 113.02 limit_prc: nan enter long namespace(trigger_price=113.02, limit_price=nan) open\n",
      "Enter: 2019-02-06T13:30 PEP 2019-02-06 13:30:00 qty: 757.0 trigger_prc: 112.97 limit_prc: nan enter long namespace(trigger_price=112.97, limit_price=nan) open\n",
      "Trade: 2019-02-06T13:45 PEP 2019-02-06 13:45:00 qty: 757.0 prc: 113.015 commission: 3785 order: PEP 2019-02-06 13:30:00 qty: 757.0 trigger_prc: 112.97 limit_prc: nan enter long namespace(trigger_price=112.97, limit_price=nan) open\n",
      "Exit: 2019-02-07T13:15 PEP 2019-02-07 13:15:00 qty: -757.0 exit long open\n",
      "Trade: 2019-02-07T13:30 PEP 2019-02-07 13:30:00 qty: -757.0 prc: 112.53 commission: 3785 order: PEP 2019-02-07 13:15:00 qty: -757.0 exit long open\n",
      "Enter: 2019-02-07T14:30 PEP 2019-02-07 14:30:00 qty: 751.0 trigger_prc: 112.86 limit_prc: nan enter long namespace(trigger_price=112.86, limit_price=nan) open\n",
      "Trade: 2019-02-07T14:45 PEP 2019-02-07 14:45:00 qty: 751.0 prc: 112.882 commission: 3755 order: PEP 2019-02-07 14:30:00 qty: 751.0 trigger_prc: 112.86 limit_prc: nan enter long namespace(trigger_price=112.86, limit_price=nan) open\n",
      "Exit: 2019-02-08T13:45 PEP 2019-02-08 13:45:00 qty: -751.0 exit long open\n",
      "Trade: 2019-02-08T14:00 PEP 2019-02-08 14:00:00 qty: -751.0 prc: 112.03 commission: 3755 order: PEP 2019-02-08 13:45:00 qty: -751.0 exit long open\n",
      "Enter: 2019-02-08T14:30 PEP 2019-02-08 14:30:00 qty: 747.0 trigger_prc: 112.36 limit_prc: nan enter long namespace(trigger_price=112.36, limit_price=nan) open\n",
      "Trade: 2019-02-08T14:45 PEP 2019-02-08 14:45:00 qty: 747.0 prc: 112.465 commission: 3735 order: PEP 2019-02-08 14:30:00 qty: 747.0 trigger_prc: 112.36 limit_prc: nan enter long namespace(trigger_price=112.36, limit_price=nan) open\n",
      "Exit: 2019-02-13T12:30 PEP 2019-02-13 12:30:00 qty: -747.0 exit long open\n",
      "Trade: 2019-02-13T12:45 PEP 2019-02-13 12:45:00 qty: -747.0 prc: 113.817 commission: 3735 order: PEP 2019-02-13 12:30:00 qty: -747.0 exit long open\n",
      "Exit: 2019-02-13T14:30 PEP 2019-02-13 14:30:00 qty: -732.0 trigger_prc: 113.75 limit_prc: nan enter short namespace(trigger_price=113.75, limit_price=nan) open\n",
      "Trade: 2019-02-13T14:45 PEP 2019-02-13 14:45:00 qty: -732.0 prc: 113.72 commission: 3660 order: PEP 2019-02-13 14:30:00 qty: -732.0 trigger_prc: 113.75 limit_prc: nan enter short namespace(trigger_price=113.75, limit_price=nan) open\n",
      "Enter: 2019-02-14T13:30 PEP 2019-02-14 13:30:00 qty: 732.0 exit short open\n",
      "Trade: 2019-02-14T13:45 PEP 2019-02-14 13:45:00 qty: 732.0 prc: 112.795 commission: 3660 order: PEP 2019-02-14 13:30:00 qty: 732.0 exit short open\n",
      "Enter: 2019-02-14T14:45 PEP 2019-02-14 14:45:00 qty: 732.0 trigger_prc: 112.74 limit_prc: nan enter long namespace(trigger_price=112.74, limit_price=nan) open\n",
      "Trade: 2019-02-14T15:00 PEP 2019-02-14 15:00:00 qty: 732.0 prc: 112.78 commission: 3660 order: PEP 2019-02-14 14:45:00 qty: 732.0 trigger_prc: 112.74 limit_prc: nan enter long namespace(trigger_price=112.74, limit_price=nan) open\n",
      "Exit: 2019-02-15T14:30 PEP 2019-02-15 14:30:00 qty: -732.0 exit long open\n",
      "Trade: 2019-02-15T14:45 PEP 2019-02-15 14:45:00 qty: -732.0 prc: 115.26 commission: 3660 order: PEP 2019-02-15 14:30:00 qty: -732.0 exit long open\n",
      "Exit: 2019-02-15T14:45 PEP 2019-02-15 14:45:00 qty: -712.0 trigger_prc: 115.24 limit_prc: nan enter short namespace(trigger_price=115.24, limit_price=nan) open\n",
      "Trade: 2019-02-15T15:00 PEP 2019-02-15 15:00:00 qty: -712.0 prc: 115.13 commission: 3560 order: PEP 2019-02-15 14:45:00 qty: -712.0 trigger_prc: 115.24 limit_prc: nan enter short namespace(trigger_price=115.24, limit_price=nan) open\n",
      "Enter: 2019-02-15T16:00 PEP 2019-02-15 16:00:00 qty: 712.0 exit short open\n",
      "Trade: 2019-02-19T09:45 PEP 2019-02-19 09:45:00 qty: 712.0 prc: 116.87 commission: 3560 order: PEP 2019-02-15 16:00:00 qty: 712.0 exit short open\n",
      "Exit: 2019-02-19T09:45 PEP 2019-02-19 09:45:00 qty: -700.0 trigger_prc: 116.03 limit_prc: nan enter short namespace(trigger_price=116.03, limit_price=nan) open\n",
      "Trade: 2019-02-19T10:00 PEP 2019-02-19 10:00:00 qty: -700.0 prc: 115.775 commission: 3500 order: PEP 2019-02-19 09:45:00 qty: -700.0 trigger_prc: 116.03 limit_prc: nan enter short namespace(trigger_price=116.03, limit_price=nan) open\n",
      "Enter: 2019-02-19T10:00 PEP 2019-02-19 10:00:00 qty: 700.0 exit short open\n",
      "Trade: 2019-02-19T10:15 PEP 2019-02-19 10:15:00 qty: 700.0 prc: 115.61 commission: 3500 order: PEP 2019-02-19 10:00:00 qty: 700.0 exit short open\n",
      "Exit: 2019-02-19T10:30 PEP 2019-02-19 10:30:00 qty: -696.0 trigger_prc: 115.63 limit_prc: nan enter short namespace(trigger_price=115.63, limit_price=nan) open\n",
      "Trade: 2019-02-19T10:45 PEP 2019-02-19 10:45:00 qty: -696.0 prc: 115.545 commission: 3480 order: PEP 2019-02-19 10:30:00 qty: -696.0 trigger_prc: 115.63 limit_prc: nan enter short namespace(trigger_price=115.63, limit_price=nan) open\n",
      "Enter: 2019-02-19T10:45 PEP 2019-02-19 10:45:00 qty: 696.0 exit short open\n",
      "Trade: 2019-02-19T11:00 PEP 2019-02-19 11:00:00 qty: 696.0 prc: 115.595 commission: 3480 order: PEP 2019-02-19 10:45:00 qty: 696.0 exit short open\n",
      "Enter: 2019-02-19T11:45 PEP 2019-02-19 11:45:00 qty: 688.0 trigger_prc: 115.97 limit_prc: nan enter long namespace(trigger_price=115.97, limit_price=nan) open\n",
      "Trade: 2019-02-19T12:00 PEP 2019-02-19 12:00:00 qty: 688.0 prc: 116.08 commission: 3440 order: PEP 2019-02-19 11:45:00 qty: 688.0 trigger_prc: 115.97 limit_prc: nan enter long namespace(trigger_price=115.97, limit_price=nan) open\n",
      "Exit: 2019-02-19T14:30 PEP 2019-02-19 14:30:00 qty: -688.0 exit long open\n",
      "Trade: 2019-02-19T14:45 PEP 2019-02-19 14:45:00 qty: -688.0 prc: 115.725 commission: 3440 order: PEP 2019-02-19 14:30:00 qty: -688.0 exit long open\n",
      "Enter: 2019-02-19T15:00 PEP 2019-02-19 15:00:00 qty: 681.0 trigger_prc: 116.14 limit_prc: nan enter long namespace(trigger_price=116.14, limit_price=nan) open\n",
      "Trade: 2019-02-19T15:15 PEP 2019-02-19 15:15:00 qty: 681.0 prc: 116.148 commission: 3405 order: PEP 2019-02-19 15:00:00 qty: 681.0 trigger_prc: 116.14 limit_prc: nan enter long namespace(trigger_price=116.14, limit_price=nan) open\n",
      "Exit: 2019-02-20T12:00 PEP 2019-02-20 12:00:00 qty: -681.0 exit long open\n",
      "Trade: 2019-02-20T12:15 PEP 2019-02-20 12:15:00 qty: -681.0 prc: 115.685 commission: 3405 order: PEP 2019-02-20 12:00:00 qty: -681.0 exit long open\n",
      "Exit: 2019-02-20T12:15 PEP 2019-02-20 12:15:00 qty: -678.0 trigger_prc: 115.6066 limit_prc: nan enter short namespace(trigger_price=115.6066, limit_price=nan) open\n",
      "Trade: 2019-02-20T12:30 PEP 2019-02-20 12:30:00 qty: -678.0 prc: 115.553 commission: 3390 order: PEP 2019-02-20 12:15:00 qty: -678.0 trigger_prc: 115.6066 limit_prc: nan enter short namespace(trigger_price=115.6066, limit_price=nan) open\n",
      "Enter: 2019-02-20T14:45 PEP 2019-02-20 14:45:00 qty: 678.0 exit short open\n",
      "Trade: 2019-02-20T15:00 PEP 2019-02-20 15:00:00 qty: 678.0 prc: 115.835 commission: 3390 order: PEP 2019-02-20 14:45:00 qty: 678.0 exit short open\n",
      "Exit: 2019-02-20T15:45 PEP 2019-02-20 15:45:00 qty: -671.0 trigger_prc: 115.74 limit_prc: nan enter short namespace(trigger_price=115.74, limit_price=nan) open\n",
      "Trade: 2019-02-20T16:00 PEP 2019-02-20 16:00:00 qty: -671.0 prc: 115.67 commission: 3355 order: PEP 2019-02-20 15:45:00 qty: -671.0 trigger_prc: 115.74 limit_prc: nan enter short namespace(trigger_price=115.74, limit_price=nan) open\n",
      "Enter: 2019-02-21T13:30 PEP 2019-02-21 13:30:00 qty: 671.0 exit short open\n",
      "Trade: 2019-02-21T13:45 PEP 2019-02-21 13:45:00 qty: 671.0 prc: 116.273 commission: 3355 order: PEP 2019-02-21 13:30:00 qty: 671.0 exit short open\n",
      "Exit: 2019-02-21T15:00 PEP 2019-02-21 15:00:00 qty: -664.0 trigger_prc: 115.835 limit_prc: nan enter short namespace(trigger_price=115.835, limit_price=nan) open\n",
      "Trade: 2019-02-21T15:15 PEP 2019-02-21 15:15:00 qty: -664.0 prc: 115.8 commission: 3320 order: PEP 2019-02-21 15:00:00 qty: -664.0 trigger_prc: 115.835 limit_prc: nan enter short namespace(trigger_price=115.835, limit_price=nan) open\n",
      "Enter: 2019-02-22T10:00 PEP 2019-02-22 10:00:00 qty: 664.0 exit short open\n",
      "Trade: 2019-02-22T10:15 PEP 2019-02-22 10:15:00 qty: 664.0 prc: 116.55 commission: 3320 order: PEP 2019-02-22 10:00:00 qty: 664.0 exit short open\n",
      "Enter: 2019-02-22T11:30 PEP 2019-02-22 11:30:00 qty: 655.0 trigger_prc: 116.49 limit_prc: nan enter long namespace(trigger_price=116.49, limit_price=nan) open\n",
      "Trade: 2019-02-22T11:45 PEP 2019-02-22 11:45:00 qty: 655.0 prc: 116.515 commission: 3275 order: PEP 2019-02-22 11:30:00 qty: 655.0 trigger_prc: 116.49 limit_prc: nan enter long namespace(trigger_price=116.49, limit_price=nan) open\n",
      "Exit: 2019-02-25T15:00 PEP 2019-02-25 15:00:00 qty: -655.0 exit long open\n",
      "Trade: 2019-02-25T15:15 PEP 2019-02-25 15:15:00 qty: -655.0 prc: 116.148 commission: 3275 order: PEP 2019-02-25 15:00:00 qty: -655.0 exit long open\n",
      "Exit: 2019-02-26T09:45 PEP 2019-02-26 09:45:00 qty: -652.0 trigger_prc: 115.85 limit_prc: nan enter short namespace(trigger_price=115.85, limit_price=nan) open\n",
      "Trade: 2019-02-26T10:00 PEP 2019-02-26 10:00:00 qty: -652.0 prc: 115.775 commission: 3260 order: PEP 2019-02-26 09:45:00 qty: -652.0 trigger_prc: 115.85 limit_prc: nan enter short namespace(trigger_price=115.85, limit_price=nan) open\n",
      "Enter: 2019-02-26T10:30 PEP 2019-02-26 10:30:00 qty: 652.0 exit short open\n",
      "Trade: 2019-02-26T10:45 PEP 2019-02-26 10:45:00 qty: 652.0 prc: 116.08 commission: 3260 order: PEP 2019-02-26 10:30:00 qty: 652.0 exit short open\n",
      "Exit: 2019-02-26T11:00 PEP 2019-02-26 11:00:00 qty: -649.0 trigger_prc: 115.46 limit_prc: nan enter short namespace(trigger_price=115.46, limit_price=nan) open\n",
      "Exit: 2019-02-26T11:15 PEP 2019-02-26 11:15:00 qty: -647.0 trigger_prc: 115.84 limit_prc: nan enter short namespace(trigger_price=115.84, limit_price=nan) open\n",
      "Trade: 2019-02-26T11:30 PEP 2019-02-26 11:30:00 qty: -647.0 prc: 115.809 commission: 3235 order: PEP 2019-02-26 11:15:00 qty: -647.0 trigger_prc: 115.84 limit_prc: nan enter short namespace(trigger_price=115.84, limit_price=nan) open\n",
      "Enter: 2019-02-26T11:30 PEP 2019-02-26 11:30:00 qty: 647.0 exit short open\n",
      "Trade: 2019-02-26T11:45 PEP 2019-02-26 11:45:00 qty: 647.0 prc: 115.87 commission: 3235 order: PEP 2019-02-26 11:30:00 qty: 647.0 exit short open\n",
      "Exit: 2019-02-26T11:45 PEP 2019-02-26 11:45:00 qty: -642.0 trigger_prc: 115.66 limit_prc: nan enter short namespace(trigger_price=115.66, limit_price=nan) open\n",
      "Trade: 2019-02-26T12:00 PEP 2019-02-26 12:00:00 qty: -642.0 prc: 115.6 commission: 3210 order: PEP 2019-02-26 11:45:00 qty: -642.0 trigger_prc: 115.66 limit_prc: nan enter short namespace(trigger_price=115.66, limit_price=nan) open\n",
      "Enter: 2019-02-26T12:45 PEP 2019-02-26 12:45:00 qty: 642.0 exit short open\n",
      "Trade: 2019-02-26T13:00 PEP 2019-02-26 13:00:00 qty: 642.0 prc: 115.971 commission: 3210 order: PEP 2019-02-26 12:45:00 qty: 642.0 exit short open\n",
      "Enter: 2019-02-26T13:15 PEP 2019-02-26 13:15:00 qty: 634.0 trigger_prc: 116.0253 limit_prc: nan enter long namespace(trigger_price=116.0253, limit_price=nan) open\n",
      "Trade: 2019-02-26T13:30 PEP 2019-02-26 13:30:00 qty: 634.0 prc: 116.088 commission: 3170 order: PEP 2019-02-26 13:15:00 qty: 634.0 trigger_prc: 116.0253 limit_prc: nan enter long namespace(trigger_price=116.0253, limit_price=nan) open\n"
     ]
    }
   ],
   "source": [
    "def build_strategy(contract_group, strategy_context):\n",
    "    strategy = pq.Strategy(timestamps, [contract_group], get_price, trade_lag = 1, strategy_context = strategy_context)\n",
    "    \n",
    "    strategy.add_indicator('o', prices.o.values)\n",
    "    strategy.add_indicator('c', prices.c.values)\n",
    "    strategy.add_indicator('h', prices.h.values)\n",
    "    strategy.add_indicator('l', prices.l.values)\n",
    "    strategy.add_indicator('sma', sma, depends_on = ['c'])\n",
    "    strategy.add_indicator('upper_band', upper_band, depends_on = ['c', 'sma'])\n",
    "    strategy.add_indicator('lower_band', lower_band, depends_on = ['c', 'sma'])\n",
    "    \n",
    "    strategy.add_signal('bb_signal', bollinger_band_signal, depends_on_indicators = ['h', 'l', 'sma', 'upper_band', 'lower_band'])\n",
    "\n",
    "    # ask pqstrat to call our trading rule when the signal has one of the values [-2, -1, 1, 2]\n",
    "    strategy.add_rule('bb_trading_rule', bollinger_band_trading_rule, \n",
    "                      signal_name = 'bb_signal', sig_true_values = [-2, -1, 1, 2])\n",
    "\n",
    "    strategy.add_market_sim(market_simulator)\n",
    "    \n",
    "    return strategy\n",
    "\n",
    "\n",
    "strategy_context = SimpleNamespace(lookback_period = 20, num_std = 1)\n",
    "strategy = build_strategy(contract_group, strategy_context)\n",
    "strategy.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lets plot our strategy and our portfolio and evaluate our returns  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:09.992856Z",
     "start_time": "2022-08-16T02:38:09.721429Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 255256 characters]\n",
      "text/plain": [
       "<Figure size 1440x1080 with 4 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "strategy.plot(primary_indicators = ['c', 'sma', 'upper_band', 'lower_band'],\n",
    "                indicator_properties = {'sma' : {'line_type' : '--'},\n",
    "                                        'upper_band' : {'line_type' : '--', 'color': 'green'},\n",
    "                                        'lower_band' : {'line_type' : '--', 'color': 'green'},\n",
    "                                        'c' : {'color' : 'blue'},\n",
    "                                       })"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:10.183115Z",
     "start_time": "2022-08-16T02:38:09.993537Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    },
    "scrolled": true
   },
   "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",
       "      <th></th>\n",
       "      <td>-0.9271</td>\n",
       "      <td>-2.596</td>\n",
       "      <td>0.008596</td>\n",
       "      <td>-19.02</td>\n",
       "      <td>-19.32</td>\n",
       "      <td>4.786</td>\n",
       "      <td>-10.38</td>\n",
       "      <td>-10.38</td>\n",
       "      <td>0.2502</td>\n",
       "      <td>2019-01-15/2019-02-26</td>\n",
       "      <td>0.2502</td>\n",
       "      <td>2019-01-15/2019-02-26</td>\n",
       "      <td>4/25/0.138</td>\n",
       "      <td>-0.9271</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    gmean   amean       std    shrp     srt      k  calmar     mar mdd_pct  \\\n",
       "  -0.9271  -2.596  0.008596  -19.02  -19.32  4.786  -10.38  -10.38  0.2502   \n",
       "\n",
       "              mdd_dates dd_3y_pct       dd_3y_timestamps      up_dwn     2019  \n",
       "  2019-01-15/2019-02-26    0.2502  2019-01-15/2019-02-26  4/25/0.138  -0.9271  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 100640 characters]\n",
      "text/plain": [
       "<Figure size 1080x576 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "strategy.evaluate_returns();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that we calculate P&L once a day so the equity line produced when we evaluate returns has fewer points than the equity line when we plot the strategy itself.\n",
    "\n",
    "We can also put multiple strategies together in a portfolio and run them simultaneously.  Lets add two instances of the Bollinger Band strategy with two different lookback periods and standard deviation thresholds."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:10.236703Z",
     "start_time": "2022-08-16T02:38:10.184010Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter: 2019-01-14T09:45 PEP 2019-01-14 09:45:00 qty: 931.0 trigger_prc: 107.38 limit_prc: nan enter long namespace(trigger_price=107.38, limit_price=nan) open\n",
      "Enter: 2019-01-14T09:45 PEP 2019-01-14 09:45:00 qty: 931.0 trigger_prc: 107.38 limit_prc: nan enter long namespace(trigger_price=107.38, limit_price=nan) open\n",
      "Trade: 2019-01-14T10:00 PEP 2019-01-14 10:00:00 qty: 931.0 prc: 107.48 commission: 4655 order: PEP 2019-01-14 09:45:00 qty: 931.0 trigger_prc: 107.38 limit_prc: nan enter long namespace(trigger_price=107.38, limit_price=nan) open\n",
      "Trade: 2019-01-14T10:00 PEP 2019-01-14 10:00:00 qty: 931.0 prc: 107.48 commission: 4655 order: PEP 2019-01-14 09:45:00 qty: 931.0 trigger_prc: 107.38 limit_prc: nan enter long namespace(trigger_price=107.38, limit_price=nan) open\n",
      "Exit: 2019-01-14T12:15 PEP 2019-01-14 12:15:00 qty: -931.0 exit long open\n",
      "Trade: 2019-01-14T12:30 PEP 2019-01-14 12:30:00 qty: -931.0 prc: 107.325 commission: 4655 order: PEP 2019-01-14 12:15:00 qty: -931.0 exit long open\n",
      "Enter: 2019-01-14T13:45 PEP 2019-01-14 13:45:00 qty: 921.0 trigger_prc: 107.56 limit_prc: nan enter long namespace(trigger_price=107.56, limit_price=nan) open\n",
      "Trade: 2019-01-14T14:00 PEP 2019-01-14 14:00:00 qty: 921.0 prc: 107.575 commission: 4605 order: PEP 2019-01-14 13:45:00 qty: 921.0 trigger_prc: 107.56 limit_prc: nan enter long namespace(trigger_price=107.56, limit_price=nan) open\n",
      "Exit: 2019-01-15T13:30 PEP 2019-01-15 13:30:00 qty: -921.0 exit long open\n",
      "Trade: 2019-01-15T13:45 PEP 2019-01-15 13:45:00 qty: -921.0 prc: 108.505 commission: 4605 order: PEP 2019-01-15 13:30:00 qty: -921.0 exit long open\n",
      "Enter: 2019-01-15T15:30 PEP 2019-01-15 15:30:00 qty: 903.0 trigger_prc: 108.755 limit_prc: nan enter long namespace(trigger_price=108.755, limit_price=nan) open\n",
      "Trade: 2019-01-15T15:45 PEP 2019-01-15 15:45:00 qty: 903.0 prc: 108.822 commission: 4515 order: PEP 2019-01-15 15:30:00 qty: 903.0 trigger_prc: 108.755 limit_prc: nan enter long namespace(trigger_price=108.755, limit_price=nan) open\n",
      "Exit: 2019-01-16T10:00 PEP 2019-01-16 10:00:00 qty: -903.0 exit long open\n",
      "Trade: 2019-01-16T10:15 PEP 2019-01-16 10:15:00 qty: -903.0 prc: 108.458 commission: 4515 order: PEP 2019-01-16 10:00:00 qty: -903.0 exit long open\n",
      "Exit: 2019-01-16T11:15 PEP 2019-01-16 11:15:00 qty: -902.0 trigger_prc: 107.91 limit_prc: nan enter short namespace(trigger_price=107.91, limit_price=nan) open\n",
      "Trade: 2019-01-16T11:30 PEP 2019-01-16 11:30:00 qty: -902.0 prc: 107.902 commission: 4510 order: PEP 2019-01-16 11:15:00 qty: -902.0 trigger_prc: 107.91 limit_prc: nan enter short namespace(trigger_price=107.91, limit_price=nan) open\n",
      "Enter: 2019-01-16T13:15 PEP 2019-01-16 13:15:00 qty: 902.0 exit short open\n",
      "Trade: 2019-01-16T13:30 PEP 2019-01-16 13:30:00 qty: 902.0 prc: 108.085 commission: 4510 order: PEP 2019-01-16 13:15:00 qty: 902.0 exit short open\n",
      "Enter: 2019-01-16T16:00 PEP 2019-01-16 16:00:00 qty: 890.0 trigger_prc: 108.33 limit_prc: nan enter long namespace(trigger_price=108.33, limit_price=nan) open\n",
      "Trade: 2019-01-17T09:45 PEP 2019-01-17 09:45:00 qty: 890.0 prc: 108.5 commission: 4450 order: PEP 2019-01-16 16:00:00 qty: 890.0 trigger_prc: 108.33 limit_prc: nan enter long namespace(trigger_price=108.33, limit_price=nan) open\n",
      "Exit: 2019-01-17T12:15 PEP 2019-01-17 12:15:00 qty: -890.0 exit long open\n",
      "Trade: 2019-01-17T12:30 PEP 2019-01-17 12:30:00 qty: -890.0 prc: 108.73 commission: 4450 order: PEP 2019-01-17 12:15:00 qty: -890.0 exit long open\n",
      "Exit: 2019-01-17T12:30 PEP 2019-01-17 12:30:00 qty: -878.0 trigger_prc: 108.76 limit_prc: nan enter short namespace(trigger_price=108.76, limit_price=nan) open\n",
      "Trade: 2019-01-17T12:45 PEP 2019-01-17 12:45:00 qty: -878.0 prc: 108.74 commission: 4390 order: PEP 2019-01-17 12:30:00 qty: -878.0 trigger_prc: 108.76 limit_prc: nan enter short namespace(trigger_price=108.76, limit_price=nan) open\n",
      "Enter: 2019-01-17T14:15 PEP 2019-01-17 14:15:00 qty: 878.0 exit short open\n",
      "Trade: 2019-01-17T14:30 PEP 2019-01-17 14:30:00 qty: 878.0 prc: 108.705 commission: 4390 order: PEP 2019-01-17 14:15:00 qty: 878.0 exit short open\n",
      "Enter: 2019-01-17T14:45 PEP 2019-01-17 14:45:00 qty: 867.0 trigger_prc: 109.16 limit_prc: nan enter long namespace(trigger_price=109.16, limit_price=nan) open\n",
      "Trade: 2019-01-17T15:00 PEP 2019-01-17 15:00:00 qty: 867.0 prc: 109.3 commission: 4335 order: PEP 2019-01-17 14:45:00 qty: 867.0 trigger_prc: 109.16 limit_prc: nan enter long namespace(trigger_price=109.16, limit_price=nan) open\n",
      "Exit: 2019-01-22T10:30 PEP 2019-01-22 10:30:00 qty: -867.0 exit long open\n",
      "Trade: 2019-01-22T10:45 PEP 2019-01-22 10:45:00 qty: -867.0 prc: 109.365 commission: 4335 order: PEP 2019-01-22 10:30:00 qty: -867.0 exit long open\n",
      "Exit: 2019-01-22T10:45 PEP 2019-01-22 10:45:00 qty: -858.0 trigger_prc: 109.33 limit_prc: nan enter short namespace(trigger_price=109.33, limit_price=nan) open\n",
      "Trade: 2019-01-22T11:00 PEP 2019-01-22 11:00:00 qty: -858.0 prc: 109.275 commission: 4290 order: PEP 2019-01-22 10:45:00 qty: -858.0 trigger_prc: 109.33 limit_prc: nan enter short namespace(trigger_price=109.33, limit_price=nan) open\n",
      "Enter: 2019-01-22T12:30 PEP 2019-01-22 12:30:00 qty: 858.0 exit short open\n",
      "Trade: 2019-01-22T12:45 PEP 2019-01-22 12:45:00 qty: 858.0 prc: 109.31 commission: 4290 order: PEP 2019-01-22 12:30:00 qty: 858.0 exit short open\n",
      "Exit: 2019-01-22T13:15 PEP 2019-01-22 13:15:00 qty: -852.0 trigger_prc: 109.09 limit_prc: nan enter short namespace(trigger_price=109.09, limit_price=nan) open\n",
      "Trade: 2019-01-22T13:30 PEP 2019-01-22 13:30:00 qty: -852.0 prc: 109.05 commission: 4260 order: PEP 2019-01-22 13:15:00 qty: -852.0 trigger_prc: 109.09 limit_prc: nan enter short namespace(trigger_price=109.09, limit_price=nan) open\n",
      "Enter: 2019-01-22T15:00 PEP 2019-01-22 15:00:00 qty: 852.0 exit short open\n",
      "Trade: 2019-01-22T15:15 PEP 2019-01-22 15:15:00 qty: 852.0 prc: 109.28 commission: 4260 order: PEP 2019-01-22 15:00:00 qty: 852.0 exit short open\n",
      "Enter: 2019-01-22T15:45 PEP 2019-01-22 15:45:00 qty: 841.0 trigger_prc: 109.43 limit_prc: nan enter long namespace(trigger_price=109.43, limit_price=nan) open\n",
      "Trade: 2019-01-22T16:00 PEP 2019-01-22 16:00:00 qty: 841.0 prc: 109.73 commission: 4205 order: PEP 2019-01-22 15:45:00 qty: 841.0 trigger_prc: 109.43 limit_prc: nan enter long namespace(trigger_price=109.43, limit_price=nan) open\n",
      "Exit: 2019-01-23T11:30 PEP 2019-01-23 11:30:00 qty: -841.0 exit long open\n",
      "Trade: 2019-01-23T11:45 PEP 2019-01-23 11:45:00 qty: -841.0 prc: 109.665 commission: 4205 order: PEP 2019-01-23 11:30:00 qty: -841.0 exit long open\n",
      "Exit: 2019-01-23T12:15 PEP 2019-01-23 12:15:00 qty: -831.0 trigger_prc: 109.72 limit_prc: nan enter short namespace(trigger_price=109.72, limit_price=nan) open\n",
      "Trade: 2019-01-23T12:30 PEP 2019-01-23 12:30:00 qty: -831.0 prc: 109.67 commission: 4155 order: PEP 2019-01-23 12:15:00 qty: -831.0 trigger_prc: 109.72 limit_prc: nan enter short namespace(trigger_price=109.72, limit_price=nan) open\n",
      "Enter: 2019-01-23T12:30 PEP 2019-01-23 12:30:00 qty: 831.0 exit short open\n",
      "Trade: 2019-01-23T12:45 PEP 2019-01-23 12:45:00 qty: 831.0 prc: 110.04 commission: 4155 order: PEP 2019-01-23 12:30:00 qty: 831.0 exit short open\n",
      "Enter: 2019-01-23T12:45 PEP 2019-01-23 12:45:00 qty: 820.0 trigger_prc: 110.09 limit_prc: nan enter long namespace(trigger_price=110.09, limit_price=nan) open\n",
      "Trade: 2019-01-23T13:00 PEP 2019-01-23 13:00:00 qty: 820.0 prc: 110.14 commission: 4100 order: PEP 2019-01-23 12:45:00 qty: 820.0 trigger_prc: 110.09 limit_prc: nan enter long namespace(trigger_price=110.09, limit_price=nan) open\n",
      "Exit: 2019-01-24T10:15 PEP 2019-01-24 10:15:00 qty: -820.0 exit long open\n",
      "Exit: 2019-01-24T10:30 PEP 2019-01-24 10:30:00 qty: -931.0 exit long open\n",
      "Trade: 2019-01-24T10:30 PEP 2019-01-24 10:30:00 qty: -820.0 prc: 108.78 commission: 4100 order: PEP 2019-01-24 10:15:00 qty: -820.0 exit long open\n",
      "Trade: 2019-01-24T10:45 PEP 2019-01-24 10:45:00 qty: -931.0 prc: 109.03 commission: 4655 order: PEP 2019-01-24 10:30:00 qty: -931.0 exit long open\n",
      "Enter: 2019-01-24T10:45 PEP 2019-01-24 10:45:00 qty: 907.0 trigger_prc: 109.44 limit_prc: nan enter long namespace(trigger_price=109.44, limit_price=nan) open\n",
      "Trade: 2019-01-24T11:00 PEP 2019-01-24 11:00:00 qty: 907.0 prc: 109.51 commission: 4535 order: PEP 2019-01-24 10:45:00 qty: 907.0 trigger_prc: 109.44 limit_prc: nan enter long namespace(trigger_price=109.44, limit_price=nan) open\n",
      "Exit: 2019-01-24T13:00 PEP 2019-01-24 13:00:00 qty: -820.0 trigger_prc: 109.01 limit_prc: nan enter short namespace(trigger_price=109.01, limit_price=nan) open\n",
      "Trade: 2019-01-24T13:15 PEP 2019-01-24 13:15:00 qty: -820.0 prc: 108.905 commission: 4100 order: PEP 2019-01-24 13:00:00 qty: -820.0 trigger_prc: 109.01 limit_prc: nan enter short namespace(trigger_price=109.01, limit_price=nan) open\n",
      "Enter: 2019-01-24T14:15 PEP 2019-01-24 14:15:00 qty: 820.0 exit short open\n",
      "Trade: 2019-01-24T14:30 PEP 2019-01-24 14:30:00 qty: 820.0 prc: 109.235 commission: 4100 order: PEP 2019-01-24 14:15:00 qty: 820.0 exit short open\n",
      "Enter: 2019-01-25T09:45 PEP 2019-01-25 09:45:00 qty: 804.0 trigger_prc: 110.12 limit_prc: nan enter long namespace(trigger_price=110.12, limit_price=nan) open\n",
      "Trade: 2019-01-25T10:00 PEP 2019-01-25 10:00:00 qty: 804.0 prc: 110.185 commission: 4020 order: PEP 2019-01-25 09:45:00 qty: 804.0 trigger_prc: 110.12 limit_prc: nan enter long namespace(trigger_price=110.12, limit_price=nan) open\n",
      "Exit: 2019-01-25T11:30 PEP 2019-01-25 11:30:00 qty: -804.0 exit long open\n",
      "Trade: 2019-01-25T11:45 PEP 2019-01-25 11:45:00 qty: -804.0 prc: 109.71 commission: 4020 order: PEP 2019-01-25 11:30:00 qty: -804.0 exit long open\n",
      "Exit: 2019-01-25T13:30 PEP 2019-01-25 13:30:00 qty: -802.0 trigger_prc: 109.405 limit_prc: nan enter short namespace(trigger_price=109.405, limit_price=nan) open\n",
      "Trade: 2019-01-25T13:45 PEP 2019-01-25 13:45:00 qty: -802.0 prc: 109.338 commission: 4010 order: PEP 2019-01-25 13:30:00 qty: -802.0 trigger_prc: 109.405 limit_prc: nan enter short namespace(trigger_price=109.405, limit_price=nan) open\n",
      "Enter: 2019-01-25T14:45 PEP 2019-01-25 14:45:00 qty: 802.0 exit short open\n",
      "Trade: 2019-01-25T15:00 PEP 2019-01-25 15:00:00 qty: 802.0 prc: 109.41 commission: 4010 order: PEP 2019-01-25 14:45:00 qty: 802.0 exit short open\n",
      "Exit: 2019-01-25T15:45 PEP 2019-01-25 15:45:00 qty: -794.0 trigger_prc: 109.39 limit_prc: nan enter short namespace(trigger_price=109.39, limit_price=nan) open\n",
      "Trade: 2019-01-25T16:00 PEP 2019-01-25 16:00:00 qty: -794.0 prc: 109.265 commission: 3970 order: PEP 2019-01-25 15:45:00 qty: -794.0 trigger_prc: 109.39 limit_prc: nan enter short namespace(trigger_price=109.39, limit_price=nan) open\n",
      "Enter: 2019-01-28T11:45 PEP 2019-01-28 11:45:00 qty: 794.0 exit short open\n",
      "Trade: 2019-01-28T12:00 PEP 2019-01-28 12:00:00 qty: 794.0 prc: 108.405 commission: 3970 order: PEP 2019-01-28 11:45:00 qty: 794.0 exit short open\n",
      "Enter: 2019-01-29T09:45 PEP 2019-01-29 09:45:00 qty: 787.0 trigger_prc: 109.55 limit_prc: nan enter long namespace(trigger_price=109.55, limit_price=nan) open\n",
      "Trade: 2019-01-29T10:00 PEP 2019-01-29 10:00:00 qty: 787.0 prc: 109.565 commission: 3935 order: PEP 2019-01-29 09:45:00 qty: 787.0 trigger_prc: 109.55 limit_prc: nan enter long namespace(trigger_price=109.55, limit_price=nan) open\n",
      "Exit: 2019-01-29T10:30 PEP 2019-01-29 10:30:00 qty: -907.0 exit long open\n",
      "Trade: 2019-01-29T10:45 PEP 2019-01-29 10:45:00 qty: -907.0 prc: 109.14 commission: 4535 order: PEP 2019-01-29 10:30:00 qty: -907.0 exit long open\n",
      "Exit: 2019-01-29T10:45 PEP 2019-01-29 10:45:00 qty: -901.0 trigger_prc: 109.04 limit_prc: nan enter short namespace(trigger_price=109.04, limit_price=nan) open\n",
      "Trade: 2019-01-29T11:00 PEP 2019-01-29 11:00:00 qty: -901.0 prc: 108.915 commission: 4505 order: PEP 2019-01-29 10:45:00 qty: -901.0 trigger_prc: 109.04 limit_prc: nan enter short namespace(trigger_price=109.04, limit_price=nan) open\n",
      "Exit: 2019-01-29T11:15 PEP 2019-01-29 11:15:00 qty: -787.0 exit long open\n",
      "Enter: 2019-01-29T11:30 PEP 2019-01-29 11:30:00 qty: 901.0 exit short open\n",
      "Trade: 2019-01-29T11:30 PEP 2019-01-29 11:30:00 qty: -787.0 prc: 108.722 commission: 3935 order: PEP 2019-01-29 11:15:00 qty: -787.0 exit long open\n",
      "Trade: 2019-01-29T11:45 PEP 2019-01-29 11:45:00 qty: 901.0 prc: 108.955 commission: 4505 order: PEP 2019-01-29 11:30:00 qty: 901.0 exit short open\n",
      "Enter: 2019-01-29T12:00 PEP 2019-01-29 12:00:00 qty: 893.0 trigger_prc: 109.02 limit_prc: nan enter long namespace(trigger_price=109.02, limit_price=nan) open\n",
      "Exit: 2019-01-29T12:15 PEP 2019-01-29 12:15:00 qty: -894.0 trigger_prc: 108.905 limit_prc: nan enter short namespace(trigger_price=108.905, limit_price=nan) open\n",
      "Trade: 2019-01-29T12:30 PEP 2019-01-29 12:30:00 qty: -894.0 prc: 108.882 commission: 4470 order: PEP 2019-01-29 12:15:00 qty: -894.0 trigger_prc: 108.905 limit_prc: nan enter short namespace(trigger_price=108.905, limit_price=nan) open\n",
      "Exit: 2019-01-29T15:00 PEP 2019-01-29 15:00:00 qty: -786.0 trigger_prc: 108.58 limit_prc: nan enter short namespace(trigger_price=108.58, limit_price=nan) open\n",
      "Trade: 2019-01-29T15:15 PEP 2019-01-29 15:15:00 qty: -786.0 prc: 108.545 commission: 3930 order: PEP 2019-01-29 15:00:00 qty: -786.0 trigger_prc: 108.58 limit_prc: nan enter short namespace(trigger_price=108.58, limit_price=nan) open\n",
      "Enter: 2019-01-29T15:30 PEP 2019-01-29 15:30:00 qty: 894.0 exit short open\n",
      "Trade: 2019-01-29T15:45 PEP 2019-01-29 15:45:00 qty: 894.0 prc: 108.835 commission: 4470 order: PEP 2019-01-29 15:30:00 qty: 894.0 exit short open\n",
      "Enter: 2019-01-29T15:45 PEP 2019-01-29 15:45:00 qty: 886.0 trigger_prc: 108.8985 limit_prc: nan enter long namespace(trigger_price=108.8985, limit_price=nan) open\n",
      "Enter: 2019-01-29T15:45 PEP 2019-01-29 15:45:00 qty: 786.0 exit short open\n",
      "Trade: 2019-01-29T16:00 PEP 2019-01-29 16:00:00 qty: 886.0 prc: 108.979 commission: 4430 order: PEP 2019-01-29 15:45:00 qty: 886.0 trigger_prc: 108.8985 limit_prc: nan enter long namespace(trigger_price=108.8985, limit_price=nan) open\n",
      "Trade: 2019-01-29T16:00 PEP 2019-01-29 16:00:00 qty: 786.0 prc: 108.995 commission: 3930 order: PEP 2019-01-29 15:45:00 qty: 786.0 exit short open\n",
      "Enter: 2019-01-29T16:00 PEP 2019-01-29 16:00:00 qty: 775.0 trigger_prc: 108.99 limit_prc: nan enter long namespace(trigger_price=108.99, limit_price=nan) open\n",
      "Trade: 2019-01-30T09:45 PEP 2019-01-30 09:45:00 qty: 775.0 prc: 109.41 commission: 3875 order: PEP 2019-01-29 16:00:00 qty: 775.0 trigger_prc: 108.99 limit_prc: nan enter long namespace(trigger_price=108.99, limit_price=nan) open\n",
      "Exit: 2019-01-30T13:30 PEP 2019-01-30 13:30:00 qty: -775.0 exit long open\n",
      "Trade: 2019-01-30T13:45 PEP 2019-01-30 13:45:00 qty: -775.0 prc: 110.05 commission: 3875 order: PEP 2019-01-30 13:30:00 qty: -775.0 exit long open\n",
      "Enter: 2019-01-30T14:15 PEP 2019-01-30 14:15:00 qty: 755.0 trigger_prc: 110.96 limit_prc: nan enter long namespace(trigger_price=110.96, limit_price=nan) open\n",
      "Trade: 2019-01-30T14:30 PEP 2019-01-30 14:30:00 qty: 755.0 prc: 110.985 commission: 3775 order: PEP 2019-01-30 14:15:00 qty: 755.0 trigger_prc: 110.96 limit_prc: nan enter long namespace(trigger_price=110.96, limit_price=nan) open\n",
      "Exit: 2019-01-31T13:30 PEP 2019-01-31 13:30:00 qty: -755.0 exit long open\n",
      "Trade: 2019-01-31T13:45 PEP 2019-01-31 13:45:00 qty: -755.0 prc: 111.904 commission: 3775 order: PEP 2019-01-31 13:30:00 qty: -755.0 exit long open\n",
      "Enter: 2019-01-31T15:00 PEP 2019-01-31 15:00:00 qty: 741.0 trigger_prc: 112.13 limit_prc: nan enter long namespace(trigger_price=112.13, limit_price=nan) open\n",
      "Enter: 2019-01-31T15:45 PEP 2019-01-31 15:45:00 qty: 740.0 trigger_prc: 112.31 limit_prc: nan enter long namespace(trigger_price=112.31, limit_price=nan) open\n",
      "Trade: 2019-01-31T16:00 PEP 2019-01-31 16:00:00 qty: 740.0 prc: 112.6 commission: 3700 order: PEP 2019-01-31 15:45:00 qty: 740.0 trigger_prc: 112.31 limit_prc: nan enter long namespace(trigger_price=112.31, limit_price=nan) open\n",
      "Exit: 2019-02-01T11:15 PEP 2019-02-01 11:15:00 qty: -740.0 exit long open\n",
      "Exit: 2019-02-01T11:30 PEP 2019-02-01 11:30:00 qty: -886.0 exit long open\n",
      "Trade: 2019-02-01T11:30 PEP 2019-02-01 11:30:00 qty: -740.0 prc: 112.215 commission: 3700 order: PEP 2019-02-01 11:15:00 qty: -740.0 exit long open\n",
      "Trade: 2019-02-01T11:45 PEP 2019-02-01 11:45:00 qty: -886.0 prc: 112.128 commission: 4430 order: PEP 2019-02-01 11:30:00 qty: -886.0 exit long open\n",
      "Exit: 2019-02-01T11:45 PEP 2019-02-01 11:45:00 qty: -855.0 trigger_prc: 112.1 limit_prc: nan enter short namespace(trigger_price=112.1, limit_price=nan) open\n",
      "Exit: 2019-02-01T12:00 PEP 2019-02-01 12:00:00 qty: -853.0 trigger_prc: 112.365 limit_prc: nan enter short namespace(trigger_price=112.365, limit_price=nan) open\n",
      "Trade: 2019-02-01T12:15 PEP 2019-02-01 12:15:00 qty: -853.0 prc: 112.213 commission: 4265 order: PEP 2019-02-01 12:00:00 qty: -853.0 trigger_prc: 112.365 limit_prc: nan enter short namespace(trigger_price=112.365, limit_price=nan) open\n",
      "Enter: 2019-02-01T13:45 PEP 2019-02-01 13:45:00 qty: 853.0 exit short open\n",
      "Trade: 2019-02-01T14:00 PEP 2019-02-01 14:00:00 qty: 853.0 prc: 111.86 commission: 4265 order: PEP 2019-02-01 13:45:00 qty: 853.0 exit short open\n",
      "Enter: 2019-02-01T14:00 PEP 2019-02-01 14:00:00 qty: 848.0 trigger_prc: 112.12 limit_prc: nan enter long namespace(trigger_price=112.12, limit_price=nan) open\n",
      "Trade: 2019-02-01T14:15 PEP 2019-02-01 14:15:00 qty: 848.0 prc: 112.195 commission: 4240 order: PEP 2019-02-01 14:00:00 qty: 848.0 trigger_prc: 112.12 limit_prc: nan enter long namespace(trigger_price=112.12, limit_price=nan) open\n",
      "Enter: 2019-02-04T09:45 PEP 2019-02-04 09:45:00 qty: 731.0 trigger_prc: 112.57 limit_prc: nan enter long namespace(trigger_price=112.57, limit_price=nan) open\n",
      "Trade: 2019-02-04T10:00 PEP 2019-02-04 10:00:00 qty: 731.0 prc: 112.755 commission: 3655 order: PEP 2019-02-04 09:45:00 qty: 731.0 trigger_prc: 112.57 limit_prc: nan enter long namespace(trigger_price=112.57, limit_price=nan) open\n",
      "Exit: 2019-02-04T10:45 PEP 2019-02-04 10:45:00 qty: -731.0 exit long open\n",
      "Trade: 2019-02-04T11:00 PEP 2019-02-04 11:00:00 qty: -731.0 prc: 112.06 commission: 3655 order: PEP 2019-02-04 10:45:00 qty: -731.0 exit long open\n",
      "Exit: 2019-02-04T15:15 PEP 2019-02-04 15:15:00 qty: -721.0 trigger_prc: 113.08 limit_prc: nan enter short namespace(trigger_price=113.08, limit_price=nan) open\n",
      "Exit: 2019-02-04T15:30 PEP 2019-02-04 15:30:00 qty: -848.0 exit long open\n",
      "Trade: 2019-02-04T15:30 PEP 2019-02-04 15:30:00 qty: -721.0 prc: 113.072 commission: 3605 order: PEP 2019-02-04 15:15:00 qty: -721.0 trigger_prc: 113.08 limit_prc: nan enter short namespace(trigger_price=113.08, limit_price=nan) open\n",
      "Trade: 2019-02-04T15:45 PEP 2019-02-04 15:45:00 qty: -848.0 prc: 113.04 commission: 4240 order: PEP 2019-02-04 15:30:00 qty: -848.0 exit long open\n",
      "Exit: 2019-02-04T15:45 PEP 2019-02-04 15:45:00 qty: -833.0 trigger_prc: 113.18 limit_prc: nan enter short namespace(trigger_price=113.18, limit_price=nan) open\n",
      "Trade: 2019-02-04T16:00 PEP 2019-02-04 16:00:00 qty: -833.0 prc: 113.085 commission: 4165 order: PEP 2019-02-04 15:45:00 qty: -833.0 trigger_prc: 113.18 limit_prc: nan enter short namespace(trigger_price=113.18, limit_price=nan) open\n",
      "Enter: 2019-02-05T10:15 PEP 2019-02-05 10:15:00 qty: 833.0 exit short open\n",
      "Trade: 2019-02-05T10:30 PEP 2019-02-05 10:30:00 qty: 833.0 prc: 113.015 commission: 4165 order: PEP 2019-02-05 10:15:00 qty: 833.0 exit short open\n",
      "Enter: 2019-02-05T10:30 PEP 2019-02-05 10:30:00 qty: 826.0 trigger_prc: 113.11 limit_prc: nan enter long namespace(trigger_price=113.11, limit_price=nan) open\n",
      "Enter: 2019-02-05T10:30 PEP 2019-02-05 10:30:00 qty: 721.0 exit short open\n",
      "Trade: 2019-02-05T10:45 PEP 2019-02-05 10:45:00 qty: 826.0 prc: 113.267 commission: 4130 order: PEP 2019-02-05 10:30:00 qty: 826.0 trigger_prc: 113.11 limit_prc: nan enter long namespace(trigger_price=113.11, limit_price=nan) open\n",
      "Trade: 2019-02-05T10:45 PEP 2019-02-05 10:45:00 qty: 721.0 prc: 113.277 commission: 3605 order: PEP 2019-02-05 10:30:00 qty: 721.0 exit short open\n",
      "Enter: 2019-02-05T11:00 PEP 2019-02-05 11:00:00 qty: 712.0 trigger_prc: 113.395 limit_prc: nan enter long namespace(trigger_price=113.395, limit_price=nan) open\n",
      "Trade: 2019-02-05T11:15 PEP 2019-02-05 11:15:00 qty: 712.0 prc: 113.407 commission: 3560 order: PEP 2019-02-05 11:00:00 qty: 712.0 trigger_prc: 113.395 limit_prc: nan enter long namespace(trigger_price=113.395, limit_price=nan) open\n",
      "Exit: 2019-02-05T12:45 PEP 2019-02-05 12:45:00 qty: -712.0 exit long open\n",
      "Trade: 2019-02-05T13:00 PEP 2019-02-05 13:00:00 qty: -712.0 prc: 112.98 commission: 3560 order: PEP 2019-02-05 12:45:00 qty: -712.0 exit long open\n",
      "Exit: 2019-02-05T13:00 PEP 2019-02-05 13:00:00 qty: -709.0 trigger_prc: 112.98 limit_prc: nan enter short namespace(trigger_price=112.98, limit_price=nan) open\n",
      "Trade: 2019-02-05T13:15 PEP 2019-02-05 13:15:00 qty: -709.0 prc: 112.925 commission: 3545 order: PEP 2019-02-05 13:00:00 qty: -709.0 trigger_prc: 112.98 limit_prc: nan enter short namespace(trigger_price=112.98, limit_price=nan) open\n",
      "Enter: 2019-02-05T14:15 PEP 2019-02-05 14:15:00 qty: 709.0 exit short open\n",
      "Trade: 2019-02-05T14:30 PEP 2019-02-05 14:30:00 qty: 709.0 prc: 113.054 commission: 3545 order: PEP 2019-02-05 14:15:00 qty: 709.0 exit short open\n",
      "Exit: 2019-02-05T16:00 PEP 2019-02-05 16:00:00 qty: -703.0 trigger_prc: 112.9 limit_prc: nan enter short namespace(trigger_price=112.9, limit_price=nan) open\n",
      "Trade: 2019-02-06T09:45 PEP 2019-02-06 09:45:00 qty: -703.0 prc: 112.715 commission: 3515 order: PEP 2019-02-05 16:00:00 qty: -703.0 trigger_prc: 112.9 limit_prc: nan enter short namespace(trigger_price=112.9, limit_price=nan) open\n",
      "Enter: 2019-02-06T10:30 PEP 2019-02-06 10:30:00 qty: 703.0 exit short open\n",
      "Trade: 2019-02-06T10:45 PEP 2019-02-06 10:45:00 qty: 703.0 prc: 112.875 commission: 3515 order: PEP 2019-02-06 10:30:00 qty: 703.0 exit short open\n",
      "Enter: 2019-02-06T13:00 PEP 2019-02-06 13:00:00 qty: 696.0 trigger_prc: 112.9 limit_prc: nan enter long namespace(trigger_price=112.9, limit_price=nan) open\n",
      "Trade: 2019-02-06T13:15 PEP 2019-02-06 13:15:00 qty: 696.0 prc: 112.965 commission: 3480 order: PEP 2019-02-06 13:00:00 qty: 696.0 trigger_prc: 112.9 limit_prc: nan enter long namespace(trigger_price=112.9, limit_price=nan) open\n",
      "Exit: 2019-02-07T10:15 PEP 2019-02-07 10:15:00 qty: -826.0 exit long open\n",
      "Exit: 2019-02-07T10:15 PEP 2019-02-07 10:15:00 qty: -696.0 exit long open\n",
      "Trade: 2019-02-07T10:30 PEP 2019-02-07 10:30:00 qty: -826.0 prc: 112.605 commission: 4130 order: PEP 2019-02-07 10:15:00 qty: -826.0 exit long open\n",
      "Enter: 2019-02-07T10:30 PEP 2019-02-07 10:30:00 qty: 820.0 trigger_prc: 112.94 limit_prc: nan enter long namespace(trigger_price=112.94, limit_price=nan) open\n",
      "Trade: 2019-02-07T10:30 PEP 2019-02-07 10:30:00 qty: -696.0 prc: 112.605 commission: 3480 order: PEP 2019-02-07 10:15:00 qty: -696.0 exit long open\n",
      "Trade: 2019-02-07T10:45 PEP 2019-02-07 10:45:00 qty: 820.0 prc: 112.945 commission: 4100 order: PEP 2019-02-07 10:30:00 qty: 820.0 trigger_prc: 112.94 limit_prc: nan enter long namespace(trigger_price=112.94, limit_price=nan) open\n",
      "Enter: 2019-02-07T14:30 PEP 2019-02-07 14:30:00 qty: 690.0 trigger_prc: 112.86 limit_prc: nan enter long namespace(trigger_price=112.86, limit_price=nan) open\n",
      "Trade: 2019-02-07T14:45 PEP 2019-02-07 14:45:00 qty: 690.0 prc: 112.882 commission: 3450 order: PEP 2019-02-07 14:30:00 qty: 690.0 trigger_prc: 112.86 limit_prc: nan enter long namespace(trigger_price=112.86, limit_price=nan) open\n",
      "Exit: 2019-02-08T10:00 PEP 2019-02-08 10:00:00 qty: -690.0 exit long open\n",
      "Exit: 2019-02-08T10:15 PEP 2019-02-08 10:15:00 qty: -820.0 exit long open\n",
      "Trade: 2019-02-08T10:15 PEP 2019-02-08 10:15:00 qty: -690.0 prc: 112.205 commission: 3450 order: PEP 2019-02-08 10:00:00 qty: -690.0 exit long open\n",
      "Trade: 2019-02-08T10:30 PEP 2019-02-08 10:30:00 qty: -820.0 prc: 112.055 commission: 4100 order: PEP 2019-02-08 10:15:00 qty: -820.0 exit long open\n",
      "Exit: 2019-02-08T10:30 PEP 2019-02-08 10:30:00 qty: -817.0 trigger_prc: 112.25 limit_prc: nan enter short namespace(trigger_price=112.25, limit_price=nan) open\n",
      "Exit: 2019-02-08T10:30 PEP 2019-02-08 10:30:00 qty: -687.0 trigger_prc: 112.25 limit_prc: nan enter short namespace(trigger_price=112.25, limit_price=nan) open\n",
      "Trade: 2019-02-08T10:45 PEP 2019-02-08 10:45:00 qty: -817.0 prc: 112.185 commission: 4085 order: PEP 2019-02-08 10:30:00 qty: -817.0 trigger_prc: 112.25 limit_prc: nan enter short namespace(trigger_price=112.25, limit_price=nan) open\n",
      "Trade: 2019-02-08T10:45 PEP 2019-02-08 10:45:00 qty: -687.0 prc: 112.185 commission: 3435 order: PEP 2019-02-08 10:30:00 qty: -687.0 trigger_prc: 112.25 limit_prc: nan enter short namespace(trigger_price=112.25, limit_price=nan) open\n",
      "Enter: 2019-02-08T11:45 PEP 2019-02-08 11:45:00 qty: 687.0 exit short open\n",
      "Trade: 2019-02-08T12:00 PEP 2019-02-08 12:00:00 qty: 687.0 prc: 112.515 commission: 3435 order: PEP 2019-02-08 11:45:00 qty: 687.0 exit short open\n",
      "Enter: 2019-02-08T12:00 PEP 2019-02-08 12:00:00 qty: 681.0 trigger_prc: 112.19 limit_prc: nan enter long namespace(trigger_price=112.19, limit_price=nan) open\n",
      "Trade: 2019-02-08T12:15 PEP 2019-02-08 12:15:00 qty: 681.0 prc: 112.203 commission: 3405 order: PEP 2019-02-08 12:00:00 qty: 681.0 trigger_prc: 112.19 limit_prc: nan enter long namespace(trigger_price=112.19, limit_price=nan) open\n",
      "Exit: 2019-02-08T12:15 PEP 2019-02-08 12:15:00 qty: -681.0 exit long open\n",
      "Trade: 2019-02-08T12:30 PEP 2019-02-08 12:30:00 qty: -681.0 prc: 112.02 commission: 3405 order: PEP 2019-02-08 12:15:00 qty: -681.0 exit long open\n",
      "Enter: 2019-02-08T14:15 PEP 2019-02-08 14:15:00 qty: 675.0 trigger_prc: 112.25 limit_prc: nan enter long namespace(trigger_price=112.25, limit_price=nan) open\n",
      "Trade: 2019-02-08T14:30 PEP 2019-02-08 14:30:00 qty: 675.0 prc: 112.305 commission: 3375 order: PEP 2019-02-08 14:15:00 qty: 675.0 trigger_prc: 112.25 limit_prc: nan enter long namespace(trigger_price=112.25, limit_price=nan) open\n",
      "Enter: 2019-02-08T15:15 PEP 2019-02-08 15:15:00 qty: 817.0 exit short open\n",
      "Trade: 2019-02-08T15:30 PEP 2019-02-08 15:30:00 qty: 817.0 prc: 112.477 commission: 4085 order: PEP 2019-02-08 15:15:00 qty: 817.0 exit short open\n",
      "Exit: 2019-02-08T15:30 PEP 2019-02-08 15:30:00 qty: -808.0 trigger_prc: 112.465 limit_prc: nan enter short namespace(trigger_price=112.465, limit_price=nan) open\n",
      "Trade: 2019-02-08T15:45 PEP 2019-02-08 15:45:00 qty: -808.0 prc: 112.428 commission: 4040 order: PEP 2019-02-08 15:30:00 qty: -808.0 trigger_prc: 112.465 limit_prc: nan enter short namespace(trigger_price=112.465, limit_price=nan) open\n",
      "Enter: 2019-02-11T10:15 PEP 2019-02-11 10:15:00 qty: 808.0 exit short open\n",
      "Trade: 2019-02-11T10:30 PEP 2019-02-11 10:30:00 qty: 808.0 prc: 113.045 commission: 4040 order: PEP 2019-02-11 10:15:00 qty: 808.0 exit short open\n",
      "Exit: 2019-02-11T10:45 PEP 2019-02-11 10:45:00 qty: -794.0 trigger_prc: 113.3 limit_prc: nan enter short namespace(trigger_price=113.3, limit_price=nan) open\n",
      "Trade: 2019-02-11T11:00 PEP 2019-02-11 11:00:00 qty: -794.0 prc: 113.205 commission: 3970 order: PEP 2019-02-11 10:45:00 qty: -794.0 trigger_prc: 113.3 limit_prc: nan enter short namespace(trigger_price=113.3, limit_price=nan) open\n",
      "Enter: 2019-02-11T11:00 PEP 2019-02-11 11:00:00 qty: 794.0 exit short open\n",
      "Trade: 2019-02-11T11:15 PEP 2019-02-11 11:15:00 qty: 794.0 prc: 113.14 commission: 3970 order: PEP 2019-02-11 11:00:00 qty: 794.0 exit short open\n",
      "Exit: 2019-02-11T11:45 PEP 2019-02-11 11:45:00 qty: -789.0 trigger_prc: 113.045 limit_prc: nan enter short namespace(trigger_price=113.045, limit_price=nan) open\n",
      "Exit: 2019-02-11T11:45 PEP 2019-02-11 11:45:00 qty: -675.0 exit long open\n",
      "Trade: 2019-02-11T12:00 PEP 2019-02-11 12:00:00 qty: -789.0 prc: 113.012 commission: 3945 order: PEP 2019-02-11 11:45:00 qty: -789.0 trigger_prc: 113.045 limit_prc: nan enter short namespace(trigger_price=113.045, limit_price=nan) open\n",
      "Trade: 2019-02-11T12:00 PEP 2019-02-11 12:00:00 qty: -675.0 prc: 113.014 commission: 3375 order: PEP 2019-02-11 11:45:00 qty: -675.0 exit long open\n",
      "Exit: 2019-02-11T13:45 PEP 2019-02-11 13:45:00 qty: -667.0 trigger_prc: 112.72 limit_prc: nan enter short namespace(trigger_price=112.72, limit_price=nan) open\n",
      "Trade: 2019-02-11T14:00 PEP 2019-02-11 14:00:00 qty: -667.0 prc: 112.685 commission: 3335 order: PEP 2019-02-11 13:45:00 qty: -667.0 trigger_prc: 112.72 limit_prc: nan enter short namespace(trigger_price=112.72, limit_price=nan) open\n",
      "Enter: 2019-02-11T14:15 PEP 2019-02-11 14:15:00 qty: 789.0 exit short open\n",
      "Trade: 2019-02-11T14:30 PEP 2019-02-11 14:30:00 qty: 789.0 prc: 112.8 commission: 3945 order: PEP 2019-02-11 14:15:00 qty: 789.0 exit short open\n",
      "Exit: 2019-02-11T14:30 PEP 2019-02-11 14:30:00 qty: -785.0 trigger_prc: 112.675 limit_prc: nan enter short namespace(trigger_price=112.675, limit_price=nan) open\n",
      "Enter: 2019-02-11T14:45 PEP 2019-02-11 14:45:00 qty: 784.0 trigger_prc: 112.835 limit_prc: nan enter long namespace(trigger_price=112.835, limit_price=nan) open\n",
      "Enter: 2019-02-11T14:45 PEP 2019-02-11 14:45:00 qty: 667.0 exit short open\n",
      "Trade: 2019-02-11T15:00 PEP 2019-02-11 15:00:00 qty: 784.0 prc: 112.871 commission: 3920 order: PEP 2019-02-11 14:45:00 qty: 784.0 trigger_prc: 112.835 limit_prc: nan enter long namespace(trigger_price=112.835, limit_price=nan) open\n",
      "Trade: 2019-02-11T15:00 PEP 2019-02-11 15:00:00 qty: 667.0 prc: 112.873 commission: 3335 order: PEP 2019-02-11 14:45:00 qty: 667.0 exit short open\n",
      "Exit: 2019-02-12T09:45 PEP 2019-02-12 09:45:00 qty: -659.0 trigger_prc: 113.0 limit_prc: nan enter short namespace(trigger_price=113.0, limit_price=nan) open\n",
      "Trade: 2019-02-12T10:00 PEP 2019-02-12 10:00:00 qty: -659.0 prc: 112.78 commission: 3295 order: PEP 2019-02-12 09:45:00 qty: -659.0 trigger_prc: 113.0 limit_prc: nan enter short namespace(trigger_price=113.0, limit_price=nan) open\n",
      "Enter: 2019-02-12T10:00 PEP 2019-02-12 10:00:00 qty: 659.0 exit short open\n",
      "Trade: 2019-02-12T10:15 PEP 2019-02-12 10:15:00 qty: 659.0 prc: 112.585 commission: 3295 order: PEP 2019-02-12 10:00:00 qty: 659.0 exit short open\n",
      "Exit: 2019-02-12T10:15 PEP 2019-02-12 10:15:00 qty: -655.0 trigger_prc: 112.63 limit_prc: nan enter short namespace(trigger_price=112.63, limit_price=nan) open\n",
      "Trade: 2019-02-12T10:30 PEP 2019-02-12 10:30:00 qty: -655.0 prc: 112.615 commission: 3275 order: PEP 2019-02-12 10:15:00 qty: -655.0 trigger_prc: 112.63 limit_prc: nan enter short namespace(trigger_price=112.63, limit_price=nan) open\n",
      "Enter: 2019-02-12T11:00 PEP 2019-02-12 11:00:00 qty: 655.0 exit short open\n",
      "Trade: 2019-02-12T11:15 PEP 2019-02-12 11:15:00 qty: 655.0 prc: 113.32 commission: 3275 order: PEP 2019-02-12 11:00:00 qty: 655.0 exit short open\n",
      "Enter: 2019-02-12T11:15 PEP 2019-02-12 11:15:00 qty: 644.0 trigger_prc: 113.46 limit_prc: nan enter long namespace(trigger_price=113.46, limit_price=nan) open\n",
      "Trade: 2019-02-12T11:30 PEP 2019-02-12 11:30:00 qty: 644.0 prc: 113.5 commission: 3220 order: PEP 2019-02-12 11:15:00 qty: 644.0 trigger_prc: 113.46 limit_prc: nan enter long namespace(trigger_price=113.46, limit_price=nan) open\n",
      "Exit: 2019-02-12T14:45 PEP 2019-02-12 14:45:00 qty: -644.0 exit long open\n",
      "Trade: 2019-02-12T15:00 PEP 2019-02-12 15:00:00 qty: -644.0 prc: 113.715 commission: 3220 order: PEP 2019-02-12 14:45:00 qty: -644.0 exit long open\n",
      "Exit: 2019-02-12T15:15 PEP 2019-02-12 15:15:00 qty: -784.0 exit long open\n",
      "Trade: 2019-02-12T15:30 PEP 2019-02-12 15:30:00 qty: -784.0 prc: 113.733 commission: 3920 order: PEP 2019-02-12 15:15:00 qty: -784.0 exit long open\n",
      "Exit: 2019-02-12T15:30 PEP 2019-02-12 15:30:00 qty: -770.0 trigger_prc: 113.8301 limit_prc: nan enter short namespace(trigger_price=113.8301, limit_price=nan) open\n",
      "Trade: 2019-02-12T15:45 PEP 2019-02-12 15:45:00 qty: -770.0 prc: 113.66 commission: 3850 order: PEP 2019-02-12 15:30:00 qty: -770.0 trigger_prc: 113.8301 limit_prc: nan enter short namespace(trigger_price=113.8301, limit_price=nan) open\n",
      "Enter: 2019-02-13T09:45 PEP 2019-02-13 09:45:00 qty: 632.0 trigger_prc: 114.62 limit_prc: nan enter long namespace(trigger_price=114.62, limit_price=nan) open\n",
      "Trade: 2019-02-13T10:00 PEP 2019-02-13 10:00:00 qty: 632.0 prc: 114.66 commission: 3160 order: PEP 2019-02-13 09:45:00 qty: 632.0 trigger_prc: 114.62 limit_prc: nan enter long namespace(trigger_price=114.62, limit_price=nan) open\n",
      "Enter: 2019-02-13T10:15 PEP 2019-02-13 10:15:00 qty: 770.0 exit short open\n",
      "Trade: 2019-02-13T10:30 PEP 2019-02-13 10:30:00 qty: 770.0 prc: 114.13 commission: 3850 order: PEP 2019-02-13 10:15:00 qty: 770.0 exit short open\n",
      "Exit: 2019-02-13T10:45 PEP 2019-02-13 10:45:00 qty: -764.0 trigger_prc: 113.74 limit_prc: nan enter short namespace(trigger_price=113.74, limit_price=nan) open\n",
      "Trade: 2019-02-13T11:00 PEP 2019-02-13 11:00:00 qty: -764.0 prc: 113.71 commission: 3820 order: PEP 2019-02-13 10:45:00 qty: -764.0 trigger_prc: 113.74 limit_prc: nan enter short namespace(trigger_price=113.74, limit_price=nan) open\n",
      "Exit: 2019-02-13T11:00 PEP 2019-02-13 11:00:00 qty: -632.0 exit long open\n",
      "Enter: 2019-02-13T11:15 PEP 2019-02-13 11:15:00 qty: 764.0 exit short open\n",
      "Trade: 2019-02-13T11:15 PEP 2019-02-13 11:15:00 qty: -632.0 prc: 113.87 commission: 3160 order: PEP 2019-02-13 11:00:00 qty: -632.0 exit long open\n",
      "Trade: 2019-02-13T11:30 PEP 2019-02-13 11:30:00 qty: 764.0 prc: 114.055 commission: 3820 order: PEP 2019-02-13 11:15:00 qty: 764.0 exit short open\n",
      "Enter: 2019-02-13T11:30 PEP 2019-02-13 11:30:00 qty: 755.0 trigger_prc: 114.04 limit_prc: nan enter long namespace(trigger_price=114.04, limit_price=nan) open\n",
      "Exit: 2019-02-13T12:00 PEP 2019-02-13 12:00:00 qty: -755.0 trigger_prc: 113.98 limit_prc: nan enter short namespace(trigger_price=113.98, limit_price=nan) open\n",
      "Trade: 2019-02-13T12:15 PEP 2019-02-13 12:15:00 qty: -755.0 prc: 113.895 commission: 3775 order: PEP 2019-02-13 12:00:00 qty: -755.0 trigger_prc: 113.98 limit_prc: nan enter short namespace(trigger_price=113.98, limit_price=nan) open\n",
      "Exit: 2019-02-13T14:30 PEP 2019-02-13 14:30:00 qty: -631.0 trigger_prc: 113.75 limit_prc: nan enter short namespace(trigger_price=113.75, limit_price=nan) open\n",
      "Trade: 2019-02-13T14:45 PEP 2019-02-13 14:45:00 qty: -631.0 prc: 113.72 commission: 3155 order: PEP 2019-02-13 14:30:00 qty: -631.0 trigger_prc: 113.75 limit_prc: nan enter short namespace(trigger_price=113.75, limit_price=nan) open\n",
      "Enter: 2019-02-13T15:15 PEP 2019-02-13 15:15:00 qty: 631.0 exit short open\n",
      "Trade: 2019-02-13T15:30 PEP 2019-02-13 15:30:00 qty: 631.0 prc: 113.855 commission: 3155 order: PEP 2019-02-13 15:15:00 qty: 631.0 exit short open\n",
      "Enter: 2019-02-13T15:45 PEP 2019-02-13 15:45:00 qty: 625.0 trigger_prc: 113.925 limit_prc: nan enter long namespace(trigger_price=113.925, limit_price=nan) open\n",
      "Trade: 2019-02-13T16:00 PEP 2019-02-13 16:00:00 qty: 625.0 prc: 114.037 commission: 3125 order: PEP 2019-02-13 15:45:00 qty: 625.0 trigger_prc: 113.925 limit_prc: nan enter long namespace(trigger_price=113.925, limit_price=nan) open\n",
      "Exit: 2019-02-14T10:15 PEP 2019-02-14 10:15:00 qty: -625.0 exit long open\n",
      "Trade: 2019-02-14T10:30 PEP 2019-02-14 10:30:00 qty: -625.0 prc: 112.525 commission: 3125 order: PEP 2019-02-14 10:15:00 qty: -625.0 exit long open\n",
      "Enter: 2019-02-14T12:00 PEP 2019-02-14 12:00:00 qty: 755.0 exit short open\n",
      "Trade: 2019-02-14T12:15 PEP 2019-02-14 12:15:00 qty: 755.0 prc: 112.405 commission: 3775 order: PEP 2019-02-14 12:00:00 qty: 755.0 exit short open\n",
      "Enter: 2019-02-14T12:15 PEP 2019-02-14 12:15:00 qty: 760.0 trigger_prc: 112.49 limit_prc: nan enter long namespace(trigger_price=112.49, limit_price=nan) open\n",
      "Trade: 2019-02-14T12:30 PEP 2019-02-14 12:30:00 qty: 760.0 prc: 112.61 commission: 3800 order: PEP 2019-02-14 12:15:00 qty: 760.0 trigger_prc: 112.49 limit_prc: nan enter long namespace(trigger_price=112.49, limit_price=nan) open\n",
      "Enter: 2019-02-14T15:15 PEP 2019-02-14 15:15:00 qty: 625.0 trigger_prc: 112.66 limit_prc: nan enter long namespace(trigger_price=112.66, limit_price=nan) open\n",
      "Trade: 2019-02-14T15:30 PEP 2019-02-14 15:30:00 qty: 625.0 prc: 112.73 commission: 3125 order: PEP 2019-02-14 15:15:00 qty: 625.0 trigger_prc: 112.66 limit_prc: nan enter long namespace(trigger_price=112.66, limit_price=nan) open\n",
      "Exit: 2019-02-15T14:00 PEP 2019-02-15 14:00:00 qty: -625.0 exit long open\n",
      "Trade: 2019-02-15T14:15 PEP 2019-02-15 14:15:00 qty: -625.0 prc: 115.725 commission: 3125 order: PEP 2019-02-15 14:00:00 qty: -625.0 exit long open\n",
      "Exit: 2019-02-15T14:15 PEP 2019-02-15 14:15:00 qty: -605.0 trigger_prc: 115.675 limit_prc: nan enter short namespace(trigger_price=115.675, limit_price=nan) open\n",
      "Trade: 2019-02-15T14:30 PEP 2019-02-15 14:30:00 qty: -605.0 prc: 115.507 commission: 3025 order: PEP 2019-02-15 14:15:00 qty: -605.0 trigger_prc: 115.675 limit_prc: nan enter short namespace(trigger_price=115.675, limit_price=nan) open\n",
      "Enter: 2019-02-15T16:00 PEP 2019-02-15 16:00:00 qty: 605.0 exit short open\n",
      "Trade: 2019-02-19T09:45 PEP 2019-02-19 09:45:00 qty: 605.0 prc: 116.87 commission: 3025 order: PEP 2019-02-15 16:00:00 qty: 605.0 exit short open\n",
      "Enter: 2019-02-19T09:45 PEP 2019-02-19 09:45:00 qty: 597.0 trigger_prc: 116.03 limit_prc: nan enter long namespace(trigger_price=116.03, limit_price=nan) open\n",
      "Trade: 2019-02-19T10:00 PEP 2019-02-19 10:00:00 qty: 597.0 prc: 116.06 commission: 2985 order: PEP 2019-02-19 09:45:00 qty: 597.0 trigger_prc: 116.03 limit_prc: nan enter long namespace(trigger_price=116.03, limit_price=nan) open\n",
      "Exit: 2019-02-19T13:15 PEP 2019-02-19 13:15:00 qty: -597.0 exit long open\n",
      "Trade: 2019-02-19T13:30 PEP 2019-02-19 13:30:00 qty: -597.0 prc: 115.74 commission: 2985 order: PEP 2019-02-19 13:15:00 qty: -597.0 exit long open\n",
      "Enter: 2019-02-19T13:45 PEP 2019-02-19 13:45:00 qty: 592.0 trigger_prc: 116.0 limit_prc: nan enter long namespace(trigger_price=116.0, limit_price=nan) open\n",
      "Trade: 2019-02-19T14:00 PEP 2019-02-19 14:00:00 qty: 592.0 prc: 116.01 commission: 2960 order: PEP 2019-02-19 13:45:00 qty: 592.0 trigger_prc: 116.0 limit_prc: nan enter long namespace(trigger_price=116.0, limit_price=nan) open\n",
      "Exit: 2019-02-19T14:30 PEP 2019-02-19 14:30:00 qty: -760.0 exit long open\n",
      "Exit: 2019-02-19T14:30 PEP 2019-02-19 14:30:00 qty: -592.0 exit long open\n",
      "Trade: 2019-02-19T14:45 PEP 2019-02-19 14:45:00 qty: -760.0 prc: 115.725 commission: 3800 order: PEP 2019-02-19 14:30:00 qty: -760.0 exit long open\n",
      "Exit: 2019-02-19T14:45 PEP 2019-02-19 14:45:00 qty: -733.0 trigger_prc: 115.92 limit_prc: nan enter short namespace(trigger_price=115.92, limit_price=nan) open\n",
      "Trade: 2019-02-19T14:45 PEP 2019-02-19 14:45:00 qty: -592.0 prc: 115.725 commission: 2960 order: PEP 2019-02-19 14:30:00 qty: -592.0 exit long open\n",
      "Enter: 2019-02-19T15:00 PEP 2019-02-19 15:00:00 qty: 731.0 trigger_prc: 116.14 limit_prc: nan enter long namespace(trigger_price=116.14, limit_price=nan) open\n",
      "Trade: 2019-02-19T15:15 PEP 2019-02-19 15:15:00 qty: 731.0 prc: 116.148 commission: 3655 order: PEP 2019-02-19 15:00:00 qty: 731.0 trigger_prc: 116.14 limit_prc: nan enter long namespace(trigger_price=116.14, limit_price=nan) open\n",
      "Enter: 2019-02-20T09:45 PEP 2019-02-20 09:45:00 qty: 586.0 trigger_prc: 116.245 limit_prc: nan enter long namespace(trigger_price=116.245, limit_price=nan) open\n",
      "Trade: 2019-02-20T10:00 PEP 2019-02-20 10:00:00 qty: 586.0 prc: 116.352 commission: 2930 order: PEP 2019-02-20 09:45:00 qty: 586.0 trigger_prc: 116.245 limit_prc: nan enter long namespace(trigger_price=116.245, limit_price=nan) open\n",
      "Exit: 2019-02-20T11:00 PEP 2019-02-20 11:00:00 qty: -586.0 exit long open\n",
      "Trade: 2019-02-20T11:15 PEP 2019-02-20 11:15:00 qty: -586.0 prc: 115.805 commission: 2930 order: PEP 2019-02-20 11:00:00 qty: -586.0 exit long open\n",
      "Enter: 2019-02-20T14:00 PEP 2019-02-20 14:00:00 qty: 582.0 trigger_prc: 116.01 limit_prc: nan enter long namespace(trigger_price=116.01, limit_price=nan) open\n",
      "Trade: 2019-02-20T14:15 PEP 2019-02-20 14:15:00 qty: 582.0 prc: 116.105 commission: 2910 order: PEP 2019-02-20 14:00:00 qty: 582.0 trigger_prc: 116.01 limit_prc: nan enter long namespace(trigger_price=116.01, limit_price=nan) open\n",
      "Exit: 2019-02-21T13:30 PEP 2019-02-21 13:30:00 qty: -582.0 exit long open\n",
      "Trade: 2019-02-21T13:45 PEP 2019-02-21 13:45:00 qty: -582.0 prc: 116.203 commission: 2910 order: PEP 2019-02-21 13:30:00 qty: -582.0 exit long open\n",
      "Exit: 2019-02-21T15:30 PEP 2019-02-21 15:30:00 qty: -731.0 exit long open\n",
      "Trade: 2019-02-21T15:45 PEP 2019-02-21 15:45:00 qty: -731.0 prc: 115.708 commission: 3655 order: PEP 2019-02-21 15:30:00 qty: -731.0 exit long open\n",
      "Exit: 2019-02-21T15:45 PEP 2019-02-21 15:45:00 qty: -727.0 trigger_prc: 115.84 limit_prc: nan enter short namespace(trigger_price=115.84, limit_price=nan) open\n",
      "Enter: 2019-02-21T16:00 PEP 2019-02-21 16:00:00 qty: 725.0 trigger_prc: 116.09 limit_prc: nan enter long namespace(trigger_price=116.09, limit_price=nan) open\n",
      "Trade: 2019-02-22T09:45 PEP 2019-02-22 09:45:00 qty: 725.0 prc: 116.195 commission: 3625 order: PEP 2019-02-21 16:00:00 qty: 725.0 trigger_prc: 116.09 limit_prc: nan enter long namespace(trigger_price=116.09, limit_price=nan) open\n",
      "Enter: 2019-02-22T10:00 PEP 2019-02-22 10:00:00 qty: 574.0 trigger_prc: 116.43 limit_prc: nan enter long namespace(trigger_price=116.43, limit_price=nan) open\n",
      "Trade: 2019-02-22T10:15 PEP 2019-02-22 10:15:00 qty: 574.0 prc: 116.51 commission: 2870 order: PEP 2019-02-22 10:00:00 qty: 574.0 trigger_prc: 116.43 limit_prc: nan enter long namespace(trigger_price=116.43, limit_price=nan) open\n",
      "Exit: 2019-02-22T13:00 PEP 2019-02-22 13:00:00 qty: -574.0 exit long open\n",
      "Trade: 2019-02-22T13:15 PEP 2019-02-22 13:15:00 qty: -574.0 prc: 116.255 commission: 2870 order: PEP 2019-02-22 13:00:00 qty: -574.0 exit long open\n",
      "Enter: 2019-02-22T16:00 PEP 2019-02-22 16:00:00 qty: 568.0 trigger_prc: 116.76 limit_prc: nan enter long namespace(trigger_price=116.76, limit_price=nan) open\n",
      "Trade: 2019-02-25T09:45 PEP 2019-02-25 09:45:00 qty: 568.0 prc: 117.02 commission: 2840 order: PEP 2019-02-22 16:00:00 qty: 568.0 trigger_prc: 116.76 limit_prc: nan enter long namespace(trigger_price=116.76, limit_price=nan) open\n",
      "Exit: 2019-02-25T13:00 PEP 2019-02-25 13:00:00 qty: -568.0 exit long open\n",
      "Trade: 2019-02-25T13:15 PEP 2019-02-25 13:15:00 qty: -568.0 prc: 115.94 commission: 2840 order: PEP 2019-02-25 13:00:00 qty: -568.0 exit long open\n",
      "Exit: 2019-02-26T09:45 PEP 2019-02-26 09:45:00 qty: -567.0 trigger_prc: 115.85 limit_prc: nan enter short namespace(trigger_price=115.85, limit_price=nan) open\n",
      "Trade: 2019-02-26T10:00 PEP 2019-02-26 10:00:00 qty: -567.0 prc: 115.775 commission: 2835 order: PEP 2019-02-26 09:45:00 qty: -567.0 trigger_prc: 115.85 limit_prc: nan enter short namespace(trigger_price=115.85, limit_price=nan) open\n",
      "Enter: 2019-02-26T10:15 PEP 2019-02-26 10:15:00 qty: 567.0 exit short open\n",
      "Trade: 2019-02-26T10:30 PEP 2019-02-26 10:30:00 qty: 567.0 prc: 116.115 commission: 2835 order: PEP 2019-02-26 10:15:00 qty: 567.0 exit short open\n",
      "Exit: 2019-02-26T11:00 PEP 2019-02-26 11:00:00 qty: -564.0 trigger_prc: 115.46 limit_prc: nan enter short namespace(trigger_price=115.46, limit_price=nan) open\n",
      "Exit: 2019-02-26T11:15 PEP 2019-02-26 11:15:00 qty: -562.0 trigger_prc: 115.84 limit_prc: nan enter short namespace(trigger_price=115.84, limit_price=nan) open\n",
      "Trade: 2019-02-26T11:30 PEP 2019-02-26 11:30:00 qty: -562.0 prc: 115.809 commission: 2810 order: PEP 2019-02-26 11:15:00 qty: -562.0 trigger_prc: 115.84 limit_prc: nan enter short namespace(trigger_price=115.84, limit_price=nan) open\n",
      "Enter: 2019-02-26T11:30 PEP 2019-02-26 11:30:00 qty: 562.0 exit short open\n",
      "Trade: 2019-02-26T11:45 PEP 2019-02-26 11:45:00 qty: 562.0 prc: 115.87 commission: 2810 order: PEP 2019-02-26 11:30:00 qty: 562.0 exit short open\n",
      "Enter: 2019-02-26T13:15 PEP 2019-02-26 13:15:00 qty: 556.0 trigger_prc: 116.0253 limit_prc: nan enter long namespace(trigger_price=116.0253, limit_price=nan) open\n",
      "Trade: 2019-02-26T13:30 PEP 2019-02-26 13:30:00 qty: 556.0 prc: 116.088 commission: 2780 order: PEP 2019-02-26 13:15:00 qty: 556.0 trigger_prc: 116.0253 limit_prc: nan enter long namespace(trigger_price=116.0253, limit_price=nan) open\n"
     ]
    }
   ],
   "source": [
    "strategy1 = build_strategy(contract_group, SimpleNamespace(lookback_period = 5, num_std = 1))\n",
    "strategy2 = build_strategy(contract_group, SimpleNamespace(lookback_period = 10, num_std = 2))\n",
    "portfolio = pq.Portfolio()\n",
    "portfolio.add_strategy('bb_strategy_1', strategy1)\n",
    "portfolio.add_strategy('bb_strategy_2', strategy2)\n",
    "portfolio.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's plot the output of the two strategies as well as the portfolio output.  The portfolio returns will be the sum of the returns of the 2 strategies."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:10.549572Z",
     "start_time": "2022-08-16T02:38:10.237511Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 306208 characters]\n",
      "text/plain": [
       "<Figure size 1440x1080 with 4 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "strategy1.plot(title = 'Strategy 1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:10.844511Z",
     "start_time": "2022-08-16T02:38:10.550230Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 293116 characters]\n",
      "text/plain": [
       "<Figure size 1440x1080 with 4 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "strategy2.plot(title = 'Strategy 2', primary_indicators = ['c', 'sma', 'upper_band', 'lower_band']);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:11.059655Z",
     "start_time": "2022-08-16T02:38:10.845247Z"
    },
    "run_control": {
     "frozen": false,
     "read_only": false
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 99460 characters]\n",
      "text/plain": [
       "<Figure size 1080x576 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "portfolio.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-08-16T02:38:11.251288Z",
     "start_time": "2022-08-16T02:38:11.060718Z"
    },
    "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",
       "      <th></th>\n",
       "      <td>-0.9758</td>\n",
       "      <td>-3.687</td>\n",
       "      <td>0.007762</td>\n",
       "      <td>-29.92</td>\n",
       "      <td>-30.15</td>\n",
       "      <td>4.746</td>\n",
       "      <td>-10.66</td>\n",
       "      <td>-10.66</td>\n",
       "      <td>0.3459</td>\n",
       "      <td>2019-01-15/2019-02-26</td>\n",
       "      <td>0.3459</td>\n",
       "      <td>2019-01-15/2019-02-26</td>\n",
       "      <td>1/28/0.0345</td>\n",
       "      <td>-0.9758</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    gmean   amean       std    shrp     srt      k  calmar     mar mdd_pct  \\\n",
       "  -0.9758  -3.687  0.007762  -29.92  -30.15  4.746  -10.66  -10.66  0.3459   \n",
       "\n",
       "              mdd_dates dd_3y_pct       dd_3y_timestamps       up_dwn     2019  \n",
       "  2019-01-15/2019-02-26    0.3459  2019-01-15/2019-02-26  1/28/0.0345  -0.9758  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 102424 characters]\n",
      "text/plain": [
       "<Figure size 1080x576 with 3 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "strategy2.evaluate_returns();"
   ]
  }
 ],
 "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.9.13"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
