Files
quant/vectorbt/tests/notebooks/records.ipynb

10960 lines
525 KiB
Plaintext
Raw Permalink Normal View History

2025-11-01 09:32:26 +08:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# records"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import vectorbt as vbt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"Collapsed": "false"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from numba import njit\n",
"from collections import namedtuple\n",
"from datetime import datetime"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Disable caching for performance testing\n",
"# NOTE: Expect waterfall of executions, since some attributes depend on other attributes \n",
"# that have to be calculated again and again\n",
"vbt.settings.caching['enabled'] = False"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"example_dt = np.dtype([\n",
" ('id', np.int64),\n",
" ('idx', np.int64),\n",
" ('col', np.int64),\n",
" ('some_field1', np.float64),\n",
" ('some_field2', np.float64)\n",
"], align=True)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[(0, 0, 0, 10., 21.) (1, 1, 0, 11., 20.) (2, 2, 0, 12., 19.)\n",
" (3, 0, 1, 13., 18.) (4, 1, 1, 14., 17.) (5, 2, 1, 13., 18.)\n",
" (6, 0, 2, 12., 19.) (7, 1, 2, 11., 20.) (8, 2, 2, 10., 21.)]\n",
"(9,)\n"
]
}
],
"source": [
"records_arr = np.asarray([\n",
" (0, 0, 0, 10, 21),\n",
" (1, 1, 0, 11, 20),\n",
" (2, 2, 0, 12, 19),\n",
" (3, 0, 1, 13, 18),\n",
" (4, 1, 1, 14, 17),\n",
" (5, 2, 1, 13, 18),\n",
" (6, 0, 2, 12, 19),\n",
" (7, 1, 2, 11, 20),\n",
" (8, 2, 2, 10, 21)\n",
"], dtype=example_dt)\n",
"print(records_arr)\n",
"print(records_arr.shape)\n",
"\n",
"columns = pd.MultiIndex.from_arrays([[0, 1, 1, 1], ['a', 'b', 'c', 'd']], names=['lvl1', 'lvl2'])\n",
"wrapper = vbt.ArrayWrapper(index=['x', 'y', 'z'], columns=columns, ndim=2, freq='1 days')\n",
"records = vbt.Records(wrapper, records_arr)\n",
"\n",
"records_grouped = vbt.Records(wrapper.copy(group_by=0), records_arr)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1000000,)\n"
]
}
],
"source": [
"big_records_arr = np.asarray(list(zip(*(\n",
" np.arange(1000000),\n",
" np.tile(np.arange(1000), 1000),\n",
" np.repeat(np.arange(1000), 1000),\n",
" np.random.randint(0, 100, size=1000000),\n",
" np.random.randint(0, 100, size=1000000)))), dtype=example_dt)\n",
"print(big_records_arr.shape)\n",
"\n",
"big_columns = pd.MultiIndex.from_arrays([np.repeat(np.array([0, 1]), 500), np.arange(1000)], names=['lvl1', 'lvl2'])\n",
"big_wrapper = vbt.ArrayWrapper(index=np.arange(1000), columns=big_columns, ndim=2, freq='1 days')\n",
"big_records = vbt.Records(big_wrapper, big_records_arr)\n",
"\n",
"big_records_grouped = vbt.Records(big_wrapper.copy(group_by=0), big_records_arr)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[(8, 2, 2, 10., 21.) (7, 1, 2, 11., 20.) (6, 0, 2, 12., 19.)\n",
" (5, 2, 1, 13., 18.) (4, 1, 1, 14., 17.) (3, 0, 1, 13., 18.)\n",
" (2, 2, 0, 12., 19.) (1, 1, 0, 11., 20.) (0, 0, 0, 10., 21.)]\n"
]
}
],
"source": [
"records_nosort = records.copy(records_arr=records.records_arr[::-1])\n",
"print(records_nosort.records_arr)\n",
"\n",
"big_records_nosort = big_records.copy(records_arr=big_records.records_arr[::-1])"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"group_by = pd.Series(['first', 'first', 'second', 'second'], name='group')\n",
"big_group_by = pd.Series(np.repeat(np.array([0, 1]), 500))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## ColumnMapper"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0 0 0 1 1 1 2 2 2]\n"
]
}
],
"source": [
"print(records.col_mapper.col_arr)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0 0 0 1 1 1 2 2 2]\n",
"[0 0 0 1 1 1 1 1 1]\n",
"7.57 µs ± 81.5 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
]
}
],
"source": [
"print(records.col_mapper.get_col_arr())\n",
"print(records_grouped.col_mapper.get_col_arr())\n",
"\n",
"%timeit big_records_grouped.col_mapper.get_col_arr()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0 3]\n",
" [ 3 6]\n",
" [ 6 9]\n",
" [-1 -1]]\n",
"6.99 µs ± 73.1 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
]
}
],
"source": [
"print(records.col_mapper.col_range)\n",
"\n",
"%timeit big_records.col_mapper.col_range"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0 3]\n",
" [ 3 6]\n",
" [ 6 9]\n",
" [-1 -1]]\n",
"[[0 3]\n",
" [3 9]]\n",
"7.38 µs ± 56.5 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
]
}
],
"source": [
"print(records.col_mapper.get_col_range())\n",
"print(records_grouped.col_mapper.get_col_range())\n",
"\n",
"%timeit big_records_grouped.col_mapper.get_col_range()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(array([0, 1, 2, 3, 4, 5, 6, 7, 8]), array([3, 3, 3, 0]))\n",
"7.03 µs ± 22.4 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
]
}
],
"source": [
"print(records.col_mapper.col_map)\n",
"\n",
"%timeit big_records.col_mapper.col_map"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(array([0, 1, 2, 3, 4, 5, 6, 7, 8]), array([3, 3, 3, 0]))\n",
"(array([0, 1, 2, 3, 4, 5, 6, 7, 8]), array([3, 6]))\n",
"7.43 µs ± 46.4 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
]
}
],
"source": [
"print(records.col_mapper.get_col_map())\n",
"print(records_grouped.col_mapper.get_col_map())\n",
"\n",
"%timeit big_records_grouped.col_mapper.get_col_map()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"7.48 µs ± 48.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n",
"False\n",
"7.49 µs ± 8.8 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
]
}
],
"source": [
"print(records.col_mapper.is_sorted())\n",
"%timeit big_records.col_mapper.is_sorted()\n",
"\n",
"print(records_nosort.col_mapper.is_sorted())\n",
"%timeit big_records_nosort.col_mapper.is_sorted()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## MappedArray"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"mapped_array = records.map_field('some_field1')\n",
"big_mapped_array = big_records.map_field('some_field1')\n",
"\n",
"mapped_array_nosort = records_nosort.map_field('some_field1')\n",
"big_mapped_array_nosort = big_records_nosort.map_field('some_field1')\n",
"\n",
"mapped_array_grouped = records_grouped.map_field('some_field1')\n",
"big_mapped_array_grouped = big_records_grouped.map_field('some_field1')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[10. 11. 12.]\n",
"[0 0 0]\n",
"MultiIndex([(0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"[13. 14. 13.]\n",
"[0 0 0]\n",
"MultiIndex([(1, 'b')],\n",
" names=['lvl1', 'lvl2'])\n",
"[10. 11. 12. 10. 11. 12.]\n",
"[0 0 0 1 1 1]\n",
"MultiIndex([(0, 'a'),\n",
" (0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"[10. 11. 12. 13. 14. 13.]\n",
"[0 0 0 1 1 1]\n",
"MultiIndex([(0, 'a'),\n",
" (1, 'b')],\n",
" names=['lvl1', 'lvl2'])\n",
"954 µs ± 11.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"13.7 ms ± 1.09 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array[(0, 'a')].values)\n",
"print(mapped_array[(0, 'a')].col_arr)\n",
"print(mapped_array[(0, 'a')].wrapper.columns)\n",
"\n",
"print(mapped_array[(1, 'b')].values)\n",
"print(mapped_array[(1, 'b')].col_arr)\n",
"print(mapped_array[(1, 'b')].wrapper.columns)\n",
"\n",
"print(mapped_array[[(0, 'a'), (0, 'a')]].values)\n",
"print(mapped_array[[(0, 'a'), (0, 'a')]].col_arr)\n",
"print(mapped_array[[(0, 'a'), (0, 'a')]].wrapper.columns)\n",
"\n",
"print(mapped_array[[(0, 'a'), (1, 'b')]].values)\n",
"print(mapped_array[[(0, 'a'), (1, 'b')]].col_arr)\n",
"print(mapped_array[[(0, 'a'), (1, 'b')]].wrapper.columns)\n",
"\n",
"%timeit big_mapped_array.iloc[0]\n",
"%timeit big_mapped_array.iloc[:]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[12. 11. 10.]\n",
"[0 0 0]\n",
"MultiIndex([(0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"[13. 14. 13.]\n",
"[0 0 0]\n",
"MultiIndex([(1, 'b')],\n",
" names=['lvl1', 'lvl2'])\n",
"[12. 11. 10. 12. 11. 10.]\n",
"[0 0 0 1 1 1]\n",
"MultiIndex([(0, 'a'),\n",
" (0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"[12. 11. 10. 13. 14. 13.]\n",
"[0 0 0 1 1 1]\n",
"MultiIndex([(0, 'a'),\n",
" (1, 'b')],\n",
" names=['lvl1', 'lvl2'])\n",
"954 µs ± 7.38 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"14.2 ms ± 448 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array_nosort[(0, 'a')].values)\n",
"print(mapped_array_nosort[(0, 'a')].col_arr)\n",
"print(mapped_array_nosort[(0, 'a')].wrapper.columns)\n",
"\n",
"print(mapped_array_nosort[(1, 'b')].values)\n",
"print(mapped_array_nosort[(1, 'b')].col_arr)\n",
"print(mapped_array_nosort[(1, 'b')].wrapper.columns)\n",
"\n",
"print(mapped_array_nosort[[(0, 'a'), (0, 'a')]].values)\n",
"print(mapped_array_nosort[[(0, 'a'), (0, 'a')]].col_arr)\n",
"print(mapped_array_nosort[[(0, 'a'), (0, 'a')]].wrapper.columns)\n",
"\n",
"print(mapped_array_nosort[[(0, 'a'), (1, 'b')]].values)\n",
"print(mapped_array_nosort[[(0, 'a'), (1, 'b')]].col_arr)\n",
"print(mapped_array_nosort[[(0, 'a'), (1, 'b')]].wrapper.columns)\n",
"\n",
"%timeit big_mapped_array_nosort.iloc[0]\n",
"%timeit big_mapped_array_nosort.iloc[:]"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MultiIndex([(0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"1\n",
"1\n",
"Index([0], dtype='int64', name='lvl1')\n",
"MultiIndex([(1, 'b'),\n",
" (1, 'c'),\n",
" (1, 'd')],\n",
" names=['lvl1', 'lvl2'])\n",
"2\n",
"1\n",
"Index([1, 1, 1], dtype='int64', name='lvl1')\n",
"MultiIndex([(0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"2\n",
"2\n",
"Index([0], dtype='int64', name='lvl1')\n",
"MultiIndex([(0, 'a'),\n",
" (1, 'b'),\n",
" (1, 'c'),\n",
" (1, 'd')],\n",
" names=['lvl1', 'lvl2'])\n",
"2\n",
"2\n",
"Index([0, 1, 1, 1], dtype='int64', name='lvl1')\n",
"5.57 ms ± 375 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"12.1 ms ± 451 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array_grouped[0].wrapper.columns) # indexing on groups, not columns!\n",
"print(mapped_array_grouped[0].wrapper.ndim)\n",
"print(mapped_array_grouped[0].wrapper.grouped_ndim)\n",
"print(mapped_array_grouped[0].wrapper.grouper.group_by)\n",
"\n",
"print(mapped_array_grouped[1].wrapper.columns)\n",
"print(mapped_array_grouped[1].wrapper.ndim)\n",
"print(mapped_array_grouped[1].wrapper.grouped_ndim)\n",
"print(mapped_array_grouped[1].wrapper.grouper.group_by)\n",
"\n",
"print(mapped_array_grouped[[0]].wrapper.columns)\n",
"print(mapped_array_grouped[[0]].wrapper.ndim)\n",
"print(mapped_array_grouped[[0]].wrapper.grouped_ndim)\n",
"print(mapped_array_grouped[[0]].wrapper.grouper.group_by)\n",
"\n",
"print(mapped_array_grouped[[0, 1]].wrapper.columns)\n",
"print(mapped_array_grouped[[0, 1]].wrapper.ndim)\n",
"print(mapped_array_grouped[[0, 1]].wrapper.grouped_ndim)\n",
"print(mapped_array_grouped[[0, 1]].wrapper.grouper.group_by)\n",
"\n",
"%timeit big_mapped_array_grouped.iloc[0]\n",
"%timeit big_mapped_array_grouped.iloc[:]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Index(['x', 'y', 'z'], dtype='object')\n",
"MultiIndex([(0, 'a'),\n",
" (1, 'b'),\n",
" (1, 'c'),\n",
" (1, 'd')],\n",
" names=['lvl1', 'lvl2'])\n",
"2\n",
"None\n",
"Index(['x', 'y', 'z'], dtype='object')\n",
"MultiIndex([(0, 'a'),\n",
" (1, 'b'),\n",
" (1, 'c'),\n",
" (1, 'd')],\n",
" names=['lvl1', 'lvl2'])\n",
"2\n",
"Index([0, 1, 1, 1], dtype='int64', name='lvl1')\n"
]
}
],
"source": [
"print(mapped_array.wrapper.index)\n",
"print(mapped_array.wrapper.columns)\n",
"print(mapped_array.wrapper.ndim)\n",
"print(mapped_array.wrapper.grouper.group_by)\n",
"\n",
"print(mapped_array_grouped.wrapper.index)\n",
"print(mapped_array_grouped.wrapper.columns)\n",
"print(mapped_array_grouped.wrapper.ndim)\n",
"print(mapped_array_grouped.wrapper.grouper.group_by)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[10. 11. 12. 13. 14. 13. 12. 11. 10.]\n"
]
}
],
"source": [
"print(mapped_array.values)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0 0 0 1 1 1 2 2 2]\n"
]
}
],
"source": [
"print(mapped_array.col_arr)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0 1 2 3 4 5 6 7 8]\n"
]
}
],
"source": [
"print(mapped_array.id_arr)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0 1 2 0 1 2 0 1 2]\n"
]
}
],
"source": [
"print(mapped_array.idx_arr)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"1.04 ms ± 7.48 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"False\n",
"7.84 µs ± 31 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n",
"True\n",
"1.58 ms ± 65.5 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"False\n",
"6.99 µs ± 20.4 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
]
}
],
"source": [
"print(mapped_array.is_sorted())\n",
"%timeit big_mapped_array.is_sorted()\n",
"\n",
"print(mapped_array_nosort.is_sorted())\n",
"%timeit big_mapped_array_nosort.is_sorted()\n",
"\n",
"print(mapped_array.is_sorted(incl_id=True))\n",
"%timeit big_mapped_array.is_sorted(incl_id=True)\n",
"\n",
"print(mapped_array_nosort.is_sorted(incl_id=True))\n",
"%timeit big_mapped_array_nosort.is_sorted(incl_id=True)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0 0 0 1 1 1 2 2 2]\n",
"[0 1 2 3 4 5 6 7 8]\n",
"1.41 ms ± 48.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"[0 0 0 1 1 1 2 2 2]\n",
"[2 1 0 5 4 3 8 7 6]\n",
"20.1 ms ± 544 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"[0 0 0 1 1 1 2 2 2]\n",
"[0 1 2 3 4 5 6 7 8]\n",
"1.91 ms ± 3.77 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"[0 0 0 1 1 1 2 2 2]\n",
"[0 1 2 3 4 5 6 7 8]\n",
"16.1 ms ± 1.42 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array.sort().col_arr)\n",
"print(mapped_array.sort().id_arr)\n",
"%timeit big_mapped_array.sort()\n",
"\n",
"print(mapped_array_nosort.sort().col_arr)\n",
"print(mapped_array_nosort.sort().id_arr)\n",
"%timeit big_mapped_array_nosort.sort()\n",
"\n",
"print(mapped_array.sort(incl_id=True).col_arr)\n",
"print(mapped_array.sort(incl_id=True).id_arr)\n",
"%timeit big_mapped_array.sort(incl_id=True)\n",
"\n",
"print(mapped_array_nosort.sort(incl_id=True).col_arr)\n",
"print(mapped_array_nosort.sort(incl_id=True).id_arr)\n",
"%timeit big_mapped_array_nosort.sort(incl_id=True)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[12. 13. 14. 13. 12.]\n",
"18.2 ms ± 487 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"17.9 ms ± 143 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"mask = mapped_array.values >= mapped_array.values.mean()\n",
"print(mapped_array.apply_mask(mask).values)\n",
"\n",
"big_mask = big_mapped_array.values >= big_mapped_array.values.mean()\n",
"%timeit big_mapped_array.apply_mask(big_mask)\n",
"%timeit big_mapped_array_nosort.apply_mask(big_mask)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ True False True True False True True False True]\n",
"1.11 ms ± 3.83 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"1.64 ms ± 43.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"@njit\n",
"def every_2_nb(inout, idxs, col, mapped_arr):\n",
" inout[idxs[::2]] = True\n",
"\n",
"print(mapped_array.map_to_mask(every_2_nb))\n",
"%timeit big_mapped_array.map_to_mask(every_2_nb)\n",
"%timeit big_mapped_array_nosort.map_to_mask(every_2_nb)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[10. 11. 12. 13. 14. 13. 12. 11. 10.]\n",
"[False False True False True False True False False]\n",
"50.8 ms ± 76.3 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"[ True False False True False False False False True]\n",
"51.6 ms ± 358 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"print(mapped_array.values)\n",
"\n",
"print(mapped_array.top_n_mask(1))\n",
"%timeit big_mapped_array.top_n_mask(100)\n",
"\n",
"print(mapped_array.bottom_n_mask(1))\n",
"%timeit big_mapped_array.bottom_n_mask(100)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[12. 14. 12.]\n",
"61.2 ms ± 642 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"[10. 13. 10.]\n",
"59.6 ms ± 362 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"print(mapped_array.top_n(1).values)\n",
"%timeit big_mapped_array.top_n(100)\n",
"\n",
"print(mapped_array.bottom_n(1).values)\n",
"%timeit big_mapped_array.bottom_n(100)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"2.44 ms ± 11.7 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array.is_expandable())\n",
"\n",
"%timeit big_mapped_array.is_expandable()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"x 10.0 13.0 12.0 NaN\n",
"y 11.0 14.0 11.0 NaN\n",
"z 12.0 13.0 10.0 NaN\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"x 10.0 13.0 12.0 0.0\n",
"y 11.0 14.0 11.0 0.0\n",
"z 12.0 13.0 10.0 0.0\n",
"5.41 ms ± 239 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array.to_pd())\n",
"print(mapped_array.to_pd(fill_value=0.))\n",
"\n",
"%timeit big_mapped_array.to_pd()"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 10.0\n",
"1 11.0\n",
"2 12.0\n",
"Name: (0, a), dtype: float64\n",
"8.29 ms ± 1.09 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"0 10.0 13.0 12.0 NaN\n",
"1 11.0 14.0 11.0 NaN\n",
"2 12.0 13.0 10.0 NaN\n",
"3.48 ms ± 202 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 0 1\n",
"0 10.0 13.0\n",
"1 11.0 14.0\n",
"2 12.0 13.0\n",
"3 NaN 12.0\n",
"4 NaN 11.0\n",
"5 NaN 10.0\n",
"lvl1 0 1\n",
"0 10.0 13.0\n",
"1 11.0 14.0\n",
"2 12.0 13.0\n",
"3 0.0 12.0\n",
"4 0.0 11.0\n",
"5 0.0 10.0\n",
"3.34 ms ± 79.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array[(0, 'a')].to_pd(ignore_index=True))\n",
"%timeit big_mapped_array[0].to_pd(ignore_index=True)\n",
"\n",
"print(mapped_array.to_pd(ignore_index=True))\n",
"%timeit big_mapped_array.to_pd(ignore_index=True)\n",
"\n",
"print(mapped_array_grouped.to_pd(ignore_index=True))\n",
"print(mapped_array_grouped.to_pd(ignore_index=True, fill_value=0))\n",
"%timeit big_mapped_array_grouped.to_pd(ignore_index=True)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"11.0\n",
"lvl1 lvl2\n",
"0 a 11.000000\n",
"1 b 13.333333\n",
"Name: reduce, dtype: float64\n",
"lvl1 lvl2\n",
"0 a 11.000000\n",
"1 b 13.333333\n",
" c 11.000000\n",
" d NaN\n",
"Name: reduce, dtype: float64\n",
"lvl1 lvl2\n",
"0 a 11.000000\n",
"1 b 13.333333\n",
" c 11.000000\n",
" d 0.000000\n",
"Name: reduce, dtype: float64\n",
"lvl1 lvl2\n",
"0 a 11.000000\n",
"1 b 13.333333\n",
" c 11.000000\n",
" d 0.000000\n",
"Name: reduce, dtype: float64\n",
"lvl1 lvl2\n",
"0 a 11 days 00:00:00\n",
"1 b 13 days 08:00:00\n",
" c 11 days 00:00:00\n",
" d NaT\n",
"Name: reduce, dtype: timedelta64[ns]\n",
"2.07 ms ± 18.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"2.52 ms ± 38 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"@njit\n",
"def mean_reduce_nb(col, a):\n",
" return np.mean(a)\n",
"\n",
"print(mapped_array[(0, 'a')].reduce(mean_reduce_nb))\n",
"print(mapped_array[[(0, 'a'), (1, 'b')]].reduce(mean_reduce_nb))\n",
"print(mapped_array.reduce(mean_reduce_nb))\n",
"print(mapped_array.reduce(mean_reduce_nb, fill_value=0.))\n",
"print(mapped_array.reduce(mean_reduce_nb, fill_value=0., wrap_kwargs=dict(dtype=np.int64)))\n",
"print(mapped_array.reduce(mean_reduce_nb, wrap_kwargs=dict(to_timedelta=True)))\n",
"\n",
"%timeit big_mapped_array.reduce(mean_reduce_nb)\n",
"%timeit big_mapped_array_nosort.reduce(mean_reduce_nb)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"11.0\n",
"lvl1\n",
"0 11.0\n",
"Name: reduce, dtype: float64\n",
"lvl1\n",
"0 11.000000\n",
"1 12.166667\n",
"Name: reduce, dtype: float64\n",
"lvl1 lvl2\n",
"0 a 11.000000\n",
"1 b 13.333333\n",
" c 11.000000\n",
" d NaN\n",
"Name: reduce, dtype: float64\n",
"2.13 ms ± 141 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array_grouped[0].reduce(mean_reduce_nb))\n",
"print(mapped_array_grouped[[0]].reduce(mean_reduce_nb))\n",
"print(mapped_array_grouped.reduce(mean_reduce_nb))\n",
"print(mapped_array_grouped.reduce(mean_reduce_nb, group_by=False))\n",
"\n",
"%timeit big_mapped_array_grouped.reduce(mean_reduce_nb)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a x\n",
"1 b x\n",
" c z\n",
" d NaN\n",
"Name: reduce, dtype: object\n",
"3.9 ms ± 76.7 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 lvl2\n",
"0 a 0\n",
"1 b 0\n",
" c 2\n",
" d -1\n",
"Name: reduce, dtype: int64\n",
"2.89 ms ± 113 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1\n",
"0 x\n",
"1 z\n",
"Name: reduce, dtype: object\n",
"3.15 ms ± 100 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"@njit\n",
"def argmin_reduce_nb(col, a):\n",
" return np.argmin(a)\n",
"\n",
"print(mapped_array.reduce(argmin_reduce_nb, returns_idx=True))\n",
"%timeit big_mapped_array.reduce(argmin_reduce_nb, returns_idx=True)\n",
"\n",
"print(mapped_array.reduce(argmin_reduce_nb, returns_idx=True, to_index=False))\n",
"%timeit big_mapped_array.reduce(argmin_reduce_nb, returns_idx=True, to_index=False)\n",
"\n",
"print(mapped_array_grouped.reduce(argmin_reduce_nb, returns_idx=True))\n",
"%timeit big_mapped_array_grouped.reduce(argmin_reduce_nb, returns_idx=True)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 10.0\n",
"1 12.0\n",
"Name: (0, a), dtype: float64\n",
"lvl1 0 1\n",
"lvl2 a b\n",
"0 10.0 13.0\n",
"1 12.0 14.0\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"0 10.0 13.0 10.0 NaN\n",
"1 12.0 14.0 12.0 NaN\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"min 10.0 13.0 10.0 NaN\n",
"max 12.0 14.0 12.0 NaN\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"min 10.0 13.0 10.0 0.0\n",
"max 12.0 14.0 12.0 0.0\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"0 10 days 13 days 10 days NaT\n",
"1 12 days 14 days 12 days NaT\n",
"2.45 ms ± 12.1 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"@njit\n",
"def min_max_reduce_nb(col, a):\n",
" return np.array([np.min(a), np.max(a)])\n",
"\n",
"print(mapped_array[(0, 'a')].reduce(min_max_reduce_nb, returns_array=True))\n",
"print(mapped_array[[(0, 'a'), (1, 'b')]].reduce(min_max_reduce_nb, returns_array=True))\n",
"print(mapped_array.reduce(min_max_reduce_nb, returns_array=True))\n",
"print(mapped_array.reduce(min_max_reduce_nb, returns_array=True, wrap_kwargs=dict(name_or_index=['min', 'max'])))\n",
"print(mapped_array.reduce(min_max_reduce_nb, returns_array=True, wrap_kwargs=dict(name_or_index=['min', 'max']), fill_value=0.))\n",
"print(mapped_array.reduce(min_max_reduce_nb, returns_array=True, wrap_kwargs=dict(to_timedelta=True)))\n",
"\n",
"%timeit big_mapped_array.reduce(min_max_reduce_nb, returns_array=True)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 10.0\n",
"1 12.0\n",
"dtype: float64\n",
"lvl1 0\n",
"0 10.0\n",
"1 12.0\n",
"lvl1 0 1\n",
"0 10.0 10.0\n",
"1 12.0 14.0\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"0 10.0 13.0 10.0 NaN\n",
"1 12.0 14.0 12.0 NaN\n",
"2.38 ms ± 3.66 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array_grouped[0].reduce(min_max_reduce_nb, returns_array=True))\n",
"print(mapped_array_grouped[[0]].reduce(min_max_reduce_nb, returns_array=True))\n",
"print(mapped_array_grouped.reduce(min_max_reduce_nb, returns_array=True))\n",
"print(mapped_array_grouped.reduce(min_max_reduce_nb, returns_array=True, group_by=False))\n",
"\n",
"%timeit big_mapped_array_grouped.reduce(min_max_reduce_nb, returns_array=True)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"0 x x z NaN\n",
"1 z y x NaN\n",
"82.4 ms ± 388 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"0 0 0 2 -1\n",
"1 2 1 0 -1\n",
"4.04 ms ± 17.8 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 0 1\n",
"0 x z\n",
"1 z y\n",
"4.45 ms ± 3.78 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"@njit\n",
"def idxmin_idxmax_reduce_nb(col, a):\n",
" return np.array([np.argmin(a), np.argmax(a)])\n",
"\n",
"print(mapped_array.reduce(idxmin_idxmax_reduce_nb, returns_array=True, returns_idx=True))\n",
"%timeit big_mapped_array.reduce(idxmin_idxmax_reduce_nb, returns_array=True, returns_idx=True)\n",
"\n",
"print(mapped_array.reduce(idxmin_idxmax_reduce_nb, returns_array=True, returns_idx=True, to_index=False))\n",
"%timeit big_mapped_array.reduce(idxmin_idxmax_reduce_nb, returns_array=True, returns_idx=True, to_index=False)\n",
"\n",
"print(mapped_array_grouped.reduce(idxmin_idxmax_reduce_nb, returns_array=True, returns_idx=True))\n",
"%timeit big_mapped_array_grouped.reduce(idxmin_idxmax_reduce_nb, returns_array=True, returns_idx=True)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a 10.0\n",
"1 b 13.0\n",
" c 12.0\n",
" d NaN\n",
"Name: nth, dtype: float64\n",
"lvl1 lvl2\n",
"0 a 12.0\n",
"1 b 13.0\n",
" c 10.0\n",
" d NaN\n",
"Name: nth, dtype: float64\n",
"1.03 ms ± 1.44 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"lvl1\n",
"0 10.0\n",
"1 13.0\n",
"Name: nth, dtype: float64\n",
"1.11 ms ± 3.55 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(mapped_array.nth(0))\n",
"print(mapped_array.nth(-1))\n",
"%timeit big_mapped_array.nth(0)\n",
"\n",
"print(mapped_array_grouped.nth(0))\n",
"%timeit big_mapped_array_grouped.nth(0)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a 10.0\n",
"1 b 13.0\n",
" c 10.0\n",
" d NaN\n",
"Name: min, dtype: float64\n",
"10.1 ms ± 458 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 lvl2\n",
"0 a 10.0\n",
"1 b 13.0\n",
" c 10.0\n",
" d NaN\n",
"Name: min, dtype: float64\n",
"2.98 ms ± 4.29 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1\n",
"0 10.0\n",
"1 10.0\n",
"Name: min, dtype: float64\n",
"3.02 ms ± 5.68 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array.to_pd().vbt.min())\n",
"%timeit big_mapped_array.to_pd().vbt.min()\n",
"\n",
"print(mapped_array.min())\n",
"%timeit big_mapped_array.min()\n",
"\n",
"print(mapped_array_grouped.min())\n",
"%timeit big_mapped_array_grouped.min()"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a 12.0\n",
"1 b 14.0\n",
" c 12.0\n",
" d NaN\n",
"Name: max, dtype: float64\n",
"9.97 ms ± 92 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 lvl2\n",
"0 a 12.0\n",
"1 b 14.0\n",
" c 12.0\n",
" d NaN\n",
"Name: max, dtype: float64\n",
"2.98 ms ± 6.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1\n",
"0 12.0\n",
"1 14.0\n",
"Name: max, dtype: float64\n",
"3.03 ms ± 3.58 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array.to_pd().vbt.max())\n",
"%timeit big_mapped_array.to_pd().vbt.max()\n",
"\n",
"print(mapped_array.max())\n",
"%timeit big_mapped_array.max()\n",
"\n",
"print(mapped_array_grouped.max())\n",
"%timeit big_mapped_array_grouped.max()"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a 11.000000\n",
"1 b 13.333333\n",
" c 11.000000\n",
" d NaN\n",
"Name: mean, dtype: float64\n",
"8.4 ms ± 336 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 lvl2\n",
"0 a 11.000000\n",
"1 b 13.333333\n",
" c 11.000000\n",
" d NaN\n",
"Name: mean, dtype: float64\n",
"3.27 ms ± 10.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1\n",
"0 11.000000\n",
"1 12.166667\n",
"Name: mean, dtype: float64\n",
"3.32 ms ± 5.36 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array.to_pd().vbt.mean())\n",
"%timeit big_mapped_array.to_pd().vbt.mean()\n",
"\n",
"print(mapped_array.mean())\n",
"%timeit big_mapped_array.mean()\n",
"\n",
"print(mapped_array_grouped.mean())\n",
"%timeit big_mapped_array_grouped.mean()"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a 11.0\n",
"1 b 13.0\n",
" c 11.0\n",
" d NaN\n",
"Name: median, dtype: float64\n",
"16.9 ms ± 151 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 lvl2\n",
"0 a 11.0\n",
"1 b 13.0\n",
" c 11.0\n",
" d NaN\n",
"Name: median, dtype: float64\n",
"12.5 ms ± 7.77 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1\n",
"0 11.0\n",
"1 12.5\n",
"Name: median, dtype: float64\n",
"11.7 ms ± 13.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array.to_pd().vbt.median())\n",
"%timeit big_mapped_array.to_pd().vbt.median()\n",
"\n",
"print(mapped_array.median())\n",
"%timeit big_mapped_array.median()\n",
"\n",
"print(mapped_array_grouped.median())\n",
"%timeit big_mapped_array_grouped.median()"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a 1.00000\n",
"1 b 0.57735\n",
" c 1.00000\n",
" d NaN\n",
"Name: std, dtype: float64\n",
"lvl1 lvl2\n",
"0 a 0.816497\n",
"1 b 0.471405\n",
" c 0.816497\n",
" d NaN\n",
"Name: std, dtype: float64\n",
"8.7 ms ± 23.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 lvl2\n",
"0 a 1.00000\n",
"1 b 0.57735\n",
" c 1.00000\n",
" d NaN\n",
"Name: std, dtype: float64\n",
"lvl1 lvl2\n",
"0 a 0.816497\n",
"1 b 0.471405\n",
" c 0.816497\n",
" d NaN\n",
"Name: std, dtype: float64\n",
"6.59 ms ± 134 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1\n",
"0 1.00000\n",
"1 1.47196\n",
"Name: std, dtype: float64\n",
"6.24 ms ± 3.6 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array.to_pd().vbt.std())\n",
"print(mapped_array.to_pd().vbt.std(ddof=0))\n",
"%timeit big_mapped_array.to_pd().vbt.std()\n",
"\n",
"print(mapped_array.std())\n",
"print(mapped_array.std(ddof=0))\n",
"%timeit big_mapped_array.std()\n",
"\n",
"print(mapped_array_grouped.std())\n",
"%timeit big_mapped_array_grouped.std()"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a 33.0\n",
"1 b 40.0\n",
" c 33.0\n",
" d 0.0\n",
"Name: sum, dtype: float64\n",
"8.63 ms ± 36.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 lvl2\n",
"0 a 33.0\n",
"1 b 40.0\n",
" c 33.0\n",
" d 0.0\n",
"Name: sum, dtype: float64\n",
"3.26 ms ± 6.28 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1\n",
"0 33.0\n",
"1 73.0\n",
"Name: sum, dtype: float64\n",
"3.31 ms ± 3.33 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array.to_pd().vbt.sum())\n",
"%timeit big_mapped_array.to_pd().vbt.sum()\n",
"\n",
"print(mapped_array.sum())\n",
"%timeit big_mapped_array.sum()\n",
"\n",
"print(mapped_array_grouped.sum())\n",
"%timeit big_mapped_array_grouped.sum()"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a x\n",
"1 b x\n",
" c z\n",
" d NaN\n",
"Name: idxmin, dtype: object\n",
"9.22 ms ± 130 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 lvl2\n",
"0 a x\n",
"1 b x\n",
" c z\n",
" d NaN\n",
"Name: idxmin, dtype: object\n",
"4.86 ms ± 28.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1\n",
"0 x\n",
"1 z\n",
"Name: idxmin, dtype: object\n",
"4.21 ms ± 7.54 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array.to_pd().vbt.idxmin())\n",
"%timeit big_mapped_array.to_pd().vbt.idxmin()\n",
"\n",
"print(mapped_array.idxmin())\n",
"%timeit big_mapped_array.idxmin()\n",
"\n",
"print(mapped_array_grouped.idxmin())\n",
"%timeit big_mapped_array_grouped.idxmin()"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a z\n",
"1 b y\n",
" c x\n",
" d NaN\n",
"Name: idxmax, dtype: object\n",
"9.4 ms ± 395 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 lvl2\n",
"0 a z\n",
"1 b y\n",
" c x\n",
" d NaN\n",
"Name: idxmax, dtype: object\n",
"4.88 ms ± 41.7 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1\n",
"0 z\n",
"1 y\n",
"Name: idxmax, dtype: object\n",
"4.22 ms ± 7.03 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array.to_pd().vbt.idxmax())\n",
"%timeit big_mapped_array.to_pd().vbt.idxmax()\n",
"\n",
"print(mapped_array.idxmax())\n",
"%timeit big_mapped_array.idxmax()\n",
"\n",
"print(mapped_array_grouped.idxmax())\n",
"%timeit big_mapped_array_grouped.idxmax()"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"count 3.0 3.000000 3.0 0.0\n",
"mean 11.0 13.333333 11.0 NaN\n",
"std 1.0 0.577350 1.0 NaN\n",
"min 10.0 13.000000 10.0 NaN\n",
"25% 10.5 13.000000 10.5 NaN\n",
"50% 11.0 13.000000 11.0 NaN\n",
"75% 11.5 13.500000 11.5 NaN\n",
"max 12.0 14.000000 12.0 NaN\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"count 3.0 3.000000 3.0 0.0\n",
"mean 11.0 13.333333 11.0 NaN\n",
"std 1.0 0.577350 1.0 NaN\n",
"min 10.0 13.000000 10.0 NaN\n",
"30% 10.6 13.000000 10.6 NaN\n",
"50% 11.0 13.000000 11.0 NaN\n",
"70% 11.4 13.400000 11.4 NaN\n",
"max 12.0 14.000000 12.0 NaN\n",
"41.4 ms ± 24.4 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"count 3.0 3.000000 3.0 0.0\n",
"mean 11.0 13.333333 11.0 NaN\n",
"std 1.0 0.577350 1.0 NaN\n",
"min 10.0 13.000000 10.0 NaN\n",
"25% 10.5 13.000000 10.5 NaN\n",
"50% 11.0 13.000000 11.0 NaN\n",
"75% 11.5 13.500000 11.5 NaN\n",
"max 12.0 14.000000 12.0 NaN\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"count 3.0 3.000000 3.0 0.0\n",
"mean 11.0 13.333333 11.0 NaN\n",
"std 1.0 0.577350 1.0 NaN\n",
"min 10.0 13.000000 10.0 NaN\n",
"30% 10.6 13.000000 10.6 NaN\n",
"50% 11.0 13.000000 11.0 NaN\n",
"70% 11.4 13.400000 11.4 NaN\n",
"max 12.0 14.000000 12.0 NaN\n",
"35.6 ms ± 432 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"lvl1 0 1\n",
"count 3.0 6.000000\n",
"mean 11.0 12.166667\n",
"std 1.0 1.471960\n",
"min 10.0 10.000000\n",
"25% 10.5 11.250000\n",
"50% 11.0 12.500000\n",
"75% 11.5 13.000000\n",
"max 12.0 14.000000\n",
"37.9 ms ± 123 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"print(mapped_array.to_pd().vbt.describe())\n",
"print(mapped_array.to_pd().vbt.describe(percentiles=[0.3, 0.7]))\n",
"%timeit big_mapped_array.to_pd().vbt.describe()\n",
"\n",
"print(mapped_array.describe())\n",
"print(mapped_array.describe(percentiles=[0.3, 0.7]))\n",
"%timeit big_mapped_array.describe()\n",
"\n",
"print(mapped_array_grouped.describe())\n",
"%timeit big_mapped_array_grouped.describe()"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a 3\n",
"1 b 3\n",
" c 3\n",
" d 0\n",
"Name: count, dtype: int64\n",
"7.45 ms ± 215 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 lvl2\n",
"0 a 3\n",
"1 b 3\n",
" c 3\n",
" d 0\n",
"Name: count, dtype: int64\n",
"49.6 µs ± 200 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n",
"lvl1\n",
"0 3\n",
"1 6\n",
"Name: count, dtype: int64\n",
"48.3 µs ± 83.7 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
]
}
],
"source": [
"print(mapped_array.to_pd().vbt.count())\n",
"%timeit big_mapped_array.to_pd().vbt.count()\n",
"\n",
"print(mapped_array.count())\n",
"%timeit big_mapped_array.count()\n",
"\n",
"print(mapped_array_grouped.count())\n",
"%timeit big_mapped_array_grouped.count()"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
"mapping = {x: str(x) for x in np.unique(mapped_array.values)}\n",
"big_mapping = {x: str(x) for x in np.unique(big_mapped_array.values)}"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10.0 1\n",
"11.0 1\n",
"12.0 1\n",
"Name: (0, a), dtype: int64\n",
"13.4 ms ± 584 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"10.0 1\n",
"11.0 1\n",
"12.0 1\n",
"Name: (0, a), dtype: int64\n",
"12.9 ms ± 353 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"10.0 1 0 1 0\n",
"11.0 1 0 1 0\n",
"12.0 1 0 1 0\n",
"13.0 0 2 0 0\n",
"14.0 0 1 0 0\n",
"10.9 ms ± 23.5 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 0 1 \n",
"lvl2 a b c d\n",
"10.0 1 0 1 0\n",
"11.0 1 0 1 0\n",
"12.0 1 0 1 0\n",
"13.0 0 2 0 0\n",
"14.0 0 1 0 0\n",
"11.2 ms ± 121 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"lvl1 0 1\n",
"10.0 1 1\n",
"11.0 1 1\n",
"12.0 1 1\n",
"13.0 0 2\n",
"14.0 0 1\n",
"10.9 ms ± 451 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(mapped_array[(0, 'a')].value_counts())\n",
"%timeit big_mapped_array[0].value_counts()\n",
"\n",
"print(mapped_array[(0, 'a')].value_counts(mapping=mapping))\n",
"%timeit big_mapped_array[0].value_counts(mapping=big_mapping)\n",
"\n",
"print(mapped_array.value_counts())\n",
"%timeit big_mapped_array.value_counts()\n",
"\n",
"print(mapped_array.value_counts(mapping=mapping))\n",
"%timeit big_mapped_array.value_counts(mapping=big_mapping)\n",
"\n",
"print(mapped_array_grouped.value_counts())\n",
"%timeit big_mapped_array_grouped.value_counts()"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Start x\n",
"End z\n",
"Period 3 days 00:00:00\n",
"Count 3\n",
"Mean 11.0\n",
"Std 1.0\n",
"Min 10.0\n",
"Median 11.0\n",
"Max 12.0\n",
"Min Index x\n",
"Max Index z\n",
"Name: (0, a), dtype: object\n",
"29 ms ± 287 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"Start x\n",
"End z\n",
"Period 3 days 00:00:00\n",
"Count 3\n",
"Mean 11.0\n",
"Std 1.0\n",
"Min 10.0\n",
"Median 11.0\n",
"Max 12.0\n",
"Min Index x\n",
"Max Index z\n",
"Name: (0, a), dtype: object\n",
"46 ms ± 1.01 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"Start x\n",
"End z\n",
"Period 3 days 00:00:00\n",
"Count 2.25\n",
"Mean 11.777778\n",
"Std 0.859117\n",
"Min 11.0\n",
"Median 11.666667\n",
"Max 12.666667\n",
"Name: agg_func_mean, dtype: object\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/miniconda3/lib/python3.7/site-packages/ipykernel_launcher.py:7: UserWarning: Metric 'idx_min' returned multiple values despite having no aggregation function\n",
" import sys\n",
"/Users/olegpolakow/miniconda3/lib/python3.7/site-packages/ipykernel_launcher.py:7: UserWarning: Metric 'idx_max' returned multiple values despite having no aggregation function\n",
" import sys\n",
"/Users/olegpolakow/miniconda3/lib/python3.7/site-packages/ipykernel_launcher.py:7: UserWarning: Object has multiple columns. Aggregating using <function mean at 0x7feb1013b598>. Pass column to select a single column/group.\n",
" import sys\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"44.3 ms ± 343 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"Start x\n",
"End z\n",
"Period 3 days 00:00:00\n",
"Count 2.25\n",
"Value Counts: 10.0 0.5\n",
"Value Counts: 11.0 0.5\n",
"Value Counts: 12.0 0.5\n",
"Value Counts: 13.0 0.5\n",
"Value Counts: 14.0 0.25\n",
"Name: agg_func_mean, dtype: object\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/miniconda3/lib/python3.7/site-packages/ipykernel_launcher.py:10: UserWarning: Object has multiple columns. Aggregating using <function mean at 0x7feb1013b598>. Pass column to select a single column/group.\n",
" # Remove the CWD from sys.path while we load stuff.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"23.1 ms ± 475 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"print(mapped_array[(0, 'a')].stats())\n",
"%timeit big_mapped_array[0].stats(silence_warnings=True)\n",
"\n",
"print(mapped_array.stats(column=(0, 'a')))\n",
"%timeit big_mapped_array.stats(column=0, silence_warnings=True)\n",
"\n",
"print(mapped_array.stats())\n",
"%timeit big_mapped_array.stats(silence_warnings=True)\n",
"\n",
"print(mapped_array.copy(mapping=mapping).stats())\n",
"%timeit big_mapped_array.copy(mapping=big_mapping).stats(silence_warnings=True)"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-c70295\"><g class=\"clips\"><clipPath id=\"clipc70295xyplot\" class=\"plotclip\"><rect width=\"637\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clipc70295x\"><rect x=\"33\" y=\"0\" width=\"637\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clipc70295y\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clipc70295xy\"><rect x=\"33\" y=\"46\" width=\"637\" height=\"274\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"33\" y=\"46\" width=\"637\" height=\"274\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"/><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,254.93)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,189.85)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,124.77)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,59.7)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"><path class=\"yzl zl crisp\" transform=\"translate(0,320)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 2px;\"/></g><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(33,46)\" clip-path=\"url(#clipc70295xyplot)\"><g class=\"barlayer mlayer\"><g class=\"trace bars\" shape-rendering=\"crispEdges\" style=\"opacity: 1;\"><g class=\"points\"><g class=\"point\"><path d=\"M0,274V13.7H318.5V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/></g><g class=\"point\"><path d=\"M318.5,274V143.85H637V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/></g></g></g></g></g><g class=\"overplot\"/><path class=\"xlines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><path class=\"ylines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><g class=\"overlines-above\"/><g class=\"xaxislayer-above\"><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"333\" transform=\"translate(33,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\">9.5</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"333\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(112.63,0)\">10</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"333\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(192.25,0)\">10.5</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"333\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(271.88,0)\">11</
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-6addc6\"><g class=\"clips\"><clipPath id=\"clip6addc6xyplot\" class=\"plotclip\"><rect width=\"637\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clip6addc6x\"><rect x=\"33\" y=\"0\" width=\"637\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clip6addc6y\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clip6addc6xy\"><rect x=\"33\" y=\"46\" width=\"637\" height=\"274\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"33\" y=\"46\" width=\"637\" height=\"274\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"/><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,254.93)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,189.85)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,124.77)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,59.7)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"><path class=\"yzl zl crisp\" transform=\"translate(0,320)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 2px;\"/></g><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(33,46)\" clip-path=\"url(#clip6addc6xyplot)\"><g class=\"barlayer mlayer\"><g class=\"trace bars\" shape-rendering=\"crispEdges\" style=\"opacity: 0.75;\"><g class=\"points\"><g class=\"point\"><path d=\"M0,274V13.7H254.8V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/></g><g class=\"point\"><path d=\"M254.8,274V143.85H509.6V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/></g></g></g><g class=\"trace bars\" shape-rendering=\"crispEdges\" style=\"opacity: 0.75;\"><g class=\"points\"><g class=\"point\"><path d=\"M382.2,274V13.7H509.6V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(255, 127, 14); fill-opacity: 1;\"/></g><g class=\"point\"><path d=\"M509.6,274V143.85H637V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(255, 127, 14); fill-opacity: 1;\"/></g></g></g><g class=\"trace bars\" shape-rendering=\"crispEdges\" style=\"opacity: 0.75;\"><g class=\"points\"><g class=\"point\"><path d=\"M0,274V13.7H254.8V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(44, 160, 44); fill-opacity: 1;\"/></g><g class=\"point\"><path d=\"M254.8,274V143.85H509.6V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(44, 160, 44); fill-opacity: 1;\"/></g></g></g></g></g><g class=\"overplot\"/><path class=\"xlines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><path class=\"ylines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><g class=\"overlines-above\"/><g class=\"xaxislayer-above\"><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"333\" transform=\"translate(96.7,0)\" style=\
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-61099c\"><g class=\"clips\"><clipPath id=\"clip61099cxyplot\" class=\"plotclip\"><rect width=\"637\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clip61099cx\"><rect x=\"33\" y=\"0\" width=\"637\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clip61099cy\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clip61099cxy\"><rect x=\"33\" y=\"46\" width=\"637\" height=\"274\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"33\" y=\"46\" width=\"637\" height=\"274\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"/><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,276.62)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,233.23)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,189.85)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,146.47)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,103.08)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,59.7)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"><path class=\"yzl zl crisp\" transform=\"translate(0,320)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 2px;\"/></g><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(33,46)\" clip-path=\"url(#clip61099cxyplot)\"><g class=\"barlayer mlayer\"><g class=\"trace bars\" shape-rendering=\"crispEdges\" style=\"opacity: 0.75;\"><g class=\"points\"><g class=\"point\"><path d=\"M0,274V100.47H212.33V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/></g><g class=\"point\"><path d=\"M212.33,274V187.23H424.67V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/></g></g></g><g class=\"trace bars\" shape-rendering=\"crispEdges\" style=\"opacity: 0.75;\"><g class=\"points\"><g class=\"point\"><path d=\"M0,274V100.47H212.33V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(255, 127, 14); fill-opacity: 1;\"/></g><g class=\"point\"><path d=\"M212.33,274V13.7H424.67V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(255, 127, 14); fill-opacity: 1;\"/></g><g class=\"point\"><path d=\"M424.67,274V187.23H637V274Z\" style=\"vector-effect: non-scaling-stroke; opacity: 1; stroke-width: 0px; fill: rgb(255, 127, 14); fill-opacity: 1;\"/></g></g></g></g></g><g class=\"overplot\"/><path class=\"xlines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><path class=\"ylines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><g class=\"overlines-above\"/><g class=\"xaxislayer-above\"><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"333\" transfo
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"mapped_array[(0, 'a')].histplot().show_svg()\n",
"mapped_array.histplot().show_svg()\n",
"mapped_array_grouped.histplot().show_svg()"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-2d103d\"><g class=\"clips\"><clipPath id=\"clip2d103dxyplot\" class=\"plotclip\"><rect width=\"630\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2d103dx\"><rect x=\"40\" y=\"0\" width=\"630\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2d103dy\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2d103dxy\"><rect x=\"40\" y=\"46\" width=\"630\" height=\"274\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"40\" y=\"46\" width=\"630\" height=\"274\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"/><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,306.3)\" d=\"M40,0h630\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,244.65)\" d=\"M40,0h630\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,183)\" d=\"M40,0h630\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,121.35)\" d=\"M40,0h630\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,59.7)\" d=\"M40,0h630\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"/><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(40,46)\" clip-path=\"url(#clip2d103dxyplot)\"><g class=\"boxlayer mlayer\"><g class=\"trace boxes\" style=\"opacity: 1;\"><path class=\"box\" d=\"M160.65,137H469.35M160.65,229.47H469.35V44.52H160.65ZM315,229.47V260.3M315,44.52V13.7M237.83,260.3H392.17M237.83,13.7H392.17\" style=\"vector-effect: non-scaling-stroke; stroke-width: 2px; stroke: rgb(31, 119, 180); stroke-opacity: 1; fill: rgb(31, 119, 180); fill-opacity: 0.5;\"/><g class=\"points\"/></g></g></g><g class=\"overplot\"/><path class=\"xlines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><path class=\"ylines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><g class=\"overlines-above\"/><g class=\"xaxislayer-above\"><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"333\" transform=\"translate(355,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\">(0, 'a')</text></g></g><g class=\"yaxislayer-above\"><g class=\"ytick\"><text text-anchor=\"end\" x=\"39\" y=\"4.199999999999999\" transform=\"translate(0,306.3)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\">10</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"39\" y=\"4.199999999999999\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(0,244.65)\">10.5</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"39\" y=\"4.199999999999999\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(0,183)\">11</text></g><g class=
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-7cd63b\"><g class=\"clips\"><clipPath id=\"clip7cd63bxyplot\" class=\"plotclip\"><rect width=\"640\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clip7cd63bx\"><rect x=\"30\" y=\"0\" width=\"640\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clip7cd63by\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clip7cd63bxy\"><rect x=\"30\" y=\"46\" width=\"640\" height=\"274\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"30\" y=\"46\" width=\"640\" height=\"274\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"/><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,306.3)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,244.65)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,183)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,121.35)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,59.7)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"/><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(30,46)\" clip-path=\"url(#clip7cd63bxyplot)\"><g class=\"boxlayer mlayer\"><g class=\"trace boxes\" style=\"opacity: 1;\"><path class=\"box\" d=\"M54.4,198.65H158.93M54.4,244.89H158.93V152.41H54.4ZM106.67,244.89V260.3M106.67,152.41V137M80.53,260.3H132.8M80.53,137H132.8\" style=\"vector-effect: non-scaling-stroke; stroke-width: 2px; stroke: rgb(31, 119, 180); stroke-opacity: 1; fill: rgb(31, 119, 180); fill-opacity: 0.5;\"/><g class=\"points\"/></g><g class=\"trace boxes\" style=\"opacity: 1;\"><path class=\"box\" d=\"M267.73,74.35H372.27M267.73,75.35H372.27V29.11H267.73ZM320,75.35V75.35M320,29.11V13.7M293.87,75.35H346.13M293.87,13.7H346.13\" style=\"vector-effect: non-scaling-stroke; stroke-width: 2px; stroke: rgb(255, 127, 14); stroke-opacity: 1; fill: rgb(255, 127, 14); fill-opacity: 0.5;\"/><g class=\"points\"/></g><g class=\"trace boxes\" style=\"opacity: 1;\"><path class=\"box\" d=\"M481.07,198.65H585.6M481.07,244.89H585.6V152.41H481.07ZM533.33,244.89V260.3M533.33,152.41V137M507.2,260.3H559.47M507.2,137H559.47\" style=\"vector-effect: non-scaling-stroke; stroke-width: 2px; stroke: rgb(44, 160, 44); stroke-opacity: 1; fill: rgb(44, 160, 44); fill-opacity: 0.5;\"/><g class=\"points\"/></g></g></g><g class=\"overplot\"/><path class=\"xlines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><path class=\"ylines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><g class=\"overlines-above\"/><g class=\"xaxislayer-above\"><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"333\" transform=\"translate(136.67000000000002,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\">(0, 'a')</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"333\" transform=\"translate(350,0)\"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-bff574\"><g class=\"clips\"><clipPath id=\"clipbff574xyplot\" class=\"plotclip\"><rect width=\"640\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clipbff574x\"><rect x=\"30\" y=\"0\" width=\"640\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clipbff574y\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"274\"/></clipPath><clipPath class=\"axesclip\" id=\"clipbff574xy\"><rect x=\"30\" y=\"46\" width=\"640\" height=\"274\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"30\" y=\"46\" width=\"640\" height=\"274\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"/><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,306.3)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,244.65)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,183)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,121.35)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,59.7)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"/><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(30,46)\" clip-path=\"url(#clipbff574xyplot)\"><g class=\"boxlayer mlayer\"><g class=\"trace boxes\" style=\"opacity: 1;\"><path class=\"box\" d=\"M81.6,198.65H238.4M81.6,244.89H238.4V152.41H81.6ZM160,244.89V260.3M160,152.41V137M120.8,260.3H199.2M120.8,137H199.2\" style=\"vector-effect: non-scaling-stroke; stroke-width: 2px; stroke: rgb(31, 119, 180); stroke-opacity: 1; fill: rgb(31, 119, 180); fill-opacity: 0.5;\"/><g class=\"points\"/></g><g class=\"trace boxes\" style=\"opacity: 1;\"><path class=\"box\" d=\"M401.6,106.17H558.4M401.6,198.65H558.4V75.35H401.6ZM480,198.65V260.3M480,75.35V13.7M440.8,260.3H519.2M440.8,13.7H519.2\" style=\"vector-effect: non-scaling-stroke; stroke-width: 2px; stroke: rgb(255, 127, 14); stroke-opacity: 1; fill: rgb(255, 127, 14); fill-opacity: 0.5;\"/><g class=\"points\"/></g></g></g><g class=\"overplot\"/><path class=\"xlines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><path class=\"ylines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><g class=\"overlines-above\"/><g class=\"xaxislayer-above\"><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"333\" transform=\"translate(190,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\">0</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"333\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-opacity: 1; white-space: pre; opacity: 1;\" transform=\"translate(510,0)\">1</text></g></g><g class=\"yaxislayer-above\"><g class=\"ytick\"><text text-anchor=\"end\" x=\"29\" y=\"4.199999999999999\" transform=\"translate(0,306.3)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(42, 63, 95); fill-o
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"mapped_array[(0, 'a')].boxplot().show_svg()\n",
"mapped_array.boxplot().show_svg()\n",
"mapped_array_grouped.boxplot().show_svg()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"750\" height=\"380\" style=\"\" viewBox=\"0 0 750 380\"><rect x=\"0\" y=\"0\" width=\"750\" height=\"380\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-f7d873\"><g class=\"clips\"><clipPath id=\"clipf7d873xyplot\" class=\"plotclip\"><rect width=\"680\" height=\"260\"/></clipPath><clipPath class=\"axesclip\" id=\"clipf7d873x\"><rect x=\"40\" y=\"0\" width=\"680\" height=\"380\"/></clipPath><clipPath class=\"axesclip\" id=\"clipf7d873y\"><rect x=\"0\" y=\"68\" width=\"750\" height=\"260\"/></clipPath><clipPath class=\"axesclip\" id=\"clipf7d873xy\"><rect x=\"40\" y=\"68\" width=\"680\" height=\"260\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"40\" y=\"68\" width=\"680\" height=\"260\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(77.75,0)\" d=\"M0,68v260\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(380,0)\" d=\"M0,68v260\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(682.25,0)\" d=\"M0,68v260\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,311.25)\" d=\"M40,0h680\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,254.63)\" d=\"M40,0h680\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,198)\" d=\"M40,0h680\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,141.38)\" d=\"M40,0h680\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,84.75)\" d=\"M40,0h680\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"/><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(40,68)\" clip-path=\"url(#clipf7d873xyplot)\"><g class=\"scatterlayer mlayer\"><g class=\"trace scatter tracefdacad43-8d85-4678-b212-b17c94fa4875\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"><path class=\"js-line\" d=\"M37.75,243.25L642.25,16.75\" style=\"vector-effect: non-scaling-stroke; fill: none; stroke: rgb(31, 119, 180); stroke-opacity: 1; stroke-width: 2px; opacity: 1;\"/></g><g class=\"points\"><path class=\"point\" transform=\"translate(37.75,243.25)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(340,130)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(642.25,16.75)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/></g><g class=\"text\"/></g></g></g><g class=\"overplot\"/><path class=\"xlines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><path class=\"ylines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><g class=\"overlines-above\"/><g class=\"xaxislayer-above\"><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"341\" transform
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"750\" height=\"380\" style=\"\" viewBox=\"0 0 750 380\"><rect x=\"0\" y=\"0\" width=\"750\" height=\"380\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-a82e1d\"><g class=\"clips\"><clipPath id=\"clipa82e1dxyplot\" class=\"plotclip\"><rect width=\"690\" height=\"260\"/></clipPath><clipPath class=\"axesclip\" id=\"clipa82e1dx\"><rect x=\"30\" y=\"0\" width=\"690\" height=\"380\"/></clipPath><clipPath class=\"axesclip\" id=\"clipa82e1dy\"><rect x=\"0\" y=\"68\" width=\"750\" height=\"260\"/></clipPath><clipPath class=\"axesclip\" id=\"clipa82e1dxy\"><rect x=\"30\" y=\"68\" width=\"690\" height=\"260\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"30\" y=\"68\" width=\"690\" height=\"260\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(68.25,0)\" d=\"M0,68v260\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(375,0)\" d=\"M0,68v260\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(681.75,0)\" d=\"M0,68v260\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,311.25)\" d=\"M30,0h690\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,254.63)\" d=\"M30,0h690\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,198)\" d=\"M30,0h690\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,141.37)\" d=\"M30,0h690\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,84.75)\" d=\"M30,0h690\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"/><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(30,68)\" clip-path=\"url(#clipa82e1dxyplot)\"><g class=\"scatterlayer mlayer\"><g class=\"trace scatter traceb037390a-7b3e-4e76-8666-79cdfea531ae\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"><path class=\"js-line\" d=\"M38.25,243.25L651.75,130\" style=\"vector-effect: non-scaling-stroke; fill: none; stroke: rgb(31, 119, 180); stroke-opacity: 1; stroke-width: 2px; opacity: 1;\"/></g><g class=\"points\"><path class=\"point\" transform=\"translate(38.25,243.25)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(345,186.63)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(651.75,130)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/></g><g class=\"text\"/></g><g class=\"trace scatter trace0131fe6f-7c6c-4715-b573-e77b83a0326c\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"><path class=\"js-line\" d=\"M38.25,73.37L345,16.75L651.75,73.37\" style=\"vector-effect: non-scaling-stroke; fill: none; stroke:
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"mapped_array[(0, 'a')].plots().show_svg()\n",
"mapped_array.plots().show_svg()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Records"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[(0, 0, 0, 10., 21.) (1, 1, 0, 11., 20.) (2, 2, 0, 12., 19.)]\n",
"MultiIndex([(0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"[(3, 0, 0, 13., 18.) (4, 1, 0, 14., 17.) (5, 2, 0, 13., 18.)]\n",
"MultiIndex([(1, 'b')],\n",
" names=['lvl1', 'lvl2'])\n",
"[(0, 0, 0, 10., 21.) (1, 1, 0, 11., 20.) (2, 2, 0, 12., 19.)\n",
" (0, 0, 1, 10., 21.) (1, 1, 1, 11., 20.) (2, 2, 1, 12., 19.)]\n",
"MultiIndex([(0, 'a'),\n",
" (0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"[(0, 0, 0, 10., 21.) (1, 1, 0, 11., 20.) (2, 2, 0, 12., 19.)\n",
" (3, 0, 1, 13., 18.) (4, 1, 1, 14., 17.) (5, 2, 1, 13., 18.)]\n",
"MultiIndex([(0, 'a'),\n",
" (1, 'b')],\n",
" names=['lvl1', 'lvl2'])\n",
"810 µs ± 9.11 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"13.7 ms ± 259 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(records[(0, 'a')].values)\n",
"print(records[(0, 'a')].wrapper.columns)\n",
"\n",
"print(records[(1, 'b')].values)\n",
"print(records[(1, 'b')].wrapper.columns)\n",
"\n",
"print(records[[(0, 'a'), (0, 'a')]].values)\n",
"print(records[[(0, 'a'), (0, 'a')]].wrapper.columns)\n",
"\n",
"print(records[[(0, 'a'), (1, 'b')]].values)\n",
"print(records[[(0, 'a'), (1, 'b')]].wrapper.columns)\n",
"\n",
"%timeit big_records.iloc[0]\n",
"%timeit big_records.iloc[:]"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[(2, 2, 0, 12., 19.) (1, 1, 0, 11., 20.) (0, 0, 0, 10., 21.)]\n",
"MultiIndex([(0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"[(5, 2, 0, 13., 18.) (4, 1, 0, 14., 17.) (3, 0, 0, 13., 18.)]\n",
"MultiIndex([(1, 'b')],\n",
" names=['lvl1', 'lvl2'])\n",
"[(2, 2, 0, 12., 19.) (1, 1, 0, 11., 20.) (0, 0, 0, 10., 21.)\n",
" (2, 2, 1, 12., 19.) (1, 1, 1, 11., 20.) (0, 0, 1, 10., 21.)]\n",
"MultiIndex([(0, 'a'),\n",
" (0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"[(2, 2, 0, 12., 19.) (1, 1, 0, 11., 20.) (0, 0, 0, 10., 21.)\n",
" (5, 2, 1, 13., 18.) (4, 1, 1, 14., 17.) (3, 0, 1, 13., 18.)]\n",
"MultiIndex([(0, 'a'),\n",
" (1, 'b')],\n",
" names=['lvl1', 'lvl2'])\n",
"842 µs ± 5.42 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"15.9 ms ± 678 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(records_nosort[(0, 'a')].values)\n",
"print(records_nosort[(0, 'a')].wrapper.columns)\n",
"\n",
"print(records_nosort[(1, 'b')].values)\n",
"print(records_nosort[(1, 'b')].wrapper.columns)\n",
"\n",
"print(records_nosort[[(0, 'a'), (0, 'a')]].values)\n",
"print(records_nosort[[(0, 'a'), (0, 'a')]].wrapper.columns)\n",
"\n",
"print(records_nosort[[(0, 'a'), (1, 'b')]].values)\n",
"print(records_nosort[[(0, 'a'), (1, 'b')]].wrapper.columns)\n",
"\n",
"%timeit big_records_nosort.iloc[0]\n",
"%timeit big_records_nosort.iloc[:]"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MultiIndex([(0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"1\n",
"1\n",
"Index([0], dtype='int64', name='lvl1')\n",
"MultiIndex([(1, 'b'),\n",
" (1, 'c'),\n",
" (1, 'd')],\n",
" names=['lvl1', 'lvl2'])\n",
"2\n",
"1\n",
"Index([1, 1, 1], dtype='int64', name='lvl1')\n",
"MultiIndex([(0, 'a')],\n",
" names=['lvl1', 'lvl2'])\n",
"2\n",
"2\n",
"Index([0], dtype='int64', name='lvl1')\n",
"MultiIndex([(0, 'a'),\n",
" (1, 'b'),\n",
" (1, 'c'),\n",
" (1, 'd')],\n",
" names=['lvl1', 'lvl2'])\n",
"2\n",
"2\n",
"Index([0, 1, 1, 1], dtype='int64', name='lvl1')\n",
"6.25 ms ± 70.1 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"13.9 ms ± 264 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(records_grouped[0].wrapper.columns) # indexing on groups, not columns!\n",
"print(records_grouped[0].wrapper.ndim)\n",
"print(records_grouped[0].wrapper.grouped_ndim)\n",
"print(records_grouped[0].wrapper.grouper.group_by)\n",
"\n",
"print(records_grouped[1].wrapper.columns)\n",
"print(records_grouped[1].wrapper.ndim)\n",
"print(records_grouped[1].wrapper.grouped_ndim)\n",
"print(records_grouped[1].wrapper.grouper.group_by)\n",
"\n",
"print(records_grouped[[0]].wrapper.columns)\n",
"print(records_grouped[[0]].wrapper.ndim)\n",
"print(records_grouped[[0]].wrapper.grouped_ndim)\n",
"print(records_grouped[[0]].wrapper.grouper.group_by)\n",
"\n",
"print(records_grouped[[0, 1]].wrapper.columns)\n",
"print(records_grouped[[0, 1]].wrapper.ndim)\n",
"print(records_grouped[[0, 1]].wrapper.grouped_ndim)\n",
"print(records_grouped[[0, 1]].wrapper.grouper.group_by)\n",
"\n",
"%timeit big_records_grouped.iloc[0]\n",
"%timeit big_records_grouped.iloc[:]"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Index(['x', 'y', 'z'], dtype='object')\n",
"MultiIndex([(0, 'a'),\n",
" (1, 'b'),\n",
" (1, 'c'),\n",
" (1, 'd')],\n",
" names=['lvl1', 'lvl2'])\n",
"2\n",
"None\n",
"Index(['x', 'y', 'z'], dtype='object')\n",
"MultiIndex([(0, 'a'),\n",
" (1, 'b'),\n",
" (1, 'c'),\n",
" (1, 'd')],\n",
" names=['lvl1', 'lvl2'])\n",
"2\n",
"Index([0, 1, 1, 1], dtype='int64', name='lvl1')\n"
]
}
],
"source": [
"print(records.wrapper.index)\n",
"print(records.wrapper.columns)\n",
"print(records.wrapper.ndim)\n",
"print(records.wrapper.grouper.group_by)\n",
"\n",
"print(records_grouped.wrapper.index)\n",
"print(records_grouped.wrapper.columns)\n",
"print(records_grouped.wrapper.ndim)\n",
"print(records_grouped.wrapper.grouper.group_by)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[(0, 0, 0, 10., 21.) (1, 1, 0, 11., 20.) (2, 2, 0, 12., 19.)\n",
" (3, 0, 1, 13., 18.) (4, 1, 1, 14., 17.) (5, 2, 1, 13., 18.)\n",
" (6, 0, 2, 12., 19.) (7, 1, 2, 11., 20.) (8, 2, 2, 10., 21.)]\n",
"[(0, 0, 0, 10., 21.) (1, 1, 0, 11., 20.) (2, 2, 0, 12., 19.)\n",
" (3, 0, 1, 13., 18.) (4, 1, 1, 14., 17.) (5, 2, 1, 13., 18.)\n",
" (6, 0, 2, 12., 19.) (7, 1, 2, 11., 20.) (8, 2, 2, 10., 21.)]\n",
"3.54 µs ± 13.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
]
}
],
"source": [
"print(records.values)\n",
"\n",
"print(records.recarray)\n",
"%timeit big_records.recarray"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" id idx col some_field1 some_field2\n",
"0 0 0 0 10.0 21.0\n",
"1 1 1 0 11.0 20.0\n",
"2 2 2 0 12.0 19.0\n",
"3 3 0 1 13.0 18.0\n",
"4 4 1 1 14.0 17.0\n",
"5 5 2 1 13.0 18.0\n",
"6 6 0 2 12.0 19.0\n",
"7 7 1 2 11.0 20.0\n",
"8 8 2 2 10.0 21.0\n"
]
}
],
"source": [
"print(records.records)"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"1.06 ms ± 1.99 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"False\n",
"8.89 µs ± 232 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n",
"True\n",
"1.56 ms ± 1.74 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"False\n",
"8.41 µs ± 37.3 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
]
}
],
"source": [
"print(records.is_sorted())\n",
"%timeit big_records.is_sorted()\n",
"\n",
"print(records_nosort.is_sorted())\n",
"%timeit big_records_nosort.is_sorted()\n",
"\n",
"print(records.is_sorted(incl_id=True))\n",
"%timeit big_records.is_sorted(incl_id=True)\n",
"\n",
"print(records_nosort.is_sorted(incl_id=True))\n",
"%timeit big_records_nosort.is_sorted(incl_id=True)"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[(0, 0, 0, 10., 21.) (1, 1, 0, 11., 20.) (2, 2, 0, 12., 19.)\n",
" (3, 0, 1, 13., 18.) (4, 1, 1, 14., 17.) (5, 2, 1, 13., 18.)\n",
" (6, 0, 2, 12., 19.) (7, 1, 2, 11., 20.) (8, 2, 2, 10., 21.)]\n",
"1.3 ms ± 771 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"[(2, 2, 0, 12., 19.) (1, 1, 0, 11., 20.) (0, 0, 0, 10., 21.)\n",
" (5, 2, 1, 13., 18.) (4, 1, 1, 14., 17.) (3, 0, 1, 13., 18.)\n",
" (8, 2, 2, 10., 21.) (7, 1, 2, 11., 20.) (6, 0, 2, 12., 19.)]\n",
"70.6 ms ± 1.59 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"[(0, 0, 0, 10., 21.) (1, 1, 0, 11., 20.) (2, 2, 0, 12., 19.)\n",
" (3, 0, 1, 13., 18.) (4, 1, 1, 14., 17.) (5, 2, 1, 13., 18.)\n",
" (6, 0, 2, 12., 19.) (7, 1, 2, 11., 20.) (8, 2, 2, 10., 21.)]\n",
"1.83 ms ± 12.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"[(0, 0, 0, 10., 21.) (1, 1, 0, 11., 20.) (2, 2, 0, 12., 19.)\n",
" (3, 0, 1, 13., 18.) (4, 1, 1, 14., 17.) (5, 2, 1, 13., 18.)\n",
" (6, 0, 2, 12., 19.) (7, 1, 2, 11., 20.) (8, 2, 2, 10., 21.)]\n",
"66 ms ± 1.53 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"print(records.sort().records_arr)\n",
"%timeit big_records.sort()\n",
"\n",
"print(records_nosort.sort().records_arr)\n",
"%timeit big_records_nosort.sort()\n",
"\n",
"print(records.sort(incl_id=True).records_arr)\n",
"%timeit big_records.sort(incl_id=True)\n",
"\n",
"print(records_nosort.sort(incl_id=True).records_arr)\n",
"%timeit big_records_nosort.sort(incl_id=True)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[(2, 2, 0, 12., 19.) (3, 0, 1, 13., 18.) (4, 1, 1, 14., 17.)\n",
" (5, 2, 1, 13., 18.) (6, 0, 2, 12., 19.)]\n",
"10.4 ms ± 232 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"mask = records.values['some_field1'] >= records.values['some_field1'].mean()\n",
"print(records.apply_mask(mask).values)\n",
"\n",
"big_mask = big_records.values['some_field1'] >= big_records.values['some_field1'].mean()\n",
"%timeit big_records.apply_mask(big_mask)"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a 153.0\n",
"1 b 146.0\n",
" c 153.0\n",
" d 0.0\n",
"Name: sum, dtype: float64\n",
"lvl1\n",
"0 153.0\n",
"1 299.0\n",
"Name: sum, dtype: float64\n",
"lvl1 lvl2\n",
"0 a 153.0\n",
"1 b 146.0\n",
" c 153.0\n",
" d 0.0\n",
"Name: sum, dtype: float64\n",
"3.25 ms ± 735 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"4.53 ms ± 278 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"@njit\n",
"def map_nb(record):\n",
" return record.some_field1 + record.some_field2 * 2\n",
"\n",
"print(records.map(map_nb).sum())\n",
"print(records_grouped.map(map_nb).sum())\n",
"print(records_grouped.map(map_nb, group_by=False).sum())\n",
"\n",
"%timeit vbt.records.MappedArray(\\\n",
" big_wrapper,\\\n",
" big_records_arr['some_field1'] + big_records_arr['some_field2'] * 2,\\\n",
" big_records_arr['col'],\\\n",
")\n",
"%timeit big_records.map(map_nb) # faster"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0 0 0 1 1 1 2 2 2]\n",
"[0 1 2 0 1 2 0 1 2]\n",
"[10. 11. 12. 13. 14. 13. 12. 11. 10.]\n",
"[21. 20. 19. 18. 17. 18. 19. 20. 21.]\n",
"lvl1 lvl2\n",
"0 a 33.0\n",
"1 b 40.0\n",
" c 33.0\n",
" d 0.0\n",
"Name: sum, dtype: float64\n",
"lvl1\n",
"0 33.0\n",
"1 73.0\n",
"Name: sum, dtype: float64\n",
"lvl1 lvl2\n",
"0 a 33.0\n",
"1 b 40.0\n",
" c 33.0\n",
" d 0.0\n",
"Name: sum, dtype: float64\n",
"293 µs ± 4.43 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(records.map_field('col').values)\n",
"print(records.map_field('idx').values)\n",
"print(records.map_field('some_field1').values)\n",
"print(records.map_field('some_field2').values)\n",
"\n",
"print(records.map_field('some_field1').sum())\n",
"print(records_grouped.map_field('some_field1').sum())\n",
"print(records_grouped.map_field('some_field1', group_by=False).sum())\n",
"\n",
"%timeit big_records.map_field('some_field1')"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[52. 51. 50. 49. 48. 49. 50. 51. 52.]\n",
"lvl1\n",
"0 153.0\n",
"1 299.0\n",
"Name: sum, dtype: float64\n",
"lvl1 lvl2\n",
"0 a 153.0\n",
"1 b 146.0\n",
" c 153.0\n",
" d 0.0\n",
"Name: sum, dtype: float64\n",
"2.55 ms ± 544 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(records.map_array(records_arr['some_field1'] + records_arr['some_field2'] * 2).values)\n",
"print(records_grouped.map_array(records_arr['some_field1'] + records_arr['some_field2'] * 2).sum())\n",
"print(records_grouped.map_array(records_arr['some_field1'] + records_arr['some_field2'] * 2, group_by=False).sum())\n",
"\n",
"%timeit big_records.map_array(big_records_arr['some_field1'] + big_records_arr['some_field2'] * 2)"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a 3\n",
"1 b 3\n",
" c 3\n",
" d 0\n",
"Name: count, dtype: int64\n",
"lvl1\n",
"0 3\n",
"1 6\n",
"Name: count, dtype: int64\n",
"lvl1 lvl2\n",
"0 a 3\n",
"1 b 3\n",
" c 3\n",
" d 0\n",
"Name: count, dtype: int64\n",
"49.5 µs ± 133 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n",
"48.5 µs ± 595 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
]
}
],
"source": [
"print(records.count())\n",
"print(records_grouped.count())\n",
"print(records_grouped.count(group_by=False))\n",
"\n",
"%timeit big_records.count()\n",
"%timeit big_records_grouped.count()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"lvl1 lvl2\n",
"0 a 1\n",
"1 b 0\n",
" c 1\n",
" d 0\n",
"Name: count, dtype: int64\n",
"lvl1\n",
"0 1\n",
"1 1\n",
"Name: count, dtype: int64\n",
"lvl1 lvl2\n",
"0 a 1\n",
"1 b 0\n",
" c 1\n",
" d 0\n",
"Name: count, dtype: int64\n"
]
}
],
"source": [
"filter_mask = np.array([True, False, False, False, False, False, False, False, True])\n",
"\n",
"print(records.apply_mask(filter_mask).count())\n",
"print(records_grouped.apply_mask(filter_mask).count())\n",
"print(records_grouped.apply_mask(filter_mask, group_by=False).count())"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" id idx col some_field1 some_field2\n",
"0 0 0 0 10.0 21.0\n",
"1 8 2 2 10.0 21.0\n"
]
}
],
"source": [
"filtered_records = records.apply_mask(filter_mask)\n",
"print(filtered_records.records)"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" id idx col some_field1 some_field2\n",
"0 0 0 0 10.0 21.0\n",
"[10.]\n",
"10.0\n",
"1\n"
]
}
],
"source": [
"print(filtered_records[(0, 'a')].records)\n",
"print(filtered_records[(0, 'a')].map_field('some_field1').values)\n",
"print(filtered_records[(0, 'a')].map_field('some_field1').min())\n",
"print(filtered_records[(0, 'a')].count())"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Empty DataFrame\n",
"Columns: [id, idx, col, some_field1, some_field2]\n",
"Index: []\n",
"[]\n",
"nan\n",
"0\n"
]
}
],
"source": [
"print(filtered_records[(1, 'b')].records)\n",
"print(filtered_records[(1, 'b')].map_field('some_field1').values)\n",
"print(filtered_records[(1, 'b')].map_field('some_field1').min())\n",
"print(filtered_records[(1, 'b')].count())"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" id idx col some_field1 some_field2\n",
"0 8 2 0 10.0 21.0\n",
"[10.]\n",
"10.0\n",
"1\n"
]
}
],
"source": [
"print(filtered_records[(1, 'c')].records)\n",
"print(filtered_records[(1, 'c')].map_field('some_field1').values)\n",
"print(filtered_records[(1, 'c')].map_field('some_field1').min())\n",
"print(filtered_records[(1, 'c')].count())"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Empty DataFrame\n",
"Columns: [id, idx, col, some_field1, some_field2]\n",
"Index: []\n",
"[]\n",
"nan\n",
"0\n"
]
}
],
"source": [
"print(filtered_records[(1, 'd')].records)\n",
"print(filtered_records[(1, 'd')].map_field('some_field1').values)\n",
"print(filtered_records[(1, 'd')].map_field('some_field1').min())\n",
"print(filtered_records[(1, 'd')].count())"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Start x\n",
"End z\n",
"Period 3 days 00:00:00\n",
"Count 3\n",
"Name: (0, a), dtype: object\n",
"12.7 ms ± 680 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"Start x\n",
"End z\n",
"Period 3 days 00:00:00\n",
"Count 3\n",
"Name: (0, a), dtype: object\n",
"2.18 ms ± 42.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"Start x\n",
"End z\n",
"Period 3 days 00:00:00\n",
"Count 2.25\n",
"Name: agg_func_mean, dtype: object\n",
"2.1 ms ± 1.67 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/miniconda3/lib/python3.7/site-packages/ipykernel_launcher.py:7: UserWarning:\n",
"\n",
"Object has multiple columns. Aggregating using <function mean at 0x7fbd30c34598>. Pass column to select a single column/group.\n",
"\n"
]
}
],
"source": [
"print(records[(0, 'a')].stats())\n",
"%timeit big_records[0].stats(silence_warnings=True)\n",
"\n",
"print(records.stats(column=(0, 'a')))\n",
"%timeit big_records.stats(column=0, silence_warnings=True)\n",
"\n",
"print(records.stats())\n",
"%timeit big_records.stats(silence_warnings=True)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/miniconda3/lib/python3.7/site-packages/ipykernel_launcher.py:1: UserWarning:\n",
"\n",
"No subplots to plot\n",
"\n"
]
}
],
"source": [
"records[(0, 'a')].plots()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Drawdowns"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"ts = pd.DataFrame({\n",
" 'a': [2, 1, 3, 1, 4, 1], \n",
" 'b': [1, 2, 1, 3, 1, 4],\n",
" 'c': [1, 2, 3, 2, 1, 2],\n",
" 'd': [1, 2, 3, 4, 5, 6]\n",
"}, index=[\n",
" datetime(2020, 1, 1),\n",
" datetime(2020, 1, 2),\n",
" datetime(2020, 1, 3),\n",
" datetime(2020, 1, 4),\n",
" datetime(2020, 1, 5),\n",
" datetime(2020, 1, 6)\n",
"])\n",
"\n",
"np.random.seed(42)\n",
"big_ts = pd.DataFrame(np.random.randint(1, 10, size=(1000, 1000)))"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(6,)\n"
]
}
],
"source": [
"drawdowns = vbt.Drawdowns.from_ts(ts, freq='1 days')\n",
"print(drawdowns.values.shape)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(99845,)\n"
]
}
],
"source": [
"big_drawdowns = vbt.Drawdowns.from_ts(big_ts, freq='1 days')\n",
"print(big_drawdowns.values.shape)"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5.37 ms ± 57.5 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"%timeit vbt.Drawdowns.from_ts(big_ts, freq='1 days')"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" id col peak_idx start_idx valley_idx end_idx peak_val valley_val \\\n",
"0 0 0 0 1 1 2 2.0 1.0 \n",
"1 1 0 2 3 3 4 3.0 1.0 \n",
"2 2 0 4 5 5 5 4.0 1.0 \n",
"3 3 1 1 2 2 3 2.0 1.0 \n",
"4 4 1 3 4 4 5 3.0 1.0 \n",
"5 5 2 2 3 4 5 3.0 1.0 \n",
"\n",
" end_val status \n",
"0 2.0 1 \n",
"1 3.0 1 \n",
"2 1.0 0 \n",
"3 2.0 1 \n",
"4 3.0 1 \n",
"5 2.0 0 \n",
" a b c d\n",
"2020-01-01 2 1 1 1\n",
"2020-01-02 1 2 2 2\n",
"2020-01-03 3 1 3 3\n",
"2020-01-04 1 3 2 4\n",
"2020-01-05 4 1 1 5\n",
"2020-01-06 1 4 2 6\n",
" id col peak_idx start_idx valley_idx end_idx peak_val valley_val \\\n",
"0 0 0 0 1 1 2 2.0 1.0 \n",
"1 1 0 2 3 3 4 3.0 1.0 \n",
"2 2 0 4 5 5 5 4.0 1.0 \n",
"\n",
" end_val status \n",
"0 2.0 1 \n",
"1 3.0 1 \n",
"2 1.0 0 \n",
"2020-01-01 2\n",
"2020-01-02 1\n",
"2020-01-03 3\n",
"2020-01-04 1\n",
"2020-01-05 4\n",
"2020-01-06 1\n",
"Name: a, dtype: int64\n",
"1.21 ms ± 12.6 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"3.81 ms ± 418 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(drawdowns.records)\n",
"print(drawdowns.ts)\n",
"\n",
"print(drawdowns['a'].records)\n",
"print(drawdowns['a'].ts)\n",
"\n",
"%timeit big_drawdowns.iloc[0]\n",
"%timeit big_drawdowns.iloc[:]"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Drawdown Id Column Peak Timestamp Start Timestamp Valley Timestamp \\\n",
"0 0 a 2020-01-01 2020-01-02 2020-01-02 \n",
"1 1 a 2020-01-03 2020-01-04 2020-01-04 \n",
"2 2 a 2020-01-05 2020-01-06 2020-01-06 \n",
"3 3 b 2020-01-02 2020-01-03 2020-01-03 \n",
"4 4 b 2020-01-04 2020-01-05 2020-01-05 \n",
"5 5 c 2020-01-03 2020-01-04 2020-01-05 \n",
"\n",
" End Timestamp Peak Value Valley Value End Value Status \n",
"0 2020-01-03 2.0 1.0 2.0 Recovered \n",
"1 2020-01-05 3.0 1.0 3.0 Recovered \n",
"2 2020-01-06 4.0 1.0 1.0 Active \n",
"3 2020-01-04 2.0 1.0 2.0 Recovered \n",
"4 2020-01-06 3.0 1.0 3.0 Recovered \n",
"5 2020-01-06 3.0 1.0 2.0 Active \n"
]
}
],
"source": [
"print(drawdowns.records_readable)"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n",
"a 3\n",
"b 2\n",
"c 1\n",
"d 0\n",
"Name: count, dtype: int64\n",
"group\n",
"first 5\n",
"second 1\n",
"Name: count, dtype: int64\n"
]
}
],
"source": [
"print(drawdowns['a'].count())\n",
"\n",
"print(drawdowns.count())\n",
"print(drawdowns.count(group_by=group_by))"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2020-01-01 NaN\n",
"2020-01-02 NaN\n",
"2020-01-03 -0.500000\n",
"2020-01-04 NaN\n",
"2020-01-05 -0.666667\n",
"2020-01-06 -0.750000\n",
"Name: a, dtype: float64\n",
" a b c d\n",
"2020-01-01 NaN NaN NaN NaN\n",
"2020-01-02 NaN NaN NaN NaN\n",
"2020-01-03 -0.500000 NaN NaN NaN\n",
"2020-01-04 NaN -0.500000 NaN NaN\n",
"2020-01-05 -0.666667 NaN NaN NaN\n",
"2020-01-06 -0.750000 -0.666667 -0.666667 NaN\n",
"463 µs ± 21.5 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].drawdown.to_pd())\n",
"print(drawdowns.drawdown.to_pd())\n",
"\n",
"%timeit big_drawdowns.drawdown"
]
},
{
"cell_type": "code",
"execution_count": 81,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.6388888888888888\n",
"a -0.638889\n",
"b -0.583333\n",
"c -0.666667\n",
"d NaN\n",
"Name: avg_drawdown, dtype: float64\n",
"1.12 ms ± 200 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"group\n",
"first -0.616667\n",
"second -0.666667\n",
"Name: avg_drawdown, dtype: float64\n",
"4.65 ms ± 1.91 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].avg_drawdown())\n",
"print(drawdowns.avg_drawdown())\n",
"%timeit big_drawdowns.avg_drawdown()\n",
"\n",
"print(drawdowns.avg_drawdown(group_by=group_by))\n",
"%timeit big_drawdowns.avg_drawdown(group_by=big_group_by)"
]
},
{
"cell_type": "code",
"execution_count": 82,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.75\n",
"a -0.750000\n",
"b -0.666667\n",
"c -0.666667\n",
"d NaN\n",
"Name: max_drawdown, dtype: float64\n",
"1.15 ms ± 214 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"group\n",
"first -0.750000\n",
"second -0.666667\n",
"Name: max_drawdown, dtype: float64\n",
"3.81 ms ± 652 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].max_drawdown())\n",
"print(drawdowns.max_drawdown())\n",
"%timeit big_drawdowns.max_drawdown()\n",
"\n",
"print(drawdowns.max_drawdown(group_by=group_by))\n",
"%timeit big_drawdowns.max_drawdown(group_by=big_group_by)"
]
},
{
"cell_type": "code",
"execution_count": 83,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2020-01-01 NaN\n",
"2020-01-02 NaN\n",
"2020-01-03 1.0\n",
"2020-01-04 NaN\n",
"2020-01-05 2.0\n",
"2020-01-06 0.0\n",
"Name: a, dtype: float64\n",
" a b c d\n",
"2020-01-01 NaN NaN NaN NaN\n",
"2020-01-02 NaN NaN NaN NaN\n",
"2020-01-03 1.0 NaN NaN NaN\n",
"2020-01-04 NaN 1.0 NaN NaN\n",
"2020-01-05 2.0 NaN NaN NaN\n",
"2020-01-06 0.0 2.0 1.0 NaN\n",
"479 µs ± 45.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].recovery_return.to_pd())\n",
"print(drawdowns.recovery_return.to_pd())\n",
"\n",
"%timeit big_drawdowns.recovery_return"
]
},
{
"cell_type": "code",
"execution_count": 84,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.0\n",
"a 1.0\n",
"b 1.5\n",
"c 1.0\n",
"d NaN\n",
"Name: avg_recovery_return, dtype: float64\n",
"1.01 ms ± 8.88 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"group\n",
"first 1.2\n",
"second 1.0\n",
"Name: avg_recovery_return, dtype: float64\n",
"3.48 ms ± 80 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].avg_recovery_return())\n",
"print(drawdowns.avg_recovery_return())\n",
"%timeit big_drawdowns.avg_recovery_return()\n",
"\n",
"print(drawdowns.avg_recovery_return(group_by=group_by))\n",
"%timeit big_drawdowns.avg_recovery_return(group_by=big_group_by)"
]
},
{
"cell_type": "code",
"execution_count": 85,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.0\n",
"a 2.0\n",
"b 2.0\n",
"c 1.0\n",
"d NaN\n",
"Name: max_recovery_return, dtype: float64\n",
"1.06 ms ± 35.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"group\n",
"first 2.0\n",
"second 1.0\n",
"Name: max_recovery_return, dtype: float64\n",
"3.72 ms ± 302 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].max_recovery_return())\n",
"print(drawdowns.max_recovery_return())\n",
"%timeit big_drawdowns.max_recovery_return()\n",
"\n",
"print(drawdowns.max_recovery_return(group_by=group_by))\n",
"%timeit big_drawdowns.max_recovery_return(group_by=big_group_by)"
]
},
{
"cell_type": "code",
"execution_count": 86,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2020-01-01 NaN\n",
"2020-01-02 NaN\n",
"2020-01-03 1.0\n",
"2020-01-04 NaN\n",
"2020-01-05 1.0\n",
"2020-01-06 1.0\n",
"Name: a, dtype: float64\n",
" a b c d\n",
"2020-01-01 NaN NaN NaN NaN\n",
"2020-01-02 NaN NaN NaN NaN\n",
"2020-01-03 1.0 NaN NaN NaN\n",
"2020-01-04 NaN 1.0 NaN NaN\n",
"2020-01-05 1.0 NaN NaN NaN\n",
"2020-01-06 1.0 1.0 3.0 NaN\n",
"483 µs ± 6.53 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].duration.to_pd())\n",
"print(drawdowns.duration.to_pd())\n",
"\n",
"%timeit big_drawdowns.duration"
]
},
{
"cell_type": "code",
"execution_count": 87,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 days 00:00:00\n",
"a 1 days\n",
"b 1 days\n",
"c 3 days\n",
"d NaT\n",
"Name: avg_duration, dtype: timedelta64[ns]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/base/array_wrapper.py:661: UserWarning:\n",
"\n",
"Couldn't parse the frequency of index. Pass it as `freq` or define it globally under `settings.array_wrapper`.\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"905 µs ± 3.32 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"group\n",
"first 1 days\n",
"second 3 days\n",
"Name: avg_duration, dtype: timedelta64[ns]\n",
"3.34 ms ± 35.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].avg_duration())\n",
"print(drawdowns.avg_duration())\n",
"%timeit big_drawdowns.avg_duration()\n",
"\n",
"print(drawdowns.avg_duration(group_by=group_by))\n",
"%timeit big_drawdowns.avg_duration(group_by=big_group_by)"
]
},
{
"cell_type": "code",
"execution_count": 88,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 days 00:00:00\n",
"a 1 days\n",
"b 1 days\n",
"c 3 days\n",
"d NaT\n",
"Name: max_duration, dtype: timedelta64[ns]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/base/array_wrapper.py:661: UserWarning:\n",
"\n",
"Couldn't parse the frequency of index. Pass it as `freq` or define it globally under `settings.array_wrapper`.\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"992 µs ± 72.6 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"group\n",
"first 1 days\n",
"second 3 days\n",
"Name: max_duration, dtype: timedelta64[ns]\n",
"3.35 ms ± 18.6 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].max_duration())\n",
"print(drawdowns.max_duration())\n",
"%timeit big_drawdowns.max_duration()\n",
"\n",
"print(drawdowns.max_duration(group_by=group_by))\n",
"%timeit big_drawdowns.max_duration(group_by=big_group_by)"
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.5\n",
"a 0.500000\n",
"b 0.333333\n",
"c 0.500000\n",
"d NaN\n",
"Name: coverage, dtype: float64\n",
"13.8 ms ± 181 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"group\n",
"first 0.416667\n",
"second 0.250000\n",
"Name: coverage, dtype: float64\n",
"16.8 ms ± 164 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].coverage())\n",
"print(drawdowns.coverage())\n",
"%timeit big_drawdowns.coverage()\n",
"\n",
"print(drawdowns.coverage(group_by=group_by))\n",
"%timeit big_drawdowns.coverage(group_by=big_group_by)"
]
},
{
"cell_type": "code",
"execution_count": 90,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2020-01-01 NaN\n",
"2020-01-02 NaN\n",
"2020-01-03 1.0\n",
"2020-01-04 NaN\n",
"2020-01-05 1.0\n",
"2020-01-06 1.0\n",
"Name: a, dtype: float64\n",
" a b c d\n",
"2020-01-01 NaN NaN NaN NaN\n",
"2020-01-02 NaN NaN NaN NaN\n",
"2020-01-03 1.0 NaN NaN NaN\n",
"2020-01-04 NaN 1.0 NaN NaN\n",
"2020-01-05 1.0 NaN NaN NaN\n",
"2020-01-06 1.0 1.0 2.0 NaN\n",
"518 µs ± 30.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].decline_duration.to_pd())\n",
"print(drawdowns.decline_duration.to_pd())\n",
"\n",
"%timeit big_drawdowns.decline_duration"
]
},
{
"cell_type": "code",
"execution_count": 91,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2020-01-01 NaN\n",
"2020-01-02 NaN\n",
"2020-01-03 1.0\n",
"2020-01-04 NaN\n",
"2020-01-05 1.0\n",
"2020-01-06 0.0\n",
"Name: a, dtype: float64\n",
" a b c d\n",
"2020-01-01 NaN NaN NaN NaN\n",
"2020-01-02 NaN NaN NaN NaN\n",
"2020-01-03 1.0 NaN NaN NaN\n",
"2020-01-04 NaN 1.0 NaN NaN\n",
"2020-01-05 1.0 NaN NaN NaN\n",
"2020-01-06 0.0 1.0 1.0 NaN\n",
"479 µs ± 17.5 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].recovery_duration.to_pd())\n",
"print(drawdowns.recovery_duration.to_pd())\n",
"\n",
"%timeit big_drawdowns.recovery_duration"
]
},
{
"cell_type": "code",
"execution_count": 92,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2020-01-01 NaN\n",
"2020-01-02 NaN\n",
"2020-01-03 1.0\n",
"2020-01-04 NaN\n",
"2020-01-05 1.0\n",
"2020-01-06 0.0\n",
"Name: a, dtype: float64\n",
" a b c d\n",
"2020-01-01 NaN NaN NaN NaN\n",
"2020-01-02 NaN NaN NaN NaN\n",
"2020-01-03 1.0 NaN NaN NaN\n",
"2020-01-04 NaN 1.0 NaN NaN\n",
"2020-01-05 1.0 NaN NaN NaN\n",
"2020-01-06 0.0 1.0 0.5 NaN\n",
"699 µs ± 43.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].recovery_duration_ratio.to_pd())\n",
"print(drawdowns.recovery_duration_ratio.to_pd())\n",
"\n",
"%timeit big_drawdowns.recovery_duration_ratio"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Drawdowns(**Config({\n",
" \"wrapper\": \"<vectorbt.base.array_wrapper.ArrayWrapper object at 0x7fa004833748> of shape (6, 4)\",\n",
" \"records_arr\": \"<numpy.ndarray object at 0x7fa021f50870> of shape (2,)\",\n",
" \"col_mapper\": null,\n",
" \"ts\": \"<pandas.core.frame.DataFrame object at 0x7f9ff803f898> of shape (6, 4)\",\n",
" \"freq\": \"1 days\"\n",
"}))\n",
" id col peak_idx start_idx valley_idx end_idx peak_val valley_val \\\n",
"0 2 0 4 5 5 5 4.0 1.0 \n",
"\n",
" end_val status \n",
"0 1.0 0 \n",
" id col peak_idx start_idx valley_idx end_idx peak_val valley_val \\\n",
"0 2 0 4 5 5 5 4.0 1.0 \n",
"\n",
" end_val status \n",
"0 1.0 0 \n",
" id col peak_idx start_idx valley_idx end_idx peak_val valley_val \\\n",
"0 2 0 4 5 5 5 4.0 1.0 \n",
"1 5 2 2 3 4 5 3.0 1.0 \n",
"\n",
" end_val status \n",
"0 1.0 0 \n",
"1 2.0 0 \n",
"707 µs ± 42.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(drawdowns.active)\n",
"print(drawdowns['a'].active.records)\n",
"print(drawdowns.active['a'].records)\n",
"print(drawdowns.active.records)\n",
"\n",
"%timeit big_drawdowns.active"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Drawdowns(**Config({\n",
" \"wrapper\": \"<vectorbt.base.array_wrapper.ArrayWrapper object at 0x7fa004833748> of shape (6, 4)\",\n",
" \"records_arr\": \"<numpy.ndarray object at 0x7fa021f4bad8> of shape (4,)\",\n",
" \"col_mapper\": null,\n",
" \"ts\": \"<pandas.core.frame.DataFrame object at 0x7f9ff803f898> of shape (6, 4)\",\n",
" \"freq\": \"1 days\"\n",
"}))\n",
" id col peak_idx start_idx valley_idx end_idx peak_val valley_val \\\n",
"0 0 0 0 1 1 2 2.0 1.0 \n",
"1 1 0 2 3 3 4 3.0 1.0 \n",
"\n",
" end_val status \n",
"0 2.0 1 \n",
"1 3.0 1 \n",
" id col peak_idx start_idx valley_idx end_idx peak_val valley_val \\\n",
"0 0 0 0 1 1 2 2.0 1.0 \n",
"1 1 0 2 3 3 4 3.0 1.0 \n",
"\n",
" end_val status \n",
"0 2.0 1 \n",
"1 3.0 1 \n",
" id col peak_idx start_idx valley_idx end_idx peak_val valley_val \\\n",
"0 0 0 0 1 1 2 2.0 1.0 \n",
"1 1 0 2 3 3 4 3.0 1.0 \n",
"2 3 1 1 2 2 3 2.0 1.0 \n",
"3 4 1 3 4 4 5 3.0 1.0 \n",
"\n",
" end_val status \n",
"0 2.0 1 \n",
"1 3.0 1 \n",
"2 2.0 1 \n",
"3 3.0 1 \n",
"2.26 ms ± 266 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(drawdowns.recovered)\n",
"print(drawdowns['a'].recovered.records)\n",
"print(drawdowns.recovered['a'].records)\n",
"print(drawdowns.recovered.records)\n",
"\n",
"%timeit big_drawdowns.recovered"
]
},
{
"cell_type": "code",
"execution_count": 95,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.75\n",
"a -0.750000\n",
"b NaN\n",
"c -0.333333\n",
"d NaN\n",
"Name: active_drawdown, dtype: float64\n",
"2.03 ms ± 48.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].active_drawdown())\n",
"print(drawdowns.active_drawdown())\n",
"\n",
"%timeit big_drawdowns.active_drawdown()"
]
},
{
"cell_type": "code",
"execution_count": 96,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 days 00:00:00\n",
"a 1 days\n",
"b NaT\n",
"c 3 days\n",
"d NaT\n",
"Name: active_duration, dtype: timedelta64[ns]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/base/array_wrapper.py:661: UserWarning:\n",
"\n",
"Couldn't parse the frequency of index. Pass it as `freq` or define it globally under `settings.array_wrapper`.\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.41 ms ± 65.6 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].active_duration())\n",
"print(drawdowns.active_duration())\n",
"\n",
"%timeit big_drawdowns.active_duration()"
]
},
{
"cell_type": "code",
"execution_count": 97,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.0\n",
"a 0.0\n",
"b NaN\n",
"c 1.0\n",
"d NaN\n",
"Name: active_recovery_return, dtype: float64\n",
"1.43 ms ± 43.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].active_recovery_return())\n",
"print(drawdowns.active_recovery_return())\n",
"\n",
"%timeit big_drawdowns.active_recovery_return()"
]
},
{
"cell_type": "code",
"execution_count": 98,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 days 00:00:00\n",
"a 0 days\n",
"b NaT\n",
"c 1 days\n",
"d NaT\n",
"Name: active_recovery_duration, dtype: timedelta64[ns]\n",
"1.41 ms ± 53.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].active_recovery_duration())\n",
"print(drawdowns.active_recovery_duration())\n",
"\n",
"%timeit big_drawdowns.active_recovery_duration()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Start 2020-01-01 00:00:00\n",
"End 2020-01-06 00:00:00\n",
"Period 6 days 00:00:00\n",
"Coverage [%] 50.0\n",
"Total Records 3\n",
"Total Recovered Drawdowns 2\n",
"Total Active Drawdowns 1\n",
"Active Drawdown [%] 75.0\n",
"Active Duration 1 days 00:00:00\n",
"Active Recovery [%] 0.0\n",
"Active Recovery Return [%] 0.0\n",
"Active Recovery Duration 0 days 00:00:00\n",
"Max Drawdown [%] 66.666667\n",
"Avg Drawdown [%] 58.333333\n",
"Max Drawdown Duration 1 days 00:00:00\n",
"Avg Drawdown Duration 1 days 00:00:00\n",
"Max Recovery Return [%] 200.0\n",
"Avg Recovery Return [%] 150.0\n",
"Max Recovery Duration 1 days 00:00:00\n",
"Avg Recovery Duration 1 days 00:00:00\n",
"Avg Recovery Duration Ratio 1.0\n",
"Name: a, dtype: object\n",
"21.6 ms ± 115 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"Start 2020-01-01 00:00:00\n",
"End 2020-01-06 00:00:00\n",
"Period 6 days 00:00:00\n",
"Coverage [%] 50.0\n",
"Total Records 3\n",
"Total Recovered Drawdowns 2\n",
"Total Active Drawdowns 1\n",
"Active Drawdown [%] 75.0\n",
"Active Duration 1 days 00:00:00\n",
"Active Recovery [%] 0.0\n",
"Active Recovery Return [%] 0.0\n",
"Active Recovery Duration 0 days 00:00:00\n",
"Max Drawdown [%] 66.666667\n",
"Avg Drawdown [%] 58.333333\n",
"Max Drawdown Duration 1 days 00:00:00\n",
"Avg Drawdown Duration 1 days 00:00:00\n",
"Max Recovery Return [%] 200.0\n",
"Avg Recovery Return [%] 150.0\n",
"Max Recovery Duration 1 days 00:00:00\n",
"Avg Recovery Duration 1 days 00:00:00\n",
"Avg Recovery Duration Ratio 1.0\n",
"Name: a, dtype: object\n",
"44.9 ms ± 2.18 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"Start 2020-01-01 00:00:00\n",
"End 2020-01-06 00:00:00\n",
"Period 6 days 00:00:00\n",
"Coverage [%] 44.444444\n",
"Total Records 1.5\n",
"Total Recovered Drawdowns 1.0\n",
"Total Active Drawdowns 0.5\n",
"Active Drawdown [%] 54.166667\n",
"Active Duration 2 days 00:00:00\n",
"Active Recovery [%] 25.0\n",
"Active Recovery Return [%] 50.0\n",
"Active Recovery Duration 0 days 12:00:00\n",
"Max Drawdown [%] 66.666667\n",
"Avg Drawdown [%] 58.333333\n",
"Max Drawdown Duration 1 days 00:00:00\n",
"Avg Drawdown Duration 1 days 00:00:00\n",
"Max Recovery Return [%] 200.0\n",
"Avg Recovery Return [%] 150.0\n",
"Max Recovery Duration 1 days 00:00:00\n",
"Avg Recovery Duration 1 days 00:00:00\n",
"Avg Recovery Duration Ratio 1.0\n",
"Name: agg_func_mean, dtype: object\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/miniconda3/lib/python3.7/site-packages/ipykernel_launcher.py:7: UserWarning: Object has multiple columns. Aggregating using <function mean at 0x7fa020856598>. Pass column to select a single column/group.\n",
" import sys\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"45.2 ms ± 757 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"print(drawdowns['a'].stats())\n",
"%timeit big_drawdowns[0].stats(silence_warnings=True)\n",
"\n",
"print(drawdowns.stats(column='a'))\n",
"%timeit big_drawdowns.stats(column=0, silence_warnings=True)\n",
"\n",
"print(drawdowns.stats())\n",
"%timeit big_drawdowns.stats(silence_warnings=True)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-e02067\"><g class=\"clips\"><clipPath id=\"clipe02067xyplot\" class=\"plotclip\"><rect width=\"637\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clipe02067x\"><rect x=\"33\" y=\"0\" width=\"637\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clipe02067y\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clipe02067xy\"><rect x=\"33\" y=\"46\" width=\"637\" height=\"261\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"33\" y=\"46\" width=\"637\" height=\"261\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"><path data-index=\"0\" fill-rule=\"evenodd\" d=\"M69.22,307H182.13V46H69.22Z\" clip-path=\"url(#clipe02067x)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(255, 0, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"1\" fill-rule=\"evenodd\" d=\"M295.04,307H407.96V46H295.04Z\" clip-path=\"url(#clipe02067x)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(255, 0, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"2\" fill-rule=\"evenodd\" d=\"M182.13,307H295.04V46H182.13Z\" clip-path=\"url(#clipe02067x)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 128, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"3\" fill-rule=\"evenodd\" d=\"M407.96,307H520.87V46H407.96Z\" clip-path=\"url(#clipe02067x)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 128, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"4\" fill-rule=\"evenodd\" d=\"M520.87,307H633.78V46H520.87Z\" clip-path=\"url(#clipe02067x)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(255, 165, 0); fill-opacity: 1; stroke-width: 0px;\"/></g></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(69.22,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(182.13,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(295.04,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(407.96,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(520.87,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(633.78,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,289.58000000000004)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,251.88)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,214.19)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,176.5)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,138.81)\" d=\"M33,0h637\" style=\"stroke:
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawdowns['a'].plot().show_svg()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-36aee7\"><g class=\"clips\"><clipPath id=\"clip36aee7xyplot\" class=\"plotclip\"><rect width=\"637\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clip36aee7x\"><rect x=\"33\" y=\"0\" width=\"637\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clip36aee7y\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clip36aee7xy\"><rect x=\"33\" y=\"46\" width=\"637\" height=\"261\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"33\" y=\"46\" width=\"637\" height=\"261\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"><path data-index=\"0\" fill-rule=\"evenodd\" d=\"M520.74,307H633.78V46H520.74Z\" clip-path=\"url(#clip36aee7x)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(255, 165, 0); fill-opacity: 1; stroke-width: 0px;\"/></g></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(68.6,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(181.64,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(294.67,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(407.71,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(520.74,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(633.78,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,289.58000000000004)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,251.88)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,214.19)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,176.5)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,138.81)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,101.12)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,63.43)\" d=\"M33,0h637\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"/><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(33,46)\" clip-path=\"url(#clip36aee7xyplot)\"><g class=\"scatterlayer mlayer\"><g class=\"trace scatter trace36f1672b-06da-42f9-8948-bb7e08e1231a\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"><path class=\"js-line\" d=\"M35.6,168.19L148.64,243.58L261.67,92
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawdowns.plot(column='a', top_n=1).show_svg()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"750\" height=\"380\" style=\"\" viewBox=\"0 0 750 380\"><rect x=\"0\" y=\"0\" width=\"750\" height=\"380\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-ae7538\"><g class=\"clips\"><clipPath id=\"clipae7538xyplot\" class=\"plotclip\"><rect width=\"687\" height=\"245\"/></clipPath><clipPath class=\"axesclip\" id=\"clipae7538x\"><rect x=\"33\" y=\"0\" width=\"687\" height=\"380\"/></clipPath><clipPath class=\"axesclip\" id=\"clipae7538y\"><rect x=\"0\" y=\"67\" width=\"750\" height=\"245\"/></clipPath><clipPath class=\"axesclip\" id=\"clipae7538xy\"><rect x=\"33\" y=\"67\" width=\"687\" height=\"245\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"33\" y=\"67\" width=\"687\" height=\"245\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"><path data-index=\"0\" fill-rule=\"evenodd\" d=\"M71.72999999999999,312H193.64V67H71.72999999999999Z\" clip-path=\"url(#clipae7538x)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(255, 0, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"1\" fill-rule=\"evenodd\" d=\"M315.55,312H437.45V67H315.55Z\" clip-path=\"url(#clipae7538x)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(255, 0, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"2\" fill-rule=\"evenodd\" d=\"M193.64,312H315.55V67H193.64Z\" clip-path=\"url(#clipae7538x)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 128, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"3\" fill-rule=\"evenodd\" d=\"M437.45,312H559.36V67H437.45Z\" clip-path=\"url(#clipae7538x)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 128, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"4\" fill-rule=\"evenodd\" d=\"M559.36,312H681.27V67H559.36Z\" clip-path=\"url(#clipae7538x)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(255, 165, 0); fill-opacity: 1; stroke-width: 0px;\"/></g></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(71.72999999999999,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(193.64,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(315.55,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(437.45,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(559.36,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(681.27,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,295.38)\" d=\"M33,0h687\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,260.08000000000004)\" d=\"M33,0h687\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,224.79)\" d=\"M33,0h687\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,189.5)\" d=\"M33,0h687\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,154.2
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawdowns['a'].plots().show_svg()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Orders"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" a b c d\n",
"2020-01-01 1 1 1 1\n",
"2020-01-02 2 2 2 2\n",
"2020-01-03 3 3 3 3\n",
"2020-01-04 4 4 4 4\n",
"2020-01-05 5 5 5 5\n",
"2020-01-06 6 6 6 6\n",
"2020-01-07 7 7 7 7\n",
"2020-01-08 8 8 8 8\n"
]
}
],
"source": [
"close = pd.Series([1, 2, 3, 4, 5, 6, 7, 8], index=[\n",
" datetime(2020, 1, 1),\n",
" datetime(2020, 1, 2),\n",
" datetime(2020, 1, 3),\n",
" datetime(2020, 1, 4),\n",
" datetime(2020, 1, 5),\n",
" datetime(2020, 1, 6),\n",
" datetime(2020, 1, 7),\n",
" datetime(2020, 1, 8)\n",
"]).vbt.tile(4, keys=['a', 'b', 'c', 'd'])\n",
"print(close)\n",
"\n",
"big_close = pd.DataFrame(np.random.uniform(1, 10, size=(1000, 1000)))"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(21,)\n"
]
}
],
"source": [
"from vectorbt.portfolio.enums import order_dt\n",
"\n",
"records_arr = np.asarray([\n",
" (0, 0, 0, 1. , 1., 0.01 , 0), (1, 0, 1, 0.1, 2., 0.002, 0),\n",
" (2, 0, 2, 1. , 3., 0.03 , 1), (3, 0, 3, 0.1, 4., 0.004, 1),\n",
" (4, 0, 5, 1. , 6., 0.06 , 0), (5, 0, 6, 1. , 7., 0.07 , 1),\n",
" (6, 0, 7, 2. , 8., 0.16 , 0), (7, 1, 0, 1. , 1., 0.01 , 1),\n",
" (8, 1, 1, 0.1, 2., 0.002, 1), (9, 1, 2, 1. , 3., 0.03 , 0),\n",
" (10, 1, 3, 0.1, 4., 0.004, 0), (11, 1, 5, 1. , 6., 0.06 , 1),\n",
" (12, 1, 6, 1. , 7., 0.07 , 0), (13, 1, 7, 2. , 8., 0.16 , 1),\n",
" (14, 2, 0, 1. , 1., 0.01 , 0), (15, 2, 1, 0.1, 2., 0.002, 0),\n",
" (16, 2, 2, 1. , 3., 0.03 , 1), (17, 2, 3, 0.1, 4., 0.004, 1),\n",
" (18, 2, 5, 1. , 6., 0.06 , 0), (19, 2, 6, 2. , 7., 0.14 , 1),\n",
" (20, 2, 7, 2. , 8., 0.16 , 0)\n",
"], dtype=order_dt)\n",
"print(records_arr.shape)\n",
"\n",
"wrapper = vbt.ArrayWrapper.from_obj(close, freq='1 days')\n",
"orders = vbt.Orders(wrapper, records_arr, close)\n",
"orders_grouped = vbt.Orders(wrapper.regroup(group_by), records_arr, close)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1000000,)\n"
]
}
],
"source": [
"big_records_arr = np.asarray(list(zip(*(\n",
" np.arange(1000000),\n",
" np.tile(np.arange(1000), 1000),\n",
" np.repeat(np.arange(1000), 1000),\n",
" np.full(1000000, 10),\n",
" np.random.uniform(1, 10, size=1000000),\n",
" np.full(1000000, 1),\n",
" np.full(1000000, 1)\n",
"))), dtype=order_dt)\n",
"big_records_arr['side'][::2] = 0\n",
"print(big_records_arr.shape)\n",
"\n",
"big_wrapper = vbt.ArrayWrapper.from_obj(big_close, freq='1 days')\n",
"big_orders = vbt.Orders(big_wrapper, big_records_arr, big_close)\n",
"big_orders_grouped = vbt.Orders(big_wrapper.copy(group_by=big_group_by), big_records_arr, big_close)"
]
},
{
"cell_type": "code",
"execution_count": 106,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" id col idx size price fees side\n",
"0 0 0 0 1.0 1.0 0.010 0\n",
"1 1 0 1 0.1 2.0 0.002 0\n",
"2 2 0 2 1.0 3.0 0.030 1\n",
"3 3 0 3 0.1 4.0 0.004 1\n",
"4 4 0 5 1.0 6.0 0.060 0\n",
"5 5 0 6 1.0 7.0 0.070 1\n",
"6 6 0 7 2.0 8.0 0.160 0\n",
"7 7 1 0 1.0 1.0 0.010 1\n",
"8 8 1 1 0.1 2.0 0.002 1\n",
"9 9 1 2 1.0 3.0 0.030 0\n",
"10 10 1 3 0.1 4.0 0.004 0\n",
"11 11 1 5 1.0 6.0 0.060 1\n",
"12 12 1 6 1.0 7.0 0.070 0\n",
"13 13 1 7 2.0 8.0 0.160 1\n",
"14 14 2 0 1.0 1.0 0.010 0\n",
"15 15 2 1 0.1 2.0 0.002 0\n",
"16 16 2 2 1.0 3.0 0.030 1\n",
"17 17 2 3 0.1 4.0 0.004 1\n",
"18 18 2 5 1.0 6.0 0.060 0\n",
"19 19 2 6 2.0 7.0 0.140 1\n",
"20 20 2 7 2.0 8.0 0.160 0\n",
" a b c d\n",
"2020-01-01 1 1 1 1\n",
"2020-01-02 2 2 2 2\n",
"2020-01-03 3 3 3 3\n",
"2020-01-04 4 4 4 4\n",
"2020-01-05 5 5 5 5\n",
"2020-01-06 6 6 6 6\n",
"2020-01-07 7 7 7 7\n",
"2020-01-08 8 8 8 8\n",
" id col idx size price fees side\n",
"0 0 0 0 1.0 1.0 0.010 0\n",
"1 1 0 1 0.1 2.0 0.002 0\n",
"2 2 0 2 1.0 3.0 0.030 1\n",
"3 3 0 3 0.1 4.0 0.004 1\n",
"4 4 0 5 1.0 6.0 0.060 0\n",
"5 5 0 6 1.0 7.0 0.070 1\n",
"6 6 0 7 2.0 8.0 0.160 0\n",
"2020-01-01 1\n",
"2020-01-02 2\n",
"2020-01-03 3\n",
"2020-01-04 4\n",
"2020-01-05 5\n",
"2020-01-06 6\n",
"2020-01-07 7\n",
"2020-01-08 8\n",
"Name: a, dtype: int64\n",
"1.06 ms ± 17.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"12.5 ms ± 2.47 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"13.5 ms ± 1.52 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"13 ms ± 4.86 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"print(orders.records)\n",
"print(orders.close)\n",
"\n",
"print(orders['a'].records)\n",
"print(orders['a'].close)\n",
"\n",
"%timeit big_orders.iloc[0]\n",
"%timeit big_orders.iloc[:]\n",
"\n",
"%timeit big_orders_grouped.iloc[0]\n",
"%timeit big_orders_grouped.iloc[:]"
]
},
{
"cell_type": "code",
"execution_count": 107,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Order Id Column Timestamp Size Price Fees Side\n",
"0 0 a 2020-01-01 1.0 1.0 0.010 Buy\n",
"1 1 a 2020-01-02 0.1 2.0 0.002 Buy\n",
"2 2 a 2020-01-03 1.0 3.0 0.030 Sell\n",
"3 3 a 2020-01-04 0.1 4.0 0.004 Sell\n",
"4 4 a 2020-01-06 1.0 6.0 0.060 Buy\n",
"5 5 a 2020-01-07 1.0 7.0 0.070 Sell\n",
"6 6 a 2020-01-08 2.0 8.0 0.160 Buy\n",
"7 7 b 2020-01-01 1.0 1.0 0.010 Sell\n",
"8 8 b 2020-01-02 0.1 2.0 0.002 Sell\n",
"9 9 b 2020-01-03 1.0 3.0 0.030 Buy\n",
"10 10 b 2020-01-04 0.1 4.0 0.004 Buy\n",
"11 11 b 2020-01-06 1.0 6.0 0.060 Sell\n",
"12 12 b 2020-01-07 1.0 7.0 0.070 Buy\n",
"13 13 b 2020-01-08 2.0 8.0 0.160 Sell\n",
"14 14 c 2020-01-01 1.0 1.0 0.010 Buy\n",
"15 15 c 2020-01-02 0.1 2.0 0.002 Buy\n",
"16 16 c 2020-01-03 1.0 3.0 0.030 Sell\n",
"17 17 c 2020-01-04 0.1 4.0 0.004 Sell\n",
"18 18 c 2020-01-06 1.0 6.0 0.060 Buy\n",
"19 19 c 2020-01-07 2.0 7.0 0.140 Sell\n",
"20 20 c 2020-01-08 2.0 8.0 0.160 Buy\n"
]
}
],
"source": [
"print(orders.records_readable)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Orders(**Config({\n",
" \"wrapper\": \"<vectorbt.base.array_wrapper.ArrayWrapper object at 0x7f9f78606d30> of shape (8, 4)\",\n",
" \"records_arr\": \"<numpy.ndarray object at 0x7f9f780709d0> of shape (11,)\",\n",
" \"col_mapper\": null,\n",
" \"close\": \"<pandas.core.frame.DataFrame object at 0x7f9f782a4390> of shape (8, 4)\"\n",
"}))\n",
" id col idx size price fees side\n",
"0 0 0 0 1.0 1.0 0.010 0\n",
"1 1 0 1 0.1 2.0 0.002 0\n",
"2 4 0 5 1.0 6.0 0.060 0\n",
"3 6 0 7 2.0 8.0 0.160 0\n",
" id col idx size price fees side\n",
"0 0 0 0 1.0 1.0 0.010 0\n",
"1 1 0 1 0.1 2.0 0.002 0\n",
"2 4 0 5 1.0 6.0 0.060 0\n",
"3 6 0 7 2.0 8.0 0.160 0\n",
" id col idx size price fees side\n",
"0 0 0 0 1.0 1.0 0.010 0\n",
"1 1 0 1 0.1 2.0 0.002 0\n",
"2 4 0 5 1.0 6.0 0.060 0\n",
"3 6 0 7 2.0 8.0 0.160 0\n",
"4 9 1 2 1.0 3.0 0.030 0\n",
"5 10 1 3 0.1 4.0 0.004 0\n",
"6 12 1 6 1.0 7.0 0.070 0\n",
"7 14 2 0 1.0 1.0 0.010 0\n",
"8 15 2 1 0.1 2.0 0.002 0\n",
"9 18 2 5 1.0 6.0 0.060 0\n",
"10 20 2 7 2.0 8.0 0.160 0\n",
"11.1 ms ± 387 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(orders.buy)\n",
"print(orders['a'].buy.records)\n",
"print(orders.buy['a'].records)\n",
"print(orders.buy.records)\n",
"\n",
"%timeit big_orders.buy"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Orders(**Config({\n",
" \"wrapper\": \"<vectorbt.base.array_wrapper.ArrayWrapper object at 0x7f9f78606d30> of shape (8, 4)\",\n",
" \"records_arr\": \"<numpy.ndarray object at 0x7fa0223c06b8> of shape (10,)\",\n",
" \"col_mapper\": null,\n",
" \"close\": \"<pandas.core.frame.DataFrame object at 0x7f9f782a4390> of shape (8, 4)\"\n",
"}))\n",
" id col idx size price fees side\n",
"0 2 0 2 1.0 3.0 0.030 1\n",
"1 3 0 3 0.1 4.0 0.004 1\n",
"2 5 0 6 1.0 7.0 0.070 1\n",
" id col idx size price fees side\n",
"0 2 0 2 1.0 3.0 0.030 1\n",
"1 3 0 3 0.1 4.0 0.004 1\n",
"2 5 0 6 1.0 7.0 0.070 1\n",
" id col idx size price fees side\n",
"0 2 0 2 1.0 3.0 0.030 1\n",
"1 3 0 3 0.1 4.0 0.004 1\n",
"2 5 0 6 1.0 7.0 0.070 1\n",
"3 7 1 0 1.0 1.0 0.010 1\n",
"4 8 1 1 0.1 2.0 0.002 1\n",
"5 11 1 5 1.0 6.0 0.060 1\n",
"6 13 1 7 2.0 8.0 0.160 1\n",
"7 16 2 2 1.0 3.0 0.030 1\n",
"8 17 2 3 0.1 4.0 0.004 1\n",
"9 19 2 6 2.0 7.0 0.140 1\n",
"10.7 ms ± 117 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(orders.sell)\n",
"print(orders['a'].sell.records)\n",
"print(orders.sell['a'].records)\n",
"print(orders.sell.records)\n",
"\n",
"%timeit big_orders.sell"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Start 2020-01-01 00:00:00\n",
"End 2020-01-08 00:00:00\n",
"Period 8 days 00:00:00\n",
"Total Records 7\n",
"Total Buy Orders 4\n",
"Total Sell Orders 3\n",
"Min Size 0.1\n",
"Max Size 2.0\n",
"Avg Size 0.885714\n",
"Avg Buy Size 1.025\n",
"Avg Sell Size 0.7\n",
"Avg Buy Price 4.25\n",
"Avg Sell Price 4.666667\n",
"Total Fees 0.336\n",
"Min Fees 0.002\n",
"Max Fees 0.16\n",
"Avg Fees 0.048\n",
"Avg Buy Fees 0.058\n",
"Avg Sell Fees 0.034667\n",
"Name: a, dtype: object\n",
"14 ms ± 171 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"Start 2020-01-01 00:00:00\n",
"End 2020-01-08 00:00:00\n",
"Period 8 days 00:00:00\n",
"Total Records 7\n",
"Total Buy Orders 4\n",
"Total Sell Orders 3\n",
"Min Size 0.1\n",
"Max Size 2.0\n",
"Avg Size 0.885714\n",
"Avg Buy Size 1.025\n",
"Avg Sell Size 0.7\n",
"Avg Buy Price 4.25\n",
"Avg Sell Price 4.666667\n",
"Total Fees 0.336\n",
"Min Fees 0.002\n",
"Max Fees 0.16\n",
"Avg Fees 0.048\n",
"Avg Buy Fees 0.058\n",
"Avg Sell Fees 0.034667\n",
"Name: a, dtype: object\n",
"85.6 ms ± 3.18 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"Start 2020-01-01 00:00:00\n",
"End 2020-01-08 00:00:00\n",
"Period 8 days 00:00:00\n",
"Total Records 5.25\n",
"Total Buy Orders 2.75\n",
"Total Sell Orders 2.5\n",
"Min Size 0.1\n",
"Max Size 2.0\n",
"Avg Size 0.933333\n",
"Avg Buy Size 0.916667\n",
"Avg Sell Size 0.919444\n",
"Avg Buy Price 4.388889\n",
"Avg Sell Price 4.527778\n",
"Total Fees 0.2695\n",
"Min Fees 0.002\n",
"Max Fees 0.16\n",
"Avg Fees 0.051333\n",
"Avg Buy Fees 0.050222\n",
"Avg Sell Fees 0.050222\n",
"Name: agg_func_mean, dtype: object\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/miniconda3/lib/python3.7/site-packages/ipykernel_launcher.py:7: UserWarning: Object has multiple columns. Aggregating using <function mean at 0x7fa020856598>. Pass column to select a single column/group.\n",
" import sys\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"84.7 ms ± 2.13 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"print(orders['a'].stats())\n",
"%timeit big_orders[0].stats(silence_warnings=True)\n",
"\n",
"print(orders.stats(column='a'))\n",
"%timeit big_orders.stats(column=0, silence_warnings=True)\n",
"\n",
"print(orders.stats())\n",
"%timeit big_orders.stats(silence_warnings=True)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-f204e7\"><g class=\"clips\"><clipPath id=\"clipf204e7xyplot\" class=\"plotclip\"><rect width=\"640\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clipf204e7x\"><rect x=\"30\" y=\"0\" width=\"640\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clipf204e7y\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clipf204e7xy\"><rect x=\"30\" y=\"46\" width=\"640\" height=\"261\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"30\" y=\"46\" width=\"640\" height=\"261\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(67,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(147.86,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(228.71,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(309.57,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(390.43,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(471.29,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(552.14,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(633,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,256.82)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,192.56)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,128.31)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,64.05)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"/><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(30,46)\" clip-path=\"url(#clipf204e7xyplot)\"><g class=\"scatterlayer mlayer\"><g class=\"trace scatter trace615bd783-5476-4ca3-8638-ccc06f1ffe19\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"><path class=\"js-line\" d=\"M37,242.95L603,18.05\" style=\"vector-effect: non-scaling-stroke; fill: none; stroke: rgb(31, 119, 180); stroke-opacity: 1; stroke-width: 2px; opacity: 1;\"/></g><g class=\"points\"><path class=\"point\" transform=\"translate(37,242.95)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(117.86,210.82)\" d=\"M3,0A3,3 0 1,1 0,-3A
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"orders['a'].plot().show_svg()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-88ebb4\"><g class=\"clips\"><clipPath id=\"clip88ebb4xyplot\" class=\"plotclip\"><rect width=\"640\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clip88ebb4x\"><rect x=\"30\" y=\"0\" width=\"640\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clip88ebb4y\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clip88ebb4xy\"><rect x=\"30\" y=\"46\" width=\"640\" height=\"261\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"30\" y=\"46\" width=\"640\" height=\"261\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(67,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(147.86,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(228.71,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(309.57,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(390.43,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(471.29,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(552.14,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(633,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,256.82)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,192.56)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,128.31)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,64.05)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"/><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(30,46)\" clip-path=\"url(#clip88ebb4xyplot)\"><g class=\"scatterlayer mlayer\"><g class=\"trace scatter trace0d852ff7-75c2-4f03-97f1-dd0253cece74\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"><path class=\"js-line\" d=\"M37,242.95L603,18.05\" style=\"vector-effect: non-scaling-stroke; fill: none; stroke: rgb(31, 119, 180); stroke-opacity: 1; stroke-width: 2px; opacity: 1;\"/></g><g class=\"points\"><path class=\"point\" transform=\"translate(37,242.95)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(117.86,210.82)\" d=\"M3,0A3,3 0 1,1 0,-3A
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"orders.plot(column='a').show_svg()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"750\" height=\"380\" style=\"\" viewBox=\"0 0 750 380\"><rect x=\"0\" y=\"0\" width=\"750\" height=\"380\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-de2bd3\"><g class=\"clips\"><clipPath id=\"clipde2bd3xyplot\" class=\"plotclip\"><rect width=\"675\" height=\"245\"/></clipPath><clipPath class=\"axesclip\" id=\"clipde2bd3x\"><rect x=\"45\" y=\"0\" width=\"675\" height=\"380\"/></clipPath><clipPath class=\"axesclip\" id=\"clipde2bd3y\"><rect x=\"0\" y=\"67\" width=\"750\" height=\"245\"/></clipPath><clipPath class=\"axesclip\" id=\"clipde2bd3xy\"><rect x=\"45\" y=\"67\" width=\"675\" height=\"245\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"45\" y=\"67\" width=\"675\" height=\"245\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(83.75,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(169.11,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(254.46,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(339.82,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(425.18,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(510.54,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(595.89,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(681.25,0)\" d=\"M0,67v245\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,264.68)\" d=\"M45,0h675\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,204.54)\" d=\"M45,0h675\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,144.39)\" d=\"M45,0h675\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,84.25)\" d=\"M45,0h675\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"/><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(45,67)\" clip-path=\"url(#clipde2bd3xyplot)\"><g class=\"scatterlayer mlayer\"><g class=\"trace scatter trace2184e6aa-811e-43d4-8dd8-c056817cdfac\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"><path class=\"js-line\" d=\"M38.75,227.75L636.25,17.25\" style=\"vector-effect: non-scaling-stroke; fill: none; stroke: rgb(31, 119, 180); stroke-opacity: 1; stroke-width: 2px; opacity: 1;\"/></g><g class=\"points\"><path class=\"point\" transform=\"translate(38.75,227.75)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(124.11,197.68)\" d=\"M3,0A
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"orders.plots(column='a').show_svg()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Trades"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(13,)\n"
]
}
],
"source": [
"trades = vbt.ExitTrades.from_orders(orders)\n",
"trades_grouped = vbt.ExitTrades.from_orders(orders_grouped)\n",
"print(trades.values.shape)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1000,)\n"
]
}
],
"source": [
"big_trades = vbt.ExitTrades.from_orders(big_orders)\n",
"big_trades_grouped = vbt.ExitTrades.from_orders(big_orders_grouped)\n",
"print(big_trades.values.shape)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4.55 ms ± 46.1 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"%timeit vbt.ExitTrades.from_orders(big_orders)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 1 0 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 2 0 1.0 5 6.000000 0.060000 6 7.0 \n",
"3 3 0 2.0 7 8.000000 0.160000 7 8.0 \n",
"4 4 1 1.0 0 1.090909 0.010909 2 3.0 \n",
"5 5 1 0.1 0 1.090909 0.001091 3 4.0 \n",
"6 6 1 1.0 5 6.000000 0.060000 6 7.0 \n",
"7 7 1 2.0 7 8.000000 0.160000 7 8.0 \n",
"8 8 2 1.0 0 1.090909 0.010909 2 3.0 \n",
"9 9 2 0.1 0 1.090909 0.001091 3 4.0 \n",
"10 10 2 1.0 5 6.000000 0.060000 6 7.0 \n",
"11 11 2 1.0 6 7.000000 0.070000 7 8.0 \n",
"12 12 2 1.0 7 8.000000 0.080000 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 1.868182 1.712500 0 1 0 \n",
"1 0.004 0.285818 2.620000 0 1 0 \n",
"2 0.070 0.870000 0.145000 0 1 1 \n",
"3 0.000 -0.160000 -0.010000 0 0 2 \n",
"4 0.030 -1.950000 -1.787500 1 1 3 \n",
"5 0.004 -0.296000 -2.713333 1 1 3 \n",
"6 0.070 -1.130000 -0.188333 1 1 4 \n",
"7 0.000 -0.160000 -0.010000 1 0 5 \n",
"8 0.030 1.868182 1.712500 0 1 6 \n",
"9 0.004 0.285818 2.620000 0 1 6 \n",
"10 0.070 0.870000 0.145000 0 1 7 \n",
"11 0.080 -1.150000 -0.164286 1 1 8 \n",
"12 0.000 -0.080000 -0.010000 0 0 9 \n",
" a b c d\n",
"2020-01-01 1 1 1 1\n",
"2020-01-02 2 2 2 2\n",
"2020-01-03 3 3 3 3\n",
"2020-01-04 4 4 4 4\n",
"2020-01-05 5 5 5 5\n",
"2020-01-06 6 6 6 6\n",
"2020-01-07 7 7 7 7\n",
"2020-01-08 8 8 8 8\n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 1 0 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 2 0 1.0 5 6.000000 0.060000 6 7.0 \n",
"3 3 0 2.0 7 8.000000 0.160000 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 1.868182 1.7125 0 1 0 \n",
"1 0.004 0.285818 2.6200 0 1 0 \n",
"2 0.070 0.870000 0.1450 0 1 1 \n",
"3 0.000 -0.160000 -0.0100 0 0 2 \n",
"2020-01-01 1\n",
"2020-01-02 2\n",
"2020-01-03 3\n",
"2020-01-04 4\n",
"2020-01-05 5\n",
"2020-01-06 6\n",
"2020-01-07 7\n",
"2020-01-08 8\n",
"Name: a, dtype: int64\n",
"1.56 ms ± 288 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"3.37 ms ± 567 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"2.84 ms ± 218 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"3.65 ms ± 225 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(trades.records)\n",
"print(trades.close)\n",
"\n",
"print(trades['a'].records)\n",
"print(trades['a'].close)\n",
"\n",
"%timeit big_trades.iloc[0]\n",
"%timeit big_trades.iloc[:]\n",
"\n",
"%timeit big_trades_grouped.iloc[0]\n",
"%timeit big_trades_grouped.iloc[:]"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Trade Id Column Size Entry Timestamp Avg Entry Price Entry Fees \\\n",
"0 0 a 1.0 2020-01-01 1.090909 0.010909 \n",
"1 1 a 0.1 2020-01-01 1.090909 0.001091 \n",
"2 2 a 1.0 2020-01-06 6.000000 0.060000 \n",
"3 3 a 2.0 2020-01-08 8.000000 0.160000 \n",
"4 4 b 1.0 2020-01-01 1.090909 0.010909 \n",
"5 5 b 0.1 2020-01-01 1.090909 0.001091 \n",
"6 6 b 1.0 2020-01-06 6.000000 0.060000 \n",
"7 7 b 2.0 2020-01-08 8.000000 0.160000 \n",
"8 8 c 1.0 2020-01-01 1.090909 0.010909 \n",
"9 9 c 0.1 2020-01-01 1.090909 0.001091 \n",
"10 10 c 1.0 2020-01-06 6.000000 0.060000 \n",
"11 11 c 1.0 2020-01-07 7.000000 0.070000 \n",
"12 12 c 1.0 2020-01-08 8.000000 0.080000 \n",
"\n",
" Exit Timestamp Avg Exit Price Exit Fees PnL Return Direction \\\n",
"0 2020-01-03 3.0 0.030 1.868182 1.712500 Long \n",
"1 2020-01-04 4.0 0.004 0.285818 2.620000 Long \n",
"2 2020-01-07 7.0 0.070 0.870000 0.145000 Long \n",
"3 2020-01-08 8.0 0.000 -0.160000 -0.010000 Long \n",
"4 2020-01-03 3.0 0.030 -1.950000 -1.787500 Short \n",
"5 2020-01-04 4.0 0.004 -0.296000 -2.713333 Short \n",
"6 2020-01-07 7.0 0.070 -1.130000 -0.188333 Short \n",
"7 2020-01-08 8.0 0.000 -0.160000 -0.010000 Short \n",
"8 2020-01-03 3.0 0.030 1.868182 1.712500 Long \n",
"9 2020-01-04 4.0 0.004 0.285818 2.620000 Long \n",
"10 2020-01-07 7.0 0.070 0.870000 0.145000 Long \n",
"11 2020-01-08 8.0 0.080 -1.150000 -0.164286 Short \n",
"12 2020-01-08 8.0 0.000 -0.080000 -0.010000 Long \n",
"\n",
" Status Position Id \n",
"0 Closed 0 \n",
"1 Closed 0 \n",
"2 Closed 1 \n",
"3 Open 2 \n",
"4 Closed 3 \n",
"5 Closed 3 \n",
"6 Closed 4 \n",
"7 Open 5 \n",
"8 Closed 6 \n",
"9 Closed 6 \n",
"10 Closed 7 \n",
"11 Closed 8 \n",
"12 Open 9 \n"
]
}
],
"source": [
"print(trades.records_readable)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n",
"a 4\n",
"b 4\n",
"c 5\n",
"d 0\n",
"Name: count, dtype: int64\n",
"49.4 µs ± 504 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n",
"group\n",
"first 8\n",
"second 5\n",
"Name: count, dtype: int64\n",
"49 µs ± 303 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
]
}
],
"source": [
"print(trades['a'].count())\n",
"print(trades.count())\n",
"%timeit big_trades.count()\n",
"\n",
"print(trades_grouped.count())\n",
"%timeit big_trades_grouped.count()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Trades(**Config({\n",
" \"wrapper\": \"<vectorbt.base.array_wrapper.ArrayWrapper object at 0x7f9f78606d30> of shape (8, 4)\",\n",
" \"records_arr\": \"<numpy.ndarray object at 0x7f9f7cf155b0> of shape (6,)\",\n",
" \"col_mapper\": null,\n",
" \"ts\": null,\n",
" \"close\": \"<pandas.core.frame.DataFrame object at 0x7f9f782a4390> of shape (8, 4)\"\n",
"}))\n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 1 0 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 2 0 1.0 5 6.000000 0.060000 6 7.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 1.868182 1.7125 0 1 0 \n",
"1 0.004 0.285818 2.6200 0 1 0 \n",
"2 0.070 0.870000 0.1450 0 1 1 \n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 1 0 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 2 0 1.0 5 6.000000 0.060000 6 7.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 1.868182 1.7125 0 1 0 \n",
"1 0.004 0.285818 2.6200 0 1 0 \n",
"2 0.070 0.870000 0.1450 0 1 1 \n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 1 0 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 2 0 1.0 5 6.000000 0.060000 6 7.0 \n",
"3 8 2 1.0 0 1.090909 0.010909 2 3.0 \n",
"4 9 2 0.1 0 1.090909 0.001091 3 4.0 \n",
"5 10 2 1.0 5 6.000000 0.060000 6 7.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 1.868182 1.7125 0 1 0 \n",
"1 0.004 0.285818 2.6200 0 1 0 \n",
"2 0.070 0.870000 0.1450 0 1 1 \n",
"3 0.030 1.868182 1.7125 0 1 6 \n",
"4 0.004 0.285818 2.6200 0 1 6 \n",
"5 0.070 0.870000 0.1450 0 1 7 \n",
"756 µs ± 11 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(trades.winning)\n",
"print(trades['a'].winning.records)\n",
"print(trades.winning['a'].records)\n",
"print(trades.winning.records)\n",
"\n",
"%timeit big_trades.winning"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Trades(**Config({\n",
" \"wrapper\": \"<vectorbt.base.array_wrapper.ArrayWrapper object at 0x7f9f78606d30> of shape (8, 4)\",\n",
" \"records_arr\": \"<numpy.ndarray object at 0x7fa007ca3a28> of shape (7,)\",\n",
" \"col_mapper\": null,\n",
" \"ts\": null,\n",
" \"close\": \"<pandas.core.frame.DataFrame object at 0x7f9f782a4390> of shape (8, 4)\"\n",
"}))\n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 3 0 2.0 7 8.0 0.16 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.0 -0.16 -0.01 0 0 2 \n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 3 0 2.0 7 8.0 0.16 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.0 -0.16 -0.01 0 0 2 \n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 3 0 2.0 7 8.000000 0.160000 7 8.0 \n",
"1 4 1 1.0 0 1.090909 0.010909 2 3.0 \n",
"2 5 1 0.1 0 1.090909 0.001091 3 4.0 \n",
"3 6 1 1.0 5 6.000000 0.060000 6 7.0 \n",
"4 7 1 2.0 7 8.000000 0.160000 7 8.0 \n",
"5 11 2 1.0 6 7.000000 0.070000 7 8.0 \n",
"6 12 2 1.0 7 8.000000 0.080000 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.000 -0.160 -0.010000 0 0 2 \n",
"1 0.030 -1.950 -1.787500 1 1 3 \n",
"2 0.004 -0.296 -2.713333 1 1 3 \n",
"3 0.070 -1.130 -0.188333 1 1 4 \n",
"4 0.000 -0.160 -0.010000 1 0 5 \n",
"5 0.080 -1.150 -0.164286 1 1 8 \n",
"6 0.000 -0.080 -0.010000 0 0 9 \n",
"751 µs ± 8.53 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(trades.losing)\n",
"print(trades['a'].losing.records)\n",
"print(trades.losing['a'].records)\n",
"print(trades.losing.records)\n",
"\n",
"%timeit big_trades.losing"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 1\n",
"1 2\n",
"2 3\n",
"3 0\n",
"Name: a, dtype: int64\n",
" a b c d\n",
"0 1.0 0.0 1.0 NaN\n",
"1 2.0 0.0 2.0 NaN\n",
"2 3.0 0.0 3.0 NaN\n",
"3 0.0 0.0 0.0 NaN\n",
"4 NaN NaN 0.0 NaN\n",
"565 µs ± 7.54 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(trades['a'].winning_streak.to_pd(ignore_index=True))\n",
"print(trades.winning_streak.to_pd(ignore_index=True))\n",
"\n",
"%timeit big_trades.winning_streak"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 0\n",
"1 0\n",
"2 0\n",
"3 1\n",
"Name: a, dtype: int64\n",
" a b c d\n",
"0 0.0 1.0 0.0 NaN\n",
"1 0.0 2.0 0.0 NaN\n",
"2 0.0 3.0 0.0 NaN\n",
"3 1.0 4.0 1.0 NaN\n",
"4 NaN NaN 2.0 NaN\n",
"551 µs ± 5.51 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(trades['a'].losing_streak.to_pd(ignore_index=True))\n",
"print(trades.losing_streak.to_pd(ignore_index=True))\n",
"\n",
"%timeit big_trades.losing_streak"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.75\n",
"a 0.75\n",
"b 0.00\n",
"c 0.60\n",
"d NaN\n",
"Name: win_rate, dtype: float64\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:530: RuntimeWarning:\n",
"\n",
"invalid value encountered in true_divide\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"951 µs ± 3.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"group\n",
"first 0.375\n",
"second 0.600\n",
"Name: win_rate, dtype: float64\n",
"5.47 ms ± 21.8 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(trades['a'].win_rate())\n",
"print(trades.win_rate())\n",
"%timeit big_trades.win_rate()\n",
"\n",
"print(trades.win_rate(group_by=group_by))\n",
"%timeit big_trades.win_rate(group_by=big_group_by)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"18.9\n",
"a 18.900000\n",
"b 0.000000\n",
"c 2.458537\n",
"d NaN\n",
"Name: profit_factor, dtype: float64\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:544: RuntimeWarning:\n",
"\n",
"invalid value encountered in true_divide\n",
"\n",
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:544: RuntimeWarning:\n",
"\n",
"divide by zero encountered in true_divide\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.65 ms ± 136 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"group\n",
"first 0.818182\n",
"second 2.458537\n",
"Name: profit_factor, dtype: float64\n",
"2.57 ms ± 65.5 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(trades['a'].profit_factor())\n",
"print(trades.profit_factor())\n",
"%timeit big_trades.profit_factor()\n",
"\n",
"print(trades_grouped.profit_factor())\n",
"%timeit big_trades_grouped.profit_factor()"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.716\n",
"a 0.7160\n",
"b -0.8840\n",
"c 0.3588\n",
"d NaN\n",
"Name: expectancy, dtype: float64\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:530: RuntimeWarning:\n",
"\n",
"invalid value encountered in true_divide\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.55 ms ± 34.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"group\n",
"first -0.0840\n",
"second 0.3588\n",
"Name: expectancy, dtype: float64\n",
"3.54 ms ± 37.8 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(trades['a'].expectancy())\n",
"print(trades.expectancy())\n",
"%timeit big_trades.expectancy()\n",
"\n",
"print(trades_grouped.expectancy())\n",
"%timeit big_trades_grouped.expectancy()"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.634155521947584\n",
"a 1.634156\n",
"b -2.130073\n",
"c 0.716604\n",
"d NaN\n",
"Name: sqn, dtype: float64\n",
"1.32 ms ± 11.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"group\n",
"first -0.204047\n",
"second 0.716604\n",
"Name: sqn, dtype: float64\n",
"924 µs ± 9.78 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(trades['a'].sqn())\n",
"print(trades.sqn())\n",
"%timeit big_trades.sqn()\n",
"\n",
"print(trades_grouped.sqn())\n",
"%timeit big_trades_grouped.sqn()"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Trades(**Config({\n",
" \"wrapper\": \"<vectorbt.base.array_wrapper.ArrayWrapper object at 0x7f9f78606d30> of shape (8, 4)\",\n",
" \"records_arr\": \"<numpy.ndarray object at 0x7f9f68734be0> of shape (8,)\",\n",
" \"col_mapper\": null,\n",
" \"ts\": null,\n",
" \"close\": \"<pandas.core.frame.DataFrame object at 0x7f9f782a4390> of shape (8, 4)\"\n",
"}))\n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 1 0 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 2 0 1.0 5 6.000000 0.060000 6 7.0 \n",
"3 3 0 2.0 7 8.000000 0.160000 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 1.868182 1.7125 0 1 0 \n",
"1 0.004 0.285818 2.6200 0 1 0 \n",
"2 0.070 0.870000 0.1450 0 1 1 \n",
"3 0.000 -0.160000 -0.0100 0 0 2 \n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 1 0 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 2 0 1.0 5 6.000000 0.060000 6 7.0 \n",
"3 3 0 2.0 7 8.000000 0.160000 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 1.868182 1.7125 0 1 0 \n",
"1 0.004 0.285818 2.6200 0 1 0 \n",
"2 0.070 0.870000 0.1450 0 1 1 \n",
"3 0.000 -0.160000 -0.0100 0 0 2 \n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 1 0 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 2 0 1.0 5 6.000000 0.060000 6 7.0 \n",
"3 3 0 2.0 7 8.000000 0.160000 7 8.0 \n",
"4 8 2 1.0 0 1.090909 0.010909 2 3.0 \n",
"5 9 2 0.1 0 1.090909 0.001091 3 4.0 \n",
"6 10 2 1.0 5 6.000000 0.060000 6 7.0 \n",
"7 12 2 1.0 7 8.000000 0.080000 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 1.868182 1.7125 0 1 0 \n",
"1 0.004 0.285818 2.6200 0 1 0 \n",
"2 0.070 0.870000 0.1450 0 1 1 \n",
"3 0.000 -0.160000 -0.0100 0 0 2 \n",
"4 0.030 1.868182 1.7125 0 1 6 \n",
"5 0.004 0.285818 2.6200 0 1 6 \n",
"6 0.070 0.870000 0.1450 0 1 7 \n",
"7 0.000 -0.080000 -0.0100 0 0 9 \n",
"764 µs ± 12.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(trades.long)\n",
"print(trades['a'].long.records)\n",
"print(trades.long['a'].records)\n",
"print(trades.long.records)\n",
"\n",
"%timeit big_trades.long"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Trades(**Config({\n",
" \"wrapper\": \"<vectorbt.base.array_wrapper.ArrayWrapper object at 0x7f9f78606d30> of shape (8, 4)\",\n",
" \"records_arr\": \"<numpy.ndarray object at 0x7f9f7a2d8608> of shape (5,)\",\n",
" \"col_mapper\": null,\n",
" \"ts\": null,\n",
" \"close\": \"<pandas.core.frame.DataFrame object at 0x7f9f782a4390> of shape (8, 4)\"\n",
"}))\n",
"Empty DataFrame\n",
"Columns: [id, col, size, entry_idx, entry_price, entry_fees, exit_idx, exit_price, exit_fees, pnl, return, direction, status, position_id]\n",
"Index: []\n",
"Empty DataFrame\n",
"Columns: [id, col, size, entry_idx, entry_price, entry_fees, exit_idx, exit_price, exit_fees, pnl, return, direction, status, position_id]\n",
"Index: []\n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 4 1 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 5 1 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 6 1 1.0 5 6.000000 0.060000 6 7.0 \n",
"3 7 1 2.0 7 8.000000 0.160000 7 8.0 \n",
"4 11 2 1.0 6 7.000000 0.070000 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 -1.950 -1.787500 1 1 3 \n",
"1 0.004 -0.296 -2.713333 1 1 3 \n",
"2 0.070 -1.130 -0.188333 1 1 4 \n",
"3 0.000 -0.160 -0.010000 1 0 5 \n",
"4 0.080 -1.150 -0.164286 1 1 8 \n",
"762 µs ± 9.5 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(trades.short)\n",
"print(trades['a'].short.records)\n",
"print(trades.short['a'].records)\n",
"print(trades.short.records)\n",
"\n",
"%timeit big_trades.short"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Trades(**Config({\n",
" \"wrapper\": \"<vectorbt.base.array_wrapper.ArrayWrapper object at 0x7f9f78606d30> of shape (8, 4)\",\n",
" \"records_arr\": \"<numpy.ndarray object at 0x7f9f7cd48978> of shape (3,)\",\n",
" \"col_mapper\": null,\n",
" \"ts\": null,\n",
" \"close\": \"<pandas.core.frame.DataFrame object at 0x7f9f782a4390> of shape (8, 4)\"\n",
"}))\n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 3 0 2.0 7 8.0 0.16 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.0 -0.16 -0.01 0 0 2 \n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 3 0 2.0 7 8.0 0.16 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.0 -0.16 -0.01 0 0 2 \n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 3 0 2.0 7 8.0 0.16 7 8.0 \n",
"1 7 1 2.0 7 8.0 0.16 7 8.0 \n",
"2 12 2 1.0 7 8.0 0.08 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.0 -0.16 -0.01 0 0 2 \n",
"1 0.0 -0.16 -0.01 1 0 5 \n",
"2 0.0 -0.08 -0.01 0 0 9 \n",
"777 µs ± 10.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(trades.open)\n",
"print(trades['a'].open.records)\n",
"print(trades.open['a'].records)\n",
"print(trades.open.records)\n",
"\n",
"%timeit big_trades.open"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Trades(**Config({\n",
" \"wrapper\": \"<vectorbt.base.array_wrapper.ArrayWrapper object at 0x7f9f78606d30> of shape (8, 4)\",\n",
" \"records_arr\": \"<numpy.ndarray object at 0x7f9f7a4e3608> of shape (10,)\",\n",
" \"col_mapper\": null,\n",
" \"ts\": null,\n",
" \"close\": \"<pandas.core.frame.DataFrame object at 0x7f9f782a4390> of shape (8, 4)\"\n",
"}))\n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 1 0 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 2 0 1.0 5 6.000000 0.060000 6 7.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 1.868182 1.7125 0 1 0 \n",
"1 0.004 0.285818 2.6200 0 1 0 \n",
"2 0.070 0.870000 0.1450 0 1 1 \n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 1 0 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 2 0 1.0 5 6.000000 0.060000 6 7.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 1.868182 1.7125 0 1 0 \n",
"1 0.004 0.285818 2.6200 0 1 0 \n",
"2 0.070 0.870000 0.1450 0 1 1 \n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.0 0 1.090909 0.010909 2 3.0 \n",
"1 1 0 0.1 0 1.090909 0.001091 3 4.0 \n",
"2 2 0 1.0 5 6.000000 0.060000 6 7.0 \n",
"3 4 1 1.0 0 1.090909 0.010909 2 3.0 \n",
"4 5 1 0.1 0 1.090909 0.001091 3 4.0 \n",
"5 6 1 1.0 5 6.000000 0.060000 6 7.0 \n",
"6 8 2 1.0 0 1.090909 0.010909 2 3.0 \n",
"7 9 2 0.1 0 1.090909 0.001091 3 4.0 \n",
"8 10 2 1.0 5 6.000000 0.060000 6 7.0 \n",
"9 11 2 1.0 6 7.000000 0.070000 7 8.0 \n",
"\n",
" exit_fees pnl return direction status position_id \n",
"0 0.030 1.868182 1.712500 0 1 0 \n",
"1 0.004 0.285818 2.620000 0 1 0 \n",
"2 0.070 0.870000 0.145000 0 1 1 \n",
"3 0.030 -1.950000 -1.787500 1 1 3 \n",
"4 0.004 -0.296000 -2.713333 1 1 3 \n",
"5 0.070 -1.130000 -0.188333 1 1 4 \n",
"6 0.030 1.868182 1.712500 0 1 6 \n",
"7 0.004 0.285818 2.620000 0 1 6 \n",
"8 0.070 0.870000 0.145000 0 1 7 \n",
"9 0.080 -1.150000 -0.164286 1 1 8 \n",
"759 µs ± 11.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"print(trades.closed)\n",
"print(trades['a'].closed.records)\n",
"print(trades.closed['a'].records)\n",
"print(trades.closed.records)\n",
"\n",
"%timeit big_trades.closed"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:544: RuntimeWarning:\n",
"\n",
"divide by zero encountered in true_divide\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Start 2020-01-01 00:00:00\n",
"End 2020-01-08 00:00:00\n",
"Period 8 days 00:00:00\n",
"First Trade Start 2020-01-01 00:00:00\n",
"Last Trade End 2020-01-08 00:00:00\n",
"Coverage 5 days 00:00:00\n",
"Overlap Coverage 2 days 00:00:00\n",
"Total Records 4\n",
"Total Long Trades 4\n",
"Total Short Trades 0\n",
"Total Closed Trades 3\n",
"Total Open Trades 1\n",
"Open Trade PnL -0.16\n",
"Win Rate [%] 100.0\n",
"Max Win Streak 3\n",
"Max Loss Streak 0\n",
"Best Trade [%] 262.0\n",
"Worst Trade [%] 14.5\n",
"Avg Winning Trade [%] 149.25\n",
"Avg Losing Trade [%] NaN\n",
"Avg Winning Trade Duration 2 days 00:00:00\n",
"Avg Losing Trade Duration NaT\n",
"Profit Factor inf\n",
"Expectancy 1.008\n",
"SQN 2.181955\n",
"Name: a, dtype: object\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:530: RuntimeWarning:\n",
"\n",
"invalid value encountered in true_divide\n",
"\n",
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:544: RuntimeWarning:\n",
"\n",
"invalid value encountered in true_divide\n",
"\n",
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:530: RuntimeWarning:\n",
"\n",
"invalid value encountered in true_divide\n",
"\n",
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:544: RuntimeWarning:\n",
"\n",
"invalid value encountered in true_divide\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"42.1 ms ± 2.02 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
"Start 2020-01-01 00:00:00\n",
"End 2020-01-08 00:00:00\n",
"Period 8 days 00:00:00\n",
"First Trade Start 2020-01-01 00:00:00\n",
"Last Trade End 2020-01-08 00:00:00\n",
"Coverage 5 days 00:00:00\n",
"Overlap Coverage 2 days 00:00:00\n",
"Total Records 4\n",
"Total Long Trades 4\n",
"Total Short Trades 0\n",
"Total Closed Trades 3\n",
"Total Open Trades 1\n",
"Open Trade PnL -0.16\n",
"Win Rate [%] 100.0\n",
"Max Win Streak 3\n",
"Max Loss Streak 0\n",
"Best Trade [%] 262.0\n",
"Worst Trade [%] 14.5\n",
"Avg Winning Trade [%] 149.25\n",
"Avg Losing Trade [%] NaN\n",
"Avg Winning Trade Duration 2 days 00:00:00\n",
"Avg Losing Trade Duration NaT\n",
"Profit Factor inf\n",
"Expectancy 1.008\n",
"SQN 2.181955\n",
"Name: a, dtype: object\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:530: RuntimeWarning:\n",
"\n",
"invalid value encountered in true_divide\n",
"\n",
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:544: RuntimeWarning:\n",
"\n",
"divide by zero encountered in true_divide\n",
"\n",
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:544: RuntimeWarning:\n",
"\n",
"invalid value encountered in true_divide\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"44.4 ms ± 1.17 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
"Start 2020-01-01 00:00:00\n",
"End 2020-01-08 00:00:00\n",
"Period 8 days 00:00:00\n",
"First Trade Start 2020-01-01 00:00:00\n",
"Last Trade End 2020-01-08 00:00:00\n",
"Coverage 5 days 08:00:00\n",
"Overlap Coverage 2 days 00:00:00\n",
"Total Records 3.25\n",
"Total Long Trades 2.0\n",
"Total Short Trades 1.25\n",
"Total Closed Trades 2.5\n",
"Total Open Trades 0.75\n",
"Open Trade PnL -0.1\n",
"Win Rate [%] 58.333333\n",
"Max Win Streak 2.0\n",
"Max Loss Streak 1.333333\n",
"Best Trade [%] 168.388889\n",
"Worst Trade [%] -91.087302\n",
"Avg Winning Trade [%] 149.25\n",
"Avg Losing Trade [%] -86.367063\n",
"Avg Winning Trade Duration 2 days 00:00:00\n",
"Avg Losing Trade Duration 1 days 12:00:00\n",
"Profit Factor inf\n",
"Expectancy 0.117056\n",
"SQN 0.189316\n",
"Name: agg_func_mean, dtype: object\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:530: RuntimeWarning:\n",
"\n",
"invalid value encountered in true_divide\n",
"\n",
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:544: RuntimeWarning:\n",
"\n",
"divide by zero encountered in true_divide\n",
"\n",
"/Users/olegpolakow/Documents/SourceTree/vectorbt/vectorbt/portfolio/trades.py:544: RuntimeWarning:\n",
"\n",
"invalid value encountered in true_divide\n",
"\n",
"/Users/olegpolakow/miniconda3/lib/python3.7/site-packages/ipykernel_launcher.py:7: UserWarning:\n",
"\n",
"Object has multiple columns. Aggregating using <function mean at 0x7fa020856598>. Pass column to select a single column/group.\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"44.9 ms ± 1.26 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"print(trades['a'].stats())\n",
"%timeit big_trades[0].stats(silence_warnings=True)\n",
"\n",
"print(trades.stats(column='a'))\n",
"%timeit big_trades.stats(column=0, silence_warnings=True)\n",
"\n",
"print(trades.stats())\n",
"%timeit big_trades.stats(silence_warnings=True)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-b04e8a\"><g class=\"clips\"><clipPath id=\"clipb04e8axyplot\" class=\"plotclip\"><rect width=\"640\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clipb04e8ax\"><rect x=\"30\" y=\"0\" width=\"640\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clipb04e8ay\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clipb04e8axy\"><rect x=\"30\" y=\"46\" width=\"640\" height=\"261\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"30\" y=\"46\" width=\"640\" height=\"261\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"><path data-index=\"0\" fill-rule=\"evenodd\" d=\"M66.38,287.25H228.45V225.41H66.38Z\" clip-path=\"url(#clipb04e8axy)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 128, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"1\" fill-rule=\"evenodd\" d=\"M66.38,287.25H309.48V193.01H66.38Z\" clip-path=\"url(#clipb04e8axy)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 128, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"2\" fill-rule=\"evenodd\" d=\"M471.55,128.22H552.59V95.82H471.55Z\" clip-path=\"url(#clipb04e8axy)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 128, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"3\" fill-rule=\"evenodd\" d=\"M552.59,95.82H633.62V63.43H552.59Z\" clip-path=\"url(#clipb04e8axy)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(255, 0, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"4\" fill-rule=\"evenodd\" d=\"M633.62,63.43H633.62V63.43H633.62Z\" clip-path=\"url(#clipb04e8axy)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(255, 0, 0); fill-opacity: 1; stroke-width: 0px;\"/></g><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(66.38,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(147.41,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(228.45,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(309.48,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(390.52,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(471.55,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(552.59,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(633.62,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,257.8)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,193.01)\" d=\"M30,0h640\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,128.22)\" d=\"M30,0h64
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"trades['c'].plot().show_svg()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"700\" height=\"350\" style=\"\" viewBox=\"0 0 700 350\"><rect x=\"0\" y=\"0\" width=\"700\" height=\"350\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-843819\"><g class=\"clips\"><clipPath id=\"clip843819xyplot\" class=\"plotclip\"><rect width=\"602\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clip843819x\"><rect x=\"68\" y=\"0\" width=\"602\" height=\"350\"/></clipPath><clipPath class=\"axesclip\" id=\"clip843819y\"><rect x=\"0\" y=\"46\" width=\"700\" height=\"261\"/></clipPath><clipPath class=\"axesclip\" id=\"clip843819xy\"><rect x=\"68\" y=\"46\" width=\"602\" height=\"261\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"68\" y=\"46\" width=\"602\" height=\"261\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(105.33,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(211.32,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(317.3,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(423.29,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(529.28,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(635.27,0)\" d=\"M0,46v261\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"><path class=\"ygrid crisp\" transform=\"translate(0,236.47)\" d=\"M68,0h602\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,196.69)\" d=\"M68,0h602\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,156.91)\" d=\"M68,0h602\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,117.13)\" d=\"M68,0h602\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"ygrid crisp\" transform=\"translate(0,77.35)\" d=\"M68,0h602\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/></g></g><g class=\"zerolinelayer\"><path class=\"yzl zl crisp\" transform=\"translate(0,276.25)\" d=\"M68,0h602\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 2px;\"/></g><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(68,46)\" clip-path=\"url(#clip843819xyplot)\"><g class=\"scatterlayer mlayer\"><g class=\"trace scatter traced6244cc8-81aa-4320-8773-35fd6a0ac042\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"/><g class=\"points\"><path class=\"point plotly-customdata\" transform=\"translate(37.33,94)\" d=\"M5.78,0A5.78,5.78 0 1,1 0,-5.78A5.78,5.78 0 0,1 5.78,0Z\" style=\"opacity: 0.847845; stroke-width: 1px; fill: rgb(55, 177, 63); fill-opacity: 1; stroke: rgb(38, 123, 44); stroke-opacity: 1;\"/><path class=\"point plotly-customdata\" transform=\"translate(143.32,21.8)\" d=\"M7,0A7,7 0 1,1 0,-7A7,7 0 0,1 7,0Z\" style=\"opacity: 0.9; stroke-width: 1px; fill: rgb(55, 17
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"trades['c'].plot_pnl().show_svg()"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"750\" height=\"670\" style=\"\" viewBox=\"0 0 750 670\"><rect x=\"0\" y=\"0\" width=\"750\" height=\"670\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-6012c9\"><g class=\"clips\"><clipPath id=\"clip6012c9xyplot\" class=\"plotclip\"><rect width=\"627\" height=\"240.24626865671644\"/></clipPath><clipPath id=\"clip6012c9x2y2plot\" class=\"plotclip\"><rect width=\"627\" height=\"240.24626865671644\"/></clipPath><clipPath class=\"axesclip\" id=\"clip6012c9x\"><rect x=\"93\" y=\"0\" width=\"627\" height=\"670\"/></clipPath><clipPath class=\"axesclip\" id=\"clip6012c9y\"><rect x=\"0\" y=\"91\" width=\"750\" height=\"240.24626865671644\"/></clipPath><clipPath class=\"axesclip\" id=\"clip6012c9xy\"><rect x=\"93\" y=\"91\" width=\"627\" height=\"240.24626865671644\"/></clipPath><clipPath class=\"axesclip\" id=\"clip6012c9y2\"><rect x=\"0\" y=\"361.75373134328356\" width=\"750\" height=\"240.24626865671644\"/></clipPath><clipPath class=\"axesclip\" id=\"clip6012c9xy2\"><rect x=\"93\" y=\"361.75373134328356\" width=\"627\" height=\"240.24626865671644\"/></clipPath><clipPath class=\"axesclip\" id=\"clip6012c9x2\"><rect x=\"93\" y=\"0\" width=\"627\" height=\"670\"/></clipPath><clipPath class=\"axesclip\" id=\"clip6012c9x2y\"><rect x=\"93\" y=\"91\" width=\"627\" height=\"240.24626865671644\"/></clipPath><clipPath class=\"axesclip\" id=\"clip6012c9x2y2\"><rect x=\"93\" y=\"361.75373134328356\" width=\"627\" height=\"240.24626865671644\"/></clipPath></g><g class=\"gradients\"/><g class=\"patterns\"/></defs><g class=\"bglayer\"><rect class=\"bg\" x=\"93\" y=\"91\" width=\"627\" height=\"240.24626865671644\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/><rect class=\"bg\" x=\"93\" y=\"361.75373134328356\" width=\"627\" height=\"240.24626865671644\" style=\"fill: rgb(229, 236, 246); fill-opacity: 1; stroke-width: 0;\"/></g><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"><path data-index=\"0\" fill-rule=\"evenodd\" d=\"M128.72,312.78H287.45V256.03H128.72Z\" clip-path=\"url(#clip6012c9xy)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 128, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"1\" fill-rule=\"evenodd\" d=\"M128.72,312.78H366.82V226.3H128.72Z\" clip-path=\"url(#clip6012c9xy)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 128, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"2\" fill-rule=\"evenodd\" d=\"M525.55,166.84H604.9100000000001V137.12H525.55Z\" clip-path=\"url(#clip6012c9xy)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(0, 128, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"3\" fill-rule=\"evenodd\" d=\"M604.9100000000001,137.12H684.28V107.39H604.9100000000001Z\" clip-path=\"url(#clip6012c9xy)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(255, 0, 0); fill-opacity: 1; stroke-width: 0px;\"/><path data-index=\"4\" fill-rule=\"evenodd\" d=\"M684.28,107.39H684.28V107.39H684.28Z\" clip-path=\"url(#clip6012c9xy)\" style=\"opacity: 0.2; stroke: rgb(0, 0, 0); stroke-opacity: 0; fill: rgb(255, 0, 0); fill-opacity: 1; stroke-width: 0px;\"/></g><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(128.72,0)\" d=\"M0,91v240.24626865671644\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(208.09,0)\" d=\"M0,91v240.24626865671644\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(287.45,0)\" d=\"M0,91v240.24626865671644\" style=\"stroke: rgb(255, 255, 255); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(366.82,0)\" d=\
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"trades.plots(column='c').show_svg()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Positions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(10,)\n"
]
}
],
"source": [
"positions = vbt.Positions.from_trades(trades)\n",
"positions_grouped = vbt.Positions.from_trades(trades_grouped)\n",
"print(positions.values.shape)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1000,)\n"
]
}
],
"source": [
"big_positions = vbt.Positions.from_trades(big_trades)\n",
"big_positions_grouped = vbt.Positions.from_trades(big_trades_grouped)\n",
"print(big_positions.values.shape)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"724 µs ± 12.6 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"source": [
"%timeit vbt.Positions.from_trades(big_trades)"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.1 0 1.090909 0.012 3 3.090909 \n",
"1 1 0 1.0 5 6.000000 0.060 6 7.000000 \n",
"2 2 0 2.0 7 8.000000 0.160 7 8.000000 \n",
"3 3 1 1.1 0 1.090909 0.012 3 3.090909 \n",
"4 4 1 1.0 5 6.000000 0.060 6 7.000000 \n",
"5 5 1 2.0 7 8.000000 0.160 7 8.000000 \n",
"6 6 2 1.1 0 1.090909 0.012 3 3.090909 \n",
"7 7 2 1.0 5 6.000000 0.060 6 7.000000 \n",
"8 8 2 1.0 6 7.000000 0.070 7 8.000000 \n",
"9 9 2 1.0 7 8.000000 0.080 7 8.000000 \n",
"\n",
" exit_fees pnl return direction status \n",
"0 0.034 2.154 1.795000 0 1 \n",
"1 0.070 0.870 0.145000 0 1 \n",
"2 0.000 -0.160 -0.010000 0 0 \n",
"3 0.034 -2.246 -1.871667 1 1 \n",
"4 0.070 -1.130 -0.188333 1 1 \n",
"5 0.000 -0.160 -0.010000 1 0 \n",
"6 0.034 2.154 1.795000 0 1 \n",
"7 0.070 0.870 0.145000 0 1 \n",
"8 0.080 -1.150 -0.164286 1 1 \n",
"9 0.000 -0.080 -0.010000 0 0 \n",
" a b c d\n",
"2020-01-01 1 1 1 1\n",
"2020-01-02 2 2 2 2\n",
"2020-01-03 3 3 3 3\n",
"2020-01-04 4 4 4 4\n",
"2020-01-05 5 5 5 5\n",
"2020-01-06 6 6 6 6\n",
"2020-01-07 7 7 7 7\n",
"2020-01-08 8 8 8 8\n",
" id col size entry_idx entry_price entry_fees exit_idx exit_price \\\n",
"0 0 0 1.1 0 1.090909 0.012 3 3.090909 \n",
"1 1 0 1.0 5 6.000000 0.060 6 7.000000 \n",
"2 2 0 2.0 7 8.000000 0.160 7 8.000000 \n",
"\n",
" exit_fees pnl return direction status \n",
"0 0.034 2.154 1.795 0 1 \n",
"1 0.070 0.870 0.145 0 1 \n",
"2 0.000 -0.160 -0.010 0 0 \n",
"2020-01-01 1\n",
"2020-01-02 2\n",
"2020-01-03 3\n",
"2020-01-04 4\n",
"2020-01-05 5\n",
"2020-01-06 6\n",
"2020-01-07 7\n",
"2020-01-08 8\n",
"Name: a, dtype: int64\n",
"1.4 ms ± 43.5 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
"3.06 ms ± 757 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"2.52 ms ± 53.5 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
"3.22 ms ± 89.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
]
}
],
"source": [
"print(positions.records)\n",
"print(positions.close)\n",
"\n",
"print(positions['a'].records)\n",
"print(positions['a'].close)\n",
"\n",
"%timeit big_positions.iloc[0]\n",
"%timeit big_positions.iloc[:]\n",
"\n",
"%timeit big_positions_grouped.iloc[0]\n",
"%timeit big_positions_grouped.iloc[:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.3"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {
"01f2862665d847b1bb454f087835c35c": {
"buffers": [
{
"data": "AAAAAAAAJEAAAAAAAAAmQAAAAAAAAChA",
"encoding": "base64",
"path": [
"_data",
0,
"x",
"value"
]
}
],
"model_module": "plotlywidget",
"model_module_version": "^4.12.0",
"model_name": "FigureModel",
"state": {
"_config": {
"plotlyServerURL": "https://plot.ly"
},
"_data": [
{
"name": "(0, 'a')",
"opacity": 1,
"showlegend": true,
"type": "histogram",
"uid": "d6ad8d12-ddd8-4fb4-aff9-ddb84ce5205f",
"x": {
"dtype": "float64",
"shape": [
3
],
"value": {}
}
}
],
"_js2py_layoutDelta": {},
"_js2py_pointsCallback": {},
"_js2py_relayout": {},
"_js2py_restyle": {},
"_js2py_traceDeltas": {},
"_js2py_update": {},
"_last_layout_edit_id": 4,
"_last_trace_edit_id": 4,
"_layout": {
"barmode": "overlay",
"height": 350,
"legend": {
"orientation": "h",
"traceorder": "normal",
"x": 1,
"xanchor": "right",
"y": 1.02,
"yanchor": "bottom"
},
"margin": {
"b": 30,
"l": 30,
"r": 30,
"t": 30
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#dc3912",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
"#bcbd22",
"#17becf"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"width": 700
},
"_py2js_animate": {},
"_py2js_deleteTraces": {},
"_py2js_moveTraces": {},
"_py2js_removeLayoutProps": {},
"_py2js_removeTraceProps": {},
"_py2js_restyle": {},
"_view_count": 0
}
},
"79a61fd995a84866a542584e78df56d1": {
"buffers": [
{
"data": "AAAAAAAAJEAAAAAAAAAmQAAAAAAAAChA",
"encoding": "base64",
"path": [
"_data",
0,
"y",
"value"
]
}
],
"model_module": "plotlywidget",
"model_module_version": "^4.12.0",
"model_name": "FigureModel",
"state": {
"_config": {
"plotlyServerURL": "https://plot.ly"
},
"_data": [
{
"name": "(0, 'a')",
"showlegend": true,
"type": "box",
"uid": "1fa6ad97-f9a4-4da3-841b-66b3f4beb921",
"y": {
"dtype": "float64",
"shape": [
3
],
"value": {}
}
}
],
"_js2py_layoutDelta": {},
"_js2py_pointsCallback": {},
"_js2py_relayout": {},
"_js2py_restyle": {},
"_js2py_traceDeltas": {},
"_js2py_update": {},
"_last_layout_edit_id": 3,
"_last_trace_edit_id": 3,
"_layout": {
"height": 350,
"legend": {
"orientation": "h",
"traceorder": "normal",
"x": 1,
"xanchor": "right",
"y": 1.02,
"yanchor": "bottom"
},
"margin": {
"b": 30,
"l": 30,
"r": 30,
"t": 30
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#dc3912",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
"#bcbd22",
"#17becf"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"width": 700
},
"_py2js_animate": {},
"_py2js_deleteTraces": {},
"_py2js_moveTraces": {},
"_py2js_removeLayoutProps": {},
"_py2js_removeTraceProps": {},
"_py2js_restyle": {},
"_view_count": 0
}
},
"89915dfe9c2b4c91a324caa8d4969786": {
"buffers": [
{
"data": "AAAAAAAAJEAAAAAAAAAmQAAAAAAAAChA",
"encoding": "base64",
"path": [
"_data",
0,
"y",
"value"
]
},
{
"data": "AAAAAAAAKkAAAAAAAAAsQAAAAAAAACpAAAAAAAAAKEAAAAAAAAAmQAAAAAAAACRA",
"encoding": "base64",
"path": [
"_data",
1,
"y",
"value"
]
}
],
"model_module": "plotlywidget",
"model_module_version": "^4.12.0",
"model_name": "FigureModel",
"state": {
"_config": {
"plotlyServerURL": "https://plot.ly"
},
"_data": [
{
"name": "0",
"showlegend": true,
"type": "box",
"uid": "e0541b76-ce8c-45e1-8a1e-68e4c5921079",
"y": {
"dtype": "float64",
"shape": [
3
],
"value": {}
}
},
{
"name": "1",
"showlegend": true,
"type": "box",
"uid": "a9166b36-beee-4861-9054-495819dcb9ef",
"y": {
"dtype": "float64",
"shape": [
6
],
"value": {}
}
}
],
"_js2py_layoutDelta": {},
"_js2py_pointsCallback": {},
"_js2py_relayout": {},
"_js2py_restyle": {},
"_js2py_traceDeltas": {},
"_js2py_update": {},
"_last_layout_edit_id": 4,
"_last_trace_edit_id": 4,
"_layout": {
"height": 350,
"legend": {
"orientation": "h",
"traceorder": "normal",
"x": 1,
"xanchor": "right",
"y": 1.02,
"yanchor": "bottom"
},
"margin": {
"b": 30,
"l": 30,
"r": 30,
"t": 30
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#dc3912",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
"#bcbd22",
"#17becf"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"width": 700
},
"_py2js_animate": {},
"_py2js_deleteTraces": {},
"_py2js_moveTraces": {},
"_py2js_removeLayoutProps": {},
"_py2js_removeTraceProps": {},
"_py2js_restyle": {},
"_view_count": 0
}
},
"93ddeb7c978d49de996a76faa04701cc": {
"buffers": [
{
"data": "AAAAAAAAJEAAAAAAAAAmQAAAAAAAAChA",
"encoding": "base64",
"path": [
"_data",
0,
"x",
"value"
]
},
{
"data": "AAAAAAAAKkAAAAAAAAAsQAAAAAAAACpAAAAAAAAAKEAAAAAAAAAmQAAAAAAAACRA",
"encoding": "base64",
"path": [
"_data",
1,
"x",
"value"
]
}
],
"model_module": "plotlywidget",
"model_module_version": "^4.12.0",
"model_name": "FigureModel",
"state": {
"_config": {
"plotlyServerURL": "https://plot.ly"
},
"_data": [
{
"name": "0",
"opacity": 0.75,
"showlegend": true,
"type": "histogram",
"uid": "bcc86c80-120a-4970-a4b2-cbee900c6043",
"x": {
"dtype": "float64",
"shape": [
3
],
"value": {}
}
},
{
"name": "1",
"opacity": 0.75,
"showlegend": true,
"type": "histogram",
"uid": "ff85ebe1-0dcb-4f0a-a6ee-7d45aad5accf",
"x": {
"dtype": "float64",
"shape": [
6
],
"value": {}
}
}
],
"_js2py_layoutDelta": {},
"_js2py_pointsCallback": {},
"_js2py_relayout": {},
"_js2py_restyle": {},
"_js2py_traceDeltas": {},
"_js2py_update": {},
"_last_layout_edit_id": 5,
"_last_trace_edit_id": 5,
"_layout": {
"barmode": "overlay",
"height": 350,
"legend": {
"orientation": "h",
"traceorder": "normal",
"x": 1,
"xanchor": "right",
"y": 1.02,
"yanchor": "bottom"
},
"margin": {
"b": 30,
"l": 30,
"r": 30,
"t": 30
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#dc3912",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
"#bcbd22",
"#17becf"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"width": 700
},
"_py2js_animate": {},
"_py2js_deleteTraces": {},
"_py2js_moveTraces": {},
"_py2js_removeLayoutProps": {},
"_py2js_removeTraceProps": {},
"_py2js_restyle": {},
"_view_count": 0
}
},
"a1d98ee391a546aab5dee0d48124fe8b": {
"buffers": [
{
"data": "AAAAAAAAJEAAAAAAAAAmQAAAAAAAAChA",
"encoding": "base64",
"path": [
"_data",
0,
"y",
"value"
]
},
{
"data": "AAAAAAAAKkAAAAAAAAAsQAAAAAAAACpA",
"encoding": "base64",
"path": [
"_data",
1,
"y",
"value"
]
},
{
"data": "AAAAAAAAKEAAAAAAAAAmQAAAAAAAACRA",
"encoding": "base64",
"path": [
"_data",
2,
"y",
"value"
]
},
{
"data": "",
"encoding": "base64",
"path": [
"_data",
3,
"y",
"value"
]
}
],
"model_module": "plotlywidget",
"model_module_version": "^4.12.0",
"model_name": "FigureModel",
"state": {
"_config": {
"plotlyServerURL": "https://plot.ly"
},
"_data": [
{
"name": "(0, 'a')",
"showlegend": true,
"type": "box",
"uid": "bff04ef0-65a9-4d0d-affc-c114f58b1c09",
"y": {
"dtype": "float64",
"shape": [
3
],
"value": {}
}
},
{
"name": "(1, 'b')",
"showlegend": true,
"type": "box",
"uid": "cfcf055c-4505-408d-b1b8-019b4745e9f1",
"y": {
"dtype": "float64",
"shape": [
3
],
"value": {}
}
},
{
"name": "(1, 'c')",
"showlegend": true,
"type": "box",
"uid": "ab247355-ae71-437b-a265-1fa933b14825",
"y": {
"dtype": "float64",
"shape": [
3
],
"value": {}
}
},
{
"name": "(1, 'd')",
"showlegend": true,
"type": "box",
"uid": "a65f4612-893d-4275-a63c-194d79ff9835",
"y": {
"dtype": "float64",
"shape": [
0
],
"value": {}
}
}
],
"_js2py_layoutDelta": {},
"_js2py_pointsCallback": {},
"_js2py_relayout": {},
"_js2py_restyle": {},
"_js2py_traceDeltas": {},
"_js2py_update": {},
"_last_layout_edit_id": 6,
"_last_trace_edit_id": 6,
"_layout": {
"height": 350,
"legend": {
"orientation": "h",
"traceorder": "normal",
"x": 1,
"xanchor": "right",
"y": 1.02,
"yanchor": "bottom"
},
"margin": {
"b": 30,
"l": 30,
"r": 30,
"t": 30
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#dc3912",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
"#bcbd22",
"#17becf"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"width": 700
},
"_py2js_animate": {},
"_py2js_deleteTraces": {},
"_py2js_moveTraces": {},
"_py2js_removeLayoutProps": {},
"_py2js_removeTraceProps": {},
"_py2js_restyle": {},
"_view_count": 0
}
},
"fd37871bcc874793ba07083a4019fbc3": {
"buffers": [
{
"data": "AAAAAAAAJEAAAAAAAAAmQAAAAAAAAChA",
"encoding": "base64",
"path": [
"_data",
0,
"x",
"value"
]
},
{
"data": "AAAAAAAAKkAAAAAAAAAsQAAAAAAAACpA",
"encoding": "base64",
"path": [
"_data",
1,
"x",
"value"
]
},
{
"data": "AAAAAAAAKEAAAAAAAAAmQAAAAAAAACRA",
"encoding": "base64",
"path": [
"_data",
2,
"x",
"value"
]
},
{
"data": "",
"encoding": "base64",
"path": [
"_data",
3,
"x",
"value"
]
}
],
"model_module": "plotlywidget",
"model_module_version": "^4.12.0",
"model_name": "FigureModel",
"state": {
"_config": {
"plotlyServerURL": "https://plot.ly"
},
"_data": [
{
"name": "(0, 'a')",
"opacity": 0.75,
"showlegend": true,
"type": "histogram",
"uid": "4975905f-a756-4611-89a5-9c7ae1744815",
"x": {
"dtype": "float64",
"shape": [
3
],
"value": {}
}
},
{
"name": "(1, 'b')",
"opacity": 0.75,
"showlegend": true,
"type": "histogram",
"uid": "43f4ff61-f06e-4ba4-9da8-0dbe4f6f076a",
"x": {
"dtype": "float64",
"shape": [
3
],
"value": {}
}
},
{
"name": "(1, 'c')",
"opacity": 0.75,
"showlegend": true,
"type": "histogram",
"uid": "265a8e4f-c1c4-4120-9217-95abd3c1cc52",
"x": {
"dtype": "float64",
"shape": [
3
],
"value": {}
}
},
{
"name": "(1, 'd')",
"opacity": 0.75,
"showlegend": true,
"type": "histogram",
"uid": "410fa7a5-e933-41c7-9804-947f616077b6",
"x": {
"dtype": "float64",
"shape": [
0
],
"value": {}
}
}
],
"_js2py_layoutDelta": {},
"_js2py_pointsCallback": {},
"_js2py_relayout": {},
"_js2py_restyle": {},
"_js2py_traceDeltas": {},
"_js2py_update": {},
"_last_layout_edit_id": 7,
"_last_trace_edit_id": 7,
"_layout": {
"barmode": "overlay",
"height": 350,
"legend": {
"orientation": "h",
"traceorder": "normal",
"x": 1,
"xanchor": "right",
"y": 1.02,
"yanchor": "bottom"
},
"margin": {
"b": 30,
"l": 30,
"r": 30,
"t": 30
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#1f77b4",
"#ff7f0e",
"#2ca02c",
"#dc3912",
"#9467bd",
"#8c564b",
"#e377c2",
"#7f7f7f",
"#bcbd22",
"#17becf"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"width": 700
},
"_py2js_animate": {},
"_py2js_deleteTraces": {},
"_py2js_moveTraces": {},
"_py2js_removeLayoutProps": {},
"_py2js_removeTraceProps": {},
"_py2js_restyle": {},
"_view_count": 0
}
}
},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}