{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Intraday vwap mean reverting\n", "\n", "Desription: mean reverting intraday strategy with momentum entry\n", "\n", "Goal is to recreate strategy in vectorbptro and compare with v2trading engine backtest.\n", "\n", "Symbol: BAC\n", "Timeframe: 12s\n", "Backtested on: 1s\n", "Entry window: 0 - 380 (mins. from open)\n", "EOD Exit: 382-390\n", "\n", "Indicators:\n", "- vwap_cum - Anchored daily cumulative vwap \n", "- div_vwap_cum - Divergence of vwap_cum and close \n", "- div_vwap_angle - Linreg angle of div_vwap_cum over period N (hp1)\n", "\n", "**Long entries:**\n", "- div_vwap_angle.AND.go_short_if_fallingc = 3 (hp2)\n", "- div_vwap_cum.AND.go_short_if_above = 0 (hp3)\n", "\n", "**Short entries:**\n", "- div_vwap_angle.AND.go_long_if_risingc = 3 (hp2)\n", "- div_vwap_cum.AND.go_long_if_below = 0 (hp3)\n", "\n", "**Exits:**\n", "only SL, TP pct based\n", "- SL: 0.3 (hp4)\n", "- TP: 0.4 (hp5)\n", "\n", "hp - hyperparameters for tuning" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import vectorbtpro as vbt\n", "import ttools as tts\n", "from lightweight_charts import chart, Panel, PlotDFAccessor, PlotSRAccessor\n", "import talib\n", "from numba import jit\n", "import pandas as pd\n", "import numpy as np\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "255a22ec7b404e7ea929bf9706a23368", "version_major": 2, "version_minor": 0 }, "text/plain": [ "100%|##########| 1/1 [00:02<00:00, 2.76s/it, symbol=BAC]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ " #fetching from remote db\n", "from lib.db import Connection\n", "SYMBOL = \"BAC\"\n", "SCHEMA = \"ohlcv_1s\" #time based 1s other options ohlcv_vol_200 (volume based ohlcv with resolution of 200), ohlcv_renko_20 (renko with 20 bricks size) ...\n", "DB = \"market_data\"\n", "\n", "con = Connection(db_name=DB, default_schema=SCHEMA, create_db=True)\n", "basic_data = con.pull(symbols=[SYMBOL], schema=SCHEMA,start=\"2024-10-14\", end=\"2024-10-17\", tz_convert='America/New_York')\n", "\n", "#basic_data = basic_data.add_symbol(\"BAC2\", basic_data.data[\"BAC\"])\n", "\n", "#basic_data.index.normalize().nunique()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "basic_data = basic_data[['open',\n", " 'high',\n", " 'low',\n", " 'close',\n", " 'volume']]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#Resample to 12s\n", "s12_data = basic_data.resample(\"12s\")\n", "s12_data = s12_data.transform(lambda df: df.between_time('09:30', '16:00').dropna())\n", "\n", "s12_data.data[\"BAC\"].lw.plot()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['BAC']" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#s12_data = s12_data.add_symbol(\"BAC3\", s12_data.data[\"BAC\"])\n", "s12_data.symbols" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "#s12_data = s12_data.add_symbol(\"BAC-SHORT\", s12_data.data[\"BAC-LONG\"])" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['talib:DIV']" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "vbt.IF.list_indicators(\"*DIV*\")" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "LINEARREG_ANGLE.run(\n", " close,\n", " timeperiod=Default(value=14),\n", " timeframe=Default(value=None),\n", " short_name='linearreg_angle',\n", " hide_params=None,\n", " hide_default=True,\n", " **kwargs\n", "):\n", " Run `LINEARREG_ANGLE` indicator.\n", " \n", " * Inputs: `close`\n", " * Parameters: `timeperiod`, `timeframe`\n", " * Outputs: `real`\n", " \n", " Pass a list of parameter names as `hide_params` to hide their column levels, or True to hide all.\n", " Set `hide_default` to False to show the column levels of the parameters with a default value.\n", " \n", " Other keyword arguments are passed to `LINEARREG_ANGLE.run_pipeline`.\n" ] } ], "source": [ "vbt.phelp(vbt.indicator(\"talib:LINEARREG_ANGLE\").run)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "from numba import jit\n", "import numpy as np\n", "\n", "@jit(nopython=True)\n", "def isrisingc(pole: np.ndarray, pocet: int) -> np.ndarray:\n", " # Ensure pocet is valid\n", " if pocet < 1 or pocet > pole.shape[0]:\n", " raise ValueError(\"Invalid window size.\")\n", "\n", " # Create a result array initialized to False\n", " result = np.zeros(pole.shape[0], dtype=np.bool_)\n", "\n", " # Iterate through the array, starting from the first valid rolling window\n", " for i in range(pocet - 1, pole.shape[0]):\n", " is_increasing = True\n", " # Compare the current value with the previous value within the rolling window\n", " for j in range(i - pocet + 2, i + 1): # Start comparison from the second element in the window\n", " if pole[j] <= pole[j - 1]: # Check if current element is not greater than the previous one\n", " is_increasing = False\n", " break\n", " result[i] = is_increasing\n", "\n", " return result\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "#s12_data.ohlcv.data[\"BAC\"].vbt.xloc[slice(\"2024-10-14 15:50:00\", \"2024-10-15 15:50:00\")].obj.head(10)\n", "\n", "# a = div_vwap_cum.xloc[slice(\"2024-10-14 15:50:00\", \"2024-10-15 15:50:00\")].div.head(60)\n", "# a" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
symbolBAC
time
2024-10-14 09:30:00-04:0042.0737
2024-10-14 09:30:12-04:0042.0750
2024-10-14 09:30:24-04:0042.0650
2024-10-14 09:30:36-04:0042.0300
2024-10-14 09:30:48-04:0041.9700
......
2024-10-16 15:59:00-04:0042.7550
2024-10-16 15:59:12-04:0042.7700
2024-10-16 15:59:24-04:0042.7800
2024-10-16 15:59:36-04:0042.7900
2024-10-16 15:59:48-04:0042.8100
\n", "

5842 rows × 1 columns

\n", "
" ], "text/plain": [ "symbol BAC\n", "time \n", "2024-10-14 09:30:00-04:00 42.0737\n", "2024-10-14 09:30:12-04:00 42.0750\n", "2024-10-14 09:30:24-04:00 42.0650\n", "2024-10-14 09:30:36-04:00 42.0300\n", "2024-10-14 09:30:48-04:00 41.9700\n", "... ...\n", "2024-10-16 15:59:00-04:00 42.7550\n", "2024-10-16 15:59:12-04:00 42.7700\n", "2024-10-16 15:59:24-04:00 42.7800\n", "2024-10-16 15:59:36-04:00 42.7900\n", "2024-10-16 15:59:48-04:00 42.8100\n", "\n", "[5842 rows x 1 columns]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s12_data.close" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
openhighlowclosevolume
time
2024-10-14 09:30:01-04:0041.960042.045041.820041.9650429666.0
2024-10-14 09:30:02-04:0041.953641.990041.953641.9800895.0
2024-10-14 09:30:03-04:0041.990042.010041.990042.005015707.0
2024-10-14 09:30:04-04:0042.010042.080042.010042.060022696.0
2024-10-14 09:30:05-04:0042.040042.050042.020042.0400525.0
2024-10-14 09:30:06-04:0042.000042.030041.990042.01008735.0
2024-10-14 09:30:07-04:0042.020042.040042.020042.0200400.0
2024-10-14 09:30:08-04:0042.060042.060042.060042.0600100.0
2024-10-14 09:30:09-04:0042.020042.020042.020042.0200100.0
2024-10-14 09:30:10-04:0042.047342.060042.040042.06001614.0
2024-10-14 09:30:11-04:0042.060042.073742.060042.07372100.0
2024-10-14 09:30:13-04:0042.084842.090042.084842.09005179.0
2024-10-14 09:30:14-04:0042.070042.080042.070042.0800200.0
2024-10-14 09:30:15-04:0042.070042.090042.070042.08505875.0
2024-10-14 09:30:16-04:0042.080042.090042.080042.0850951.0
2024-10-14 09:30:17-04:0042.085042.090042.075042.09001100.0
2024-10-14 09:30:18-04:0042.080042.090042.055042.09004242.0
2024-10-14 09:30:19-04:0042.090042.090042.060042.06503214.0
2024-10-14 09:30:20-04:0042.072142.072142.065042.06506666.0
2024-10-14 09:30:21-04:0042.065042.065042.065042.0650500.0
2024-10-14 09:30:22-04:0042.070042.070042.065042.065010100.0
2024-10-14 09:30:23-04:0042.070042.075042.065042.0750800.0
2024-10-14 09:30:24-04:0042.070042.090042.070042.0900800.0
2024-10-14 09:30:25-04:0042.090042.090042.060042.06002622.0
2024-10-14 09:30:26-04:0042.055042.075042.050042.05002530.0
2024-10-14 09:30:27-04:0042.065042.065042.055042.06001222.0
2024-10-14 09:30:28-04:0042.030042.030042.030042.03001200.0
2024-10-14 09:30:29-04:0042.040042.060042.040042.06002345.0
2024-10-14 09:30:30-04:0042.060042.060042.050042.05002417.0
2024-10-14 09:30:31-04:0042.050042.050042.050042.0500100.0
2024-10-14 09:30:32-04:0042.050042.060042.050042.0600775.0
2024-10-14 09:30:33-04:0042.050042.050042.050042.0500100.0
2024-10-14 09:30:35-04:0042.060042.065042.048942.0650750.0
2024-10-14 09:30:36-04:0042.065042.085042.065042.07001614.0
2024-10-14 09:30:37-04:0042.080042.080042.070042.0700300.0
2024-10-14 09:30:38-04:0042.060042.060042.060042.0600100.0
2024-10-14 09:30:39-04:0042.055042.060042.055042.0600963.0
2024-10-14 09:30:41-04:0042.050042.050042.020142.02011301.0
2024-10-14 09:30:42-04:0042.040042.040042.035042.03501300.0
2024-10-14 09:30:43-04:0042.020042.035042.020042.03003123.0
2024-10-14 09:30:44-04:0042.036242.036242.030042.0350500.0
2024-10-14 09:30:45-04:0042.033142.033142.020042.0200900.0
2024-10-14 09:30:46-04:0042.040042.040042.040042.0400112.0
2024-10-14 09:30:47-04:0042.020042.030042.020042.0300300.0
2024-10-14 09:30:48-04:0042.020042.020042.005042.00501166.0
2024-10-14 09:30:50-04:0042.020042.020042.020042.02001207.0
2024-10-14 09:30:51-04:0042.010042.010042.010042.0100209.0
2024-10-14 09:30:53-04:0042.010042.015042.010042.01002490.0
2024-10-14 09:30:54-04:0042.010042.010042.010042.0100600.0
2024-10-14 09:30:56-04:0042.010042.010042.010042.0100400.0
\n", "
" ], "text/plain": [ " open high low close volume\n", "time \n", "2024-10-14 09:30:01-04:00 41.9600 42.0450 41.8200 41.9650 429666.0\n", "2024-10-14 09:30:02-04:00 41.9536 41.9900 41.9536 41.9800 895.0\n", "2024-10-14 09:30:03-04:00 41.9900 42.0100 41.9900 42.0050 15707.0\n", "2024-10-14 09:30:04-04:00 42.0100 42.0800 42.0100 42.0600 22696.0\n", "2024-10-14 09:30:05-04:00 42.0400 42.0500 42.0200 42.0400 525.0\n", "2024-10-14 09:30:06-04:00 42.0000 42.0300 41.9900 42.0100 8735.0\n", "2024-10-14 09:30:07-04:00 42.0200 42.0400 42.0200 42.0200 400.0\n", "2024-10-14 09:30:08-04:00 42.0600 42.0600 42.0600 42.0600 100.0\n", "2024-10-14 09:30:09-04:00 42.0200 42.0200 42.0200 42.0200 100.0\n", "2024-10-14 09:30:10-04:00 42.0473 42.0600 42.0400 42.0600 1614.0\n", "2024-10-14 09:30:11-04:00 42.0600 42.0737 42.0600 42.0737 2100.0\n", "2024-10-14 09:30:13-04:00 42.0848 42.0900 42.0848 42.0900 5179.0\n", "2024-10-14 09:30:14-04:00 42.0700 42.0800 42.0700 42.0800 200.0\n", "2024-10-14 09:30:15-04:00 42.0700 42.0900 42.0700 42.0850 5875.0\n", "2024-10-14 09:30:16-04:00 42.0800 42.0900 42.0800 42.0850 951.0\n", "2024-10-14 09:30:17-04:00 42.0850 42.0900 42.0750 42.0900 1100.0\n", "2024-10-14 09:30:18-04:00 42.0800 42.0900 42.0550 42.0900 4242.0\n", "2024-10-14 09:30:19-04:00 42.0900 42.0900 42.0600 42.0650 3214.0\n", "2024-10-14 09:30:20-04:00 42.0721 42.0721 42.0650 42.0650 6666.0\n", "2024-10-14 09:30:21-04:00 42.0650 42.0650 42.0650 42.0650 500.0\n", "2024-10-14 09:30:22-04:00 42.0700 42.0700 42.0650 42.0650 10100.0\n", "2024-10-14 09:30:23-04:00 42.0700 42.0750 42.0650 42.0750 800.0\n", "2024-10-14 09:30:24-04:00 42.0700 42.0900 42.0700 42.0900 800.0\n", "2024-10-14 09:30:25-04:00 42.0900 42.0900 42.0600 42.0600 2622.0\n", "2024-10-14 09:30:26-04:00 42.0550 42.0750 42.0500 42.0500 2530.0\n", "2024-10-14 09:30:27-04:00 42.0650 42.0650 42.0550 42.0600 1222.0\n", "2024-10-14 09:30:28-04:00 42.0300 42.0300 42.0300 42.0300 1200.0\n", "2024-10-14 09:30:29-04:00 42.0400 42.0600 42.0400 42.0600 2345.0\n", "2024-10-14 09:30:30-04:00 42.0600 42.0600 42.0500 42.0500 2417.0\n", "2024-10-14 09:30:31-04:00 42.0500 42.0500 42.0500 42.0500 100.0\n", "2024-10-14 09:30:32-04:00 42.0500 42.0600 42.0500 42.0600 775.0\n", "2024-10-14 09:30:33-04:00 42.0500 42.0500 42.0500 42.0500 100.0\n", "2024-10-14 09:30:35-04:00 42.0600 42.0650 42.0489 42.0650 750.0\n", "2024-10-14 09:30:36-04:00 42.0650 42.0850 42.0650 42.0700 1614.0\n", "2024-10-14 09:30:37-04:00 42.0800 42.0800 42.0700 42.0700 300.0\n", "2024-10-14 09:30:38-04:00 42.0600 42.0600 42.0600 42.0600 100.0\n", "2024-10-14 09:30:39-04:00 42.0550 42.0600 42.0550 42.0600 963.0\n", "2024-10-14 09:30:41-04:00 42.0500 42.0500 42.0201 42.0201 1301.0\n", "2024-10-14 09:30:42-04:00 42.0400 42.0400 42.0350 42.0350 1300.0\n", "2024-10-14 09:30:43-04:00 42.0200 42.0350 42.0200 42.0300 3123.0\n", "2024-10-14 09:30:44-04:00 42.0362 42.0362 42.0300 42.0350 500.0\n", "2024-10-14 09:30:45-04:00 42.0331 42.0331 42.0200 42.0200 900.0\n", "2024-10-14 09:30:46-04:00 42.0400 42.0400 42.0400 42.0400 112.0\n", "2024-10-14 09:30:47-04:00 42.0200 42.0300 42.0200 42.0300 300.0\n", "2024-10-14 09:30:48-04:00 42.0200 42.0200 42.0050 42.0050 1166.0\n", "2024-10-14 09:30:50-04:00 42.0200 42.0200 42.0200 42.0200 1207.0\n", "2024-10-14 09:30:51-04:00 42.0100 42.0100 42.0100 42.0100 209.0\n", "2024-10-14 09:30:53-04:00 42.0100 42.0150 42.0100 42.0100 2490.0\n", "2024-10-14 09:30:54-04:00 42.0100 42.0100 42.0100 42.0100 600.0\n", "2024-10-14 09:30:56-04:00 42.0100 42.0100 42.0100 42.0100 400.0" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "basic_data.data[\"BAC\"].head(50)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "# long_entries = tts.isrisingc(dvla,3).vbt & div_vwap_cum.div_below(0)\n", "# long_entries = long_entries.vbt.realign_closing(basic_data.index, ffill=False, freq=\"1s\").dropna().astype(bool)\n" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "from ttools.vbtindicators import register_custom_inds\n", "register_custom_inds(None, \"override\")\n", "#chopiness = vbt.indicator(\"technical:CHOPINESS\").run(s12_data.open, s12_data.high, s12_data.low, s12_data.close, s12_data.volume, window = 100)\n", "#vwap_cum_roll = vbt.indicator(\"technical:ROLLING_VWAP\").run(s12_data.open, s12_data.high, s12_data.low, s12_data.close, s12_data.volume, window = 100, min_periods = 5)\n", "\n", "#note that VWAP is calculated from HLCC4 rounded to 3 decimals, can be changed by hlcc4_round parameter\n", "vwap_cum_d = vbt.indicator(\"ttools:CUVWAP\").run(s12_data.high, s12_data.low, s12_data.close, s12_data.volume, anchor=vbt.Default(value=\"D\"), drag=vbt.Default(value=50), hide_default=True)\n", "div_vwap_cum = vbt.indicator(\"ttools:DIVERGENCE\").run(s12_data.close, vwap_cum_d.vwap, divtype=vbt.Default(value=\"reln\"), hide_default=True)\n", "div_vwap_lin_angle = vbt.indicator(\"talib:LINEARREG_ANGLE\").run(div_vwap_cum.div, timeperiod=2)\n", "dvla = np.round(div_vwap_lin_angle.real,4)\n", "\n", "long_entries = tts.isrisingc(dvla,3).vbt & div_vwap_cum.div_below(0)\n", "short_entries = tts.isfallingc(dvla,3).vbt & div_vwap_cum.div_above(0)\n", "\n", "#SIGNAL - make indicator with 1 - long, -1 - short, 0 nothing\n", "long_series = long_entries.squeeze()\n", "short_series = short_entries.squeeze()\n", "signals = pd.Series(0, index=long_series.index) # Initialize with 0\n", "signals[long_series] = 1 # Set 1 where entries are True\n", "signals[short_series] = -1 # Set -1 where exits are True\n", "\n", "Panel(\n", " ohlcv=(s12_data.ohlcv.data[\"BAC\"],), #[(long_entries.squeeze())],[(short_entries.squeeze())]),\n", " right=[(vwap_cum_d.vwap, \"vwap_cum_daily\")], \n", " middle1=[(dvla, \"div_vwap_angle\")],\n", " middle2=[(signals, \"signals\")],\n", " left=[(div_vwap_cum.div, \"div_vwap_cum\")]).chart(size=\"m\", xloc=slice(\"2024-10-14 15:00:00\", \"2024-10-15 16:00:00\"), precision=4)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "#TED backtest, porovnat s v2realbot, delsi obdobi, tuning parametru a zpetne vyzkouseni s realbotem\n", "#pripadne mrknout na markov variance switching zda nepujde na intraday" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [], "source": [ "from typing import Any\n", "from ttools import create_mask_from_window\n", "\n", "#single for exits, as it is just EOD exits\n", "exits = pd.DataFrame.vbt.signals.empty_like(long_entries) \n", "entry_window_opens = 0 #in minutes from start of the market\n", "entry_window_closes = 380\n", "forced_exit_start = 382\n", "forced_exit_end = 390\n", "\n", "#create mask based on main session that day\n", "entry_window_opened = create_mask_from_window(long_entries, entry_window_opens, entry_window_closes, use_cal=False)\n", "#limit entries to the window\n", "long_entries_cln = long_entries.vbt & entry_window_opened\n", "short_entries_cln = short_entries.vbt & entry_window_opened\n", "\n", "#create forced exits mask\n", "forced_exits_window = create_mask_from_window(exits, forced_exit_start, forced_exit_end, use_cal=False)\n", "\n", "#add just forced EOD exits to exits, series is ok\n", "long_exits = forced_exits_window\n", "short_exits = forced_exits_window" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [], "source": [ "from collections import namedtuple\n", "from numba import njit\n", "from numba import config\n", "\n", "#callback function in separate file signal_func_nb.py, this one is just for debugging\n", "#@njit\n", "def signal_func_nb(c, entries, exits, short_entries, short_exits, cooldown_time, cooldown_bars):\n", " entry = vbt.pf_nb.select_nb(c, entries)\n", " exit = vbt.pf_nb.select_nb(c, exits)\n", " short_entry = vbt.pf_nb.select_nb(c, short_entries)\n", " short_exit = vbt.pf_nb.select_nb(c, short_exits)\n", " if not vbt.pf_nb.in_position_nb(c): #c.last_position == 0\n", " if vbt.pf_nb.has_orders_nb(c): \n", " last_exit_idx = c.last_pos_info[c.col][\"exit_idx\"] #(92) #If not in position, position information records contain information on the last (closed) position\n", " if cooldown_time is not None and c.index[c.i] - c.index[last_exit_idx] < cooldown_time:\n", " return False, exit, False, short_exit #disable entry\n", " elif cooldown_bars is not None and last_exit_idx + cooldown_bars > c.i:\n", " return False, exit, False, short_exit #disable entry\n", " return entry, exit, short_entry, short_exit\n", "\n", "cooldown_time = None #vbt.dt.to_ns(vbt.timedelta(\"2m\"))\n", "cooldown_bars = 5\n", "size=100\n", "\n", "pf = vbt.Portfolio.from_signals(\n", " close=s12_data.close,\n", " entries=long_entries_cln,\n", " exits=long_exits,\n", " short_entries=short_entries_cln,\n", " short_exits=short_exits,\n", " signal_func_nb=\"signal_func_nb.py\",\n", " #signal_func_nb=signal_func_nb,\n", " signal_args=(\n", " vbt.Rep(\"entries\"), \n", " vbt.Rep(\"exits\"),\n", " vbt.Rep(\"short_entries\"),\n", " vbt.Rep(\"short_exits\"),\n", " cooldown_time, # cooldown in timedelta in ns after exit\n", " cooldown_bars #cooldown in number of bars after exit\n", " ),\n", " sl_stop=0.3,\n", " tp_stop = 0.4,\n", " delta_format = vbt.pf_enums.DeltaFormat.Percent100, #(Absolute, Percent, Percent100, Target)\n", " fees=0.0167/100,\n", " freq=\"12s\",\n", " size=size, # pf_enums.SizeType.Amount (Absolute, Percent, Percent100, Target)\n", " staticized=True,\n", " #jitted=False\n", " ) #sl_stop=sl_stop, tp_stop = sl_stop,, tsl_stop\n" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Start Index 2024-10-15 09:30:00-04:00\n", "End Index 2024-10-15 15:59:48-04:00\n", "Total Duration 0 days 06:29:36\n", "Start Value 101.713787\n", "Min Value 101.696804\n", "Max Value 104.96345\n", "End Value 103.671538\n", "Total Return [%] 1.924764\n", "Benchmark Return [%] -2.498843\n", "Position Coverage [%] 90.811088\n", "Max Gross Exposure [%] 100.58714\n", "Max Drawdown [%] 1.230821\n", "Max Drawdown Duration 0 days 04:47:24\n", "Total Orders 37\n", "Total Fees Paid 0.72742\n", "Total Trades 21\n", "Win Rate [%] 66.666667\n", "Best Trade [%] 0.366667\n", "Worst Trade [%] -0.33345\n", "Avg Winning Trade [%] 0.303687\n", "Avg Losing Trade [%] -0.333393\n", "Avg Winning Trade Duration 0 days 00:12:02.571428571\n", "Avg Losing Trade Duration 0 days 00:26:27.428571428\n", "Profit Factor 1.804288\n", "Expectancy 0.093226\n", "Sharpe Ratio 47.585801\n", "Calmar Ratio 12016298078859.408203\n", "Omega Ratio 1.094026\n", "Sortino Ratio 72.605526\n", "Name: agg_stats, dtype: object" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#TODO - charting trades in lw from pf.trades\n", "#obecne analyza trades a vizualizace\n", "#grafy vykonu, cas atp. + potom hyperparamater testing\n", "\n", "pf.xloc[\"2024-10-15\"].stats()\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e07372c602d0415e9bb2c16a2073275b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FigureWidget({\n", " 'data': [{'line': {'color': '#1f77b4'},\n", " 'mode': 'lines',\n", " 'name': 'Close',\n", " 'showlegend': True,\n", " 'type': 'scatter',\n", " 'uid': '0e026941-121f-4b79-86a4-de7599b923b9',\n", " 'x': array([datetime.datetime(2024, 10, 15, 9, 30, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 30, 12, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 30, 24, tzinfo=),\n", " ...,\n", " datetime.datetime(2024, 10, 15, 15, 59, 24, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 15, 59, 36, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 15, 59, 48, tzinfo=)],\n", " dtype=object),\n", " 'y': array([43.22 , 43.15 , 43.2252, ..., 42.07 , 42.1 , 42.14 ])},\n", " {'customdata': array([['0', '31', '0', '2024-10-15 09:30:48-04:00', 2.3595546147955595, 43.1,\n", " 0.016983366250914, 'Short'],\n", " ['1', '33', '1', '2024-10-15 09:32:36-04:00', 2.3820217048372174,\n", " 42.85, 0.017045628218729885, 'Short'],\n", " ['2', '35', '2', '2024-10-15 09:35:24-04:00', 2.4090258203018373,\n", " 42.525, 0.017108118442394016, 'Long'],\n", " ['3', '37', '3', '2024-10-15 09:37:00-04:00', 2.4107678999893727,\n", " 42.65, 0.017170814906069306, 'Short'],\n", " ['4', '39', '4', '2024-10-15 09:46:36-04:00', 2.429574856799703,\n", " 42.475, 0.01723376407110777, 'Long'],\n", " ['5', '41', '5', '2024-10-15 09:48:24-04:00', 2.428188423177105,\n", " 42.655, 0.017296920990833443, 'Short'],\n", " ['6', '43', '6', '2024-10-15 09:52:00-04:00', 2.4130160049479286,\n", " 42.7801, 0.017239254020876567, 'Short'],\n", " ['7', '45', '7', '2024-10-15 10:07:48-04:00', 2.438684465250174,\n", " 42.485, 0.017302454087527508, 'Long'],\n", " ['8', '47', '8', '2024-10-15 10:12:24-04:00', 2.4387242499422475,\n", " 42.64, 0.01736586273692875, 'Short'],\n", " ['9', '48', '9', '2024-10-15 10:13:12-04:00', 2.4447815769443353,\n", " 42.58, 0.017384499524228332, 'Long'],\n", " ['10', '49', '10', '2024-10-15 10:14:24-04:00', 2.443965156239894,\n", " 42.6201, 0.0173950605723618, 'Short'],\n", " ['11', '50', '11', '2024-10-15 10:20:36-04:00', 2.4609987999300142,\n", " 42.465, 0.017452554444517557, 'Long'],\n", " ['12', '51', '12', '2024-10-15 11:08:12-04:00', 2.4601769635775104,\n", " 42.59, 0.01749808245875395, 'Short'],\n", " ['13', '53', '13', '2024-10-15 11:20:00-04:00', 2.447372041466882,\n", " 42.6701, 0.01743974482768153, 'Short'],\n", " ['14', '55', '14', '2024-10-15 12:25:36-04:00', 2.426423761548037,\n", " 42.895, 0.01738160169101771, 'Short'],\n", " ['15', '57', '15', '2024-10-15 12:53:48-04:00', 2.4457819472908473,\n", " 42.7115, 0.017445323612166073, 'Short'],\n", " ['16', '58', '16', '2024-10-15 13:05:36-04:00', 2.4560400980445247,\n", " 42.615, 0.01747891284595667, 'Long'],\n", " ['17', '60', '17', '2024-10-15 13:24:24-04:00', 2.452746513028198,\n", " 42.53, 0.017420656636247145, 'Long'],\n", " ['18', '62', '18', '2024-10-15 13:55:24-04:00', 2.4523559920328935,\n", " 42.395, 0.017362594591133984, 'Long'],\n", " ['19', '64', '19', '2024-10-15 14:44:24-04:00', 2.451512851938338,\n", " 42.565, 0.017426223638636884, 'Long'],\n", " ['20', '66', '20', '2024-10-15 15:37:00-04:00', 2.4537184504216185,\n", " 42.385, 0.017368143039036, 'Long']], dtype=object),\n", " 'hovertemplate': ('
Exit Trade Id: %{customdat' ... 'br>Direction: %{customdata[7]}'),\n", " 'marker': {'color': '#4285F4',\n", " 'line': {'color': 'rgb(11,84,205)', 'width': 1},\n", " 'size': 7,\n", " 'symbol': 'square'},\n", " 'mode': 'markers',\n", " 'name': 'Entry',\n", " 'type': 'scatter',\n", " 'uid': '418db043-9c4d-4a48-bab6-88369513599a',\n", " 'x': array([datetime.datetime(2024, 10, 15, 9, 30, 48, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 32, 36, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 35, 24, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 37, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 46, 36, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 48, 24, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 52, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 10, 7, 48, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 10, 12, 24, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 10, 13, 12, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 10, 14, 24, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 10, 20, 36, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 11, 8, 12, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 11, 20, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 12, 25, 36, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 12, 53, 48, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 13, 5, 36, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 13, 24, 24, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 13, 55, 24, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 14, 44, 24, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 15, 37, tzinfo=)],\n", " dtype=object),\n", " 'y': array([43.1 , 42.85 , 42.525 , 42.65 , 42.475 , 42.655 , 42.7801, 42.485 ,\n", " 42.64 , 42.58 , 42.6201, 42.465 , 42.59 , 42.6701, 42.895 , 42.7115,\n", " 42.615 , 42.53 , 42.395 , 42.565 , 42.385 ])},\n", " {'customdata': array([['0', '32', '0', '2024-10-15 09:31:48-04:00', 2.3595546147955595,\n", " 42.9276, 0.01691543278591034, 0.37288841655394356,\n", " 0.003666668000000132, 'Short', '0 days 00:01:00'],\n", " ['1', '34', '1', '2024-10-15 09:35:00-04:00', 2.3820217048372174,\n", " 42.6786, 0.01697744570585497, 0.37425544628450974,\n", " 0.003666667999999956, 'Short', '0 days 00:02:24'],\n", " ['2', '36', '2', '2024-10-15 09:36:48-04:00', 2.4090258203018373,\n", " 42.6951, 0.017176550916161618, 0.3754906226747892,\n", " 0.0036653320000000038, 'Long', '0 days 00:01:24'],\n", " ['3', '38', '3', '2024-10-15 09:45:12-04:00', 2.4107678999893727,\n", " 42.4794, 0.01710213164644503, 0.37700405718567775,\n", " 0.0036666680000000495, 'Short', '0 days 00:08:12'],\n", " ['4', '40', '4', '2024-10-15 09:48:00-04:00', 2.429574856799703,\n", " 42.6449, 0.017302699127393188, 0.3782483049717538,\n", " 0.0036653319999998663, 'Long', '0 days 00:01:24'],\n", " ['6', '44', '6', '2024-10-15 10:07:00-04:00', 2.4130160049479286,\n", " 42.6089796, 0.017170297004793063, 0.3785067129474183,\n", " 0.0036666679999999654, 'Short', '0 days 00:15:00'],\n", " ['7', '46', '7', '2024-10-15 10:12:12-04:00', 2.438684465250174,\n", " 42.654939999999996, 0.017371663903877767, 0.3797559200331998,\n", " 0.00366533199999991, 'Long', '0 days 00:04:24'],\n", " ['8', '48', '8', '2024-10-15 10:13:12-04:00', 2.4387242499422475,\n", " 42.58, 0.017341426719942273, 0.11161616553966253,\n", " 0.001073364446529088, 'Short', '0 days 00:00:48'],\n", " ['9', '49', '9', '2024-10-15 10:14:24-04:00', 2.4447815769443353,\n", " 42.6201, 0.017400871493016723, 0.0632503702182185,\n", " 0.0006075994199154319, 'Long', '0 days 00:01:12'],\n", " ['10', '50', '10', '2024-10-15 10:20:36-04:00', 2.443965156239894,\n", " 42.465, 0.017331757720074295, 0.34433217744035494,\n", " 0.0033057357514410645, 'Short', '0 days 00:06:12'],\n", " ['11', '51', '11', '2024-10-15 11:08:12-04:00', 2.4609987999300142,\n", " 42.59, 0.017503927794466224, 0.2726683677522586,\n", " 0.0026091090309665896, 'Long', '0 days 00:47:36'],\n", " ['14', '56', '14', '2024-10-15 12:44:48-04:00', 2.426423761548037,\n", " 42.723420000000004, 0.017312075284253638, 0.381632112031136,\n", " 0.0036666679999999533, 'Short', '0 days 00:19:12'],\n", " ['15', '58', '15', '2024-10-15 13:05:36-04:00', 2.4457819472908473,\n", " 42.615, 0.01740590861319721, 0.2011667256881971,\n", " 0.0019257219835406457, 'Short', '0 days 00:11:48'],\n", " ['18', '63', '18', '2024-10-15 14:43:36-04:00', 2.4523559920328935,\n", " 42.56458000000001, 0.017432044969497698, 0.3810758895683205,\n", " 0.003665332000000128, 'Long', '0 days 00:48:00']], dtype=object),\n", " 'hovertemplate': ('
Exit Trade Id: %{customdat' ... 'br>Duration: %{customdata[10]}'),\n", " 'marker': {'color': '#37B13F',\n", " 'line': {'color': 'rgb(38,123,44)', 'width': 1},\n", " 'size': 7,\n", " 'symbol': 'square'},\n", " 'mode': 'markers',\n", " 'name': 'Exit - Profit',\n", " 'type': 'scatter',\n", " 'uid': 'acfa2bd8-6260-44a5-a4de-051f447240db',\n", " 'x': array([datetime.datetime(2024, 10, 15, 9, 31, 48, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 35, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 36, 48, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 45, 12, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 9, 48, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 10, 7, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 10, 12, 12, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 10, 13, 12, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 10, 14, 24, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 10, 20, 36, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 11, 8, 12, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 12, 44, 48, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 13, 5, 36, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 14, 43, 36, tzinfo=)],\n", " dtype=object),\n", " 'y': array([42.9276 , 42.6786 , 42.6951 , 42.4794 , 42.6449 , 42.6089796,\n", " 42.65494 , 42.58 , 42.6201 , 42.465 , 42.59 , 42.72342 ,\n", " 42.615 , 42.56458 ])},\n", " {'customdata': array([['5', '42', '5', '2024-10-15 09:50:48-04:00', 2.428188423177105,\n", " 42.782965, 0.01734881175380594, -0.34536886431648733,\n", " -0.0033345009999999004, 'Short', '0 days 00:02:24'],\n", " ['12', '52', '12', '2024-10-15 11:17:00-04:00', 2.4601769635775104,\n", " 42.71777, 0.017550576706130205, -0.3493854698011755,\n", " -0.0033345009999999316, 'Short', '0 days 00:08:48'],\n", " ['13', '54', '13', '2024-10-15 12:22:24-04:00', 2.447372041466882,\n", " 42.79811029999999, 0.017492064062164574, -0.34822063812961274,\n", " -0.0033345009999997954, 'Short', '0 days 01:02:24'],\n", " ['16', '59', '16', '2024-10-15 13:22:36-04:00', 2.4560400980445247,\n", " 42.487155, 0.017426476107416097, -0.3488978352878824,\n", " -0.0033334990000000956, 'Long', '0 days 00:17:00'],\n", " ['17', '61', '17', '2024-10-15 13:54:24-04:00', 2.452746513028198,\n", " 42.40241, 0.017368394666339163, -0.34773497889985555,\n", " -0.0033334990000000063, 'Long', '0 days 00:29:48'],\n", " ['19', '65', '19', '2024-10-15 15:36:00-04:00', 2.451512851938338,\n", " 42.437304999999995, 0.01737394496772422, -0.34784610223463514,\n", " -0.0033334990000000457, 'Long', '0 days 00:51:36'],\n", " ['20', '67', '20', '2024-10-15 15:50:12-04:00', 2.4537184504216185,\n", " 42.257844999999996, 0.017316038609910007, -0.34668675121230746,\n", " -0.0033334990000000913, 'Long', '0 days 00:13:12']], dtype=object),\n", " 'hovertemplate': ('
Exit Trade Id: %{customdat' ... 'br>Duration: %{customdata[10]}'),\n", " 'marker': {'color': '#EA4335',\n", " 'line': {'color': 'rgb(181,31,18)', 'width': 1},\n", " 'size': 7,\n", " 'symbol': 'square'},\n", " 'mode': 'markers',\n", " 'name': 'Exit - Loss',\n", " 'type': 'scatter',\n", " 'uid': 'e4599e9b-5b77-46f8-997d-267c77ebdf9c',\n", " 'x': array([datetime.datetime(2024, 10, 15, 9, 50, 48, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 11, 17, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 12, 22, 24, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 13, 22, 36, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 13, 54, 24, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 15, 36, tzinfo=),\n", " datetime.datetime(2024, 10, 15, 15, 50, 12, tzinfo=)],\n", " dtype=object),\n", " 'y': array([42.782965 , 42.71777 , 42.7981103, 42.487155 , 42.40241 , 42.437305 ,\n", " 42.257845 ])}],\n", " 'layout': {'height': 350,\n", " 'legend': {'orientation': 'h',\n", " 'traceorder': 'normal',\n", " 'x': 1,\n", " 'xanchor': 'right',\n", " 'y': 1.02,\n", " 'yanchor': 'bottom'},\n", " 'margin': {'b': 30, 'l': 30, 'r': 30, 't': 30},\n", " 'shapes': [{'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 09:30:48-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 09:31:48-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 43.1,\n", " 'y1': 42.9276,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 09:32:36-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 09:35:00-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.85,\n", " 'y1': 42.6786,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 09:35:24-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 09:36:48-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.525,\n", " 'y1': 42.6951,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 09:37:00-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 09:45:12-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.65,\n", " 'y1': 42.4794,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 09:46:36-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 09:48:00-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.475,\n", " 'y1': 42.6449,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 09:52:00-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 10:07:00-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.7801,\n", " 'y1': 42.6089796,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 10:07:48-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 10:12:12-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.485,\n", " 'y1': 42.654939999999996,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 10:12:24-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 10:13:12-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.64,\n", " 'y1': 42.58,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 10:13:12-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 10:14:24-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.58,\n", " 'y1': 42.6201,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 10:14:24-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 10:20:36-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.6201,\n", " 'y1': 42.465,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 10:20:36-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 11:08:12-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.465,\n", " 'y1': 42.59,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 12:25:36-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 12:44:48-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.895,\n", " 'y1': 42.723420000000004,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 12:53:48-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 13:05:36-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.7115,\n", " 'y1': 42.615,\n", " 'yref': 'y'},\n", " {'fillcolor': '#37B13F',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 13:55:24-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 14:43:36-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.395,\n", " 'y1': 42.56458000000001,\n", " 'yref': 'y'},\n", " {'fillcolor': '#EA4335',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 09:48:24-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 09:50:48-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.655,\n", " 'y1': 42.782965,\n", " 'yref': 'y'},\n", " {'fillcolor': '#EA4335',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 11:08:12-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 11:17:00-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.59,\n", " 'y1': 42.71777,\n", " 'yref': 'y'},\n", " {'fillcolor': '#EA4335',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 11:20:00-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 12:22:24-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.6701,\n", " 'y1': 42.79811029999999,\n", " 'yref': 'y'},\n", " {'fillcolor': '#EA4335',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 13:05:36-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 13:22:36-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.615,\n", " 'y1': 42.487155,\n", " 'yref': 'y'},\n", " {'fillcolor': '#EA4335',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 13:24:24-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 13:54:24-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.53,\n", " 'y1': 42.40241,\n", " 'yref': 'y'},\n", " {'fillcolor': '#EA4335',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 14:44:24-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 15:36:00-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.565,\n", " 'y1': 42.437304999999995,\n", " 'yref': 'y'},\n", " {'fillcolor': '#EA4335',\n", " 'layer': 'below',\n", " 'line': {'width': 0},\n", " 'opacity': 0.15,\n", " 'type': 'rect',\n", " 'x0': Timestamp('2024-10-15 15:37:00-0400', tz='America/New_York'),\n", " 'x1': Timestamp('2024-10-15 15:50:12-0400', tz='America/New_York'),\n", " 'xref': 'x',\n", " 'y0': 42.385,\n", " 'y1': 42.257844999999996,\n", " 'yref': 'y'}],\n", " 'template': '...',\n", " 'width': 700}\n", "})" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pf.xloc[slice(\"2024-10-15 09:30:00\", \"2024-10-15 16:00:00\")].trades.plot()" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Order IdColumnSignal IndexCreation Index...FeesSideTypeStop Type
030(2, BAC)2024-10-15 09:30:48-04:002024-10-15 09:30:48-04:00...0.016968SellMarketNone
131(2, BAC)2024-10-15 09:30:48-04:002024-10-15 09:31:48-04:00...0.016900BuyMarketTP
232(2, BAC)2024-10-15 09:33:24-04:002024-10-15 09:33:24-04:00...0.017030SellMarketNone
333(2, BAC)2024-10-15 09:33:24-04:002024-10-15 09:35:00-04:00...0.016962BuyMarketTP
434(2, BAC)2024-10-15 09:37:00-04:002024-10-15 09:37:00-04:00...0.017093SellMarketNone
535(2, BAC)2024-10-15 09:37:00-04:002024-10-15 09:45:12-04:00...0.017025BuyMarketTP
636(2, BAC)2024-10-15 09:46:36-04:002024-10-15 09:46:36-04:00...0.017156BuyMarketNone
737(2, BAC)2024-10-15 09:46:36-04:002024-10-15 09:48:00-04:00...0.017224SellMarketTP
838(2, BAC)2024-10-15 09:50:00-04:002024-10-15 09:50:00-04:00...0.017218SellMarketNone
939(2, BAC)2024-10-15 09:50:00-04:002024-10-15 09:54:24-04:00...0.017270BuyMarketSL
1040(2, BAC)2024-10-15 09:57:00-04:002024-10-15 09:57:00-04:00...0.017161SellMarketNone
1141(2, BAC)2024-10-15 09:57:00-04:002024-10-15 10:06:36-04:00...0.017092BuyMarketTP
1242(2, BAC)2024-10-15 10:07:48-04:002024-10-15 10:07:48-04:00...0.017224BuyMarketNone
1343(2, BAC)2024-10-15 10:07:48-04:002024-10-15 10:12:12-04:00...0.017293SellMarketTP
1444(2, BAC)2024-10-15 10:13:12-04:002024-10-15 10:13:12-04:00...0.017287BuyMarketNone
1545(2, BAC)2024-10-15 10:14:24-04:002024-10-15 10:14:24-04:00...0.034601SellMarketNone
1646(2, BAC)2024-10-15 10:20:36-04:002024-10-15 10:20:36-04:00...0.034589BuyMarketNone
1747(2, BAC)2024-10-15 11:08:12-04:002024-10-15 11:08:12-04:00...0.034806SellMarketNone
1848(2, BAC)2024-10-15 11:08:12-04:002024-10-15 11:17:00-04:00...0.017452BuyMarketSL
1949(2, BAC)2024-10-15 11:20:00-04:002024-10-15 11:20:00-04:00...0.017342SellMarketNone
2050(2, BAC)2024-10-15 11:20:00-04:002024-10-15 12:22:24-04:00...0.017394BuyMarketSL
2151(2, BAC)2024-10-15 12:25:36-04:002024-10-15 12:25:36-04:00...0.017284SellMarketNone
2252(2, BAC)2024-10-15 12:25:36-04:002024-10-15 12:44:48-04:00...0.017215BuyMarketTP
2353(2, BAC)2024-10-15 12:53:48-04:002024-10-15 12:53:48-04:00...0.017348SellMarketNone
2454(2, BAC)2024-10-15 13:05:36-04:002024-10-15 13:05:36-04:00...0.034689BuyMarketNone
2555(2, BAC)2024-10-15 13:05:36-04:002024-10-15 13:22:36-04:00...0.017329SellMarketSL
2656(2, BAC)2024-10-15 13:24:24-04:002024-10-15 13:24:24-04:00...0.017323BuyMarketNone
2757(2, BAC)2024-10-15 13:24:24-04:002024-10-15 13:54:24-04:00...0.017271SellMarketSL
2858(2, BAC)2024-10-15 13:55:24-04:002024-10-15 13:55:24-04:00...0.017265BuyMarketNone
2959(2, BAC)2024-10-15 13:55:24-04:002024-10-15 14:43:36-04:00...0.017334SellMarketTP
3060(2, BAC)2024-10-15 14:59:36-04:002024-10-15 14:59:36-04:00...0.017329BuyMarketNone
3161(2, BAC)2024-10-15 14:59:36-04:002024-10-15 15:36:00-04:00...0.017277SellMarketSL
3262(2, BAC)2024-10-15 15:37:00-04:002024-10-15 15:37:00-04:00...0.017271BuyMarketNone
3363(2, BAC)2024-10-15 15:37:00-04:002024-10-15 15:50:12-04:00...0.017219SellMarketSL
\n", "

34 rows × 11 columns

\n", "
" ], "text/plain": [ " Order Id Column Signal Index Creation Index \\\n", "0 30 (2, BAC) 2024-10-15 09:30:48-04:00 2024-10-15 09:30:48-04:00 \n", "1 31 (2, BAC) 2024-10-15 09:30:48-04:00 2024-10-15 09:31:48-04:00 \n", "2 32 (2, BAC) 2024-10-15 09:33:24-04:00 2024-10-15 09:33:24-04:00 \n", "3 33 (2, BAC) 2024-10-15 09:33:24-04:00 2024-10-15 09:35:00-04:00 \n", "4 34 (2, BAC) 2024-10-15 09:37:00-04:00 2024-10-15 09:37:00-04:00 \n", "5 35 (2, BAC) 2024-10-15 09:37:00-04:00 2024-10-15 09:45:12-04:00 \n", "6 36 (2, BAC) 2024-10-15 09:46:36-04:00 2024-10-15 09:46:36-04:00 \n", "7 37 (2, BAC) 2024-10-15 09:46:36-04:00 2024-10-15 09:48:00-04:00 \n", "8 38 (2, BAC) 2024-10-15 09:50:00-04:00 2024-10-15 09:50:00-04:00 \n", "9 39 (2, BAC) 2024-10-15 09:50:00-04:00 2024-10-15 09:54:24-04:00 \n", "10 40 (2, BAC) 2024-10-15 09:57:00-04:00 2024-10-15 09:57:00-04:00 \n", "11 41 (2, BAC) 2024-10-15 09:57:00-04:00 2024-10-15 10:06:36-04:00 \n", "12 42 (2, BAC) 2024-10-15 10:07:48-04:00 2024-10-15 10:07:48-04:00 \n", "13 43 (2, BAC) 2024-10-15 10:07:48-04:00 2024-10-15 10:12:12-04:00 \n", "14 44 (2, BAC) 2024-10-15 10:13:12-04:00 2024-10-15 10:13:12-04:00 \n", "15 45 (2, BAC) 2024-10-15 10:14:24-04:00 2024-10-15 10:14:24-04:00 \n", "16 46 (2, BAC) 2024-10-15 10:20:36-04:00 2024-10-15 10:20:36-04:00 \n", "17 47 (2, BAC) 2024-10-15 11:08:12-04:00 2024-10-15 11:08:12-04:00 \n", "18 48 (2, BAC) 2024-10-15 11:08:12-04:00 2024-10-15 11:17:00-04:00 \n", "19 49 (2, BAC) 2024-10-15 11:20:00-04:00 2024-10-15 11:20:00-04:00 \n", "20 50 (2, BAC) 2024-10-15 11:20:00-04:00 2024-10-15 12:22:24-04:00 \n", "21 51 (2, BAC) 2024-10-15 12:25:36-04:00 2024-10-15 12:25:36-04:00 \n", "22 52 (2, BAC) 2024-10-15 12:25:36-04:00 2024-10-15 12:44:48-04:00 \n", "23 53 (2, BAC) 2024-10-15 12:53:48-04:00 2024-10-15 12:53:48-04:00 \n", "24 54 (2, BAC) 2024-10-15 13:05:36-04:00 2024-10-15 13:05:36-04:00 \n", "25 55 (2, BAC) 2024-10-15 13:05:36-04:00 2024-10-15 13:22:36-04:00 \n", "26 56 (2, BAC) 2024-10-15 13:24:24-04:00 2024-10-15 13:24:24-04:00 \n", "27 57 (2, BAC) 2024-10-15 13:24:24-04:00 2024-10-15 13:54:24-04:00 \n", "28 58 (2, BAC) 2024-10-15 13:55:24-04:00 2024-10-15 13:55:24-04:00 \n", "29 59 (2, BAC) 2024-10-15 13:55:24-04:00 2024-10-15 14:43:36-04:00 \n", "30 60 (2, BAC) 2024-10-15 14:59:36-04:00 2024-10-15 14:59:36-04:00 \n", "31 61 (2, BAC) 2024-10-15 14:59:36-04:00 2024-10-15 15:36:00-04:00 \n", "32 62 (2, BAC) 2024-10-15 15:37:00-04:00 2024-10-15 15:37:00-04:00 \n", "33 63 (2, BAC) 2024-10-15 15:37:00-04:00 2024-10-15 15:50:12-04:00 \n", "\n", " ... Fees Side Type Stop Type \n", "0 ... 0.016968 Sell Market None \n", "1 ... 0.016900 Buy Market TP \n", "2 ... 0.017030 Sell Market None \n", "3 ... 0.016962 Buy Market TP \n", "4 ... 0.017093 Sell Market None \n", "5 ... 0.017025 Buy Market TP \n", "6 ... 0.017156 Buy Market None \n", "7 ... 0.017224 Sell Market TP \n", "8 ... 0.017218 Sell Market None \n", "9 ... 0.017270 Buy Market SL \n", "10 ... 0.017161 Sell Market None \n", "11 ... 0.017092 Buy Market TP \n", "12 ... 0.017224 Buy Market None \n", "13 ... 0.017293 Sell Market TP \n", "14 ... 0.017287 Buy Market None \n", "15 ... 0.034601 Sell Market None \n", "16 ... 0.034589 Buy Market None \n", "17 ... 0.034806 Sell Market None \n", "18 ... 0.017452 Buy Market SL \n", "19 ... 0.017342 Sell Market None \n", "20 ... 0.017394 Buy Market SL \n", "21 ... 0.017284 Sell Market None \n", "22 ... 0.017215 Buy Market TP \n", "23 ... 0.017348 Sell Market None \n", "24 ... 0.034689 Buy Market None \n", "25 ... 0.017329 Sell Market SL \n", "26 ... 0.017323 Buy Market None \n", "27 ... 0.017271 Sell Market SL \n", "28 ... 0.017265 Buy Market None \n", "29 ... 0.017334 Sell Market TP \n", "30 ... 0.017329 Buy Market None \n", "31 ... 0.017277 Sell Market SL \n", "32 ... 0.017271 Buy Market None \n", "33 ... 0.017219 Sell Market SL \n", "\n", "[34 rows x 11 columns]" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pf.xloc[slice(\"2024-10-15 09:30:00\", \"2024-10-15 16:00:00\")].orders.readable" ] }, { "cell_type": "code", "execution_count": 153, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
linearreg_angle_timeperiod2
symbolBAC
time
2024-10-15 09:35:00-04:00True
2024-10-15 09:35:12-04:00False
2024-10-15 09:35:24-04:00False
2024-10-15 09:35:36-04:00False
2024-10-15 09:35:48-04:00False
......
2024-10-15 15:59:00-04:00False
2024-10-15 15:59:12-04:00False
2024-10-15 15:59:24-04:00False
2024-10-15 15:59:36-04:00False
2024-10-15 15:59:48-04:00False
\n", "

1923 rows × 1 columns

\n", "
" ], "text/plain": [ "linearreg_angle_timeperiod 2\n", "symbol BAC\n", "time \n", "2024-10-15 09:35:00-04:00 True\n", "2024-10-15 09:35:12-04:00 False\n", "2024-10-15 09:35:24-04:00 False\n", "2024-10-15 09:35:36-04:00 False\n", "2024-10-15 09:35:48-04:00 False\n", "... ...\n", "2024-10-15 15:59:00-04:00 False\n", "2024-10-15 15:59:12-04:00 False\n", "2024-10-15 15:59:24-04:00 False\n", "2024-10-15 15:59:36-04:00 False\n", "2024-10-15 15:59:48-04:00 False\n", "\n", "[1923 rows x 1 columns]" ] }, "execution_count": 153, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = short_entries_cln.vbt.xloc[slice(\"2024-10-15 09:35:00\", \"2024-10-15 16:00:00\")].obj\n", "a" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Start Index 2024-10-15 09:30:00-04:00\n", "End Index 2024-10-15 15:59:48-04:00\n", "Total Duration 0 days 06:29:36\n", "Start Value 101.047553\n", "Min Value 101.047553\n", "Max Value 101.047553\n", "End Value 101.047553\n", "Total Return [%] 0.0\n", "Benchmark Return [%] -2.498843\n", "Position Coverage [%] 0.0\n", "Max Gross Exposure [%] 0.0\n", "Max Drawdown [%] NaN\n", "Max Drawdown Duration NaT\n", "Total Orders 0\n", "Total Fees Paid 0.0\n", "Total Trades 0\n", "Win Rate [%] NaN\n", "Best Trade [%] NaN\n", "Worst Trade [%] NaN\n", "Avg Winning Trade [%] NaN\n", "Avg Losing Trade [%] NaN\n", "Avg Winning Trade Duration NaT\n", "Avg Losing Trade Duration NaT\n", "Profit Factor NaN\n", "Expectancy NaN\n", "Sharpe Ratio NaN\n", "Calmar Ratio NaN\n", "Omega Ratio NaN\n", "Sortino Ratio NaN\n", "Name: agg_stats, dtype: object" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pf.xloc[\"2024-10-15\"].stats()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 172, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Exit Trade IdColumnSizeEntry Order IdEntry IndexAvg Entry PriceEntry FeesExit Order IdExit IndexAvg Exit PriceExit FeesPnLReturnDirectionStatusPosition Id
00(2, BAC)2.364210322024-10-15 09:30:48-04:0043.10000.017017332024-10-15 09:31:48-04:0042.9276000.0169490.3736240.003667ShortClosed0
11(2, BAC)2.386721342024-10-15 09:32:36-04:0042.85000.017079352024-10-15 09:35:00-04:0042.6786000.0170110.3749940.003667ShortClosed1
22(2, BAC)2.413778362024-10-15 09:35:24-04:0042.52500.017142372024-10-15 09:36:48-04:0042.6951000.0172100.3762310.003665LongClosed2
33(2, BAC)2.415524382024-10-15 09:37:00-04:0042.65000.017205392024-10-15 09:45:12-04:0042.4794000.0171360.3777480.003667ShortClosed3
44(2, BAC)2.434368402024-10-15 09:46:36-04:0042.47500.017268412024-10-15 09:48:00-04:0042.6449000.0173370.3789950.003665LongClosed4
55(2, BAC)2.432979422024-10-15 09:48:24-04:0042.65500.017331432024-10-15 09:50:48-04:0042.7829650.017383-0.346050-0.003335ShortClosed5
66(2, BAC)2.417777442024-10-15 09:52:00-04:0042.78010.017273452024-10-15 10:07:00-04:0042.6089800.0172040.3792530.003667ShortClosed6
77(2, BAC)2.443496462024-10-15 10:07:48-04:0042.48500.017337472024-10-15 10:12:12-04:0042.6549400.0174060.3805050.003665LongClosed7
88(2, BAC)2.443536482024-10-15 10:12:24-04:0042.64000.017400492024-10-15 10:13:12-04:0042.5800000.0173760.1118360.001073ShortClosed8
99(2, BAC)2.449605492024-10-15 10:13:12-04:0042.58000.017419502024-10-15 10:14:24-04:0042.6201000.0174350.0633750.000608LongClosed9
1010(2, BAC)2.448787502024-10-15 10:14:24-04:0042.62010.017429512024-10-15 10:20:36-04:0042.4650000.0173660.3450110.003306ShortClosed10
1111(2, BAC)2.465854512024-10-15 10:20:36-04:0042.46500.017487522024-10-15 11:08:12-04:0042.5900000.0175380.2732060.002609LongClosed11
1212(2, BAC)2.465031522024-10-15 11:08:12-04:0042.59000.017533532024-10-15 11:17:00-04:0042.7177700.017585-0.350075-0.003335ShortClosed12
1313(2, BAC)2.452200542024-10-15 11:20:00-04:0042.67010.017474552024-10-15 12:22:24-04:0042.7981100.017527-0.348908-0.003335ShortClosed13
1414(2, BAC)2.434196562024-10-15 12:23:00-04:0042.84240.017416572024-10-15 12:56:36-04:0042.6710300.0173460.3823850.003667ShortClosed14
1515(2, BAC)2.451836582024-10-15 12:57:36-04:0042.69010.017480592024-10-15 13:05:36-04:0042.6150000.0174490.1492040.001425ShortClosed15
1616(2, BAC)2.459657592024-10-15 13:05:36-04:0042.61500.017505602024-10-15 13:22:36-04:0042.4871550.017452-0.349412-0.003333LongClosed16
1717(2, BAC)2.459539612024-10-15 13:23:00-04:0042.47500.017446622024-10-15 14:00:24-04:0042.3475750.017394-0.348247-0.003333LongClosed17
1818(2, BAC)2.455968632024-10-15 14:03:00-04:0042.39500.017388642024-10-15 14:43:36-04:0042.5645800.0174580.3816370.003665LongClosed18
1919(2, BAC)2.455123652024-10-15 14:44:24-04:0042.56500.017452662024-10-15 15:36:00-04:0042.4373050.017400-0.348358-0.003333LongClosed19
2020(2, BAC)2.455883672024-10-15 15:36:24-04:0042.41000.017394682024-10-15 15:44:36-04:0042.2827700.017342-0.347197-0.003333LongClosed20
2121(2, BAC)2.455805692024-10-15 15:47:12-04:0042.27000.017336702024-10-15 15:52:00-04:0042.2200000.017315-0.157441-0.001517LongClosed21
\n", "
" ], "text/plain": [ " Exit Trade Id Column Size Entry Order Id \\\n", "0 0 (2, BAC) 2.364210 32 \n", "1 1 (2, BAC) 2.386721 34 \n", "2 2 (2, BAC) 2.413778 36 \n", "3 3 (2, BAC) 2.415524 38 \n", "4 4 (2, BAC) 2.434368 40 \n", "5 5 (2, BAC) 2.432979 42 \n", "6 6 (2, BAC) 2.417777 44 \n", "7 7 (2, BAC) 2.443496 46 \n", "8 8 (2, BAC) 2.443536 48 \n", "9 9 (2, BAC) 2.449605 49 \n", "10 10 (2, BAC) 2.448787 50 \n", "11 11 (2, BAC) 2.465854 51 \n", "12 12 (2, BAC) 2.465031 52 \n", "13 13 (2, BAC) 2.452200 54 \n", "14 14 (2, BAC) 2.434196 56 \n", "15 15 (2, BAC) 2.451836 58 \n", "16 16 (2, BAC) 2.459657 59 \n", "17 17 (2, BAC) 2.459539 61 \n", "18 18 (2, BAC) 2.455968 63 \n", "19 19 (2, BAC) 2.455123 65 \n", "20 20 (2, BAC) 2.455883 67 \n", "21 21 (2, BAC) 2.455805 69 \n", "\n", " Entry Index Avg Entry Price Entry Fees Exit Order Id \\\n", "0 2024-10-15 09:30:48-04:00 43.1000 0.017017 33 \n", "1 2024-10-15 09:32:36-04:00 42.8500 0.017079 35 \n", "2 2024-10-15 09:35:24-04:00 42.5250 0.017142 37 \n", "3 2024-10-15 09:37:00-04:00 42.6500 0.017205 39 \n", "4 2024-10-15 09:46:36-04:00 42.4750 0.017268 41 \n", "5 2024-10-15 09:48:24-04:00 42.6550 0.017331 43 \n", "6 2024-10-15 09:52:00-04:00 42.7801 0.017273 45 \n", "7 2024-10-15 10:07:48-04:00 42.4850 0.017337 47 \n", "8 2024-10-15 10:12:24-04:00 42.6400 0.017400 49 \n", "9 2024-10-15 10:13:12-04:00 42.5800 0.017419 50 \n", "10 2024-10-15 10:14:24-04:00 42.6201 0.017429 51 \n", "11 2024-10-15 10:20:36-04:00 42.4650 0.017487 52 \n", "12 2024-10-15 11:08:12-04:00 42.5900 0.017533 53 \n", "13 2024-10-15 11:20:00-04:00 42.6701 0.017474 55 \n", "14 2024-10-15 12:23:00-04:00 42.8424 0.017416 57 \n", "15 2024-10-15 12:57:36-04:00 42.6901 0.017480 59 \n", "16 2024-10-15 13:05:36-04:00 42.6150 0.017505 60 \n", "17 2024-10-15 13:23:00-04:00 42.4750 0.017446 62 \n", "18 2024-10-15 14:03:00-04:00 42.3950 0.017388 64 \n", "19 2024-10-15 14:44:24-04:00 42.5650 0.017452 66 \n", "20 2024-10-15 15:36:24-04:00 42.4100 0.017394 68 \n", "21 2024-10-15 15:47:12-04:00 42.2700 0.017336 70 \n", "\n", " Exit Index Avg Exit Price Exit Fees PnL Return \\\n", "0 2024-10-15 09:31:48-04:00 42.927600 0.016949 0.373624 0.003667 \n", "1 2024-10-15 09:35:00-04:00 42.678600 0.017011 0.374994 0.003667 \n", "2 2024-10-15 09:36:48-04:00 42.695100 0.017210 0.376231 0.003665 \n", "3 2024-10-15 09:45:12-04:00 42.479400 0.017136 0.377748 0.003667 \n", "4 2024-10-15 09:48:00-04:00 42.644900 0.017337 0.378995 0.003665 \n", "5 2024-10-15 09:50:48-04:00 42.782965 0.017383 -0.346050 -0.003335 \n", "6 2024-10-15 10:07:00-04:00 42.608980 0.017204 0.379253 0.003667 \n", "7 2024-10-15 10:12:12-04:00 42.654940 0.017406 0.380505 0.003665 \n", "8 2024-10-15 10:13:12-04:00 42.580000 0.017376 0.111836 0.001073 \n", "9 2024-10-15 10:14:24-04:00 42.620100 0.017435 0.063375 0.000608 \n", "10 2024-10-15 10:20:36-04:00 42.465000 0.017366 0.345011 0.003306 \n", "11 2024-10-15 11:08:12-04:00 42.590000 0.017538 0.273206 0.002609 \n", "12 2024-10-15 11:17:00-04:00 42.717770 0.017585 -0.350075 -0.003335 \n", "13 2024-10-15 12:22:24-04:00 42.798110 0.017527 -0.348908 -0.003335 \n", "14 2024-10-15 12:56:36-04:00 42.671030 0.017346 0.382385 0.003667 \n", "15 2024-10-15 13:05:36-04:00 42.615000 0.017449 0.149204 0.001425 \n", "16 2024-10-15 13:22:36-04:00 42.487155 0.017452 -0.349412 -0.003333 \n", "17 2024-10-15 14:00:24-04:00 42.347575 0.017394 -0.348247 -0.003333 \n", "18 2024-10-15 14:43:36-04:00 42.564580 0.017458 0.381637 0.003665 \n", "19 2024-10-15 15:36:00-04:00 42.437305 0.017400 -0.348358 -0.003333 \n", "20 2024-10-15 15:44:36-04:00 42.282770 0.017342 -0.347197 -0.003333 \n", "21 2024-10-15 15:52:00-04:00 42.220000 0.017315 -0.157441 -0.001517 \n", "\n", " Direction Status Position Id \n", "0 Short Closed 0 \n", "1 Short Closed 1 \n", "2 Long Closed 2 \n", "3 Short Closed 3 \n", "4 Long Closed 4 \n", "5 Short Closed 5 \n", "6 Short Closed 6 \n", "7 Long Closed 7 \n", "8 Short Closed 8 \n", "9 Long Closed 9 \n", "10 Short Closed 10 \n", "11 Long Closed 11 \n", "12 Short Closed 12 \n", "13 Short Closed 13 \n", "14 Short Closed 14 \n", "15 Short Closed 15 \n", "16 Long Closed 16 \n", "17 Long Closed 17 \n", "18 Long Closed 18 \n", "19 Long Closed 19 \n", "20 Long Closed 20 \n", "21 Long Closed 21 " ] }, "execution_count": 172, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pf.xloc[slice(\"2024-10-15 09:30:00\", \"2024-10-15 16:00:00\")].trades.records_readable\n", "\n" ] }, { "cell_type": "code", "execution_count": 154, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "19393" ] }, "execution_count": 154, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s12_data.wrapper.shape[0]" ] }, { "cell_type": "code", "execution_count": 155, "metadata": {}, "outputs": [], "source": [ "group_lens =s12_data.wrapper.get_index_grouper(\"D\").get_group_lens()" ] }, { "cell_type": "code", "execution_count": 157, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 0, 1941, 3871, 5799, 7727, 9669, 11601, 13551, 15500,\n", " 17448])" ] }, "execution_count": 157, "metadata": {}, "output_type": "execute_result" } ], "source": [ "group_end_idxs = np.cumsum(group_lens)\n", "# # group_start_idxs = group_end_idxs - group_lens" ] }, { "cell_type": "code", "execution_count": 144, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "s12_data.ohlcv.data[\"BAC-LONG\"].lw.plot(right=[(vwap_cum, \"vwap\")])" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
symbolBAC
time
2024-10-03 09:30:00-04:00NaN
2024-10-03 09:30:12-04:00NaN
2024-10-03 09:30:24-04:00NaN
2024-10-03 09:30:36-04:00NaN
2024-10-03 09:30:48-04:00NaN
......
2024-10-16 15:59:00-04:0042.7735
2024-10-16 15:59:12-04:0042.7720
2024-10-16 15:59:24-04:0042.7715
2024-10-16 15:59:36-04:0042.7730
2024-10-16 15:59:48-04:0042.7770
\n", "

19393 rows × 1 columns

\n", "
" ], "text/plain": [ "symbol BAC\n", "time \n", "2024-10-03 09:30:00-04:00 NaN\n", "2024-10-03 09:30:12-04:00 NaN\n", "2024-10-03 09:30:24-04:00 NaN\n", "2024-10-03 09:30:36-04:00 NaN\n", "2024-10-03 09:30:48-04:00 NaN\n", "... ...\n", "2024-10-16 15:59:00-04:00 42.7735\n", "2024-10-16 15:59:12-04:00 42.7720\n", "2024-10-16 15:59:24-04:00 42.7715\n", "2024-10-16 15:59:36-04:00 42.7730\n", "2024-10-16 15:59:48-04:00 42.7770\n", "\n", "[19393 rows x 1 columns]" ] }, "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import talib\n", "pd.set_option('display.max_rows', 500)\n", "def apply_func_1d(close, high, timeperiod):\n", " return talib.SMA(close.astype(np.double), timeperiod)\n", "\n", "SMA = vbt.IF(\n", " input_names=['close', 'high'],\n", " param_names=['timeperiod'],\n", " output_names=['sma']\n", ").with_apply_func(\n", " apply_func_1d,\n", " takes_1d=True,\n", " timeperiod=10, #single default\n", " high=vbt.Ref('close')) #default from another input\n", "\n", "ind = SMA.run(s12_data.close)\n", "ind.sma\n", "#sma.sma" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ROLLING_VWAP.run(\n", " open,\n", " high,\n", " low,\n", " close,\n", " volume,\n", " window=Default(value=200),\n", " min_periods=Default(value=None),\n", " short_name='rolling_vwap',\n", " hide_params=None,\n", " hide_default=True,\n", " **kwargs\n", "):\n", " Run `ROLLING_VWAP` indicator.\n", " \n", " * Inputs: `open`, `high`, `low`, `close`, `volume`\n", " * Parameters: `window`, `min_periods`\n", " * Outputs: `rolling_vwap`\n", " \n", " Pass a list of parameter names as `hide_params` to hide their column levels, or True to hide all.\n", " Set `hide_default` to False to show the column levels of the parameters with a default value.\n", " \n", " Other keyword arguments are passed to `ROLLING_VWAP.run_pipeline`.\n" ] } ], "source": [ "#vbt.IF.list_indicators(\"*vwap\")\n", "vbt.phelp(vbt.indicator(\"technical:ROLLING_VWAP\").run)\n" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.10.11" } }, "nbformat": 4, "nbformat_minor": 2 }