Skip to content

Commit

Permalink
Update 9. Rebalancing Positions.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
edtechre committed Apr 23, 2023
1 parent 80f4ec3 commit ba65f77
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions docs/notebooks/9. Rebalancing Positions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"data": {
"text/plain": [
"<diskcache.core.Cache at 0x7f76bc50aac0>"
"<diskcache.core.Cache at 0x7fa0e86ccb80>"
]
},
"execution_count": 1,
Expand Down Expand Up @@ -156,7 +156,7 @@
"output_type": "stream",
"text": [
"\n",
"Finished backtest: 0:00:02\n"
"Finished backtest: 0:00:03\n"
]
}
],
Expand Down Expand Up @@ -380,7 +380,7 @@
"\n",
"pyb.param('lookback', 252) # Use past year of returns.\n",
"\n",
"def calc_returns(ctxs, lookback):\n",
"def calc_returns(ctxs: dict[str, ExecContext], lookback: int):\n",
" prices = {}\n",
" for ctx in ctxs.values():\n",
" prices[ctx.symbol] = ctx.adj_close[-lookback:]\n",
Expand Down Expand Up @@ -507,31 +507,31 @@
" <tr>\n",
" <th>1</th>\n",
" <td>buy</td>\n",
" <td>TSLA</td>\n",
" <td>AAPL</td>\n",
" <td>2019-01-03</td>\n",
" <td>1150</td>\n",
" <td>1445</td>\n",
" <td>NaN</td>\n",
" <td>20.23</td>\n",
" <td>35.97</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>buy</td>\n",
" <td>AAPL</td>\n",
" <td>AMZN</td>\n",
" <td>2019-01-03</td>\n",
" <td>1445</td>\n",
" <td>248</td>\n",
" <td>NaN</td>\n",
" <td>35.97</td>\n",
" <td>75.88</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>buy</td>\n",
" <td>AMZN</td>\n",
" <td>TSLA</td>\n",
" <td>2019-01-03</td>\n",
" <td>248</td>\n",
" <td>1150</td>\n",
" <td>NaN</td>\n",
" <td>75.88</td>\n",
" <td>20.23</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
Expand All @@ -547,11 +547,11 @@
" <tr>\n",
" <th>5</th>\n",
" <td>buy</td>\n",
" <td>TSLA</td>\n",
" <td>AMZN</td>\n",
" <td>2019-02-04</td>\n",
" <td>88</td>\n",
" <td>105</td>\n",
" <td>NaN</td>\n",
" <td>20.57</td>\n",
" <td>81.58</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
Expand All @@ -561,11 +561,11 @@
"text/plain": [
" type symbol date shares limit_price fill_price fees\n",
"id \n",
"1 buy TSLA 2019-01-03 1150 NaN 20.23 0.0\n",
"2 buy AAPL 2019-01-03 1445 NaN 35.97 0.0\n",
"3 buy AMZN 2019-01-03 248 NaN 75.88 0.0\n",
"1 buy AAPL 2019-01-03 1445 NaN 35.97 0.0\n",
"2 buy AMZN 2019-01-03 248 NaN 75.88 0.0\n",
"3 buy TSLA 2019-01-03 1150 NaN 20.23 0.0\n",
"4 sell AAPL 2019-02-04 109 NaN 42.37 0.0\n",
"5 buy TSLA 2019-02-04 88 NaN 20.57 0.0"
"5 buy AMZN 2019-02-04 105 NaN 81.58 0.0"
]
},
"execution_count": 9,
Expand Down

0 comments on commit ba65f77

Please sign in to comment.