diff --git a/asset_backtester/examples/sma_and_rebalance_example.ipynb b/asset_backtester/examples/sma_and_rebalance_example.ipynb index ef3631f..51b04ef 100644 --- a/asset_backtester/examples/sma_and_rebalance_example.ipynb +++ b/asset_backtester/examples/sma_and_rebalance_example.ipynb @@ -9,18 +9,26 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/anaconda3/lib/python3.7/site-packages/pyfolio/pos.py:27: UserWarning: Module \"zipline.assets\" not found; mutltipliers will not be applied to position notionals.\n", + " 'Module \"zipline.assets\" not found; mutltipliers will not be applied' +\n" + ] + }, { "data": { "text/plain": [ "DataTransformerRegistry.enable('default')" ] }, - "execution_count": 18, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -37,7 +45,7 @@ "import pandas_datareader as pdr\n", "import datetime\n", "\n", - "#alt.renderers.enable('jpg')\n", + "alt.renderers.enable('kaggle')\n", "alt.data_transformers.disable_max_rows()" ] }, @@ -64,11 +72,28 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "env: TIINGO_API_KEY=1daeee45348833fa26a98a8e36993b8b9c8963b5\n" + ] + } + ], + "source": [ + "%env TIINGO_API_KEY=1daeee45348833fa26a98a8e36993b8b9c8963b5\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "api_key = '1daeee45348833fa26a98a8e36993b8b9c8963b5'\n", + "api_key = os.environ[\"TIINGO_API_KEY\"]\n", "\n", "start = datetime.datetime(2010, 1, 1)\n", "end = datetime.datetime(2019, 12, 31)\n", @@ -78,7 +103,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -90,7 +115,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 9, "metadata": { "scrolled": true }, @@ -102,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 10, "metadata": { "scrolled": true }, @@ -113,7 +138,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 11, "metadata": { "scrolled": true }, @@ -121,10 +146,10 @@ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 8, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -140,7 +165,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 12, "metadata": { "scrolled": true }, @@ -150,7 +175,8 @@ "data = HistoricalAssetData(save_path)\n", "bt = Backtest(schema)\n", "bt.data = data\n", - "bt.portfolio = portfolio" + "bt.portfolio = portfolio\n", + "bt.initial_capital=1_000_000" ] }, { @@ -162,7 +188,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 13, "metadata": { "scrolled": true }, @@ -172,7 +198,7 @@ "output_type": "stream", "text": [ "0% [██████████████████████████████] 100% | ETA: 00:00:00\n", - "Total time elapsed: 00:00:43\n" + "Total time elapsed: 00:00:42\n" ] }, { @@ -727,14 +753,14 @@ "[2517 rows x 5 columns]" ] }, - "execution_count": 10, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#periods = months between rebalance\n", - "bt.run(initial_capital=1_000_000, periods=6, sma_days= 100)" + "bt.run(periods=6, sma_days= 100)" ] }, { @@ -746,7 +772,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 14, "metadata": { "scrolled": true }, @@ -755,10 +781,10 @@ "data": { "text/html": [ "\n", - "
\n", + "
\n", "