|
14 | 14 | "\n",
|
15 | 15 | "1. Load and transform necessary data\n",
|
16 | 16 | "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", |
18 | 18 | "4. Extract the necessary data for the options contracts that would be executed\n",
|
19 | 19 | "5. Analyze Profit and loss and other metrices\n"
|
20 | 20 | ]
|
21 | 21 | },
|
22 | 22 | {
|
23 | 23 | "cell_type": "code",
|
24 |
| - "execution_count": 9, |
| 24 | + "execution_count": 1, |
25 | 25 | "metadata": {},
|
26 | 26 | "outputs": [],
|
27 | 27 | "source": [
|
|
41 | 41 | },
|
42 | 42 | {
|
43 | 43 | "cell_type": "code",
|
44 |
| - "execution_count": 25, |
| 44 | + "execution_count": 2, |
45 | 45 | "metadata": {},
|
46 | 46 | "outputs": [],
|
47 | 47 | "source": [
|
|
72 | 72 | },
|
73 | 73 | {
|
74 | 74 | "cell_type": "code",
|
75 |
| - "execution_count": 94, |
| 75 | + "execution_count": 3, |
76 | 76 | "metadata": {},
|
77 | 77 | "outputs": [],
|
78 | 78 | "source": [
|
|
91 | 91 | },
|
92 | 92 | {
|
93 | 93 | "cell_type": "code",
|
94 |
| - "execution_count": 101, |
| 94 | + "execution_count": 4, |
95 | 95 | "metadata": {},
|
96 | 96 | "outputs": [
|
97 | 97 | {
|
|
106 | 106 | "dtype: datetime64[ns]"
|
107 | 107 | ]
|
108 | 108 | },
|
109 |
| - "execution_count": 101, |
| 109 | + "execution_count": 4, |
110 | 110 | "metadata": {},
|
111 | 111 | "output_type": "execute_result"
|
112 | 112 | }
|
|
138 | 138 | },
|
139 | 139 | {
|
140 | 140 | "cell_type": "code",
|
141 |
| - "execution_count": 103, |
| 141 | + "execution_count": 7, |
142 | 142 | "metadata": {},
|
143 | 143 | "outputs": [
|
144 | 144 | {
|
|
217 | 217 | "4 2019-01-07 10800 CE 10804.85"
|
218 | 218 | ]
|
219 | 219 | },
|
220 |
| - "execution_count": 103, |
| 220 | + "execution_count": 7, |
221 | 221 | "metadata": {},
|
222 | 222 | "output_type": "execute_result"
|
223 | 223 | }
|
|
227 | 227 | "nifty['spot'] = nifty.open.copy()\n",
|
228 | 228 | "nifty['opt'] = 'CE'\n",
|
229 | 229 | "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()" |
231 | 339 | ]
|
232 | 340 | }
|
233 | 341 | ],
|
|
0 commit comments