{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Contributing to C++ Financial Libraries\n",
        "\n",
        "Design a small, testable contribution to a financial C++ library instead of building another toy Python-only project.\n",
        "\n",
        "**How to use this notebook:** We give you the structure, the key ideas, starter code, and places where you need to make the important research decisions yourself."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## What you should have by the end\n",
        "\n",
        "- A working prototype\n",
        "- A few graphs/tables that explain what your model is doing\n",
        "- A short write-up of your assumptions\n",
        "- At least one extension that makes the project feel like yours"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Concept\n",
        "\n",
        "Quant dev is not just writing strategies.\n",
        "\n",
        "A strong project can be improving a numerical finance library: adding tests, documenting behaviour, speeding up a function, or implementing a small pricing/risk module. This notebook is a planning and prototyping workspace for a C++ contribution."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Starter Code\n",
        "\n",
        "1. Pick a small function or module.\n",
        "2. Write the mathematical specification.\n",
        "3. Prototype the logic in Python.\n",
        "4. Translate the core to C++.\n",
        "5. Add tests and benchmark the change.\n",
        "\n",
        "Good contribution ideas:\n",
        "\n",
        "- Fix a numerical edge case.\n",
        "- Add missing tests for an option pricing function.\n",
        "- Improve documentation for a confusing module.\n",
        "- Implement a small utility with clear scope."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "\n",
        "def reference_discount_factor(rate, time):\n",
        "    # Python reference implementation.\n",
        "    # TODO:\n",
        "    # - Decide compounding convention.\n",
        "    # - Add input validation.\n",
        "    # - Match the target library's API style.\n",
        "    return np.exp(-rate * time)\n",
        "\n",
        "test_cases = pd.DataFrame({\n",
        "    \"rate\": [0.01, 0.03, 0.05],\n",
        "    \"time\": [0.5, 1.0, 2.0]\n",
        "})\n",
        "\n",
        "test_cases[\"expected_discount_factor\"] = reference_discount_factor(\n",
        "    test_cases[\"rate\"],\n",
        "    test_cases[\"time\"]\n",
        ")\n",
        "\n",
        "test_cases"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Example C++ skeleton\n",
        "\n",
        "This is deliberately not a full library contribution. Your job is to adapt the structure to the actual library style, tests, naming conventions, and contribution guidelines.\n",
        "\n",
        "```cpp\n",
        "#pragma once\n",
        "#include <cmath>\n",
        "#include <stdexcept>\n",
        "\n",
        "namespace finance {\n",
        "\n",
        "inline double discount_factor(double rate, double time) {\n",
        "    // TODO: check the target library's convention before implementing.\n",
        "    // Should negative rates be allowed?\n",
        "    // Should time == 0 return 1?\n",
        "    // Should this use continuous or discrete compounding?\n",
        "    if (time < 0.0) {\n",
        "        throw std::invalid_argument(\"time must be non-negative\");\n",
        "    }\n",
        "    return std::exp(-rate * time);\n",
        "}\n",
        "\n",
        "} // namespace finance\n",
        "```"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "def generate_test_assertions(test_cases):\n",
        "    # Generate rough C++ test cases from Python reference values.\n",
        "    # TODO:\n",
        "    # - Convert this into the test framework used by the library.\n",
        "    # - Add edge cases.\n",
        "    # - Add tolerance rules.\n",
        "    for _, row in test_cases.iterrows():\n",
        "        print(\n",
        "            f'CHECK_CLOSE(discount_factor({row[\"rate\"]}, {row[\"time\"]}), '\n",
        "            f'{row[\"expected_discount_factor\"]:.12f}, 1e-10);'\n",
        "        )\n",
        "\n",
        "generate_test_assertions(test_cases)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Open-ended extensions\n",
        "\n",
        "- Benchmark before/after runtime.\n",
        "- Add property-based tests.\n",
        "- Reproduce a bug and write a regression test.\n",
        "- Submit a documentation-only PR first.\n",
        "- Write a short engineering note explaining why your contribution is correct."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Final write-up prompts\n",
        "\n",
        "Answer these before putting the project on your resume:\n",
        "\n",
        "1. What problem were you trying to solve?\n",
        "2. What assumptions did your model make?\n",
        "3. Where did the model work well?\n",
        "4. Where did it fail?\n",
        "5. What would you improve with more time?\n",
        "6. What is one interesting thing you learned that was not obvious before starting?"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.x"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}