|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<style scoped>\n",
- " .dataframe tbody tr th:only-of-type {\n",
- " vertical-align: middle;\n",
- " }\n",
- "\n",
- " .dataframe tbody tr th {\n",
- " vertical-align: top;\n",
- " }\n",
- "\n",
- " .dataframe thead th {\n",
- " text-align: right;\n",
- " }\n",
- "</style>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th>time</th>\n",
- " <th>amount</th>\n",
- " <th>exch</th>\n",
- " <th>price</th>\n",
- " <th>server_time</th>\n",
- " <th>side</th>\n",
- " <th>ticker</th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <td>0</td>\n",
- " <td>1531094401700852527</td>\n",
- " <td>0.0801</td>\n",
- " <td>bits</td>\n",
- " <td>6706.6001</td>\n",
- " <td>0</td>\n",
- " <td>na</td>\n",
- " <td>btc_usd</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <td>1</td>\n",
- " <td>1531094401780298519</td>\n",
- " <td>0.0284</td>\n",
- " <td>bits</td>\n",
- " <td>6706.6099</td>\n",
- " <td>0</td>\n",
- " <td>na</td>\n",
- " <td>btc_usd</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <td>2</td>\n",
- " <td>1531094402305708472</td>\n",
- " <td>0.0050</td>\n",
- " <td>btfx</td>\n",
- " <td>6707.0000</td>\n",
- " <td>0</td>\n",
- " <td>na</td>\n",
- " <td>btc_usd</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <td>3</td>\n",
- " <td>1531094403455657797</td>\n",
- " <td>0.0050</td>\n",
- " <td>btfx</td>\n",
- " <td>6706.7002</td>\n",
- " <td>0</td>\n",
- " <td>na</td>\n",
- " <td>btc_usd</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <td>4</td>\n",
- " <td>1531094403592663872</td>\n",
- " <td>0.0658</td>\n",
- " <td>btfx</td>\n",
- " <td>6705.8999</td>\n",
- " <td>0</td>\n",
- " <td>na</td>\n",
- " <td>btc_usd</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " time amount exch price server_time side ticker\n",
- "0 1531094401700852527 0.0801 bits 6706.6001 0 na btc_usd\n",
- "1 1531094401780298519 0.0284 bits 6706.6099 0 na btc_usd\n",
- "2 1531094402305708472 0.0050 btfx 6707.0000 0 na btc_usd\n",
- "3 1531094403455657797 0.0050 btfx 6706.7002 0 na btc_usd\n",
- "4 1531094403592663872 0.0658 btfx 6705.8999 0 na btc_usd"
- ]
- },
- "execution_count": 1,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df = pd.read_csv('/xfs/trades.csv', nrows=1024 * 1024)\n",
- "df.head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<style scoped>\n",
- " .dataframe tbody tr th:only-of-type {\n",
- " vertical-align: middle;\n",
- " }\n",
- "\n",
- " .dataframe tbody tr th {\n",
- " vertical-align: top;\n",
- " }\n",
- "\n",
- " .dataframe thead th {\n",
- " text-align: right;\n",
- " }\n",
- "</style>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th>time</th>\n",
- " <th>amount</th>\n",
- " <th>exch</th>\n",
- " <th>price</th>\n",
- " <th>server_time</th>\n",
- " <th>side</th>\n",
- " <th>ticker</th>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>time</th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " <th></th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <td>2018-07-09 00:00:01.700852527+00:00</td>\n",
- " <td>1531094401700852527</td>\n",
- " <td>0.0801</td>\n",
- " <td>bits</td>\n",
- " <td>6706.6001</td>\n",
- " <td>0</td>\n",
- " <td>na</td>\n",
- " <td>btc_usd</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <td>2018-07-09 00:00:01.780298519+00:00</td>\n",
- " <td>1531094401780298519</td>\n",
- " <td>0.0284</td>\n",
- " <td>bits</td>\n",
- " <td>6706.6099</td>\n",
- " <td>0</td>\n",
- " <td>na</td>\n",
- " <td>btc_usd</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <td>2018-07-09 00:00:02.305708472+00:00</td>\n",
- " <td>1531094402305708472</td>\n",
- " <td>0.0050</td>\n",
- " <td>btfx</td>\n",
- " <td>6707.0000</td>\n",
- " <td>0</td>\n",
- " <td>na</td>\n",
- " <td>btc_usd</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <td>2018-07-09 00:00:03.455657797+00:00</td>\n",
- " <td>1531094403455657797</td>\n",
- " <td>0.0050</td>\n",
- " <td>btfx</td>\n",
- " <td>6706.7002</td>\n",
- " <td>0</td>\n",
- " <td>na</td>\n",
- " <td>btc_usd</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <td>2018-07-09 00:00:03.592663872+00:00</td>\n",
- " <td>1531094403592663872</td>\n",
- " <td>0.0658</td>\n",
- " <td>btfx</td>\n",
- " <td>6705.8999</td>\n",
- " <td>0</td>\n",
- " <td>na</td>\n",
- " <td>btc_usd</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " time amount exch \\\n",
- "time \n",
- "2018-07-09 00:00:01.700852527+00:00 1531094401700852527 0.0801 bits \n",
- "2018-07-09 00:00:01.780298519+00:00 1531094401780298519 0.0284 bits \n",
- "2018-07-09 00:00:02.305708472+00:00 1531094402305708472 0.0050 btfx \n",
- "2018-07-09 00:00:03.455657797+00:00 1531094403455657797 0.0050 btfx \n",
- "2018-07-09 00:00:03.592663872+00:00 1531094403592663872 0.0658 btfx \n",
- "\n",
- " price server_time side ticker \n",
- "time \n",
- "2018-07-09 00:00:01.700852527+00:00 6706.6001 0 na btc_usd \n",
- "2018-07-09 00:00:01.780298519+00:00 6706.6099 0 na btc_usd \n",
- "2018-07-09 00:00:02.305708472+00:00 6707.0000 0 na btc_usd \n",
- "2018-07-09 00:00:03.455657797+00:00 6706.7002 0 na btc_usd \n",
- "2018-07-09 00:00:03.592663872+00:00 6705.8999 0 na btc_usd "
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df.index = pd.to_datetime(df['time'], utc=True)\n",
- "df.head()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "(Timestamp('2018-07-09 00:00:01.700852527+0000', tz='UTC'),\n",
- " Timestamp('2018-07-11 19:27:34.453569864+0000', tz='UTC'),\n",
- " Timedelta('2 days 19:27:32.752717'))"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "df.index[0], df.index[-1], df.index[-1] - df.index[0]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "1.000578250137079"
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "start = \"2018-07-10T04:00:00Z\" # <- randomly selected start/end \n",
- "end = \"2018-07-10T05:00:00Z\" # important point is, 1h span\n",
- "\n",
- "target_hr = (df.index >= start) & (df.index < end)\n",
- "assert target_hr.sum() > 0\n",
- "\n",
- "of_btcusd = df['ticker'] == 'btc_usd'\n",
- "assert of_btcusd.sum() > 0\n",
- "\n",
- "of_bmex = df['exch'] == 'bmex'\n",
- "of_gdax = df['exch'] == 'gdax'\n",
- "\n",
- "assert of_bmex.sum() > 0\n",
- "assert of_gdax.sum() > 0\n",
- "\n",
- "bmex_hr = df.loc[target_hr & of_bmex & of_btcusd, ['price', 'amount']]\n",
- "gdax_hr = df.loc[target_hr & of_gdax & of_btcusd, ['price', 'amount']]\n",
- "\n",
- "bmex_size_wt_price = (\n",
- " (bmex_hr['price'] * bmex_hr['amount']).sum()\n",
- " / bmex_hr['amount'].sum()\n",
- ")\n",
- "\n",
- "gdax_size_wt_price = (\n",
- " (gdax_hr['price'] * gdax_hr['amount']).sum()\n",
- " / gdax_hr['amount'].sum()\n",
- ")\n",
- "\n",
- "ratio = bmex_size_wt_price / gdax_size_wt_price # <- final answer (for start,end hr at least)\n",
- "ratio"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "((2714, 2), (1305, 2))"
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "bmex_hr.shape, gdax_hr.shape"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "(6642.42451802828, 6638.585754905495)"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "bmex_size_wt_price, gdax_size_wt_price"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "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.7.5"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
|