├── .qrignore ├── README.md ├── trend_day ├── Introduction.ipynb ├── trend_day.py ├── Part1-Data-Collection.ipynb └── Part4-Slippage-Research.ipynb └── LICENSE.txt /.qrignore: -------------------------------------------------------------------------------- 1 | README.md 2 | LICENSE.txt 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # trend-day 2 | 3 | Intraday momentum strategy that buys (sells) leveraged ETFs late in the trading session following a significant intraday gain (loss) and holds until the close. From Ernie Chan's book *Algorithmic Trading*. Runs in Moonshot. 4 | 5 | ## Clone in QuantRocket 6 | 7 | CLI: 8 | 9 | ```shell 10 | quantrocket codeload clone 'trend-day' 11 | ``` 12 | 13 | Python: 14 | 15 | ```python 16 | from quantrocket.codeload import clone 17 | clone("trend-day") 18 | ``` 19 | 20 | ## Browse in GitHub 21 | 22 | Start here: [trend_day/Introduction.ipynb](trend_day/Introduction.ipynb) 23 | 24 | *** 25 | 26 | Find more code in QuantRocket's [Codeload Library](https://www.quantrocket.com/code/) 27 | -------------------------------------------------------------------------------- /trend_day/Introduction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\"QuantRocket
\n", 8 | "Disclaimer" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "# Leveraged ETF Intraday Momentum Strategy\n", 16 | "\n", 17 | "This tutorial demonstrates an intraday momentum strategy from Ernie Chan's book *Algorithmic Trading*. The strategy buys (sells) leveraged ETFs late in the trading session following a significant intraday gain (loss) and holds until the close. \n", 18 | "\n", 19 | "According to Chan, the rationale for this strategy is that, when the leveraged ETF has a sizable intraday gain, the ETF sponsors are forced to buy additional shares of the underlying securities in order to maintain a constant daily leverage as stipulated by the fund prospectus. This buying further drives up the price heading into the close. A similar process occurs following a sizable intraday decline. \n", 20 | "\n", 21 | "**Source**: Ernie Chan, *Algorithmic Trading: Winning Strategies and Their Rationale*, Wiley, May 28, 2013, chapter 7. " 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "* Part 1: [Data Collection](Part1-Data-Collection.ipynb)\n", 29 | "* Part 2: [Moonshot Backtest](Part2-Moonshot-Backtest.ipynb)\n", 30 | "* Part 3: [Parameter Scans](Part3-Parameter-Scans.ipynb)\n", 31 | "* Part 4: [Slippage Research](Part4-Slippage-Research.ipynb)" 32 | ] 33 | } 34 | ], 35 | "metadata": { 36 | "kernelspec": { 37 | "display_name": "Python 3.9", 38 | "language": "python", 39 | "name": "python3" 40 | }, 41 | "language_info": { 42 | "codemirror_mode": { 43 | "name": "ipython", 44 | "version": 3 45 | }, 46 | "file_extension": ".py", 47 | "mimetype": "text/x-python", 48 | "name": "python", 49 | "nbconvert_exporter": "python", 50 | "pygments_lexer": "ipython3", 51 | "version": "3.9.7" 52 | } 53 | }, 54 | "nbformat": 4, 55 | "nbformat_minor": 4 56 | } 57 | -------------------------------------------------------------------------------- /trend_day/trend_day.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 QuantRocket LLC - All Rights Reserved 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import pandas as pd 16 | from moonshot import Moonshot 17 | from moonshot.commission import PerShareCommission 18 | 19 | class USStockCommission(PerShareCommission): 20 | BROKER_COMMISSION_PER_SHARE = 0.005 21 | 22 | class TrendDayStrategy(Moonshot): 23 | """ 24 | Intraday strategy that buys (sells) if the security is up (down) more 25 | than N% from yesterday's close as of 2:00 PM. Enters at 2:01 PM and 26 | exits the position at the market close. 27 | """ 28 | 29 | CODE = 'trend-day' 30 | DB = 'usstock-1min' 31 | UNIVERSES = "leveraged-etf" 32 | DB_TIMES = ['14:00:00', '15:59:00'] 33 | DB_FIELDS = ['Open','Close'] 34 | MIN_PCT_CHANGE = 0.06 35 | COMMISSION_CLASS = USStockCommission 36 | SLIPPAGE_BPS = 3 37 | 38 | def prices_to_signals(self, prices: pd.DataFrame): 39 | 40 | closes = prices.loc["Close"] 41 | opens = prices.loc["Open"] 42 | 43 | # Take a cross section (xs) of prices to get a specific time's price; 44 | # the close of the 15:59 bar is the session close 45 | session_closes = closes.xs("15:59:00", level="Time") 46 | # the open of the 14:00 bar is the 14:00 price 47 | afternoon_prices = opens.xs("14:00:00", level="Time") 48 | 49 | # calculate the return from yesterday's close to 14:00 50 | prior_closes = session_closes.shift() 51 | returns = (afternoon_prices - prior_closes) / prior_closes 52 | 53 | # Go long if up more than N%, go short if down more than -N% 54 | long_signals = returns > self.MIN_PCT_CHANGE 55 | short_signals = returns < -self.MIN_PCT_CHANGE 56 | 57 | # Combine long and short signals 58 | signals = long_signals.astype(int).where(long_signals, -short_signals.astype(int)) 59 | return signals 60 | 61 | def signals_to_target_weights(self, signals: pd.DataFrame, prices: pd.DataFrame): 62 | 63 | # allocate 20% of capital to each position, or equally divide capital 64 | # among positions, whichever is less 65 | target_weights = self.allocate_fixed_weights_capped(signals, 0.20, cap=1.0) 66 | return target_weights 67 | 68 | def target_weights_to_positions(self, target_weights: pd.DataFrame, prices: pd.DataFrame): 69 | 70 | # We enter on the same day as the signals/target_weights 71 | positions = target_weights.copy() 72 | return positions 73 | 74 | def positions_to_gross_returns(self, positions: pd.DataFrame, prices: pd.DataFrame): 75 | 76 | closes = prices.loc["Close"] 77 | 78 | # Our signal came at 14:00 and we enter at 14:01 (the close of the 14:00 bar) 79 | entry_prices = closes.xs("14:00:00", level="Time") 80 | session_closes = closes.xs("15:59:00", level="Time") 81 | 82 | # Our return is the 14:01-16:00 return, multiplied by the position 83 | pct_changes = (session_closes - entry_prices) / entry_prices 84 | gross_returns = pct_changes * positions 85 | return gross_returns 86 | 87 | def order_stubs_to_orders(self, orders: pd.DataFrame, prices: pd.DataFrame): 88 | 89 | # enter using market orders 90 | orders["Exchange"] = "SMART" 91 | orders["OrderType"] = "MKT" 92 | orders["Tif"] = "Day" 93 | 94 | # exit using MOC orders 95 | child_orders = self.orders_to_child_orders(orders) 96 | child_orders["OrderType"] = "MOC" 97 | 98 | orders = pd.concat([orders, child_orders]) 99 | return orders 100 | -------------------------------------------------------------------------------- /trend_day/Part1-Data-Collection.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\"QuantRocket
\n", 8 | "Disclaimer" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "***\n", 16 | "[Leveraged ETF Intraday Momentum Strategy](Introduction.ipynb) › Part 1: Data Collection\n", 17 | "***" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Data Collection\n", 25 | "\n", 26 | "The data collection process consists of collecting US stock listings, creating a universe of leveraged ETFs, then collecting 1 minute bars for the leveraged ETFs." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## Collect ETF listings\n", 34 | "\n", 35 | "First collect US Stock listings:" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 1, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "data": { 45 | "text/plain": [ 46 | "{'status': 'success', 'msg': 'successfully loaded US stock listings'}" 47 | ] 48 | }, 49 | "execution_count": 1, 50 | "metadata": {}, 51 | "output_type": "execute_result" 52 | } 53 | ], 54 | "source": [ 55 | "from quantrocket.master import collect_usstock_listings\n", 56 | "collect_usstock_listings()" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "## Define universe of leveraged ETFs \n", 64 | "\n", 65 | "Next we download a CSV of several leveraged ETFs:" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 2, 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "from quantrocket.master import download_master_file\n", 75 | "download_master_file(\n", 76 | " \"leveraged_etfs.csv\",\n", 77 | " exchanges=\"ARCX\",\n", 78 | " sec_types=\"ETF\", \n", 79 | " symbols=[\n", 80 | " \"SPXL\", # DIREXION DLY S&P 500 BULL 3X\n", 81 | " \"TNA\", # DIREXION DLY SM CAP BULL 3X\n", 82 | " \"ERX\", # DIREXION DLY ENERGY BULL 3X\n", 83 | " \"TMF\", # DRX DLY 20+ YR TREAS BULL 3X\n", 84 | " \"UPRO\", # PROSHARES ULTRAPRO S&P 500\n", 85 | " \"DRN\", # DRX DLY REAL ESTATE BULL 3X\n", 86 | " \"YINN\", # DRX DLY FTSE CHINA BULL 3X\n", 87 | " \"UDOW\", # PROSHARES ULTRAPRO DOW30\n", 88 | " \"URTY\", # PROSHARES ULTRAPRO RUSS2000\n", 89 | " \"FAS\", # DIREXION DAILY FIN BULL 3X\n", 90 | " \"EDC\", # DIREXION DLY EMG MKT BULL 3X\n", 91 | " \"RUSL\", # DIREXION DLY RUSSIA BULL 3X\n", 92 | " \"JNUG\", # DIREXION DLY JR GOLD BULL 3X\n", 93 | " \"NUGT\", # DRX DLY GOLD MINERS BULL 3X\n", 94 | " ])" 95 | ] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "metadata": {}, 100 | "source": [ 101 | "Then upload the CSV to create the \"leveraged-etf\" universe:" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 3, 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "data": { 111 | "text/plain": [ 112 | "{'code': 'leveraged-etf',\n", 113 | " 'provided': 14,\n", 114 | " 'inserted': 14,\n", 115 | " 'total_after_insert': 14}" 116 | ] 117 | }, 118 | "execution_count": 3, 119 | "metadata": {}, 120 | "output_type": "execute_result" 121 | } 122 | ], 123 | "source": [ 124 | "from quantrocket.master import create_universe\n", 125 | "create_universe(\"leveraged-etf\", infilepath_or_buffer=\"leveraged_etfs.csv\")" 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "## Collect historical data\n", 133 | "\n", 134 | "Next, we create a Zipline bundle for collecting 1-min bars." 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 4, 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "data": { 144 | "text/plain": [ 145 | "{'status': 'success', 'msg': 'successfully created usstock-1min bundle'}" 146 | ] 147 | }, 148 | "execution_count": 4, 149 | "metadata": {}, 150 | "output_type": "execute_result" 151 | } 152 | ], 153 | "source": [ 154 | "from quantrocket.zipline import create_usstock_bundle\n", 155 | "create_usstock_bundle(\"usstock-1min\")" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": {}, 161 | "source": [ 162 | "Then collect the data for the leveraged ETFs:" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 5, 168 | "metadata": {}, 169 | "outputs": [ 170 | { 171 | "data": { 172 | "text/plain": [ 173 | "{'status': 'the data will be ingested asynchronously'}" 174 | ] 175 | }, 176 | "execution_count": 5, 177 | "metadata": {}, 178 | "output_type": "execute_result" 179 | } 180 | ], 181 | "source": [ 182 | "from quantrocket.zipline import ingest_bundle\n", 183 | "ingest_bundle(\"usstock-1min\", universes=\"leveraged-etf\")" 184 | ] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "metadata": {}, 189 | "source": [ 190 | "Monitor flightlog for completion:\n", 191 | "\n", 192 | "```\n", 193 | "quantrocket.zipline: INFO [usstock-1min] Collecting minute bars for 14 securities in usstock-1min bundle\n", 194 | "quantrocket.zipline: INFO [usstock-1min] Collecting daily bars for usstock-1min bundle\n", 195 | "quantrocket.zipline: INFO [usstock-1min] Collecting adjustments for usstock-1min bundle\n", 196 | "quantrocket.zipline: INFO [usstock-1min] Collecting assets for usstock-1min bundle\n", 197 | "quantrocket.zipline: INFO [usstock-1min] Completed collecting data for 14 securities in usstock-1min bundle\n", 198 | "```" 199 | ] 200 | }, 201 | { 202 | "cell_type": "markdown", 203 | "metadata": {}, 204 | "source": [ 205 | "***\n", 206 | "\n", 207 | "## *Next Up*\n", 208 | "\n", 209 | "Part 2: [Moonshot Backtest](Part2-Moonshot-Backtest.ipynb)" 210 | ] 211 | } 212 | ], 213 | "metadata": { 214 | "kernelspec": { 215 | "display_name": "Python 3.9", 216 | "language": "python", 217 | "name": "python3" 218 | }, 219 | "language_info": { 220 | "codemirror_mode": { 221 | "name": "ipython", 222 | "version": 3 223 | }, 224 | "file_extension": ".py", 225 | "mimetype": "text/x-python", 226 | "name": "python", 227 | "nbconvert_exporter": "python", 228 | "pygments_lexer": "ipython3", 229 | "version": "3.9.7" 230 | } 231 | }, 232 | "nbformat": 4, 233 | "nbformat_minor": 4 234 | } 235 | -------------------------------------------------------------------------------- /trend_day/Part4-Slippage-Research.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\"QuantRocket
\n", 8 | "Disclaimer" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "***\n", 16 | "[Leveraged ETF Intraday Momentum Strategy](Introduction.ipynb) › Part 4: Slippage Research\n", 17 | "***" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Slippage Research\n", 25 | "\n", 26 | "The provided trading strategy code models one-way slippage of 3 basis points (see the `SLIPPAGE_BPS` parameter). This notebook investigates spreads with more precision, as they vary by leveraged ETF. To do so, we collect 1 month of bid/ask data for the leveraged ETFs and calculate the spreads at 2:15 PM (the time we enter positions).\n", 27 | "\n", 28 | "Spread analysis uses data from Interactive Brokers.\n" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## Data collection\n", 36 | "First, create a database for the historical data:" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 1, 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "data": { 46 | "text/plain": [ 47 | "{'status': 'successfully created quantrocket.v2.history.leveraged-etf-quotes-1min.sqlite'}" 48 | ] 49 | }, 50 | "execution_count": 1, 51 | "metadata": {}, 52 | "output_type": "execute_result" 53 | } 54 | ], 55 | "source": [ 56 | "from quantrocket.history import create_ibkr_db\n", 57 | "create_ibkr_db(\"leveraged-etf-quotes-1min\", \n", 58 | " universes=\"leveraged-etf\", \n", 59 | " bar_size=\"1 min\", \n", 60 | " bar_type=\"BID_ASK\", \n", 61 | " start_date=\"2019-01-01\", \n", 62 | " end_date=\"2019-01-31\",\n", 63 | " shard=\"off\")" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "Then collect the data:" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 2, 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "data": { 80 | "text/plain": [ 81 | "{'status': 'the historical data will be collected asynchronously'}" 82 | ] 83 | }, 84 | "execution_count": 2, 85 | "metadata": {}, 86 | "output_type": "execute_result" 87 | } 88 | ], 89 | "source": [ 90 | "from quantrocket.history import collect_history\n", 91 | "collect_history(\"leveraged-etf-quotes-1min\")" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "Monitor flightlog for the completion message:\n", 99 | "\n", 100 | "```\n", 101 | "quantrocket.history: INFO [leveraged-etf-quotes-1min] Collecting history from IBKR for 14 securities in leveraged-etf-quotes-1min\n", 102 | "quantrocket.history: INFO [leveraged-etf-quotes-1min] Saved 114660 total records for 14 total securities to quantrocket.v2.history.leveraged-etf-quotes-1min.sqlite\n", 103 | "```" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "## Spread analysis\n", 111 | "\n", 112 | "Now we can load the bid/ask data and check the spreads." 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 3, 118 | "metadata": {}, 119 | "outputs": [], 120 | "source": [ 121 | "from quantrocket import get_prices\n", 122 | "prices = get_prices(\"leveraged-etf-quotes-1min\", fields=[\"Open\",\"Close\"], times=\"14:15:00\")" 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "metadata": {}, 128 | "source": [ 129 | "For this bar type, the \"Open\" contains the time-average bid and the \"Close\" contains the time-average ask." 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 4, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "bids = prices.loc[\"Open\"]\n", 139 | "asks = prices.loc[\"Close\"]" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "metadata": {}, 145 | "source": [ 146 | "Compute the spreads in basis points:" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 5, 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "spreads = (asks - bids)\n", 156 | "spreads_in_bps = (spreads/bids).astype(float)" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "metadata": {}, 162 | "source": [ 163 | "Replace sids with symbols for easier readability:" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 6, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "from quantrocket.master import get_securities_reindexed_like\n", 173 | "symbols = get_securities_reindexed_like(bids, fields=\"Symbol\").loc[\"Symbol\"]\n", 174 | "symbols = symbols.iloc[0].to_dict()\n", 175 | "spreads_in_bps = spreads_in_bps.rename(columns=symbols)" 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": {}, 181 | "source": [ 182 | "Finally, check the spreads at 2:15 PM:" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 7, 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "data": { 192 | "text/plain": [ 193 | "Sid\n", 194 | "SPXL 3.140246\n", 195 | "TNA 4.769774\n", 196 | "ERX 5.654112\n", 197 | "TMF 5.985715\n", 198 | "UPRO 4.097632\n", 199 | "DRN 70.678831\n", 200 | "YINN 5.168800\n", 201 | "UDOW 3.957265\n", 202 | "URTY 9.336790\n", 203 | "FAS 7.547277\n", 204 | "EDC 10.734769\n", 205 | "RUSL 22.694030\n", 206 | "JNUG 10.018724\n", 207 | "NUGT 5.738911\n", 208 | "dtype: float64" 209 | ] 210 | }, 211 | "execution_count": 7, 212 | "metadata": {}, 213 | "output_type": "execute_result" 214 | } 215 | ], 216 | "source": [ 217 | "spreads_in_bps.xs(\"14:15:00\", level=\"Time\").mean() * 1e4" 218 | ] 219 | }, 220 | { 221 | "cell_type": "markdown", 222 | "metadata": {}, 223 | "source": [ 224 | "The spreads range from 3 basis points to 70 basis points. Because the strategy enters during the trading session and exits on-the-close, we expect to pay half the spread on our entries but we do not expect to incur any slippage on our exits. Thus, we should average the spread of the securities we intend to trade, then divide by 2 since we only expect to pay half the spread, then divide by 2 again since we only expect to incur slippage on our entries, not our exits. " 225 | ] 226 | }, 227 | { 228 | "cell_type": "markdown", 229 | "metadata": {}, 230 | "source": [ 231 | "***\n", 232 | "\n", 233 | "[Back to Introduction](Introduction.ipynb)" 234 | ] 235 | } 236 | ], 237 | "metadata": { 238 | "kernelspec": { 239 | "display_name": "Python 3.9", 240 | "language": "python", 241 | "name": "python3" 242 | }, 243 | "language_info": { 244 | "codemirror_mode": { 245 | "name": "ipython", 246 | "version": 3 247 | }, 248 | "file_extension": ".py", 249 | "mimetype": "text/x-python", 250 | "name": "python", 251 | "nbconvert_exporter": "python", 252 | "pygments_lexer": "ipython3", 253 | "version": "3.9.7" 254 | } 255 | }, 256 | "nbformat": 4, 257 | "nbformat_minor": 4 258 | } 259 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 10 | 11 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 12 | 13 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 14 | 15 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 16 | 17 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 18 | 19 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 20 | 21 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 22 | 23 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 24 | 25 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 26 | 27 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 28 | 29 | 2. Grant of Copyright License. 30 | 31 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 32 | 33 | 3. Grant of Patent License. 34 | 35 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 36 | 37 | 4. Redistribution. 38 | 39 | You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 40 | 41 | You must give any other recipients of the Work or Derivative Works a copy of this License; and 42 | You must cause any modified files to carry prominent notices stating that You changed the files; and 43 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 44 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 45 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 46 | 47 | 5. Submission of Contributions. 48 | 49 | Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 50 | 51 | 6. Trademarks. 52 | 53 | This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 54 | 55 | 7. Disclaimer of Warranty. 56 | 57 | Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 58 | 59 | 8. Limitation of Liability. 60 | 61 | In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 62 | 63 | 9. Accepting Warranty or Additional Liability. 64 | 65 | While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 66 | 67 | END OF TERMS AND CONDITIONS 68 | --------------------------------------------------------------------------------