|
- {
- "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
- }
|