{ "cells": [ { "cell_type": "markdown", "id": "5f6ccd5b", "metadata": {}, "source": [ "# CapiPort - PORTFOLIO OPTIMISATION" ] }, { "cell_type": "markdown", "id": "b1962897", "metadata": {}, "source": [ " Two things to consider for Portfolio Optimisation:\n", " \n", " 1) Minimising Risk\n", " 2) Maximising Return" ] }, { "cell_type": "markdown", "id": "9d025126", "metadata": {}, "source": [ " Basic process of Portfolio Optimisation:\n", " \n", " 1) Select the Asset class to work on.\n", " 1.1) Asset Class choosen - Equity (Stocks)\n", " 2) Select the Companies which you want to use to build a Portfolio.\n", " 2.1) Companies choosen - \n", " 2.1.1) Tata Power - TATAPOWER.NS\n", " 2.1.2) Tata Motors - TATAMOTORS.NS\n", " 2.1.3) Tata Steel - TATASTEEL.NS\n", " 2.1.4) Zomato - ZOMATO.NS\n", " 2.1.5) NHPC - NHPC.NS\n", " 2.1.6) NCC - NCC.NS\n", " 2.1.7) IREDA - IREDA.NS\n", " 2.1.8) IRCON - IRCON.NS\n", " 3) To try various Statistical Methods relating to Portfolio Optimisation.\n", " 3.1) Method 1 - Result\n", " 3.2) Method 2 - Result\n", " 4) You will obtain Weigths or Percentages of Portfolio to invest.\n", " 4.1) Method 1 - Weights\n", " 4.2) Method 2 - Weights\n", " 5) Testing the Portfolio for the future.\n", " 5.1) Method 1 - Result\n", " 5.2) Method 2 - Result\n", " 6) Final Result" ] }, { "cell_type": "markdown", "id": "a80152f2", "metadata": {}, "source": [ "# Steps of Implementation\n", "\n", " 1) Importing Libraries\n", " 2) Select the Financial Instruments\n", " 3) Get the Adjacent Close prices of Last 5 Years\n", " 4) Calculating the Log-Return of Company Dataset\n", " 5) Calculating the Sharpe Ratio\n", " 6) Getting Started with Monte Carlo\n", " 7) Let's look closer at the Simulations" ] }, { "cell_type": "markdown", "id": "42c5d329", "metadata": {}, "source": [ "## Importing Libraries" ] }, { "cell_type": "code", "execution_count": 1, "id": "945bbd48", "metadata": { "ExecuteTime": { "end_time": "2024-03-07T20:09:35.347796Z", "start_time": "2024-03-07T20:09:30.939936Z" } }, "outputs": [], "source": [ "import pathlib\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import scipy.optimize as sci_opt\n", "\n", "from pprint import pprint\n", "from sklearn.preprocessing import StandardScaler\n", "\n", "import yfinance as yf\n", "\n", "# Set some display options for Pandas.\n", "pd.set_option('expand_frame_repr', False)" ] }, { "cell_type": "markdown", "id": "8dbc2573", "metadata": {}, "source": [ "## Select the Financial Instruments" ] }, { "cell_type": "code", "execution_count": 2, "id": "08345846", "metadata": { "ExecuteTime": { "end_time": "2024-03-07T20:09:37.966003Z", "start_time": "2024-03-07T20:09:37.963670Z" } }, "outputs": [], "source": [ "## Have Choosen Stocks\n", "\n", "## The Companies selected to build a Optimal Portfolio\n", "com_sel = [\"TATAPOWER.NS\", \"TATAMOTORS.NS\", \"TATASTEEL.NS\", \"RELIANCE.NS\", \"ADANIENT.NS\", \"ADANIPORTS.NS\"]\n", "\n", "## We will need Number of Tickers for future\n", "num_tick = len(com_sel)" ] }, { "cell_type": "markdown", "id": "2376a747", "metadata": {}, "source": [ "## Get the Adjacent Close prices of Last 5 Years" ] }, { "cell_type": "code", "execution_count": 3, "id": "cb64a4c0", "metadata": { "ExecuteTime": { "end_time": "2024-03-07T20:09:39.680530Z", "start_time": "2024-03-07T20:09:38.995900Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[*********************100%%**********************] 6 of 6 completed\n" ] }, { "data": { "text/html": [ "
Ticker | \n", "ADANIENT.NS | \n", "ADANIPORTS.NS | \n", "RELIANCE.NS | \n", "TATAMOTORS.NS | \n", "TATAPOWER.NS | \n", "TATASTEEL.NS | \n", "
---|---|---|---|---|---|---|
Date | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
2019-03-01 | \n", "132.264633 | \n", "322.673431 | \n", "1098.479736 | \n", "179.739807 | \n", "61.861309 | \n", "43.332832 | \n", "
2019-03-05 | \n", "140.120483 | \n", "328.532288 | \n", "1108.872925 | \n", "193.447083 | \n", "63.798790 | \n", "44.540791 | \n", "
2019-03-06 | \n", "137.600677 | \n", "326.401764 | \n", "1133.197998 | \n", "188.213394 | \n", "65.782417 | \n", "44.463959 | \n", "
2019-03-07 | \n", "135.278519 | \n", "330.130127 | \n", "1138.080933 | \n", "188.711853 | \n", "65.090462 | \n", "44.489574 | \n", "
2019-03-08 | \n", "136.563110 | \n", "331.340698 | \n", "1135.258667 | \n", "180.637009 | \n", "64.583023 | \n", "43.354172 | \n", "