Skip to content

Commit 3ac3f2f

Browse files
committed
load necessary data
1 parent 0061d95 commit 3ac3f2f

File tree

1 file changed

+37
-18
lines changed

1 file changed

+37
-18
lines changed

notebooks/OptionsBacktesting.ipynb

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,9 @@
4141
},
4242
{
4343
"cell_type": "code",
44-
"execution_count": 24,
44+
"execution_count": 25,
4545
"metadata": {},
46-
"outputs": [
47-
{
48-
"data": {
49-
"text/plain": [
50-
"10225"
51-
]
52-
},
53-
"execution_count": 24,
54-
"metadata": {},
55-
"output_type": "execute_result"
56-
}
57-
],
46+
"outputs": [],
5847
"source": [
5948
"def itm(price, opt='C', step=100):\n",
6049
" \"\"\"\n",
@@ -83,20 +72,50 @@
8372
},
8473
{
8574
"cell_type": "code",
86-
"execution_count": 10,
75+
"execution_count": 75,
8776
"metadata": {},
8877
"outputs": [],
8978
"source": [
9079
"nifty = pd.read_csv('/home/machine/Downloads/NIFTY 50_Data.csv',\n",
91-
" parse_dates=['Date'])"
80+
" parse_dates=['Date'])\n",
81+
"der = pd.read_hdf('/media/machine/4E1EA2D152455460/data/output/fno_2019.h5')\n",
82+
"der['exp_day'] = der.expiry_dt.dt.day\n",
83+
"\n",
84+
"# Difference between expiry date and date\n",
85+
"der['day_diff'] = (der['expiry_dt'] - der['timestamp']).dt.days\n"
9286
]
9387
},
9488
{
9589
"cell_type": "code",
96-
"execution_count": null,
90+
"execution_count": 89,
9791
"metadata": {},
98-
"outputs": [],
99-
"source": []
92+
"outputs": [
93+
{
94+
"data": {
95+
"text/plain": [
96+
"2 2019-01-31\n",
97+
"1 2019-02-28\n",
98+
"3 2019-03-28\n",
99+
"0 2019-04-25\n",
100+
"4 2019-05-30\n",
101+
"5 2019-06-27\n",
102+
"dtype: datetime64[ns]"
103+
]
104+
},
105+
"execution_count": 89,
106+
"metadata": {},
107+
"output_type": "execute_result"
108+
}
109+
],
110+
"source": [
111+
"# Change your symbol here\n",
112+
"symbol = 'NIFTY'\n",
113+
"# Keep nifty data with monthly options only\n",
114+
"# This hack is incomplete and should be correctly configured\n",
115+
"q = '(symbol==\"{sym}\") & (instrument==\"OPTIDX\") & (exp_day > 24) & (day_diff<31)'\n",
116+
"df = der.query(q.format(sym=symbol))\n",
117+
"pd.Series(df.expiry_dt.unique()).sort_values()"
118+
]
100119
}
101120
],
102121
"metadata": {

0 commit comments

Comments
 (0)