{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
timeamountexchpriceserver_timesideticker
015310944017008525270.0801bits6706.60010nabtc_usd
115310944017802985190.0284bits6706.60990nabtc_usd
215310944023057084720.0050btfx6707.00000nabtc_usd
315310944034556577970.0050btfx6706.70020nabtc_usd
415310944035926638720.0658btfx6705.89990nabtc_usd
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
timeamountexchpriceserver_timesideticker
time
2018-07-09 00:00:01.700852527+00:0015310944017008525270.0801bits6706.60010nabtc_usd
2018-07-09 00:00:01.780298519+00:0015310944017802985190.0284bits6706.60990nabtc_usd
2018-07-09 00:00:02.305708472+00:0015310944023057084720.0050btfx6707.00000nabtc_usd
2018-07-09 00:00:03.455657797+00:0015310944034556577970.0050btfx6706.70020nabtc_usd
2018-07-09 00:00:03.592663872+00:0015310944035926638720.0658btfx6705.89990nabtc_usd
\n", "
" ], "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 }