{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b39a3609-b306-470f-89d5-4710794b2008",
   "metadata": {},
   "source": [
    "## Another short example to use as a template."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63c9604f-4e6e-4e72-93d7-cdb5788d81d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.insert(0, \"../src\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40025313-4ed5-4e6e-8eca-dc084830ca21",
   "metadata": {},
   "outputs": [],
   "source": [
    "import owlplanner as owl\n",
    "p = owl.Plan(['Kim', 'Sam'], ['1966-01-15', '1967-01-16'], [86, 89], 'kim+sam-spending', verbose=True)\n",
    "# p.setPlotBackend(\"plotly\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "435a0599-accb-42cd-a1c2-382b97383626",
   "metadata": {},
   "outputs": [],
   "source": [
    "# p.setPension([0, 0], [65, 65])\n",
    "p.setSocialSecurity([3750, 2083], [70, 68])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b622cd0-f176-4a2f-8470-a0b457294e87",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.setSpendingProfile('smile', 60)\n",
    "# p.setSpendingProfile('flat', 60)\n",
    "p.showProfile()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dbbf9e2f-7fb1-4861-874f-0d987966ebfb",
   "metadata": {},
   "outputs": [],
   "source": [
    "#p.setRates('historical', 1998)\n",
    "p.setRates('conservative')\n",
    "#p.setRates('historical', 1966)\n",
    "p.showRates()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "31eec280-acdb-40d0-9404-d508a60cf206",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.setAccountBalances(taxable=[1000, 0], taxDeferred=[2000, 800], taxFree=[500, 25], startDate='01-01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45f2bb63-f6c6-42a1-a112-fd8e8146f470",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.readHFP('../examples/HFP_template.xlsx');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "747f1a39-501e-4560-b856-b838720289fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.setHeirsTaxRate(33)\n",
    "p.setInterpolationMethod('s-curve')\n",
    "p.setAllocationRatios(\n",
    "    'individual',\n",
    "    generic=[[[60, 40, 0, 0], [70, 30, 0, 0]], [[60, 40, 0, 0], [70, 30, 0, 0]]]\n",
    ")\n",
    "p.showAllocations()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e153434-a9ba-4ced-b138-4dc0e844ac0f",
   "metadata": {},
   "source": [
    "### Optimize spending and save workbook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ede7fa05-8a6e-41b4-8b7c-a217d28ad41b",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%time\n",
    "options = {'maxRothConversion': 300, 'bequest': 2000}\n",
    "p.solve('maxSpending', options=options)\n",
    "p.saveConfig()\n",
    "p.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2542fd7-f087-4597-b9c4-1c3b8fa2e452",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.setDefaultPlots('today')\n",
    "p.showNetSpending()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "525f22e2-d241-4fa8-bc95-82d758238326",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.showGrossIncome()\n",
    "p.showTaxes()\n",
    "p.showSources()\n",
    "p.showAccounts()\n",
    "p.showAssetDistribution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1202e86b-4f08-4158-8546-6105da68f77a",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.saveWorkbook(True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7469daf-61b8-42a4-bcb8-22c801014d8c",
   "metadata": {},
   "source": [
    "### Optimize bequest and save workbook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73c77134-4b50-42f4-bd2d-d7eb59c5e750",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%time\n",
    "options = {'maxRothConversion': 300, 'netSpending': 180}\n",
    "p.rename('case_kim+sam-bequest')\n",
    "p.solve('maxBequest', options=options)\n",
    "p.saveConfig()\n",
    "p.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0164a9df-1943-4ead-a0af-71ed502c6417",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.showNetSpending()\n",
    "p.showGrossIncome()\n",
    "p.showTaxes()\n",
    "p.showSources()\n",
    "p.showAccounts()\n",
    "p.showAssetDistribution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2206eda7-7534-4b78-a58b-ad9879295fae",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.saveWorkbook(True)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
