Skip to content

Commit 0858535

Browse files
committed
Signals added
1 parent 9bb39b2 commit 0858535

File tree

1 file changed

+117
-9
lines changed

1 file changed

+117
-9
lines changed

notebooks/OptionsBacktesting.ipynb

Lines changed: 117 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
"\n",
1515
"1. Load and transform necessary data\n",
1616
"2. Create a list of option contracts to be entered into each day\n",
17-
"3. Create a list of signals on, whether to enter into the contract, for each day\n",
17+
"3. Create a list of signals, on whether to enter into the contract, for each day\n",
1818
"4. Extract the necessary data for the options contracts that would be executed\n",
1919
"5. Analyze Profit and loss and other metrices\n"
2020
]
2121
},
2222
{
2323
"cell_type": "code",
24-
"execution_count": 9,
24+
"execution_count": 1,
2525
"metadata": {},
2626
"outputs": [],
2727
"source": [
@@ -41,7 +41,7 @@
4141
},
4242
{
4343
"cell_type": "code",
44-
"execution_count": 25,
44+
"execution_count": 2,
4545
"metadata": {},
4646
"outputs": [],
4747
"source": [
@@ -72,7 +72,7 @@
7272
},
7373
{
7474
"cell_type": "code",
75-
"execution_count": 94,
75+
"execution_count": 3,
7676
"metadata": {},
7777
"outputs": [],
7878
"source": [
@@ -91,7 +91,7 @@
9191
},
9292
{
9393
"cell_type": "code",
94-
"execution_count": 101,
94+
"execution_count": 4,
9595
"metadata": {},
9696
"outputs": [
9797
{
@@ -106,7 +106,7 @@
106106
"dtype: datetime64[ns]"
107107
]
108108
},
109-
"execution_count": 101,
109+
"execution_count": 4,
110110
"metadata": {},
111111
"output_type": "execute_result"
112112
}
@@ -138,7 +138,7 @@
138138
},
139139
{
140140
"cell_type": "code",
141-
"execution_count": 103,
141+
"execution_count": 7,
142142
"metadata": {},
143143
"outputs": [
144144
{
@@ -217,7 +217,7 @@
217217
"4 2019-01-07 10800 CE 10804.85"
218218
]
219219
},
220-
"execution_count": 103,
220+
"execution_count": 7,
221221
"metadata": {},
222222
"output_type": "execute_result"
223223
}
@@ -227,7 +227,115 @@
227227
"nifty['spot'] = nifty.open.copy()\n",
228228
"nifty['opt'] = 'CE'\n",
229229
"cols = ['date', 'strike', 'opt', 'spot']\n",
230-
"nifty[cols].head()"
230+
"options = nifty[cols]\n",
231+
"options.head()"
232+
]
233+
},
234+
{
235+
"cell_type": "markdown",
236+
"metadata": {},
237+
"source": [
238+
"Select signals\n",
239+
"--------------\n",
240+
"\n",
241+
"A signal is a indication whether to buy or sell the contract on a daily basis. It is a single column that outputs 1 if the contract is entered into or a 0 if the contract is not entered. Since we would be trading for all the days, we simply include a 1 for all dates"
242+
]
243+
},
244+
{
245+
"cell_type": "code",
246+
"execution_count": 14,
247+
"metadata": {},
248+
"outputs": [
249+
{
250+
"data": {
251+
"text/html": [
252+
"<div>\n",
253+
"<style scoped>\n",
254+
" .dataframe tbody tr th:only-of-type {\n",
255+
" vertical-align: middle;\n",
256+
" }\n",
257+
"\n",
258+
" .dataframe tbody tr th {\n",
259+
" vertical-align: top;\n",
260+
" }\n",
261+
"\n",
262+
" .dataframe thead th {\n",
263+
" text-align: right;\n",
264+
" }\n",
265+
"</style>\n",
266+
"<table border=\"1\" class=\"dataframe\">\n",
267+
" <thead>\n",
268+
" <tr style=\"text-align: right;\">\n",
269+
" <th></th>\n",
270+
" <th>date</th>\n",
271+
" <th>strike</th>\n",
272+
" <th>opt</th>\n",
273+
" <th>spot</th>\n",
274+
" <th>signal</th>\n",
275+
" </tr>\n",
276+
" </thead>\n",
277+
" <tbody>\n",
278+
" <tr>\n",
279+
" <th>0</th>\n",
280+
" <td>2019-01-01</td>\n",
281+
" <td>10800</td>\n",
282+
" <td>CE</td>\n",
283+
" <td>10881.70</td>\n",
284+
" <td>1</td>\n",
285+
" </tr>\n",
286+
" <tr>\n",
287+
" <th>1</th>\n",
288+
" <td>2019-01-02</td>\n",
289+
" <td>10800</td>\n",
290+
" <td>CE</td>\n",
291+
" <td>10868.85</td>\n",
292+
" <td>1</td>\n",
293+
" </tr>\n",
294+
" <tr>\n",
295+
" <th>2</th>\n",
296+
" <td>2019-01-03</td>\n",
297+
" <td>10700</td>\n",
298+
" <td>CE</td>\n",
299+
" <td>10796.80</td>\n",
300+
" <td>1</td>\n",
301+
" </tr>\n",
302+
" <tr>\n",
303+
" <th>3</th>\n",
304+
" <td>2019-01-04</td>\n",
305+
" <td>10600</td>\n",
306+
" <td>CE</td>\n",
307+
" <td>10699.70</td>\n",
308+
" <td>1</td>\n",
309+
" </tr>\n",
310+
" <tr>\n",
311+
" <th>4</th>\n",
312+
" <td>2019-01-07</td>\n",
313+
" <td>10800</td>\n",
314+
" <td>CE</td>\n",
315+
" <td>10804.85</td>\n",
316+
" <td>1</td>\n",
317+
" </tr>\n",
318+
" </tbody>\n",
319+
"</table>\n",
320+
"</div>"
321+
],
322+
"text/plain": [
323+
" date strike opt spot signal\n",
324+
"0 2019-01-01 10800 CE 10881.70 1\n",
325+
"1 2019-01-02 10800 CE 10868.85 1\n",
326+
"2 2019-01-03 10700 CE 10796.80 1\n",
327+
"3 2019-01-04 10600 CE 10699.70 1\n",
328+
"4 2019-01-07 10800 CE 10804.85 1"
329+
]
330+
},
331+
"execution_count": 14,
332+
"metadata": {},
333+
"output_type": "execute_result"
334+
}
335+
],
336+
"source": [
337+
"options.loc[:, 'signal'] = 1\n",
338+
"options.head()"
231339
]
232340
}
233341
],

0 commit comments

Comments
 (0)