{
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "pygments_lexer": "ipython3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# 03 Term structure\n",
        "\n",
        "Does the gap between five-print RWTC returns in backwardation and in contango keep its sign after 2019?\n",
        "\n",
        "Holdout starts 2020-01-01. Verdict: held.\n",
        "\n",
        "This study reads stored series. It does not add a derived column."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {},
      "source": [
        "import json\n",
        "from pathlib import Path\n",
        "studies = json.loads(Path('data/studies.json').read_text())\n",
        "study = next(item for item in studies['studies'] if item['slug'] == 'term-structure')\n",
        "print(study['verdict'])\n",
        "print(study['verdict_line'])\n",
        "print(study['table']['caption'])\n",
        "for row in study['table']['rows']:\n",
        "    print(' | '.join(row))\n"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "held\n",
            "Train mean five-print RWTC return in backwardation minus contango is -0.133%. Holdout difference is -0.055%. A negative gap means backwardation did not pay more than contango. The holdout kept the train sign.\n",
            "Five-print RWTC log return by the sign of RCLC1 minus RCLC4\n",
            "Train | Backwardation (spread > 0) | 3485 | -0.007%\n",
            "Train | Contango (spread < 0) | 3949 | 0.126%\n",
            "Holdout | Backwardation (spread > 0) | 717 | 0.196%\n",
            "Holdout | Contango (spread < 0) | 349 | 0.251%\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Method\n",
        "\n",
        "On each day both the spread and RWTC print, take the log change in RWTC five published prints later. Split the days by the sign of the spread.\n",
        "\n",
        "## Result\n",
        "\n",
        "Train mean five-print RWTC return in backwardation minus contango is -0.133%. Holdout difference is -0.055%. A negative gap means backwardation did not pay more than contango. The holdout kept the train sign."
      ]
    }
  ]
}
