Skip to content

Commit

Permalink
Small fix for Volatility Harvesting
Browse files Browse the repository at this point in the history
  • Loading branch information
Hvass-Labs committed May 31, 2021
1 parent 31fb561 commit 164ecb5
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions Paper_Volatility_Harvesting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@
"See the [GitHub repository](https://github.com/Hvass-Labs/FinanceOps) for instructions on how to install and run this Python Notebook. The Python source-code is well-documented so you can hopefully understand and modify it yourself, but there is otherwise a minimum of explanations in this Notebook because it is all explained in the paper."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Errata\n",
"\n",
"### Forward-Filled Share-Prices\n",
"\n",
"The original version had forward-filled the share-prices before calculating the daily returns. Some stocks such as YHOO were delisted and did not have share-prices until the end. Due to the forward-filled share-prices, the delisted stocks were therefore padded with daily returns of zero percent.\n",
"\n",
"This does not make any difference for the Buy&Hold portfolios, but for the Rebalanced portfolios it corresponds to having that small part of the portfolio invested in cash instead, and therefore rebalancing a small part of the portfolio into cash at each time-step, which could distort the results of the rebalancing.\n",
"\n",
"The relevant code has been marked with the word \"Correction\" so you can switch between the original version and the corrected version. I have tested it and there is no material difference in the plots, statistics and conclusions of this paper."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -665,17 +680,28 @@
}
],
"source": [
"# Fill-method for the daily share-prices.\n",
"# Correction: See the Errata-section above for a detailed explanation.\n",
"# You can experiment with the two options. But there does not appear\n",
"# to be any material difference in the resulting plots and statistics.\n",
"if True:\n",
" # Forward-filling of missing share-prices, as used in the paper.\n",
" fill_method = 'ffill'\n",
"else:\n",
" # Missing share-prices are not filled.\n",
" fill_method = None\n",
"\n",
"# Daily stock-returns calculated from the \"Total Return\".\n",
"# We add 1.0 so we don't have to repeatedly add it later.\n",
"# We forward-fill missing prices, which should not be necessary,\n",
"# but we do it in case there is missing data-points.\n",
"# We could have used SimFin's function hub.returns() but\n",
"# this code makes it easier for you to use another data-source.\n",
"# This is a Pandas DataFrame in matrix-form where the rows are\n",
"# time-steps and the columns are for the individual tickers.\n",
"daily_returns_all = daily_prices.ffill().pct_change(periods=1) + 1.0\n",
"daily_returns_all = \\\n",
" daily_prices.pct_change(periods=1,\n",
" fill_method=fill_method) + 1.0\n",
"\n",
"# Remove empty rows (this should only be the first row).\n",
"# Remove empty rows where all elements are NaN (Not-a-Number).\n",
"daily_returns_all = daily_returns_all.dropna(how='all')\n",
"\n",
"# Show it.\n",
Expand Down

0 comments on commit 164ecb5

Please sign in to comment.