cryptodatapy 0.2.2__py3-none-any.whl → 0.2.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cryptodatapy/conf/fx_tickers.csv +31 -0
- cryptodatapy/transform/clean.py +171 -172
- cryptodatapy/transform/clean_perp_futures_ohlcv.ipynb +1025 -0
- cryptodatapy/transform/filter.py +83 -142
- cryptodatapy/transform/impute.py +36 -83
- cryptodatapy/transform/od.py +221 -450
- {cryptodatapy-0.2.2.dist-info → cryptodatapy-0.2.4.dist-info}/METADATA +4 -1
- {cryptodatapy-0.2.2.dist-info → cryptodatapy-0.2.4.dist-info}/RECORD +10 -8
- {cryptodatapy-0.2.2.dist-info → cryptodatapy-0.2.4.dist-info}/LICENSE +0 -0
- {cryptodatapy-0.2.2.dist-info → cryptodatapy-0.2.4.dist-info}/WHEEL +0 -0
@@ -0,0 +1,1025 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": 1,
|
6
|
+
"id": "9fea9fae",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [
|
9
|
+
{
|
10
|
+
"name": "stderr",
|
11
|
+
"output_type": "stream",
|
12
|
+
"text": [
|
13
|
+
"fatal: bad revision 'HEAD'\n",
|
14
|
+
"Importing plotly failed. Interactive plots will not work.\n"
|
15
|
+
]
|
16
|
+
}
|
17
|
+
],
|
18
|
+
"source": [
|
19
|
+
"import pandas as pd\n",
|
20
|
+
"import numpy as np\n",
|
21
|
+
"\n",
|
22
|
+
"from cryptodatapy.extract.datarequest import DataRequest\n",
|
23
|
+
"from cryptodatapy.extract.getdata import GetData\n",
|
24
|
+
"from cryptodatapy.transform.od import OutlierDetection\n",
|
25
|
+
"from cryptodatapy.transform.impute import Impute\n",
|
26
|
+
"from cryptodatapy.transform.filter import Filter\n",
|
27
|
+
"from cryptodatapy.transform.clean import CleanData, stitch_dataframes\n",
|
28
|
+
"from cryptodatapy.transform.impute import Impute"
|
29
|
+
]
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"cell_type": "code",
|
33
|
+
"execution_count": 2,
|
34
|
+
"id": "3cbdeffc",
|
35
|
+
"metadata": {},
|
36
|
+
"outputs": [],
|
37
|
+
"source": [
|
38
|
+
"# get all Binance perp futures tickers\n",
|
39
|
+
"data_req = DataRequest(source='ccxt')\n",
|
40
|
+
"perp_tickers = GetData(data_req).get_meta(method='get_markets_info', exch='binanceusdm', as_list=True)"
|
41
|
+
]
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"cell_type": "code",
|
45
|
+
"execution_count": 3,
|
46
|
+
"id": "3d084cf7",
|
47
|
+
"metadata": {},
|
48
|
+
"outputs": [
|
49
|
+
{
|
50
|
+
"data": {
|
51
|
+
"text/plain": [
|
52
|
+
"314"
|
53
|
+
]
|
54
|
+
},
|
55
|
+
"execution_count": 3,
|
56
|
+
"metadata": {},
|
57
|
+
"output_type": "execute_result"
|
58
|
+
}
|
59
|
+
],
|
60
|
+
"source": [
|
61
|
+
"len(perp_tickers)"
|
62
|
+
]
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"cell_type": "code",
|
66
|
+
"execution_count": 4,
|
67
|
+
"id": "fcb74458",
|
68
|
+
"metadata": {},
|
69
|
+
"outputs": [],
|
70
|
+
"source": [
|
71
|
+
"# get Binance spot tickers\n",
|
72
|
+
"data_req = DataRequest(source='ccxt')\n",
|
73
|
+
"spot_tickers = GetData(data_req).get_meta(method='get_markets_info', exch='binance', as_list=True)"
|
74
|
+
]
|
75
|
+
},
|
76
|
+
{
|
77
|
+
"cell_type": "code",
|
78
|
+
"execution_count": 5,
|
79
|
+
"id": "7962f7e5",
|
80
|
+
"metadata": {},
|
81
|
+
"outputs": [],
|
82
|
+
"source": [
|
83
|
+
"# find intersecting tickers\n",
|
84
|
+
"binance_tickers = [ticker for ticker in perp_tickers if ticker in spot_tickers]"
|
85
|
+
]
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"cell_type": "code",
|
89
|
+
"execution_count": 6,
|
90
|
+
"id": "877811c1",
|
91
|
+
"metadata": {},
|
92
|
+
"outputs": [
|
93
|
+
{
|
94
|
+
"data": {
|
95
|
+
"text/plain": [
|
96
|
+
"314"
|
97
|
+
]
|
98
|
+
},
|
99
|
+
"execution_count": 6,
|
100
|
+
"metadata": {},
|
101
|
+
"output_type": "execute_result"
|
102
|
+
}
|
103
|
+
],
|
104
|
+
"source": [
|
105
|
+
"# number of tickers\n",
|
106
|
+
"len(binance_tickers)"
|
107
|
+
]
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"cell_type": "code",
|
111
|
+
"execution_count": 7,
|
112
|
+
"id": "fe425163",
|
113
|
+
"metadata": {},
|
114
|
+
"outputs": [],
|
115
|
+
"source": [
|
116
|
+
"## # get cryptocompare tickers\n",
|
117
|
+
"data_req = DataRequest(source='cryptocompare')\n",
|
118
|
+
"cc_tickers = GetData(data_req).get_meta(method='get_assets_info', as_list=True)"
|
119
|
+
]
|
120
|
+
},
|
121
|
+
{
|
122
|
+
"cell_type": "code",
|
123
|
+
"execution_count": 8,
|
124
|
+
"id": "165053db",
|
125
|
+
"metadata": {},
|
126
|
+
"outputs": [],
|
127
|
+
"source": [
|
128
|
+
"# keep only USDT ticker\n",
|
129
|
+
"bin_tickers = []\n",
|
130
|
+
"for ticker in binance_tickers:\n",
|
131
|
+
" if '/' in ticker and ticker.split('/')[1] == 'USDT':\n",
|
132
|
+
" bin_tickers.append(ticker.split('/')[0])"
|
133
|
+
]
|
134
|
+
},
|
135
|
+
{
|
136
|
+
"cell_type": "code",
|
137
|
+
"execution_count": 9,
|
138
|
+
"id": "d6cf8a4c",
|
139
|
+
"metadata": {},
|
140
|
+
"outputs": [],
|
141
|
+
"source": [
|
142
|
+
"# usdt tickers\n",
|
143
|
+
"usdt_tickers = [ticker.split('/')[0] for ticker in binance_tickers if '/'in ticker and ticker.split('/')[1] == 'USDT']"
|
144
|
+
]
|
145
|
+
},
|
146
|
+
{
|
147
|
+
"cell_type": "code",
|
148
|
+
"execution_count": 10,
|
149
|
+
"id": "633f7a3e",
|
150
|
+
"metadata": {},
|
151
|
+
"outputs": [],
|
152
|
+
"source": [
|
153
|
+
"# intersecting tickers\n",
|
154
|
+
"tickers = [ticker for ticker in usdt_tickers if ticker in cc_tickers]"
|
155
|
+
]
|
156
|
+
},
|
157
|
+
{
|
158
|
+
"cell_type": "code",
|
159
|
+
"execution_count": 11,
|
160
|
+
"id": "30337a71",
|
161
|
+
"metadata": {},
|
162
|
+
"outputs": [
|
163
|
+
{
|
164
|
+
"data": {
|
165
|
+
"text/plain": [
|
166
|
+
"0"
|
167
|
+
]
|
168
|
+
},
|
169
|
+
"execution_count": 11,
|
170
|
+
"metadata": {},
|
171
|
+
"output_type": "execute_result"
|
172
|
+
}
|
173
|
+
],
|
174
|
+
"source": [
|
175
|
+
"len(tickers)"
|
176
|
+
]
|
177
|
+
},
|
178
|
+
{
|
179
|
+
"cell_type": "markdown",
|
180
|
+
"id": "f80eb97d",
|
181
|
+
"metadata": {},
|
182
|
+
"source": [
|
183
|
+
"### Binance Perp Futures"
|
184
|
+
]
|
185
|
+
},
|
186
|
+
{
|
187
|
+
"cell_type": "code",
|
188
|
+
"execution_count": 12,
|
189
|
+
"id": "49b09508",
|
190
|
+
"metadata": {},
|
191
|
+
"outputs": [],
|
192
|
+
"source": [
|
193
|
+
"# pull daily OHLC and funding rates for perp futures on Binance USDM exchange\n",
|
194
|
+
"data_req = DataRequest(source='ccxt',\n",
|
195
|
+
" tickers=tickers, \n",
|
196
|
+
" fields=['open', 'high', 'low', 'close', 'volume', 'funding_rate'], \n",
|
197
|
+
" mkt_type='perpetual_future', \n",
|
198
|
+
" freq='d')"
|
199
|
+
]
|
200
|
+
},
|
201
|
+
{
|
202
|
+
"cell_type": "code",
|
203
|
+
"execution_count": 13,
|
204
|
+
"id": "6ac9365b",
|
205
|
+
"metadata": {},
|
206
|
+
"outputs": [],
|
207
|
+
"source": [
|
208
|
+
"# df1 = GetData(data_req).get_series()"
|
209
|
+
]
|
210
|
+
},
|
211
|
+
{
|
212
|
+
"cell_type": "code",
|
213
|
+
"execution_count": 14,
|
214
|
+
"id": "98a425b2",
|
215
|
+
"metadata": {},
|
216
|
+
"outputs": [],
|
217
|
+
"source": [
|
218
|
+
"# df1.to_csv('binance_perp_futures.csv')\n",
|
219
|
+
"df1 = pd.read_csv('../../../../factorlab/notebooks/binance_perp_futures.csv', index_col=['date', 'ticker'], parse_dates=['date'])"
|
220
|
+
]
|
221
|
+
},
|
222
|
+
{
|
223
|
+
"cell_type": "code",
|
224
|
+
"execution_count": 15,
|
225
|
+
"id": "0e04da4a",
|
226
|
+
"metadata": {},
|
227
|
+
"outputs": [
|
228
|
+
{
|
229
|
+
"data": {
|
230
|
+
"text/html": [
|
231
|
+
"<div>\n",
|
232
|
+
"<style scoped>\n",
|
233
|
+
" .dataframe tbody tr th:only-of-type {\n",
|
234
|
+
" vertical-align: middle;\n",
|
235
|
+
" }\n",
|
236
|
+
"\n",
|
237
|
+
" .dataframe tbody tr th {\n",
|
238
|
+
" vertical-align: top;\n",
|
239
|
+
" }\n",
|
240
|
+
"\n",
|
241
|
+
" .dataframe thead th {\n",
|
242
|
+
" text-align: right;\n",
|
243
|
+
" }\n",
|
244
|
+
"</style>\n",
|
245
|
+
"<table border=\"1\" class=\"dataframe\">\n",
|
246
|
+
" <thead>\n",
|
247
|
+
" <tr style=\"text-align: right;\">\n",
|
248
|
+
" <th></th>\n",
|
249
|
+
" <th></th>\n",
|
250
|
+
" <th>open</th>\n",
|
251
|
+
" <th>high</th>\n",
|
252
|
+
" <th>low</th>\n",
|
253
|
+
" <th>close</th>\n",
|
254
|
+
" <th>volume</th>\n",
|
255
|
+
" <th>funding_rate</th>\n",
|
256
|
+
" </tr>\n",
|
257
|
+
" <tr>\n",
|
258
|
+
" <th>date</th>\n",
|
259
|
+
" <th>ticker</th>\n",
|
260
|
+
" <th></th>\n",
|
261
|
+
" <th></th>\n",
|
262
|
+
" <th></th>\n",
|
263
|
+
" <th></th>\n",
|
264
|
+
" <th></th>\n",
|
265
|
+
" <th></th>\n",
|
266
|
+
" </tr>\n",
|
267
|
+
" </thead>\n",
|
268
|
+
" <tbody>\n",
|
269
|
+
" <tr>\n",
|
270
|
+
" <th>2019-09-08</th>\n",
|
271
|
+
" <th>BTC</th>\n",
|
272
|
+
" <td>10000.00</td>\n",
|
273
|
+
" <td>10412.65</td>\n",
|
274
|
+
" <td>10000.00</td>\n",
|
275
|
+
" <td>10391.63</td>\n",
|
276
|
+
" <td>3096.291</td>\n",
|
277
|
+
" <td>NaN</td>\n",
|
278
|
+
" </tr>\n",
|
279
|
+
" <tr>\n",
|
280
|
+
" <th>2019-09-09</th>\n",
|
281
|
+
" <th>BTC</th>\n",
|
282
|
+
" <td>10316.62</td>\n",
|
283
|
+
" <td>10475.54</td>\n",
|
284
|
+
" <td>10077.22</td>\n",
|
285
|
+
" <td>10307.00</td>\n",
|
286
|
+
" <td>14824.373</td>\n",
|
287
|
+
" <td>NaN</td>\n",
|
288
|
+
" </tr>\n",
|
289
|
+
" <tr>\n",
|
290
|
+
" <th>2019-09-10</th>\n",
|
291
|
+
" <th>BTC</th>\n",
|
292
|
+
" <td>10307.00</td>\n",
|
293
|
+
" <td>10382.97</td>\n",
|
294
|
+
" <td>9940.87</td>\n",
|
295
|
+
" <td>10102.02</td>\n",
|
296
|
+
" <td>9068.955</td>\n",
|
297
|
+
" <td>0.0002</td>\n",
|
298
|
+
" </tr>\n",
|
299
|
+
" <tr>\n",
|
300
|
+
" <th>2019-09-11</th>\n",
|
301
|
+
" <th>BTC</th>\n",
|
302
|
+
" <td>10094.27</td>\n",
|
303
|
+
" <td>10293.11</td>\n",
|
304
|
+
" <td>9884.31</td>\n",
|
305
|
+
" <td>10159.55</td>\n",
|
306
|
+
" <td>10897.922</td>\n",
|
307
|
+
" <td>0.0003</td>\n",
|
308
|
+
" </tr>\n",
|
309
|
+
" <tr>\n",
|
310
|
+
" <th>2019-09-12</th>\n",
|
311
|
+
" <th>BTC</th>\n",
|
312
|
+
" <td>10163.06</td>\n",
|
313
|
+
" <td>10450.13</td>\n",
|
314
|
+
" <td>10042.12</td>\n",
|
315
|
+
" <td>10415.13</td>\n",
|
316
|
+
" <td>15609.634</td>\n",
|
317
|
+
" <td>0.0003</td>\n",
|
318
|
+
" </tr>\n",
|
319
|
+
" </tbody>\n",
|
320
|
+
"</table>\n",
|
321
|
+
"</div>"
|
322
|
+
],
|
323
|
+
"text/plain": [
|
324
|
+
" open high low close volume \\\n",
|
325
|
+
"date ticker \n",
|
326
|
+
"2019-09-08 BTC 10000.00 10412.65 10000.00 10391.63 3096.291 \n",
|
327
|
+
"2019-09-09 BTC 10316.62 10475.54 10077.22 10307.00 14824.373 \n",
|
328
|
+
"2019-09-10 BTC 10307.00 10382.97 9940.87 10102.02 9068.955 \n",
|
329
|
+
"2019-09-11 BTC 10094.27 10293.11 9884.31 10159.55 10897.922 \n",
|
330
|
+
"2019-09-12 BTC 10163.06 10450.13 10042.12 10415.13 15609.634 \n",
|
331
|
+
"\n",
|
332
|
+
" funding_rate \n",
|
333
|
+
"date ticker \n",
|
334
|
+
"2019-09-08 BTC NaN \n",
|
335
|
+
"2019-09-09 BTC NaN \n",
|
336
|
+
"2019-09-10 BTC 0.0002 \n",
|
337
|
+
"2019-09-11 BTC 0.0003 \n",
|
338
|
+
"2019-09-12 BTC 0.0003 "
|
339
|
+
]
|
340
|
+
},
|
341
|
+
"execution_count": 15,
|
342
|
+
"metadata": {},
|
343
|
+
"output_type": "execute_result"
|
344
|
+
}
|
345
|
+
],
|
346
|
+
"source": [
|
347
|
+
"df1.head()"
|
348
|
+
]
|
349
|
+
},
|
350
|
+
{
|
351
|
+
"cell_type": "markdown",
|
352
|
+
"id": "32f15191",
|
353
|
+
"metadata": {},
|
354
|
+
"source": [
|
355
|
+
"### Binance Spot"
|
356
|
+
]
|
357
|
+
},
|
358
|
+
{
|
359
|
+
"cell_type": "code",
|
360
|
+
"execution_count": 16,
|
361
|
+
"id": "83e9e466",
|
362
|
+
"metadata": {},
|
363
|
+
"outputs": [],
|
364
|
+
"source": [
|
365
|
+
"# pull OHLC from Binance\n",
|
366
|
+
"data_req = DataRequest(source='ccxt',\n",
|
367
|
+
" tickers=tickers, \n",
|
368
|
+
" fields=['open', 'high', 'low', 'close', 'volume'], \n",
|
369
|
+
" freq='d')"
|
370
|
+
]
|
371
|
+
},
|
372
|
+
{
|
373
|
+
"cell_type": "code",
|
374
|
+
"execution_count": 17,
|
375
|
+
"id": "82d4bbc7",
|
376
|
+
"metadata": {},
|
377
|
+
"outputs": [],
|
378
|
+
"source": [
|
379
|
+
"# df2 = GetData(data_req).get_series()"
|
380
|
+
]
|
381
|
+
},
|
382
|
+
{
|
383
|
+
"cell_type": "code",
|
384
|
+
"execution_count": 18,
|
385
|
+
"id": "4f63eb21",
|
386
|
+
"metadata": {},
|
387
|
+
"outputs": [],
|
388
|
+
"source": [
|
389
|
+
"# df2.to_csv('binance_spot.csv')\n",
|
390
|
+
"df2 = pd.read_csv('../../../../factorlab/notebooks/binance_spot.csv', index_col=['date', 'ticker'], parse_dates=['date'])"
|
391
|
+
]
|
392
|
+
},
|
393
|
+
{
|
394
|
+
"cell_type": "code",
|
395
|
+
"execution_count": 19,
|
396
|
+
"id": "ce8929c1",
|
397
|
+
"metadata": {},
|
398
|
+
"outputs": [
|
399
|
+
{
|
400
|
+
"data": {
|
401
|
+
"text/html": [
|
402
|
+
"<div>\n",
|
403
|
+
"<style scoped>\n",
|
404
|
+
" .dataframe tbody tr th:only-of-type {\n",
|
405
|
+
" vertical-align: middle;\n",
|
406
|
+
" }\n",
|
407
|
+
"\n",
|
408
|
+
" .dataframe tbody tr th {\n",
|
409
|
+
" vertical-align: top;\n",
|
410
|
+
" }\n",
|
411
|
+
"\n",
|
412
|
+
" .dataframe thead th {\n",
|
413
|
+
" text-align: right;\n",
|
414
|
+
" }\n",
|
415
|
+
"</style>\n",
|
416
|
+
"<table border=\"1\" class=\"dataframe\">\n",
|
417
|
+
" <thead>\n",
|
418
|
+
" <tr style=\"text-align: right;\">\n",
|
419
|
+
" <th></th>\n",
|
420
|
+
" <th></th>\n",
|
421
|
+
" <th>open</th>\n",
|
422
|
+
" <th>high</th>\n",
|
423
|
+
" <th>low</th>\n",
|
424
|
+
" <th>close</th>\n",
|
425
|
+
" <th>volume</th>\n",
|
426
|
+
" </tr>\n",
|
427
|
+
" <tr>\n",
|
428
|
+
" <th>date</th>\n",
|
429
|
+
" <th>ticker</th>\n",
|
430
|
+
" <th></th>\n",
|
431
|
+
" <th></th>\n",
|
432
|
+
" <th></th>\n",
|
433
|
+
" <th></th>\n",
|
434
|
+
" <th></th>\n",
|
435
|
+
" </tr>\n",
|
436
|
+
" </thead>\n",
|
437
|
+
" <tbody>\n",
|
438
|
+
" <tr>\n",
|
439
|
+
" <th rowspan=\"2\" valign=\"top\">2017-08-17</th>\n",
|
440
|
+
" <th>BTC</th>\n",
|
441
|
+
" <td>4261.48</td>\n",
|
442
|
+
" <td>4485.39</td>\n",
|
443
|
+
" <td>4200.74</td>\n",
|
444
|
+
" <td>4285.08</td>\n",
|
445
|
+
" <td>795.150377</td>\n",
|
446
|
+
" </tr>\n",
|
447
|
+
" <tr>\n",
|
448
|
+
" <th>ETH</th>\n",
|
449
|
+
" <td>301.13</td>\n",
|
450
|
+
" <td>312.18</td>\n",
|
451
|
+
" <td>298.00</td>\n",
|
452
|
+
" <td>302.00</td>\n",
|
453
|
+
" <td>7030.710340</td>\n",
|
454
|
+
" </tr>\n",
|
455
|
+
" <tr>\n",
|
456
|
+
" <th rowspan=\"2\" valign=\"top\">2017-08-18</th>\n",
|
457
|
+
" <th>BTC</th>\n",
|
458
|
+
" <td>4285.08</td>\n",
|
459
|
+
" <td>4371.52</td>\n",
|
460
|
+
" <td>3938.77</td>\n",
|
461
|
+
" <td>4108.37</td>\n",
|
462
|
+
" <td>1199.888264</td>\n",
|
463
|
+
" </tr>\n",
|
464
|
+
" <tr>\n",
|
465
|
+
" <th>ETH</th>\n",
|
466
|
+
" <td>302.00</td>\n",
|
467
|
+
" <td>311.79</td>\n",
|
468
|
+
" <td>283.94</td>\n",
|
469
|
+
" <td>293.96</td>\n",
|
470
|
+
" <td>9537.846460</td>\n",
|
471
|
+
" </tr>\n",
|
472
|
+
" <tr>\n",
|
473
|
+
" <th>2017-08-19</th>\n",
|
474
|
+
" <th>BTC</th>\n",
|
475
|
+
" <td>4108.37</td>\n",
|
476
|
+
" <td>4184.69</td>\n",
|
477
|
+
" <td>3850.00</td>\n",
|
478
|
+
" <td>4139.98</td>\n",
|
479
|
+
" <td>381.309763</td>\n",
|
480
|
+
" </tr>\n",
|
481
|
+
" </tbody>\n",
|
482
|
+
"</table>\n",
|
483
|
+
"</div>"
|
484
|
+
],
|
485
|
+
"text/plain": [
|
486
|
+
" open high low close volume\n",
|
487
|
+
"date ticker \n",
|
488
|
+
"2017-08-17 BTC 4261.48 4485.39 4200.74 4285.08 795.150377\n",
|
489
|
+
" ETH 301.13 312.18 298.00 302.00 7030.710340\n",
|
490
|
+
"2017-08-18 BTC 4285.08 4371.52 3938.77 4108.37 1199.888264\n",
|
491
|
+
" ETH 302.00 311.79 283.94 293.96 9537.846460\n",
|
492
|
+
"2017-08-19 BTC 4108.37 4184.69 3850.00 4139.98 381.309763"
|
493
|
+
]
|
494
|
+
},
|
495
|
+
"execution_count": 19,
|
496
|
+
"metadata": {},
|
497
|
+
"output_type": "execute_result"
|
498
|
+
}
|
499
|
+
],
|
500
|
+
"source": [
|
501
|
+
"df2.head()"
|
502
|
+
]
|
503
|
+
},
|
504
|
+
{
|
505
|
+
"cell_type": "markdown",
|
506
|
+
"id": "05f93b91",
|
507
|
+
"metadata": {},
|
508
|
+
"source": [
|
509
|
+
"### CryptoCompare - Historical Prices"
|
510
|
+
]
|
511
|
+
},
|
512
|
+
{
|
513
|
+
"cell_type": "code",
|
514
|
+
"execution_count": 20,
|
515
|
+
"id": "7f14d874",
|
516
|
+
"metadata": {},
|
517
|
+
"outputs": [],
|
518
|
+
"source": [
|
519
|
+
"# pull OHLC from CryptoCompare\n",
|
520
|
+
"data_req = DataRequest(source='cryptocompare',\n",
|
521
|
+
" tickers=tickers, \n",
|
522
|
+
" fields=['open', 'high', 'low', 'close', 'volume'], \n",
|
523
|
+
" freq='d')"
|
524
|
+
]
|
525
|
+
},
|
526
|
+
{
|
527
|
+
"cell_type": "code",
|
528
|
+
"execution_count": 21,
|
529
|
+
"id": "3a8708d3",
|
530
|
+
"metadata": {},
|
531
|
+
"outputs": [],
|
532
|
+
"source": [
|
533
|
+
"# df3 = GetData(data_req).get_series()"
|
534
|
+
]
|
535
|
+
},
|
536
|
+
{
|
537
|
+
"cell_type": "code",
|
538
|
+
"execution_count": 22,
|
539
|
+
"id": "aa265538",
|
540
|
+
"metadata": {},
|
541
|
+
"outputs": [],
|
542
|
+
"source": [
|
543
|
+
"# df3.to_csv('cc_spot.csv')\n",
|
544
|
+
"df3 = pd.read_csv('../../../../factorlab/notebooks/cc_spot.csv', index_col=['date', 'ticker'], parse_dates=['date'])"
|
545
|
+
]
|
546
|
+
},
|
547
|
+
{
|
548
|
+
"cell_type": "markdown",
|
549
|
+
"id": "5664e968",
|
550
|
+
"metadata": {},
|
551
|
+
"source": [
|
552
|
+
"### Clean Data"
|
553
|
+
]
|
554
|
+
},
|
555
|
+
{
|
556
|
+
"cell_type": "code",
|
557
|
+
"execution_count": 23,
|
558
|
+
"id": "f5ee4f6d",
|
559
|
+
"metadata": {},
|
560
|
+
"outputs": [],
|
561
|
+
"source": [
|
562
|
+
"df = stitch_dataframes([df1, df2, df3])\n",
|
563
|
+
"df.funding_rate = df.funding_rate.fillna(0)"
|
564
|
+
]
|
565
|
+
},
|
566
|
+
{
|
567
|
+
"cell_type": "code",
|
568
|
+
"execution_count": 24,
|
569
|
+
"id": "cbe07c91",
|
570
|
+
"metadata": {},
|
571
|
+
"outputs": [
|
572
|
+
{
|
573
|
+
"data": {
|
574
|
+
"text/html": [
|
575
|
+
"<div>\n",
|
576
|
+
"<style scoped>\n",
|
577
|
+
" .dataframe tbody tr th:only-of-type {\n",
|
578
|
+
" vertical-align: middle;\n",
|
579
|
+
" }\n",
|
580
|
+
"\n",
|
581
|
+
" .dataframe tbody tr th {\n",
|
582
|
+
" vertical-align: top;\n",
|
583
|
+
" }\n",
|
584
|
+
"\n",
|
585
|
+
" .dataframe thead th {\n",
|
586
|
+
" text-align: right;\n",
|
587
|
+
" }\n",
|
588
|
+
"</style>\n",
|
589
|
+
"<table border=\"1\" class=\"dataframe\">\n",
|
590
|
+
" <thead>\n",
|
591
|
+
" <tr style=\"text-align: right;\">\n",
|
592
|
+
" <th></th>\n",
|
593
|
+
" <th></th>\n",
|
594
|
+
" <th>open</th>\n",
|
595
|
+
" <th>high</th>\n",
|
596
|
+
" <th>low</th>\n",
|
597
|
+
" <th>close</th>\n",
|
598
|
+
" <th>volume</th>\n",
|
599
|
+
" <th>funding_rate</th>\n",
|
600
|
+
" </tr>\n",
|
601
|
+
" <tr>\n",
|
602
|
+
" <th>date</th>\n",
|
603
|
+
" <th>ticker</th>\n",
|
604
|
+
" <th></th>\n",
|
605
|
+
" <th></th>\n",
|
606
|
+
" <th></th>\n",
|
607
|
+
" <th></th>\n",
|
608
|
+
" <th></th>\n",
|
609
|
+
" <th></th>\n",
|
610
|
+
" </tr>\n",
|
611
|
+
" </thead>\n",
|
612
|
+
" <tbody>\n",
|
613
|
+
" <tr>\n",
|
614
|
+
" <th>2010-07-17</th>\n",
|
615
|
+
" <th>BTC</th>\n",
|
616
|
+
" <td>0.04951</td>\n",
|
617
|
+
" <td>0.04951</td>\n",
|
618
|
+
" <td>0.04951</td>\n",
|
619
|
+
" <td>0.04951</td>\n",
|
620
|
+
" <td>20.00</td>\n",
|
621
|
+
" <td>0.0</td>\n",
|
622
|
+
" </tr>\n",
|
623
|
+
" <tr>\n",
|
624
|
+
" <th>2010-07-18</th>\n",
|
625
|
+
" <th>BTC</th>\n",
|
626
|
+
" <td>0.04951</td>\n",
|
627
|
+
" <td>0.08585</td>\n",
|
628
|
+
" <td>0.04951</td>\n",
|
629
|
+
" <td>0.08584</td>\n",
|
630
|
+
" <td>75.01</td>\n",
|
631
|
+
" <td>0.0</td>\n",
|
632
|
+
" </tr>\n",
|
633
|
+
" <tr>\n",
|
634
|
+
" <th>2010-07-19</th>\n",
|
635
|
+
" <th>BTC</th>\n",
|
636
|
+
" <td>0.08584</td>\n",
|
637
|
+
" <td>0.09307</td>\n",
|
638
|
+
" <td>0.07723</td>\n",
|
639
|
+
" <td>0.08080</td>\n",
|
640
|
+
" <td>574.00</td>\n",
|
641
|
+
" <td>0.0</td>\n",
|
642
|
+
" </tr>\n",
|
643
|
+
" <tr>\n",
|
644
|
+
" <th>2010-07-20</th>\n",
|
645
|
+
" <th>BTC</th>\n",
|
646
|
+
" <td>0.08080</td>\n",
|
647
|
+
" <td>0.08181</td>\n",
|
648
|
+
" <td>0.07426</td>\n",
|
649
|
+
" <td>0.07474</td>\n",
|
650
|
+
" <td>262.00</td>\n",
|
651
|
+
" <td>0.0</td>\n",
|
652
|
+
" </tr>\n",
|
653
|
+
" <tr>\n",
|
654
|
+
" <th>2010-07-21</th>\n",
|
655
|
+
" <th>BTC</th>\n",
|
656
|
+
" <td>0.07474</td>\n",
|
657
|
+
" <td>0.07921</td>\n",
|
658
|
+
" <td>0.06634</td>\n",
|
659
|
+
" <td>0.07921</td>\n",
|
660
|
+
" <td>575.00</td>\n",
|
661
|
+
" <td>0.0</td>\n",
|
662
|
+
" </tr>\n",
|
663
|
+
" </tbody>\n",
|
664
|
+
"</table>\n",
|
665
|
+
"</div>"
|
666
|
+
],
|
667
|
+
"text/plain": [
|
668
|
+
" open high low close volume funding_rate\n",
|
669
|
+
"date ticker \n",
|
670
|
+
"2010-07-17 BTC 0.04951 0.04951 0.04951 0.04951 20.00 0.0\n",
|
671
|
+
"2010-07-18 BTC 0.04951 0.08585 0.04951 0.08584 75.01 0.0\n",
|
672
|
+
"2010-07-19 BTC 0.08584 0.09307 0.07723 0.08080 574.00 0.0\n",
|
673
|
+
"2010-07-20 BTC 0.08080 0.08181 0.07426 0.07474 262.00 0.0\n",
|
674
|
+
"2010-07-21 BTC 0.07474 0.07921 0.06634 0.07921 575.00 0.0"
|
675
|
+
]
|
676
|
+
},
|
677
|
+
"execution_count": 24,
|
678
|
+
"metadata": {},
|
679
|
+
"output_type": "execute_result"
|
680
|
+
}
|
681
|
+
],
|
682
|
+
"source": [
|
683
|
+
"df.head()"
|
684
|
+
]
|
685
|
+
},
|
686
|
+
{
|
687
|
+
"cell_type": "code",
|
688
|
+
"execution_count": 25,
|
689
|
+
"id": "d4c497d1",
|
690
|
+
"metadata": {},
|
691
|
+
"outputs": [],
|
692
|
+
"source": [
|
693
|
+
"delisted_tickers = ['AGIX', 'CTK', 'CVC', 'CVX', 'DGB', 'FTT', 'GLMR', 'IDEX', 'MDT',\n",
|
694
|
+
" 'OCEAN', 'RAD', 'RAY', 'SC', 'SLP', 'SNT', 'STPT', 'STRAX', 'WAVES']"
|
695
|
+
]
|
696
|
+
},
|
697
|
+
{
|
698
|
+
"cell_type": "code",
|
699
|
+
"execution_count": 26,
|
700
|
+
"id": "a9b1764c",
|
701
|
+
"metadata": {},
|
702
|
+
"outputs": [
|
703
|
+
{
|
704
|
+
"name": "stdout",
|
705
|
+
"output_type": "stream",
|
706
|
+
"text": [
|
707
|
+
"Index(['AGIX', 'CTK', 'CVC', 'CVX', 'DGB', 'FTT', 'GLMR', 'IDEX', 'MDT',\n",
|
708
|
+
" 'OCEAN', 'RAD', 'RAY', 'SC', 'SLP', 'SNT', 'STPT', 'STRAX', 'WAVES'],\n",
|
709
|
+
" dtype='object', name='ticker')\n"
|
710
|
+
]
|
711
|
+
}
|
712
|
+
],
|
713
|
+
"source": [
|
714
|
+
"# clean data\n",
|
715
|
+
"clean_df = CleanData(df).filter_delisted_tickers().\\\n",
|
716
|
+
" filter_min_nobs(ts_obs=1500, cs_obs=10).\\\n",
|
717
|
+
" filter_outliers(od_method='mad', excl_cols=['volume', 'funding_rate'], thresh_val=10).\\\n",
|
718
|
+
" repair_outliers(imp_method='fcst').\\\n",
|
719
|
+
" filter_avg_trading_val(thresh_val=1000000).\\\n",
|
720
|
+
" filter_missing_vals_gaps().\\\n",
|
721
|
+
" get(attr='df').dropna(how='all')"
|
722
|
+
]
|
723
|
+
},
|
724
|
+
{
|
725
|
+
"cell_type": "code",
|
726
|
+
"execution_count": 27,
|
727
|
+
"id": "3d423e53",
|
728
|
+
"metadata": {},
|
729
|
+
"outputs": [
|
730
|
+
{
|
731
|
+
"ename": "KeyError",
|
732
|
+
"evalue": "'OCEAN'",
|
733
|
+
"output_type": "error",
|
734
|
+
"traceback": [
|
735
|
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
736
|
+
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
|
737
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/core/indexes/base.py:3800\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m 3799\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m-> 3800\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_engine\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcasted_key\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3801\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n",
|
738
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/_libs/index.pyx:138\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
|
739
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/_libs/index.pyx:165\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n",
|
740
|
+
"File \u001b[0;32mpandas/_libs/hashtable_class_helper.pxi:5745\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
|
741
|
+
"File \u001b[0;32mpandas/_libs/hashtable_class_helper.pxi:5753\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n",
|
742
|
+
"\u001b[0;31mKeyError\u001b[0m: 'OCEAN'",
|
743
|
+
"\nThe above exception was the direct cause of the following exception:\n",
|
744
|
+
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
|
745
|
+
"Cell \u001b[0;32mIn [27], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m clean_df\u001b[38;5;241m.\u001b[39mloc[:, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mOCEAN\u001b[39m\u001b[38;5;124m'\u001b[39m, :]\n",
|
746
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/core/indexing.py:1068\u001b[0m, in \u001b[0;36m_LocationIndexer.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 1066\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_is_scalar_access(key):\n\u001b[1;32m 1067\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mobj\u001b[38;5;241m.\u001b[39m_get_value(\u001b[38;5;241m*\u001b[39mkey, takeable\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_takeable)\n\u001b[0;32m-> 1068\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_getitem_tuple\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1069\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1070\u001b[0m \u001b[38;5;66;03m# we by definition only have the 0th axis\u001b[39;00m\n\u001b[1;32m 1071\u001b[0m axis \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maxis \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;241m0\u001b[39m\n",
|
747
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/core/indexing.py:1248\u001b[0m, in \u001b[0;36m_LocIndexer._getitem_tuple\u001b[0;34m(self, tup)\u001b[0m\n\u001b[1;32m 1246\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m suppress(IndexingError):\n\u001b[1;32m 1247\u001b[0m tup \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_expand_ellipsis(tup)\n\u001b[0;32m-> 1248\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_getitem_lowerdim\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtup\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1250\u001b[0m \u001b[38;5;66;03m# no multi-index, so validate all of the indexers\u001b[39;00m\n\u001b[1;32m 1251\u001b[0m tup \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_tuple_indexer(tup)\n",
|
748
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/core/indexing.py:942\u001b[0m, in \u001b[0;36m_LocationIndexer._getitem_lowerdim\u001b[0;34m(self, tup)\u001b[0m\n\u001b[1;32m 940\u001b[0m \u001b[38;5;66;03m# we may have a nested tuples indexer here\u001b[39;00m\n\u001b[1;32m 941\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_is_nested_tuple_indexer(tup):\n\u001b[0;32m--> 942\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_getitem_nested_tuple\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtup\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 944\u001b[0m \u001b[38;5;66;03m# we maybe be using a tuple to represent multiple dimensions here\u001b[39;00m\n\u001b[1;32m 945\u001b[0m ax0 \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mobj\u001b[38;5;241m.\u001b[39m_get_axis(\u001b[38;5;241m0\u001b[39m)\n",
|
749
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/core/indexing.py:1034\u001b[0m, in \u001b[0;36m_LocationIndexer._getitem_nested_tuple\u001b[0;34m(self, tup)\u001b[0m\n\u001b[1;32m 1031\u001b[0m \u001b[38;5;66;03m# this is a series with a multi-index specified a tuple of\u001b[39;00m\n\u001b[1;32m 1032\u001b[0m \u001b[38;5;66;03m# selectors\u001b[39;00m\n\u001b[1;32m 1033\u001b[0m axis \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maxis \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;241m0\u001b[39m\n\u001b[0;32m-> 1034\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_getitem_axis\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtup\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43maxis\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1036\u001b[0m \u001b[38;5;66;03m# handle the multi-axis by taking sections and reducing\u001b[39;00m\n\u001b[1;32m 1037\u001b[0m \u001b[38;5;66;03m# this is iterative\u001b[39;00m\n\u001b[1;32m 1038\u001b[0m obj \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mobj\n",
|
750
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/core/indexing.py:1306\u001b[0m, in \u001b[0;36m_LocIndexer._getitem_axis\u001b[0;34m(self, key, axis)\u001b[0m\n\u001b[1;32m 1304\u001b[0m \u001b[38;5;66;03m# nested tuple slicing\u001b[39;00m\n\u001b[1;32m 1305\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_nested_tuple(key, labels):\n\u001b[0;32m-> 1306\u001b[0m locs \u001b[38;5;241m=\u001b[39m \u001b[43mlabels\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_locs\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1307\u001b[0m indexer \u001b[38;5;241m=\u001b[39m [\u001b[38;5;28mslice\u001b[39m(\u001b[38;5;28;01mNone\u001b[39;00m)] \u001b[38;5;241m*\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mndim\n\u001b[1;32m 1308\u001b[0m indexer[axis] \u001b[38;5;241m=\u001b[39m locs\n",
|
751
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/core/indexes/multi.py:3422\u001b[0m, in \u001b[0;36mMultiIndex.get_locs\u001b[0;34m(self, seq)\u001b[0m\n\u001b[1;32m 3418\u001b[0m \u001b[38;5;28;01mcontinue\u001b[39;00m\n\u001b[1;32m 3420\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 3421\u001b[0m \u001b[38;5;66;03m# a slice or a single label\u001b[39;00m\n\u001b[0;32m-> 3422\u001b[0m lvl_indexer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_level_indexer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlevel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mi\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mindexer\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mindexer\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3424\u001b[0m \u001b[38;5;66;03m# update indexer\u001b[39;00m\n\u001b[1;32m 3425\u001b[0m lvl_indexer \u001b[38;5;241m=\u001b[39m _to_bool_indexer(lvl_indexer)\n",
|
752
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/core/indexes/multi.py:3262\u001b[0m, in \u001b[0;36mMultiIndex._get_level_indexer\u001b[0;34m(self, key, level, indexer)\u001b[0m\n\u001b[1;32m 3258\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mslice\u001b[39m(i, j, step)\n\u001b[1;32m 3260\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 3262\u001b[0m idx \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_loc_single_level_index\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlevel_index\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3264\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m level \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_lexsort_depth \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 3265\u001b[0m \u001b[38;5;66;03m# Desired level is not sorted\u001b[39;00m\n\u001b[1;32m 3266\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(idx, \u001b[38;5;28mslice\u001b[39m):\n\u001b[1;32m 3267\u001b[0m \u001b[38;5;66;03m# test_get_loc_partial_timestamp_multiindex\u001b[39;00m\n",
|
753
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/core/indexes/multi.py:2848\u001b[0m, in \u001b[0;36mMultiIndex._get_loc_single_level_index\u001b[0;34m(self, level_index, key)\u001b[0m\n\u001b[1;32m 2846\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m\n\u001b[1;32m 2847\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 2848\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mlevel_index\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n",
|
754
|
+
"File \u001b[0;32m~/opt/anaconda3/envs/cryptodatapy/lib/python3.9/site-packages/pandas/core/indexes/base.py:3802\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m 3800\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine\u001b[38;5;241m.\u001b[39mget_loc(casted_key)\n\u001b[1;32m 3801\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[0;32m-> 3802\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n\u001b[1;32m 3803\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[1;32m 3804\u001b[0m \u001b[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001b[39;00m\n\u001b[1;32m 3805\u001b[0m \u001b[38;5;66;03m# InvalidIndexError. Otherwise we fall through and re-raise\u001b[39;00m\n\u001b[1;32m 3806\u001b[0m \u001b[38;5;66;03m# the TypeError.\u001b[39;00m\n\u001b[1;32m 3807\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_check_indexing_error(key)\n",
|
755
|
+
"\u001b[0;31mKeyError\u001b[0m: 'OCEAN'"
|
756
|
+
]
|
757
|
+
}
|
758
|
+
],
|
759
|
+
"source": [
|
760
|
+
"clean_df.loc[:, 'OCEAN', :]"
|
761
|
+
]
|
762
|
+
},
|
763
|
+
{
|
764
|
+
"cell_type": "code",
|
765
|
+
"execution_count": 28,
|
766
|
+
"id": "ad5a885c",
|
767
|
+
"metadata": {},
|
768
|
+
"outputs": [
|
769
|
+
{
|
770
|
+
"data": {
|
771
|
+
"text/html": [
|
772
|
+
"<div>\n",
|
773
|
+
"<style scoped>\n",
|
774
|
+
" .dataframe tbody tr th:only-of-type {\n",
|
775
|
+
" vertical-align: middle;\n",
|
776
|
+
" }\n",
|
777
|
+
"\n",
|
778
|
+
" .dataframe tbody tr th {\n",
|
779
|
+
" vertical-align: top;\n",
|
780
|
+
" }\n",
|
781
|
+
"\n",
|
782
|
+
" .dataframe thead th {\n",
|
783
|
+
" text-align: right;\n",
|
784
|
+
" }\n",
|
785
|
+
"</style>\n",
|
786
|
+
"<table border=\"1\" class=\"dataframe\">\n",
|
787
|
+
" <thead>\n",
|
788
|
+
" <tr style=\"text-align: right;\">\n",
|
789
|
+
" <th></th>\n",
|
790
|
+
" <th>open</th>\n",
|
791
|
+
" <th>high</th>\n",
|
792
|
+
" <th>low</th>\n",
|
793
|
+
" <th>close</th>\n",
|
794
|
+
" <th>volume</th>\n",
|
795
|
+
" <th>funding_rate</th>\n",
|
796
|
+
" </tr>\n",
|
797
|
+
" <tr>\n",
|
798
|
+
" <th>date</th>\n",
|
799
|
+
" <th></th>\n",
|
800
|
+
" <th></th>\n",
|
801
|
+
" <th></th>\n",
|
802
|
+
" <th></th>\n",
|
803
|
+
" <th></th>\n",
|
804
|
+
" <th></th>\n",
|
805
|
+
" </tr>\n",
|
806
|
+
" </thead>\n",
|
807
|
+
" <tbody>\n",
|
808
|
+
" <tr>\n",
|
809
|
+
" <th>2015-06-12</th>\n",
|
810
|
+
" <td>229.88</td>\n",
|
811
|
+
" <td>231.58</td>\n",
|
812
|
+
" <td>229.29</td>\n",
|
813
|
+
" <td>230.46</td>\n",
|
814
|
+
" <td>40744.820</td>\n",
|
815
|
+
" <td>0.000000</td>\n",
|
816
|
+
" </tr>\n",
|
817
|
+
" <tr>\n",
|
818
|
+
" <th>2015-06-13</th>\n",
|
819
|
+
" <td>230.46</td>\n",
|
820
|
+
" <td>233.14</td>\n",
|
821
|
+
" <td>229.01</td>\n",
|
822
|
+
" <td>232.48</td>\n",
|
823
|
+
" <td>38008.730</td>\n",
|
824
|
+
" <td>0.000000</td>\n",
|
825
|
+
" </tr>\n",
|
826
|
+
" <tr>\n",
|
827
|
+
" <th>2015-06-14</th>\n",
|
828
|
+
" <td>232.48</td>\n",
|
829
|
+
" <td>235.51</td>\n",
|
830
|
+
" <td>232.09</td>\n",
|
831
|
+
" <td>233.75</td>\n",
|
832
|
+
" <td>32894.870</td>\n",
|
833
|
+
" <td>0.000000</td>\n",
|
834
|
+
" </tr>\n",
|
835
|
+
" <tr>\n",
|
836
|
+
" <th>2015-06-15</th>\n",
|
837
|
+
" <td>233.75</td>\n",
|
838
|
+
" <td>238.55</td>\n",
|
839
|
+
" <td>233.29</td>\n",
|
840
|
+
" <td>237.0</td>\n",
|
841
|
+
" <td>63467.090</td>\n",
|
842
|
+
" <td>0.000000</td>\n",
|
843
|
+
" </tr>\n",
|
844
|
+
" <tr>\n",
|
845
|
+
" <th>2015-06-16</th>\n",
|
846
|
+
" <td>237.0</td>\n",
|
847
|
+
" <td>254.15</td>\n",
|
848
|
+
" <td>235.7</td>\n",
|
849
|
+
" <td>249.82</td>\n",
|
850
|
+
" <td>122473.610</td>\n",
|
851
|
+
" <td>0.000000</td>\n",
|
852
|
+
" </tr>\n",
|
853
|
+
" <tr>\n",
|
854
|
+
" <th>...</th>\n",
|
855
|
+
" <td>...</td>\n",
|
856
|
+
" <td>...</td>\n",
|
857
|
+
" <td>...</td>\n",
|
858
|
+
" <td>...</td>\n",
|
859
|
+
" <td>...</td>\n",
|
860
|
+
" <td>...</td>\n",
|
861
|
+
" </tr>\n",
|
862
|
+
" <tr>\n",
|
863
|
+
" <th>2024-07-31</th>\n",
|
864
|
+
" <td>66159.3</td>\n",
|
865
|
+
" <td>66826.3</td>\n",
|
866
|
+
" <td>64500.4</td>\n",
|
867
|
+
" <td>64601.8</td>\n",
|
868
|
+
" <td>246389.446</td>\n",
|
869
|
+
" <td>0.000141</td>\n",
|
870
|
+
" </tr>\n",
|
871
|
+
" <tr>\n",
|
872
|
+
" <th>2024-08-01</th>\n",
|
873
|
+
" <td>64601.8</td>\n",
|
874
|
+
" <td>65650.0</td>\n",
|
875
|
+
" <td>62271.2</td>\n",
|
876
|
+
" <td>65328.9</td>\n",
|
877
|
+
" <td>372654.590</td>\n",
|
878
|
+
" <td>0.000282</td>\n",
|
879
|
+
" </tr>\n",
|
880
|
+
" <tr>\n",
|
881
|
+
" <th>2024-08-02</th>\n",
|
882
|
+
" <td>65329.0</td>\n",
|
883
|
+
" <td>65577.0</td>\n",
|
884
|
+
" <td>61200.2</td>\n",
|
885
|
+
" <td>61483.7</td>\n",
|
886
|
+
" <td>421628.420</td>\n",
|
887
|
+
" <td>0.000300</td>\n",
|
888
|
+
" </tr>\n",
|
889
|
+
" <tr>\n",
|
890
|
+
" <th>2024-08-03</th>\n",
|
891
|
+
" <td>61483.7</td>\n",
|
892
|
+
" <td>63871.5</td>\n",
|
893
|
+
" <td>59800.0</td>\n",
|
894
|
+
" <td>60684.6</td>\n",
|
895
|
+
" <td>290469.956</td>\n",
|
896
|
+
" <td>0.000240</td>\n",
|
897
|
+
" </tr>\n",
|
898
|
+
" <tr>\n",
|
899
|
+
" <th>2024-08-04</th>\n",
|
900
|
+
" <td>60684.5</td>\n",
|
901
|
+
" <td>61089.5</td>\n",
|
902
|
+
" <td>60080.5</td>\n",
|
903
|
+
" <td>60357.6</td>\n",
|
904
|
+
" <td>85220.266</td>\n",
|
905
|
+
" <td>0.000153</td>\n",
|
906
|
+
" </tr>\n",
|
907
|
+
" </tbody>\n",
|
908
|
+
"</table>\n",
|
909
|
+
"<p>3342 rows × 6 columns</p>\n",
|
910
|
+
"</div>"
|
911
|
+
],
|
912
|
+
"text/plain": [
|
913
|
+
" open high low close volume funding_rate\n",
|
914
|
+
"date \n",
|
915
|
+
"2015-06-12 229.88 231.58 229.29 230.46 40744.820 0.000000\n",
|
916
|
+
"2015-06-13 230.46 233.14 229.01 232.48 38008.730 0.000000\n",
|
917
|
+
"2015-06-14 232.48 235.51 232.09 233.75 32894.870 0.000000\n",
|
918
|
+
"2015-06-15 233.75 238.55 233.29 237.0 63467.090 0.000000\n",
|
919
|
+
"2015-06-16 237.0 254.15 235.7 249.82 122473.610 0.000000\n",
|
920
|
+
"... ... ... ... ... ... ...\n",
|
921
|
+
"2024-07-31 66159.3 66826.3 64500.4 64601.8 246389.446 0.000141\n",
|
922
|
+
"2024-08-01 64601.8 65650.0 62271.2 65328.9 372654.590 0.000282\n",
|
923
|
+
"2024-08-02 65329.0 65577.0 61200.2 61483.7 421628.420 0.000300\n",
|
924
|
+
"2024-08-03 61483.7 63871.5 59800.0 60684.6 290469.956 0.000240\n",
|
925
|
+
"2024-08-04 60684.5 61089.5 60080.5 60357.6 85220.266 0.000153\n",
|
926
|
+
"\n",
|
927
|
+
"[3342 rows x 6 columns]"
|
928
|
+
]
|
929
|
+
},
|
930
|
+
"execution_count": 28,
|
931
|
+
"metadata": {},
|
932
|
+
"output_type": "execute_result"
|
933
|
+
}
|
934
|
+
],
|
935
|
+
"source": [
|
936
|
+
"clean_df.loc[:, 'BTC', :]"
|
937
|
+
]
|
938
|
+
},
|
939
|
+
{
|
940
|
+
"cell_type": "code",
|
941
|
+
"execution_count": 29,
|
942
|
+
"id": "a9c262fc",
|
943
|
+
"metadata": {},
|
944
|
+
"outputs": [],
|
945
|
+
"source": [
|
946
|
+
"clean_df.to_parquet('s3://factorlab-data/binance_historical_ohlcv_daily.parquet')"
|
947
|
+
]
|
948
|
+
},
|
949
|
+
{
|
950
|
+
"cell_type": "code",
|
951
|
+
"execution_count": 30,
|
952
|
+
"id": "893e3e38",
|
953
|
+
"metadata": {},
|
954
|
+
"outputs": [],
|
955
|
+
"source": [
|
956
|
+
"clean_df.to_parquet('../../../../factorlab/notebooks/binance_historical_ohlcv_daily.parquet')"
|
957
|
+
]
|
958
|
+
},
|
959
|
+
{
|
960
|
+
"cell_type": "code",
|
961
|
+
"execution_count": null,
|
962
|
+
"id": "8a962fa7",
|
963
|
+
"metadata": {},
|
964
|
+
"outputs": [],
|
965
|
+
"source": []
|
966
|
+
},
|
967
|
+
{
|
968
|
+
"cell_type": "code",
|
969
|
+
"execution_count": 31,
|
970
|
+
"id": "54b818cd",
|
971
|
+
"metadata": {},
|
972
|
+
"outputs": [],
|
973
|
+
"source": [
|
974
|
+
"clean_df.to_csv('../../../../factorlab/notebooks/binance_historical_ohlcv_daily.csv')"
|
975
|
+
]
|
976
|
+
},
|
977
|
+
{
|
978
|
+
"cell_type": "code",
|
979
|
+
"execution_count": 32,
|
980
|
+
"id": "a1c49f01",
|
981
|
+
"metadata": {},
|
982
|
+
"outputs": [],
|
983
|
+
"source": [
|
984
|
+
"clean_df.to_csv('s3://factorlab-data/binance_historical_ohlcv_daily.csv')"
|
985
|
+
]
|
986
|
+
},
|
987
|
+
{
|
988
|
+
"cell_type": "code",
|
989
|
+
"execution_count": null,
|
990
|
+
"id": "b8fa525d",
|
991
|
+
"metadata": {},
|
992
|
+
"outputs": [],
|
993
|
+
"source": []
|
994
|
+
},
|
995
|
+
{
|
996
|
+
"cell_type": "code",
|
997
|
+
"execution_count": null,
|
998
|
+
"id": "f9488eba",
|
999
|
+
"metadata": {},
|
1000
|
+
"outputs": [],
|
1001
|
+
"source": []
|
1002
|
+
}
|
1003
|
+
],
|
1004
|
+
"metadata": {
|
1005
|
+
"kernelspec": {
|
1006
|
+
"display_name": "cryptodatapy",
|
1007
|
+
"language": "python",
|
1008
|
+
"name": "cryptodatapy"
|
1009
|
+
},
|
1010
|
+
"language_info": {
|
1011
|
+
"codemirror_mode": {
|
1012
|
+
"name": "ipython",
|
1013
|
+
"version": 3
|
1014
|
+
},
|
1015
|
+
"file_extension": ".py",
|
1016
|
+
"mimetype": "text/x-python",
|
1017
|
+
"name": "python",
|
1018
|
+
"nbconvert_exporter": "python",
|
1019
|
+
"pygments_lexer": "ipython3",
|
1020
|
+
"version": "3.9.12"
|
1021
|
+
}
|
1022
|
+
},
|
1023
|
+
"nbformat": 4,
|
1024
|
+
"nbformat_minor": 5
|
1025
|
+
}
|