{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "57b7d32b-5db5-44bc-83b7-4b39de81c3e9", "metadata": { "tags": [] }, "source": [ "# Variables and Data Structures" ] }, { "attachments": {}, "cell_type": "markdown", "id": "3d49431a-f6ec-4ab4-8481-cb70210d9e24", "metadata": {}, "source": [ "## Keeping state across ticks" ] }, { "attachments": {}, "cell_type": "markdown", "id": "5f17e599-7a9a-4355-b4d2-6788478d0451", "metadata": {}, "source": [ "Variables can be used to keep track of state across ticks. The example below shows how we may keep track of P&L." ] }, { "cell_type": "code", "execution_count": 2, "id": "a93cd883-9d90-405a-826c-afb4466fc6a7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TimePRICESIZESIDEPROFIT
02003-12-01 00:00:00.00013.5200B-2700
12003-12-01 00:00:00.00113.6100S-1340
22003-12-01 00:00:00.00213.3150B-3335
32003-12-01 00:00:00.00314.0200S-535
\n", "
" ], "text/plain": [ " Time PRICE SIZE SIDE PROFIT\n", "0 2003-12-01 00:00:00.000 13.5 200 B -2700\n", "1 2003-12-01 00:00:00.001 13.6 100 S -1340\n", "2 2003-12-01 00:00:00.002 13.3 150 B -3335\n", "3 2003-12-01 00:00:00.003 14.0 200 S -535" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import onetick.py as otp\n", "s = otp.dt(2023, 5, 15, 9, 30)\n", "e = otp.dt(2023, 5, 15, 9, 30, 1)\n", "\n", "trd = otp.Ticks({'PRICE': [13.5, 13.6, 13.3, 14.0],\n", " 'SIZE': [200, 100, 150, 200],\n", " 'SIDE': ['B', 'S', 'B', 'S']})\n", "\n", "trd.state_vars['PROFIT'] = 0\n", "trd.state_vars['PROFIT'] += trd.apply(\n", " lambda t: t['PRICE'] * t['SIZE'] if t['SIDE'] == 'S' else -(t['PRICE'] * t['SIZE'])\n", ")\n", "\n", "trd['PROFIT'] = trd.state_vars['PROFIT']\n", "\n", "otp.run(trd)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "67ade8dd-9aea-4944-b657-ce448e8ada76", "metadata": {}, "source": [ "The variable 'PROFIT' keeps a running total. In other words, it aggregates state across trades.\n", "\n", "Note that the same can be accomplished without variables by keeping the running total in a separate column." ] }, { "cell_type": "code", "execution_count": 5, "id": "e85c42c1-c38d-47aa-a08c-9fc085bbbc48", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TimePROFIT
02022-04-01 00:00:00.000-2700.0
12022-04-01 00:00:00.001-1340.0
22022-04-01 00:00:00.002-3335.0
32022-04-01 00:00:00.003-535.0
\n", "
" ], "text/plain": [ " Time PROFIT\n", "0 2022-04-01 00:00:00.000 -2700.0\n", "1 2022-04-01 00:00:00.001 -1340.0\n", "2 2022-04-01 00:00:00.002 -3335.0\n", "3 2022-04-01 00:00:00.003 -535.0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "trd = otp.Ticks({'PRICE': [13.5, 13.6, 13.3, 14.0],\n", " 'SIZE': [200, 100, 150, 200],\n", " 'SIDE': ['B', 'S', 'B', 'S']})\n", "trd['VALUE'] = trd.apply(\n", " lambda t: t['PRICE'] * t['SIZE'] if t['SIDE'] == 'S' else -(t['PRICE'] * t['SIZE'])\n", ")\n", "trd = trd.agg({'PROFIT': otp.agg.sum('VALUE')}, running=True)\n", "otp.run(trd)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "e1d1ee63-7d33-4e89-b848-3ba69f5ca1d7", "metadata": {}, "source": [ "### Remembering the value of the last tick during aggregation / grouping" ] }, { "cell_type": "code", "execution_count": 6, "id": "2d3b08e8-c6b3-4bda-bab8-7ea390a683da", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TimeXYlast_x
02022-04-01 00:00:00.001312
12022-04-01 00:00:00.003402
22022-04-01 00:00:00.004232
\n", "
" ], "text/plain": [ " Time X Y last_x\n", "0 2022-04-01 00:00:00.001 3 1 2\n", "1 2022-04-01 00:00:00.003 4 0 2\n", "2 2022-04-01 00:00:00.004 2 3 2" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q = otp.Ticks(X=[-1, 3, -3, 4, 2], Y=[0, 1, 1, 0, 3])\n", "q.state_vars['last_x'] = 0\n", "q.state_vars['last_x'] = q['X']\n", "q = q.high('X', group_by=['Y'])\n", "q['last_x'] = q.state_vars['last_x']\n", "otp.run(q)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "58d44336-5591-4d58-8d10-b7c6a5dd4d0a", "metadata": {}, "source": [ "# Dictionaries / Maps (aka `tick sets`)\n", "## Looking up static data for every tick\n", "A map can be created with keys taken from one or more columns and holding entire ticks as values.\n", "\n", "The example below uses exchange reference data to create a map keyed by exchange code." ] }, { "cell_type": "code", "execution_count": 18, "id": "bcb1eea8-62af-4fce-bde2-acd467f14f0a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TimeEXCHANGENAMELOCATION
02022-04-01 00:00:00.000ANYSE American (Amex)US
12022-04-01 00:00:00.001BNasdaq BXUS
22022-04-01 00:00:00.002CNYSE National (NSX)US
32022-04-01 00:00:00.003DFINRA ADF + NYSE/Nasdaq TRFsUS
42022-04-01 00:00:00.004HMIAX PearlUS
52022-04-01 00:00:00.005IInternational Securities ExchangeUS
62022-04-01 00:00:00.006JCboe EDGAUS
72022-04-01 00:00:00.007KCboe EDGXUS
82022-04-01 00:00:00.008LLong-Term Stock Exchange (LTSE)US
92022-04-01 00:00:00.009MNYSE ChicagoUS
102022-04-01 00:00:00.010NNew York Stock ExchangeUS
112022-04-01 00:00:00.011PNYSE ArcaUS
122022-04-01 00:00:00.012QNasdaq (Tape C securities)US
132022-04-01 00:00:00.013SConsolidated Tape System (CTS)US
142022-04-01 00:00:00.014TNasdaq (Tape A,B securities)US
152022-04-01 00:00:00.015UMembers Exchange (MEMX)US
162022-04-01 00:00:00.016VThe Investors' Exchange (IEX)US
172022-04-01 00:00:00.017WCBOE Stock Exchange (CBSX)US
182022-04-01 00:00:00.018XNasdaq PSXUS
192022-04-01 00:00:00.019YCboe BYXUS
202022-04-01 00:00:00.020ZCboe BZXUS
\n", "
" ], "text/plain": [ " Time EXCHANGE NAME LOCATION\n", "0 2022-04-01 00:00:00.000 A NYSE American (Amex) US\n", "1 2022-04-01 00:00:00.001 B Nasdaq BX US\n", "2 2022-04-01 00:00:00.002 C NYSE National (NSX) US\n", "3 2022-04-01 00:00:00.003 D FINRA ADF + NYSE/Nasdaq TRFs US\n", "4 2022-04-01 00:00:00.004 H MIAX Pearl US\n", "5 2022-04-01 00:00:00.005 I International Securities Exchange US\n", "6 2022-04-01 00:00:00.006 J Cboe EDGA US\n", "7 2022-04-01 00:00:00.007 K Cboe EDGX US\n", "8 2022-04-01 00:00:00.008 L Long-Term Stock Exchange (LTSE) US\n", "9 2022-04-01 00:00:00.009 M NYSE Chicago US\n", "10 2022-04-01 00:00:00.010 N New York Stock Exchange US\n", "11 2022-04-01 00:00:00.011 P NYSE Arca US\n", "12 2022-04-01 00:00:00.012 Q Nasdaq (Tape C securities) US\n", "13 2022-04-01 00:00:00.013 S Consolidated Tape System (CTS) US\n", "14 2022-04-01 00:00:00.014 T Nasdaq (Tape A,B securities) US\n", "15 2022-04-01 00:00:00.015 U Members Exchange (MEMX) US\n", "16 2022-04-01 00:00:00.016 V The Investors' Exchange (IEX) US\n", "17 2022-04-01 00:00:00.017 W CBOE Stock Exchange (CBSX) US\n", "18 2022-04-01 00:00:00.018 X Nasdaq PSX US\n", "19 2022-04-01 00:00:00.019 Y Cboe BYX US\n", "20 2022-04-01 00:00:00.020 Z Cboe BZX US" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "exchanges = otp.Ticks(EXCHANGE=['A', 'B', 'C', 'D', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],\n", " NAME=['NYSE American (Amex)', 'Nasdaq BX', 'NYSE National (NSX)', 'FINRA ADF + NYSE/Nasdaq TRFs', 'MIAX Pearl', 'International Securities Exchange', 'Cboe EDGA', 'Cboe EDGX', 'Long-Term Stock Exchange (LTSE)', 'NYSE Chicago', 'New York Stock Exchange', 'NYSE Arca', 'Nasdaq (Tape C securities)', 'Consolidated Tape System (CTS)', 'Nasdaq (Tape A,B securities)', 'Members Exchange (MEMX)', \"The Investors' Exchange (IEX)\", 'CBOE Stock Exchange (CBSX)', 'Nasdaq PSX', 'Cboe BYX', 'Cboe BZX'])\n", "exchanges['LOCATION'] = 'US'\n", "otp.run(exchanges)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "eba643c4-04f8-4df7-a8fd-bfc95384f04b", "metadata": {}, "source": [ "We will add exchange name to trades. First let's examine the trades." ] }, { "cell_type": "code", "execution_count": 3, "id": "d0aa2e40-266d-4ea5-8fb0-226fb5f46ed0", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TimePRICESIZECONDEXCHANGE
02023-05-15 09:30:00.000178688412.22100TP
12023-05-15 09:30:00.000776704412.22247Z
22023-05-15 09:30:00.003603456412.22100TT
32023-05-15 09:30:00.006352128412.241IK
42023-05-15 09:30:00.007128064412.243IK
..................
3102023-05-15 09:30:00.934032640412.27160TT
3112023-05-15 09:30:00.975609344412.242ID
3122023-05-15 09:30:00.980264448412.271ID
3132023-05-15 09:30:00.985391616412.28100T
3142023-05-15 09:30:00.985394944412.28100QT
\n", "

315 rows × 5 columns

\n", "
" ], "text/plain": [ " Time PRICE SIZE COND EXCHANGE\n", "0 2023-05-15 09:30:00.000178688 412.22 100 T P\n", "1 2023-05-15 09:30:00.000776704 412.22 247 Z\n", "2 2023-05-15 09:30:00.003603456 412.22 100 T T\n", "3 2023-05-15 09:30:00.006352128 412.24 1 I K\n", "4 2023-05-15 09:30:00.007128064 412.24 3 I K\n", ".. ... ... ... ... ...\n", "310 2023-05-15 09:30:00.934032640 412.27 160 T T\n", "311 2023-05-15 09:30:00.975609344 412.24 2 I D\n", "312 2023-05-15 09:30:00.980264448 412.27 1 I D\n", "313 2023-05-15 09:30:00.985391616 412.28 100 T\n", "314 2023-05-15 09:30:00.985394944 412.28 100 Q T\n", "\n", "[315 rows x 5 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q = otp.DataSource('NYSE_TAQ', tick_type='TRD')\n", "q = q[['PRICE','SIZE','COND','EXCHANGE']]\n", "otp.run(q, start=s, end=e, symbols=['SPY'])" ] }, { "attachments": {}, "cell_type": "markdown", "id": "4b3d7ba1-c106-4dfa-9e2f-e8a69abfdd0a", "metadata": {}, "source": [ "The value of the `EXCHANGE` field from trades will be used to look up the name of the corresponding exchange." ] }, { "cell_type": "code", "execution_count": 4, "id": "ba306745-8c6a-414e-a3d2-3187a4906f9f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TimePRICESIZECONDEXCHANGEexchange_name
02023-05-15 09:30:00.000178688412.22100TPNYSE Arca
12023-05-15 09:30:00.000776704412.22247ZCboe BZX
22023-05-15 09:30:00.003603456412.22100TTNasdaq (Tape A,B securities)
32023-05-15 09:30:00.006352128412.241IKCboe EDGX
42023-05-15 09:30:00.007128064412.243IKCboe EDGX
.....................
3102023-05-15 09:30:00.934032640412.27160TTNasdaq (Tape A,B securities)
3112023-05-15 09:30:00.975609344412.242IDFINRA ADF + NYSE/Nasdaq TRFs
3122023-05-15 09:30:00.980264448412.271IDFINRA ADF + NYSE/Nasdaq TRFs
3132023-05-15 09:30:00.985391616412.28100TNasdaq (Tape A,B securities)
3142023-05-15 09:30:00.985394944412.28100QTNasdaq (Tape A,B securities)
\n", "

315 rows × 6 columns

\n", "
" ], "text/plain": [ " Time PRICE SIZE COND EXCHANGE exchange_name\n", "0 2023-05-15 09:30:00.000178688 412.22 100 T P NYSE Arca\n", "1 2023-05-15 09:30:00.000776704 412.22 247 Z Cboe BZX\n", "2 2023-05-15 09:30:00.003603456 412.22 100 T T Nasdaq (Tape A,B securities)\n", "3 2023-05-15 09:30:00.006352128 412.24 1 I K Cboe EDGX\n", "4 2023-05-15 09:30:00.007128064 412.24 3 I K Cboe EDGX\n", ".. ... ... ... ... ... ...\n", "310 2023-05-15 09:30:00.934032640 412.27 160 T T Nasdaq (Tape A,B securities)\n", "311 2023-05-15 09:30:00.975609344 412.24 2 I D FINRA ADF + NYSE/Nasdaq TRFs\n", "312 2023-05-15 09:30:00.980264448 412.27 1 I D FINRA ADF + NYSE/Nasdaq TRFs\n", "313 2023-05-15 09:30:00.985391616 412.28 100 T Nasdaq (Tape A,B securities)\n", "314 2023-05-15 09:30:00.985394944 412.28 100 Q T Nasdaq (Tape A,B securities)\n", "\n", "[315 rows x 6 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q = otp.DataSource('NYSE_TAQ', tick_type='TRD')\n", "q = q[['PRICE','SIZE','COND','EXCHANGE']]\n", "exchanges = otp.Ticks(EXCHANGE=['A', 'B', 'C', 'D', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],\n", " NAME=['NYSE American (Amex)', 'Nasdaq BX', 'NYSE National (NSX)', 'FINRA ADF + NYSE/Nasdaq TRFs', 'MIAX Pearl', 'International Securities Exchange', 'Cboe EDGA', 'Cboe EDGX', 'Long-Term Stock Exchange (LTSE)', 'NYSE Chicago', 'New York Stock Exchange', 'NYSE Arca', 'Nasdaq (Tape C securities)', 'Consolidated Tape System (CTS)', 'Nasdaq (Tape A,B securities)', 'Members Exchange (MEMX)', \"The Investors' Exchange (IEX)\", 'CBOE Stock Exchange (CBSX)', 'Nasdaq PSX', 'Cboe BYX', 'Cboe BZX'])\n", "\n", "q.state_vars['exchanges'] = otp.state.tick_set('latest', 'EXCHANGE', otp.eval(exchanges))\n", "q['exchange_name'] = q.state_vars['exchanges'].find('NAME', 'unknown')\n", "\n", "otp.run(q, start=s, end=e, symbols=['SPY'])" ] }, { "attachments": {}, "cell_type": "markdown", "id": "0a0d24b2-5453-4e6f-8467-e0c3c2da06ad", "metadata": {}, "source": [ "## Checking if ticks are present in another time series\n", "A tick set can be used to check if (a small number of) ticks are present in another time series with potentially different time stamps.\n", "\n", "We generate two \"special\" ticks." ] }, { "cell_type": "code", "execution_count": 8, "id": "49db461e-fa91-48d2-82e8-f0a57a7216bf", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TimePRICESIZEINDEX
02003-12-01 00:00:00.000412.222471
12003-12-01 00:00:00.001400.0010002
\n", "
" ], "text/plain": [ " Time PRICE SIZE INDEX\n", "0 2003-12-01 00:00:00.000 412.22 247 1\n", "1 2003-12-01 00:00:00.001 400.00 1000 2" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ticks = otp.Ticks(PRICE=[412.22, 400], SIZE=[247, 1000], INDEX=[1,2])\n", "otp.run(ticks)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "aedfb084-06be-4793-a132-fb07289f03ea", "metadata": {}, "source": [ "We then check if any of the trades match these ticks by ``PRICE`` and ``SIZE``." ] }, { "cell_type": "code", "execution_count": 9, "id": "6b198189-b8cc-4fda-9610-092696e07a70", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TimePRICESIZECONDEXCHANGEspecial
02023-05-15 09:30:00.000776704412.22247Z1
\n", "
" ], "text/plain": [ " Time PRICE SIZE COND EXCHANGE special\n", "0 2023-05-15 09:30:00.000776704 412.22 247 Z 1" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q = otp.DataSource('NYSE_TAQ', tick_type='TRD')\n", "q = q[['PRICE','SIZE','COND','EXCHANGE']]\n", "\n", "q.state_vars['special_ticks'] = otp.state.tick_set('latest', ['PRICE', 'SIZE'], otp.eval(ticks))\n", "q['special'] = q.state_vars['special_ticks'].find('INDEX', -1)\n", "\n", "q, _ = q[q['special'] != -1]\n", "\n", "otp.run(q, start=s, end=e, symbols=['SPY'])" ] } ], "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.6" } }, "nbformat": 4, "nbformat_minor": 5 }