From 72eb36259c8fba6895a84b994e91c26e864a83ed Mon Sep 17 00:00:00 2001
From: Mansi Yadav <139609682+FreeSpirit11@users.noreply.github.com>
Date: Wed, 5 Jun 2024 09:15:38 +0530
Subject: [PATCH] Add updated file
---
.../betaweighted.ipynb | 2936 +++++++++++++++++
1 file changed, 2936 insertions(+)
create mode 100644 Beta-weighted-stock-portfolio/betaweighted.ipynb
diff --git a/Beta-weighted-stock-portfolio/betaweighted.ipynb b/Beta-weighted-stock-portfolio/betaweighted.ipynb
new file mode 100644
index 00000000..baf8b61e
--- /dev/null
+++ b/Beta-weighted-stock-portfolio/betaweighted.ipynb
@@ -0,0 +1,2936 @@
+{
+ "nbformat": 4,
+ "nbformat_minor": 0,
+ "metadata": {
+ "colab": {
+ "provenance": []
+ },
+ "kernelspec": {
+ "name": "python3",
+ "display_name": "Python 3"
+ },
+ "language_info": {
+ "name": "python"
+ }
+ },
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# **Beta-Weighted Stock Portfolio**\n",
+ "**Introduction**
\n",
+ "A beta-weighted stock portfolio evaluates the risk relative to the market by considering each stock's beta. Beta measures a stock's volatility in relation to the market. A beta of 1 indicates that the stock moves with the market. A beta greater than 1 indicates higher volatility than the market, while a beta less than 1 indicates lower volatility."
+ ],
+ "metadata": {
+ "id": "4Hoq5HvWe9yB"
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "id": "hkmBkpWMakWZ"
+ },
+ "outputs": [],
+ "source": [
+ "import datetime as dt\n",
+ "import pandas as pd\n",
+ "import numpy as np\n",
+ "from scipy import stats\n",
+ "import yfinance as yf"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "start = dt.datetime(2021, 1, 1)\n",
+ "end = dt.datetime.now()\n",
+ "stocklist=['SBIN', 'ICICIBANK', 'HDFCBANK', 'AXISBANK', 'RELIANCE']\n",
+ "stocks = ['^NSEI']+[i+'.NS' for i in stocklist]"
+ ],
+ "metadata": {
+ "id": "R3SM_4Nka6y4"
+ },
+ "execution_count": 2,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "df = yf.download(stocks, start, end)\n",
+ "log_returns = np.log(df.Close / df.Close.shift(1)).dropna()\n",
+ "log_returns.head()"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 255
+ },
+ "id": "eFwTcU6Ta603",
+ "outputId": "e4e07977-954d-4b79-bd60-bf73ba0bb713"
+ },
+ "execution_count": 3,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stderr",
+ "text": [
+ "[*********************100%%**********************] 6 of 6 completed\n"
+ ]
+ },
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "Ticker AXISBANK.NS HDFCBANK.NS ICICIBANK.NS RELIANCE.NS SBIN.NS \\\n",
+ "Date \n",
+ "2021-01-04 0.001442 -0.006371 0.007931 0.001684 0.005888 \n",
+ "2021-01-05 0.061688 0.007528 0.010384 -0.012510 0.002488 \n",
+ "2021-01-06 -0.015470 -0.004320 0.017437 -0.026726 0.011644 \n",
+ "2021-01-07 0.025429 -0.003032 -0.010296 -0.001621 0.009254 \n",
+ "2021-01-08 0.002381 0.010815 0.001754 0.011730 -0.005927 \n",
+ "\n",
+ "Ticker ^NSEI \n",
+ "Date \n",
+ "2021-01-04 0.008128 \n",
+ "2021-01-05 0.004701 \n",
+ "2021-01-06 -0.003757 \n",
+ "2021-01-07 -0.000629 \n",
+ "2021-01-08 0.014738 "
+ ],
+ "text/html": [
+ "\n",
+ "
\n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " Ticker | \n",
+ " AXISBANK.NS | \n",
+ " HDFCBANK.NS | \n",
+ " ICICIBANK.NS | \n",
+ " RELIANCE.NS | \n",
+ " SBIN.NS | \n",
+ " ^NSEI | \n",
+ "
\n",
+ " \n",
+ " Date | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 2021-01-04 | \n",
+ " 0.001442 | \n",
+ " -0.006371 | \n",
+ " 0.007931 | \n",
+ " 0.001684 | \n",
+ " 0.005888 | \n",
+ " 0.008128 | \n",
+ "
\n",
+ " \n",
+ " 2021-01-05 | \n",
+ " 0.061688 | \n",
+ " 0.007528 | \n",
+ " 0.010384 | \n",
+ " -0.012510 | \n",
+ " 0.002488 | \n",
+ " 0.004701 | \n",
+ "
\n",
+ " \n",
+ " 2021-01-06 | \n",
+ " -0.015470 | \n",
+ " -0.004320 | \n",
+ " 0.017437 | \n",
+ " -0.026726 | \n",
+ " 0.011644 | \n",
+ " -0.003757 | \n",
+ "
\n",
+ " \n",
+ " 2021-01-07 | \n",
+ " 0.025429 | \n",
+ " -0.003032 | \n",
+ " -0.010296 | \n",
+ " -0.001621 | \n",
+ " 0.009254 | \n",
+ " -0.000629 | \n",
+ "
\n",
+ " \n",
+ " 2021-01-08 | \n",
+ " 0.002381 | \n",
+ " 0.010815 | \n",
+ " 0.001754 | \n",
+ " 0.011730 | \n",
+ " -0.005927 | \n",
+ " 0.014738 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ "
\n"
+ ],
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "dataframe",
+ "variable_name": "log_returns",
+ "summary": "{\n \"name\": \"log_returns\",\n \"rows\": 841,\n \"fields\": [\n {\n \"column\": \"Date\",\n \"properties\": {\n \"dtype\": \"date\",\n \"min\": \"2021-01-04 00:00:00\",\n \"max\": \"2024-05-31 00:00:00\",\n \"num_unique_values\": 841,\n \"samples\": [\n \"2022-12-19 00:00:00\",\n \"2024-04-26 00:00:00\",\n \"2021-02-16 00:00:00\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"AXISBANK.NS\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.016437351250855603,\n \"min\": -0.06866826714422139,\n \"max\": 0.08642600674250787,\n \"num_unique_values\": 841,\n \"samples\": [\n 0.011800526765262345,\n 0.002923892356169406,\n -0.02415593359582445\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"HDFCBANK.NS\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.014241941916460527,\n \"min\": -0.08813000683812074,\n \"max\": 0.09543093119288036,\n \"num_unique_values\": 841,\n \"samples\": [\n 0.0031055776683521436,\n -0.0006289921953538128,\n 0.006197537036113713\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"ICICIBANK.NS\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.01475189272653889,\n \"min\": -0.051250817366691334,\n \"max\": 0.11724490254686257,\n \"num_unique_values\": 841,\n \"samples\": [\n 0.0049213648799089895,\n -0.005266346222050799,\n -0.0234192745783055\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"RELIANCE.NS\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.014739430467673566,\n \"min\": -0.07474984574840186,\n \"max\": 0.06783811353596592,\n \"num_unique_values\": 841,\n \"samples\": [\n 0.013049865743872301,\n -0.005098629388895303,\n 0.013147496564137901\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"SBIN.NS\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.017063232066226383,\n \"min\": -0.07086631862575557,\n \"max\": 0.10166459081723568,\n \"num_unique_values\": 836,\n \"samples\": [\n 0.005338459080591873,\n 0.011555167801178493,\n -0.048000401504401304\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"^NSEI\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.00900979419379447,\n \"min\": -0.04896026903082192,\n \"max\": 0.04633334971971787,\n \"num_unique_values\": 841,\n \"samples\": [\n 0.008255783729645224,\n -0.006685928069119567,\n -8.162425642763527e-05\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
+ }
+ },
+ "metadata": {},
+ "execution_count": 3
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "def calc_beta(df):\n",
+ " np_array = df.values\n",
+ " # Market index is the first column 0\n",
+ " m = np_array[:,0]\n",
+ " beta = []\n",
+ " for ind, col in enumerate(df):\n",
+ " if ind > 0:\n",
+ " # stock returns are indexed by ind\n",
+ " s = np_array[:,ind]\n",
+ " # Calculate covariance matrix between stock and market\n",
+ " covariance = np.cov(s,m)\n",
+ " beta.append( covariance[0,1]/covariance[1,1] )\n",
+ " return pd.Series(beta, df.columns[1:], name='Beta')"
+ ],
+ "metadata": {
+ "id": "WfRRr0VVa63b"
+ },
+ "execution_count": 4,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "calc_beta(log_returns)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "weoH3M6za65w",
+ "outputId": "18ee522f-a633-458d-bf87-eaf993632d9c"
+ },
+ "execution_count": 5,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "Ticker\n",
+ "HDFCBANK.NS 0.359201\n",
+ "ICICIBANK.NS 0.575593\n",
+ "RELIANCE.NS 0.311406\n",
+ "SBIN.NS 0.585969\n",
+ "^NSEI 0.333082\n",
+ "Name: Beta, dtype: float64"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 5
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "#Linear regression\n",
+ "def regression_beta(df):\n",
+ " np_array = df.values\n",
+ " # Market index is the first column 0\n",
+ " m = np_array[:,0]\n",
+ " beta = []\n",
+ " for ind, col in enumerate(df):\n",
+ " if ind > 0:\n",
+ " s = np_array[:,ind] # stock returns are column one from numpy array\n",
+ " beta.append( stats.linregress(m,s)[0] )\n",
+ " return pd.Series(beta, df.columns[1:], name='Beta')"
+ ],
+ "metadata": {
+ "id": "FzcIKyf8blCd"
+ },
+ "execution_count": 6,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "regression_beta(log_returns)"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "SlC-XoU6blEd",
+ "outputId": "8be5dd5b-3bee-4cf4-f7b3-4e51ffe76416"
+ },
+ "execution_count": 7,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "Ticker\n",
+ "HDFCBANK.NS 0.359201\n",
+ "ICICIBANK.NS 0.575593\n",
+ "RELIANCE.NS 0.311406\n",
+ "SBIN.NS 0.585969\n",
+ "^NSEI 0.333082\n",
+ "Name: Beta, dtype: float64"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 7
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "def matrix_beta(df):\n",
+ " # Market index is the first column 0\n",
+ " X = df.values[:, [0]]\n",
+ " # add an additional column for the intercept (initalise as 1's)\n",
+ " X = np.concatenate([np.ones_like(X), X], axis=1)\n",
+ " # Apply matrix algebra for linear regression model\n",
+ " beta = np.linalg.pinv(X.T @ X) @ X.T @ df.values[:, 1:]\n",
+ " return pd.Series(beta[1], df.columns[1:], name='Beta')\n",
+ "\n",
+ "beta = matrix_beta(log_returns)\n",
+ "beta"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "ZWV3tI_SblG2",
+ "outputId": "12000af7-7023-4365-8938-87b9a0e14240"
+ },
+ "execution_count": 8,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "Ticker\n",
+ "HDFCBANK.NS 0.359201\n",
+ "ICICIBANK.NS 0.575593\n",
+ "RELIANCE.NS 0.311406\n",
+ "SBIN.NS 0.585969\n",
+ "^NSEI 0.333082\n",
+ "Name: Beta, dtype: float64"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 8
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "units = np.array([100, 250, 300, 400, 200])\n",
+ "ASXprices = df.Close[-1:].values.tolist()[0]\n",
+ "price = np.array([round(price,2) for price in ASXprices[1:]])\n",
+ "value = [unit*pr for unit, pr in zip(units, price)]\n",
+ "weight = [round(val/sum(value),2) for val in value]\n",
+ "beta = round(beta,2)"
+ ],
+ "metadata": {
+ "id": "Py7ZSklSblI8"
+ },
+ "execution_count": 9,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "Portfolio = pd.DataFrame({\n",
+ " 'Stock': stocklist,\n",
+ " 'Direction': 'Long',\n",
+ " 'Type': 'S',\n",
+ " 'Stock Price': price,\n",
+ " 'Price': price,\n",
+ " 'Units': units,\n",
+ " 'Value': units*price,\n",
+ " 'Weight': weight,\n",
+ " 'Beta': beta,\n",
+ " 'Weighted Beta': weight*beta\n",
+ "})\n",
+ "Portfolio"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 275
+ },
+ "id": "Mw3EK4i3blMi",
+ "outputId": "8899a320-009f-40a6-cb28-dd75d2313d9e"
+ },
+ "execution_count": 10,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Stock Direction Type Stock Price Price Units \\\n",
+ "Ticker \n",
+ "HDFCBANK.NS SBIN Long S 1531.55 1531.55 100 \n",
+ "ICICIBANK.NS ICICIBANK Long S 1121.05 1121.05 250 \n",
+ "RELIANCE.NS HDFCBANK Long S 2860.80 2860.80 300 \n",
+ "SBIN.NS AXISBANK Long S 830.35 830.35 400 \n",
+ "^NSEI RELIANCE Long S 22530.70 22530.70 200 \n",
+ "\n",
+ " Value Weight Beta Weighted Beta \n",
+ "Ticker \n",
+ "HDFCBANK.NS 153155.0 0.02 0.36 0.0072 \n",
+ "ICICIBANK.NS 280262.5 0.05 0.58 0.0290 \n",
+ "RELIANCE.NS 858240.0 0.14 0.31 0.0434 \n",
+ "SBIN.NS 332140.0 0.05 0.59 0.0295 \n",
+ "^NSEI 4506140.0 0.74 0.33 0.2442 "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Stock | \n",
+ " Direction | \n",
+ " Type | \n",
+ " Stock Price | \n",
+ " Price | \n",
+ " Units | \n",
+ " Value | \n",
+ " Weight | \n",
+ " Beta | \n",
+ " Weighted Beta | \n",
+ "
\n",
+ " \n",
+ " Ticker | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " HDFCBANK.NS | \n",
+ " SBIN | \n",
+ " Long | \n",
+ " S | \n",
+ " 1531.55 | \n",
+ " 1531.55 | \n",
+ " 100 | \n",
+ " 153155.0 | \n",
+ " 0.02 | \n",
+ " 0.36 | \n",
+ " 0.0072 | \n",
+ "
\n",
+ " \n",
+ " ICICIBANK.NS | \n",
+ " ICICIBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 1121.05 | \n",
+ " 1121.05 | \n",
+ " 250 | \n",
+ " 280262.5 | \n",
+ " 0.05 | \n",
+ " 0.58 | \n",
+ " 0.0290 | \n",
+ "
\n",
+ " \n",
+ " RELIANCE.NS | \n",
+ " HDFCBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 2860.80 | \n",
+ " 2860.80 | \n",
+ " 300 | \n",
+ " 858240.0 | \n",
+ " 0.14 | \n",
+ " 0.31 | \n",
+ " 0.0434 | \n",
+ "
\n",
+ " \n",
+ " SBIN.NS | \n",
+ " AXISBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 830.35 | \n",
+ " 830.35 | \n",
+ " 400 | \n",
+ " 332140.0 | \n",
+ " 0.05 | \n",
+ " 0.59 | \n",
+ " 0.0295 | \n",
+ "
\n",
+ " \n",
+ " ^NSEI | \n",
+ " RELIANCE | \n",
+ " Long | \n",
+ " S | \n",
+ " 22530.70 | \n",
+ " 22530.70 | \n",
+ " 200 | \n",
+ " 4506140.0 | \n",
+ " 0.74 | \n",
+ " 0.33 | \n",
+ " 0.2442 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ "
\n"
+ ],
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "dataframe",
+ "variable_name": "Portfolio",
+ "summary": "{\n \"name\": \"Portfolio\",\n \"rows\": 5,\n \"fields\": [\n {\n \"column\": \"Ticker\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"ICICIBANK.NS\",\n \"^NSEI\",\n \"RELIANCE.NS\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"ICICIBANK\",\n \"RELIANCE\",\n \"HDFCBANK\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Direction\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"Long\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Type\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"S\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 9398.959067324957,\n \"min\": 830.35,\n \"max\": 22530.7,\n \"num_unique_values\": 5,\n \"samples\": [\n 1121.05\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 9398.959067324957,\n \"min\": 830.35,\n \"max\": 22530.7,\n \"num_unique_values\": 5,\n \"samples\": [\n 1121.05\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Units\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 111,\n \"min\": 100,\n \"max\": 400,\n \"num_unique_values\": 5,\n \"samples\": [\n 250\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Value\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1853305.6513261648,\n \"min\": 153155.0,\n \"max\": 4506140.0,\n \"num_unique_values\": 5,\n \"samples\": [\n 280262.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Weight\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.30520484924063707,\n \"min\": 0.02,\n \"max\": 0.74,\n \"num_unique_values\": 4,\n \"samples\": [\n 0.05\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Beta\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.13903237033151666,\n \"min\": 0.31,\n \"max\": 0.59,\n \"num_unique_values\": 5,\n \"samples\": [\n 0.58\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Weighted Beta\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.0978725089082731,\n \"min\": 0.0072,\n \"max\": 0.2442,\n \"num_unique_values\": 5,\n \"samples\": [\n 0.028999999999999998\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
+ }
+ },
+ "metadata": {},
+ "execution_count": 10
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "Portfolio = Portfolio.drop(['Weight', 'Weighted Beta'], axis=1)\n",
+ "Portfolio['Delta'] = Portfolio['Units']\n",
+ "Portfolio"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 238
+ },
+ "id": "g6PKpM0Xa69V",
+ "outputId": "f18cbeb8-c0a1-46bc-d785-0ee41a03963f"
+ },
+ "execution_count": 11,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Stock Direction Type Stock Price Price Units \\\n",
+ "Ticker \n",
+ "HDFCBANK.NS SBIN Long S 1531.55 1531.55 100 \n",
+ "ICICIBANK.NS ICICIBANK Long S 1121.05 1121.05 250 \n",
+ "RELIANCE.NS HDFCBANK Long S 2860.80 2860.80 300 \n",
+ "SBIN.NS AXISBANK Long S 830.35 830.35 400 \n",
+ "^NSEI RELIANCE Long S 22530.70 22530.70 200 \n",
+ "\n",
+ " Value Beta Delta \n",
+ "Ticker \n",
+ "HDFCBANK.NS 153155.0 0.36 100 \n",
+ "ICICIBANK.NS 280262.5 0.58 250 \n",
+ "RELIANCE.NS 858240.0 0.31 300 \n",
+ "SBIN.NS 332140.0 0.59 400 \n",
+ "^NSEI 4506140.0 0.33 200 "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Stock | \n",
+ " Direction | \n",
+ " Type | \n",
+ " Stock Price | \n",
+ " Price | \n",
+ " Units | \n",
+ " Value | \n",
+ " Beta | \n",
+ " Delta | \n",
+ "
\n",
+ " \n",
+ " Ticker | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " HDFCBANK.NS | \n",
+ " SBIN | \n",
+ " Long | \n",
+ " S | \n",
+ " 1531.55 | \n",
+ " 1531.55 | \n",
+ " 100 | \n",
+ " 153155.0 | \n",
+ " 0.36 | \n",
+ " 100 | \n",
+ "
\n",
+ " \n",
+ " ICICIBANK.NS | \n",
+ " ICICIBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 1121.05 | \n",
+ " 1121.05 | \n",
+ " 250 | \n",
+ " 280262.5 | \n",
+ " 0.58 | \n",
+ " 250 | \n",
+ "
\n",
+ " \n",
+ " RELIANCE.NS | \n",
+ " HDFCBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 2860.80 | \n",
+ " 2860.80 | \n",
+ " 300 | \n",
+ " 858240.0 | \n",
+ " 0.31 | \n",
+ " 300 | \n",
+ "
\n",
+ " \n",
+ " SBIN.NS | \n",
+ " AXISBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 830.35 | \n",
+ " 830.35 | \n",
+ " 400 | \n",
+ " 332140.0 | \n",
+ " 0.59 | \n",
+ " 400 | \n",
+ "
\n",
+ " \n",
+ " ^NSEI | \n",
+ " RELIANCE | \n",
+ " Long | \n",
+ " S | \n",
+ " 22530.70 | \n",
+ " 22530.70 | \n",
+ " 200 | \n",
+ " 4506140.0 | \n",
+ " 0.33 | \n",
+ " 200 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ "
\n"
+ ],
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "dataframe",
+ "variable_name": "Portfolio",
+ "summary": "{\n \"name\": \"Portfolio\",\n \"rows\": 5,\n \"fields\": [\n {\n \"column\": \"Ticker\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"ICICIBANK.NS\",\n \"^NSEI\",\n \"RELIANCE.NS\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"ICICIBANK\",\n \"RELIANCE\",\n \"HDFCBANK\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Direction\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"Long\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Type\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"S\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 9398.959067324957,\n \"min\": 830.35,\n \"max\": 22530.7,\n \"num_unique_values\": 5,\n \"samples\": [\n 1121.05\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 9398.959067324957,\n \"min\": 830.35,\n \"max\": 22530.7,\n \"num_unique_values\": 5,\n \"samples\": [\n 1121.05\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Units\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 111,\n \"min\": 100,\n \"max\": 400,\n \"num_unique_values\": 5,\n \"samples\": [\n 250\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Value\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1853305.6513261648,\n \"min\": 153155.0,\n \"max\": 4506140.0,\n \"num_unique_values\": 5,\n \"samples\": [\n 280262.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Beta\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.13903237033151666,\n \"min\": 0.31,\n \"max\": 0.59,\n \"num_unique_values\": 5,\n \"samples\": [\n 0.58\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Delta\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 111,\n \"min\": 100,\n \"max\": 400,\n \"num_unique_values\": 5,\n \"samples\": [\n 250\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
+ }
+ },
+ "metadata": {},
+ "execution_count": 11
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "#add options\n",
+ "Options = [\n",
+ " {'option': 'SBIN0Z8', 'underlying': 'SBIN', 'price': 3.950, 'units': 2, 'delta': 0.627, 'direction': 'Short', 'type': 'Call'},\n",
+ " {'option': 'RELIANCEQB9', 'underlying': 'RELIANCE', 'price': 1.325, 'units': 2, 'delta': -0.425, 'direction': 'Long', 'type': 'Put'}\n",
+ "]\n",
+ "for index, row in enumerate(Options):\n",
+ " Portfolio.loc[row['option']] = [row['underlying'], row['direction'], row['type'], Portfolio.loc[row['underlying']+'.NS', 'Price'],\n",
+ " row['price'], row['units'], row['price']*row['units']*100, beta[row['underlying']+'.NS'],\n",
+ " (row['delta']*row['units']* 100 if row['direction'] == 'Long' else -row['delta']*row['units']*100)]\n",
+ "Portfolio"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 300
+ },
+ "id": "oMElDmxEdnog",
+ "outputId": "e774a687-09d4-45f0-e0e0-34b9e30ac0b2"
+ },
+ "execution_count": 12,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Stock Direction Type Stock Price Price Units \\\n",
+ "Ticker \n",
+ "HDFCBANK.NS SBIN Long S 1531.55 1531.550 100 \n",
+ "ICICIBANK.NS ICICIBANK Long S 1121.05 1121.050 250 \n",
+ "RELIANCE.NS HDFCBANK Long S 2860.80 2860.800 300 \n",
+ "SBIN.NS AXISBANK Long S 830.35 830.350 400 \n",
+ "^NSEI RELIANCE Long S 22530.70 22530.700 200 \n",
+ "SBIN0Z8 SBIN Short Call 830.35 3.950 2 \n",
+ "RELIANCEQB9 RELIANCE Long Put 2860.80 1.325 2 \n",
+ "\n",
+ " Value Beta Delta \n",
+ "Ticker \n",
+ "HDFCBANK.NS 153155.0 0.36 100.0 \n",
+ "ICICIBANK.NS 280262.5 0.58 250.0 \n",
+ "RELIANCE.NS 858240.0 0.31 300.0 \n",
+ "SBIN.NS 332140.0 0.59 400.0 \n",
+ "^NSEI 4506140.0 0.33 200.0 \n",
+ "SBIN0Z8 790.0 0.59 -125.4 \n",
+ "RELIANCEQB9 265.0 0.31 -85.0 "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Stock | \n",
+ " Direction | \n",
+ " Type | \n",
+ " Stock Price | \n",
+ " Price | \n",
+ " Units | \n",
+ " Value | \n",
+ " Beta | \n",
+ " Delta | \n",
+ "
\n",
+ " \n",
+ " Ticker | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " HDFCBANK.NS | \n",
+ " SBIN | \n",
+ " Long | \n",
+ " S | \n",
+ " 1531.55 | \n",
+ " 1531.550 | \n",
+ " 100 | \n",
+ " 153155.0 | \n",
+ " 0.36 | \n",
+ " 100.0 | \n",
+ "
\n",
+ " \n",
+ " ICICIBANK.NS | \n",
+ " ICICIBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 1121.05 | \n",
+ " 1121.050 | \n",
+ " 250 | \n",
+ " 280262.5 | \n",
+ " 0.58 | \n",
+ " 250.0 | \n",
+ "
\n",
+ " \n",
+ " RELIANCE.NS | \n",
+ " HDFCBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 2860.80 | \n",
+ " 2860.800 | \n",
+ " 300 | \n",
+ " 858240.0 | \n",
+ " 0.31 | \n",
+ " 300.0 | \n",
+ "
\n",
+ " \n",
+ " SBIN.NS | \n",
+ " AXISBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 830.35 | \n",
+ " 830.350 | \n",
+ " 400 | \n",
+ " 332140.0 | \n",
+ " 0.59 | \n",
+ " 400.0 | \n",
+ "
\n",
+ " \n",
+ " ^NSEI | \n",
+ " RELIANCE | \n",
+ " Long | \n",
+ " S | \n",
+ " 22530.70 | \n",
+ " 22530.700 | \n",
+ " 200 | \n",
+ " 4506140.0 | \n",
+ " 0.33 | \n",
+ " 200.0 | \n",
+ "
\n",
+ " \n",
+ " SBIN0Z8 | \n",
+ " SBIN | \n",
+ " Short | \n",
+ " Call | \n",
+ " 830.35 | \n",
+ " 3.950 | \n",
+ " 2 | \n",
+ " 790.0 | \n",
+ " 0.59 | \n",
+ " -125.4 | \n",
+ "
\n",
+ " \n",
+ " RELIANCEQB9 | \n",
+ " RELIANCE | \n",
+ " Long | \n",
+ " Put | \n",
+ " 2860.80 | \n",
+ " 1.325 | \n",
+ " 2 | \n",
+ " 265.0 | \n",
+ " 0.31 | \n",
+ " -85.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ "
\n"
+ ],
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "dataframe",
+ "variable_name": "Portfolio",
+ "summary": "{\n \"name\": \"Portfolio\",\n \"rows\": 7,\n \"fields\": [\n {\n \"column\": \"Ticker\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 7,\n \"samples\": [\n \"HDFCBANK.NS\",\n \"ICICIBANK.NS\",\n \"SBIN0Z8\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"ICICIBANK\",\n \"RELIANCE\",\n \"HDFCBANK\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Direction\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 2,\n \"samples\": [\n \"Short\",\n \"Long\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Type\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 3,\n \"samples\": [\n \"S\",\n \"Call\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 7931.7877530256455,\n \"min\": 830.35,\n \"max\": 22530.7,\n \"num_unique_values\": 5,\n \"samples\": [\n 1121.05,\n 22530.7\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 8174.759493671664,\n \"min\": 1.325,\n \"max\": 22530.7,\n \"num_unique_values\": 7,\n \"samples\": [\n 1531.55,\n 1121.05\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Units\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 151,\n \"min\": 2,\n \"max\": 400,\n \"num_unique_values\": 6,\n \"samples\": [\n 100,\n 250\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Value\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1627079.5815943882,\n \"min\": 265.0,\n \"max\": 4506140.0,\n \"num_unique_values\": 7,\n \"samples\": [\n 153155.0,\n 280262.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Beta\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.13957418235817245,\n \"min\": 0.31,\n \"max\": 0.59,\n \"num_unique_values\": 5,\n \"samples\": [\n 0.58,\n 0.33\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Delta\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 196.23740238608463,\n \"min\": -125.4,\n \"max\": 400.0,\n \"num_unique_values\": 7,\n \"samples\": [\n 100.0,\n 250.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
+ }
+ },
+ "metadata": {},
+ "execution_count": 12
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "Portfolio['ASX200 Weighted Delta (point)'] = round(Portfolio['Beta'] * (Portfolio['Stock Price']/ASXprices[0]) * Portfolio['Delta'],2)\n",
+ "Portfolio['ASX200 Weighted Delta (1%)'] = round(Portfolio['Beta'] * (Portfolio['Stock Price']) * Portfolio['Delta'] * 0.01,2)\n",
+ "Portfolio"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 372
+ },
+ "id": "pZezskDmdnkI",
+ "outputId": "2cae31cc-7171-41f5-e002-0c72a03933a2"
+ },
+ "execution_count": 13,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Stock Direction Type Stock Price Price Units \\\n",
+ "Ticker \n",
+ "HDFCBANK.NS SBIN Long S 1531.55 1531.550 100 \n",
+ "ICICIBANK.NS ICICIBANK Long S 1121.05 1121.050 250 \n",
+ "RELIANCE.NS HDFCBANK Long S 2860.80 2860.800 300 \n",
+ "SBIN.NS AXISBANK Long S 830.35 830.350 400 \n",
+ "^NSEI RELIANCE Long S 22530.70 22530.700 200 \n",
+ "SBIN0Z8 SBIN Short Call 830.35 3.950 2 \n",
+ "RELIANCEQB9 RELIANCE Long Put 2860.80 1.325 2 \n",
+ "\n",
+ " Value Beta Delta ASX200 Weighted Delta (point) \\\n",
+ "Ticker \n",
+ "HDFCBANK.NS 153155.0 0.36 100.0 47.44 \n",
+ "ICICIBANK.NS 280262.5 0.58 250.0 139.87 \n",
+ "RELIANCE.NS 858240.0 0.31 300.0 228.93 \n",
+ "SBIN.NS 332140.0 0.59 400.0 168.62 \n",
+ "^NSEI 4506140.0 0.33 200.0 1279.55 \n",
+ "SBIN0Z8 790.0 0.59 -125.4 -52.86 \n",
+ "RELIANCEQB9 265.0 0.31 -85.0 -64.86 \n",
+ "\n",
+ " ASX200 Weighted Delta (1%) \n",
+ "Ticker \n",
+ "HDFCBANK.NS 551.36 \n",
+ "ICICIBANK.NS 1625.52 \n",
+ "RELIANCE.NS 2660.54 \n",
+ "SBIN.NS 1959.63 \n",
+ "^NSEI 14870.26 \n",
+ "SBIN0Z8 -614.34 \n",
+ "RELIANCEQB9 -753.82 "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Stock | \n",
+ " Direction | \n",
+ " Type | \n",
+ " Stock Price | \n",
+ " Price | \n",
+ " Units | \n",
+ " Value | \n",
+ " Beta | \n",
+ " Delta | \n",
+ " ASX200 Weighted Delta (point) | \n",
+ " ASX200 Weighted Delta (1%) | \n",
+ "
\n",
+ " \n",
+ " Ticker | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " HDFCBANK.NS | \n",
+ " SBIN | \n",
+ " Long | \n",
+ " S | \n",
+ " 1531.55 | \n",
+ " 1531.550 | \n",
+ " 100 | \n",
+ " 153155.0 | \n",
+ " 0.36 | \n",
+ " 100.0 | \n",
+ " 47.44 | \n",
+ " 551.36 | \n",
+ "
\n",
+ " \n",
+ " ICICIBANK.NS | \n",
+ " ICICIBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 1121.05 | \n",
+ " 1121.050 | \n",
+ " 250 | \n",
+ " 280262.5 | \n",
+ " 0.58 | \n",
+ " 250.0 | \n",
+ " 139.87 | \n",
+ " 1625.52 | \n",
+ "
\n",
+ " \n",
+ " RELIANCE.NS | \n",
+ " HDFCBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 2860.80 | \n",
+ " 2860.800 | \n",
+ " 300 | \n",
+ " 858240.0 | \n",
+ " 0.31 | \n",
+ " 300.0 | \n",
+ " 228.93 | \n",
+ " 2660.54 | \n",
+ "
\n",
+ " \n",
+ " SBIN.NS | \n",
+ " AXISBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 830.35 | \n",
+ " 830.350 | \n",
+ " 400 | \n",
+ " 332140.0 | \n",
+ " 0.59 | \n",
+ " 400.0 | \n",
+ " 168.62 | \n",
+ " 1959.63 | \n",
+ "
\n",
+ " \n",
+ " ^NSEI | \n",
+ " RELIANCE | \n",
+ " Long | \n",
+ " S | \n",
+ " 22530.70 | \n",
+ " 22530.700 | \n",
+ " 200 | \n",
+ " 4506140.0 | \n",
+ " 0.33 | \n",
+ " 200.0 | \n",
+ " 1279.55 | \n",
+ " 14870.26 | \n",
+ "
\n",
+ " \n",
+ " SBIN0Z8 | \n",
+ " SBIN | \n",
+ " Short | \n",
+ " Call | \n",
+ " 830.35 | \n",
+ " 3.950 | \n",
+ " 2 | \n",
+ " 790.0 | \n",
+ " 0.59 | \n",
+ " -125.4 | \n",
+ " -52.86 | \n",
+ " -614.34 | \n",
+ "
\n",
+ " \n",
+ " RELIANCEQB9 | \n",
+ " RELIANCE | \n",
+ " Long | \n",
+ " Put | \n",
+ " 2860.80 | \n",
+ " 1.325 | \n",
+ " 2 | \n",
+ " 265.0 | \n",
+ " 0.31 | \n",
+ " -85.0 | \n",
+ " -64.86 | \n",
+ " -753.82 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ "
\n"
+ ],
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "dataframe",
+ "variable_name": "Portfolio",
+ "summary": "{\n \"name\": \"Portfolio\",\n \"rows\": 7,\n \"fields\": [\n {\n \"column\": \"Ticker\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 7,\n \"samples\": [\n \"HDFCBANK.NS\",\n \"ICICIBANK.NS\",\n \"SBIN0Z8\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"ICICIBANK\",\n \"RELIANCE\",\n \"HDFCBANK\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Direction\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 2,\n \"samples\": [\n \"Short\",\n \"Long\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Type\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 3,\n \"samples\": [\n \"S\",\n \"Call\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 7931.7877530256455,\n \"min\": 830.35,\n \"max\": 22530.7,\n \"num_unique_values\": 5,\n \"samples\": [\n 1121.05,\n 22530.7\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 8174.759493671664,\n \"min\": 1.325,\n \"max\": 22530.7,\n \"num_unique_values\": 7,\n \"samples\": [\n 1531.55,\n 1121.05\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Units\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 151,\n \"min\": 2,\n \"max\": 400,\n \"num_unique_values\": 6,\n \"samples\": [\n 100,\n 250\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Value\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1627079.5815943882,\n \"min\": 265.0,\n \"max\": 4506140.0,\n \"num_unique_values\": 7,\n \"samples\": [\n 153155.0,\n 280262.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Beta\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.13957418235817245,\n \"min\": 0.31,\n \"max\": 0.59,\n \"num_unique_values\": 5,\n \"samples\": [\n 0.58,\n 0.33\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Delta\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 196.23740238608463,\n \"min\": -125.4,\n \"max\": 400.0,\n \"num_unique_values\": 7,\n \"samples\": [\n 100.0,\n 250.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"ASX200 Weighted Delta (point)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 467.4502569512712,\n \"min\": -64.86,\n \"max\": 1279.55,\n \"num_unique_values\": 7,\n \"samples\": [\n 47.44,\n 139.87\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"ASX200 Weighted Delta (1%)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 5432.46654447262,\n \"min\": -753.82,\n \"max\": 14870.26,\n \"num_unique_values\": 7,\n \"samples\": [\n 551.36,\n 1625.52\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
+ }
+ },
+ "metadata": {},
+ "execution_count": 13
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "Portfolio.loc['Total', ['Value', 'ASX200 Weighted Delta (point)', 'ASX200 Weighted Delta (1%)']] \\\n",
+ "= Portfolio[['Value','ASX200 Weighted Delta (point)', 'ASX200 Weighted Delta (1%)']].sum()\n",
+ "Portfolio"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 404
+ },
+ "id": "wvznlXZ3dnmF",
+ "outputId": "e09eadbc-0e0d-4c90-a033-c0534c9f2486"
+ },
+ "execution_count": 14,
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " Stock Direction Type Stock Price Price Units \\\n",
+ "Ticker \n",
+ "HDFCBANK.NS SBIN Long S 1531.55 1531.550 100.0 \n",
+ "ICICIBANK.NS ICICIBANK Long S 1121.05 1121.050 250.0 \n",
+ "RELIANCE.NS HDFCBANK Long S 2860.80 2860.800 300.0 \n",
+ "SBIN.NS AXISBANK Long S 830.35 830.350 400.0 \n",
+ "^NSEI RELIANCE Long S 22530.70 22530.700 200.0 \n",
+ "SBIN0Z8 SBIN Short Call 830.35 3.950 2.0 \n",
+ "RELIANCEQB9 RELIANCE Long Put 2860.80 1.325 2.0 \n",
+ "Total NaN NaN NaN NaN NaN NaN \n",
+ "\n",
+ " Value Beta Delta ASX200 Weighted Delta (point) \\\n",
+ "Ticker \n",
+ "HDFCBANK.NS 153155.0 0.36 100.0 47.44 \n",
+ "ICICIBANK.NS 280262.5 0.58 250.0 139.87 \n",
+ "RELIANCE.NS 858240.0 0.31 300.0 228.93 \n",
+ "SBIN.NS 332140.0 0.59 400.0 168.62 \n",
+ "^NSEI 4506140.0 0.33 200.0 1279.55 \n",
+ "SBIN0Z8 790.0 0.59 -125.4 -52.86 \n",
+ "RELIANCEQB9 265.0 0.31 -85.0 -64.86 \n",
+ "Total 6130992.5 NaN NaN 1746.69 \n",
+ "\n",
+ " ASX200 Weighted Delta (1%) \n",
+ "Ticker \n",
+ "HDFCBANK.NS 551.36 \n",
+ "ICICIBANK.NS 1625.52 \n",
+ "RELIANCE.NS 2660.54 \n",
+ "SBIN.NS 1959.63 \n",
+ "^NSEI 14870.26 \n",
+ "SBIN0Z8 -614.34 \n",
+ "RELIANCEQB9 -753.82 \n",
+ "Total 20299.15 "
+ ],
+ "text/html": [
+ "\n",
+ " \n",
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Stock | \n",
+ " Direction | \n",
+ " Type | \n",
+ " Stock Price | \n",
+ " Price | \n",
+ " Units | \n",
+ " Value | \n",
+ " Beta | \n",
+ " Delta | \n",
+ " ASX200 Weighted Delta (point) | \n",
+ " ASX200 Weighted Delta (1%) | \n",
+ "
\n",
+ " \n",
+ " Ticker | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " HDFCBANK.NS | \n",
+ " SBIN | \n",
+ " Long | \n",
+ " S | \n",
+ " 1531.55 | \n",
+ " 1531.550 | \n",
+ " 100.0 | \n",
+ " 153155.0 | \n",
+ " 0.36 | \n",
+ " 100.0 | \n",
+ " 47.44 | \n",
+ " 551.36 | \n",
+ "
\n",
+ " \n",
+ " ICICIBANK.NS | \n",
+ " ICICIBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 1121.05 | \n",
+ " 1121.050 | \n",
+ " 250.0 | \n",
+ " 280262.5 | \n",
+ " 0.58 | \n",
+ " 250.0 | \n",
+ " 139.87 | \n",
+ " 1625.52 | \n",
+ "
\n",
+ " \n",
+ " RELIANCE.NS | \n",
+ " HDFCBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 2860.80 | \n",
+ " 2860.800 | \n",
+ " 300.0 | \n",
+ " 858240.0 | \n",
+ " 0.31 | \n",
+ " 300.0 | \n",
+ " 228.93 | \n",
+ " 2660.54 | \n",
+ "
\n",
+ " \n",
+ " SBIN.NS | \n",
+ " AXISBANK | \n",
+ " Long | \n",
+ " S | \n",
+ " 830.35 | \n",
+ " 830.350 | \n",
+ " 400.0 | \n",
+ " 332140.0 | \n",
+ " 0.59 | \n",
+ " 400.0 | \n",
+ " 168.62 | \n",
+ " 1959.63 | \n",
+ "
\n",
+ " \n",
+ " ^NSEI | \n",
+ " RELIANCE | \n",
+ " Long | \n",
+ " S | \n",
+ " 22530.70 | \n",
+ " 22530.700 | \n",
+ " 200.0 | \n",
+ " 4506140.0 | \n",
+ " 0.33 | \n",
+ " 200.0 | \n",
+ " 1279.55 | \n",
+ " 14870.26 | \n",
+ "
\n",
+ " \n",
+ " SBIN0Z8 | \n",
+ " SBIN | \n",
+ " Short | \n",
+ " Call | \n",
+ " 830.35 | \n",
+ " 3.950 | \n",
+ " 2.0 | \n",
+ " 790.0 | \n",
+ " 0.59 | \n",
+ " -125.4 | \n",
+ " -52.86 | \n",
+ " -614.34 | \n",
+ "
\n",
+ " \n",
+ " RELIANCEQB9 | \n",
+ " RELIANCE | \n",
+ " Long | \n",
+ " Put | \n",
+ " 2860.80 | \n",
+ " 1.325 | \n",
+ " 2.0 | \n",
+ " 265.0 | \n",
+ " 0.31 | \n",
+ " -85.0 | \n",
+ " -64.86 | \n",
+ " -753.82 | \n",
+ "
\n",
+ " \n",
+ " Total | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 6130992.5 | \n",
+ " NaN | \n",
+ " NaN | \n",
+ " 1746.69 | \n",
+ " 20299.15 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
\n",
+ "
\n"
+ ],
+ "application/vnd.google.colaboratory.intrinsic+json": {
+ "type": "dataframe",
+ "variable_name": "Portfolio",
+ "summary": "{\n \"name\": \"Portfolio\",\n \"rows\": 8,\n \"fields\": [\n {\n \"column\": \"Ticker\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 8,\n \"samples\": [\n \"ICICIBANK.NS\",\n \"SBIN0Z8\",\n \"HDFCBANK.NS\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"ICICIBANK\",\n \"RELIANCE\",\n \"HDFCBANK\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Direction\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 2,\n \"samples\": [\n \"Short\",\n \"Long\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Type\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 3,\n \"samples\": [\n \"S\",\n \"Call\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 7931.7877530256455,\n \"min\": 830.35,\n \"max\": 22530.7,\n \"num_unique_values\": 5,\n \"samples\": [\n 1121.05,\n 22530.7\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 8174.759493671665,\n \"min\": 1.325,\n \"max\": 22530.7,\n \"num_unique_values\": 7,\n \"samples\": [\n 1531.55,\n 1121.05\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Units\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 151.58213238090715,\n \"min\": 2.0,\n \"max\": 400.0,\n \"num_unique_values\": 6,\n \"samples\": [\n 100.0,\n 250.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Value\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2391912.842164625,\n \"min\": 265.0,\n \"max\": 6130992.5,\n \"num_unique_values\": 8,\n \"samples\": [\n 280262.5,\n 790.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Beta\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.13957418235817245,\n \"min\": 0.31,\n \"max\": 0.59,\n \"num_unique_values\": 5,\n \"samples\": [\n 0.58,\n 0.33\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Delta\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 196.23740238608463,\n \"min\": -125.4,\n \"max\": 400.0,\n \"num_unique_values\": 7,\n \"samples\": [\n 100.0,\n 250.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"ASX200 Weighted Delta (point)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 683.7259266642279,\n \"min\": -64.86,\n \"max\": 1746.69,\n \"num_unique_values\": 8,\n \"samples\": [\n 139.87,\n -52.86\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"ASX200 Weighted Delta (1%)\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 7945.915141085747,\n \"min\": -753.82,\n \"max\": 20299.15,\n \"num_unique_values\": 8,\n \"samples\": [\n 1625.52,\n -614.34\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
+ }
+ },
+ "metadata": {},
+ "execution_count": 14
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "import matplotlib.pyplot as plt\n",
+ "\n",
+ "# Plotting portfolio value\n",
+ "plt.figure(figsize=(10, 6))\n",
+ "plt.bar(Portfolio.index[:-1], Portfolio['Value'][:-1], color='blue', alpha=0.7)\n",
+ "plt.title('Portfolio Value by Stock')\n",
+ "plt.xlabel('Stock')\n",
+ "plt.ylabel('Value')\n",
+ "plt.xticks(rotation=45)\n",
+ "plt.show()\n",
+ "\n",
+ "# Plotting ASX200 weighted delta\n",
+ "plt.figure(figsize=(10, 6))\n",
+ "plt.bar(Portfolio.index[:-1], Portfolio['ASX200 Weighted Delta (point)'][:-1], color='green', alpha=0.7)\n",
+ "plt.title('ASX200 Weighted Delta (point) by Stock')\n",
+ "plt.xlabel('Stock')\n",
+ "plt.ylabel('Delta (points)')\n",
+ "plt.xticks(rotation=45)\n",
+ "plt.show()\n",
+ "\n",
+ "# Plotting ASX200 weighted delta as a percentage\n",
+ "plt.figure(figsize=(10, 6))\n",
+ "plt.bar(Portfolio.index[:-1], Portfolio['ASX200 Weighted Delta (1%)'][:-1], color='orange', alpha=0.7)\n",
+ "plt.title('ASX200 Weighted Delta (1%) by Stock')\n",
+ "plt.xlabel('Stock')\n",
+ "plt.ylabel('Delta (1%)')\n",
+ "plt.xticks(rotation=45)\n",
+ "plt.show()\n"
+ ],
+ "metadata": {
+ "id": "ejMCkFd8dnt6",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 1000
+ },
+ "outputId": "99102260-71cc-4a69-8214-db7d6fc6d919"
+ },
+ "execution_count": 15,
+ "outputs": [
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "