SHARE
TWEET

Untitled

a guest Aug 19th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.  "cells": [
  3.   {
  4.    "cell_type": "code",
  5.    "execution_count": 4,
  6.    "metadata": {},
  7.    "outputs": [],
  8.    "source": [
  9.     "from ipywidgets import interact\n",
  10.     "import numpy as np\n",
  11.     "import matplotlib.pyplot as plt"
  12.    ]
  13.   },
  14.   {
  15.    "cell_type": "code",
  16.    "execution_count": 5,
  17.    "metadata": {},
  18.    "outputs": [],
  19.    "source": [
  20.     "e1 = 0.1 # Ertrag Aktie 1\n",
  21.     "e2 = 0.3 # Ertrag Aktie 2\n",
  22.     "s1 = 3 # Risiko Aktie 1\n",
  23.     "s2 = 4 # Risiko Aktie 2"
  24.    ]
  25.   },
  26.   {
  27.    "cell_type": "code",
  28.    "execution_count": 6,
  29.    "metadata": {},
  30.    "outputs": [
  31.     {
  32.      "data": {
  33.       "application/vnd.jupyter.widget-view+json": {
  34.        "model_id": "f0e9c383505e45708163c969bdb78db0",
  35.        "version_major": 2,
  36.        "version_minor": 0
  37.       },
  38.       "text/plain": [
  39.        "interactive(children=(FloatSlider(value=0.0, description='p', max=1.0, min=-1.0), Output()), _dom_classes=('wi…"
  40.       ]
  41.      },
  42.      "metadata": {},
  43.      "output_type": "display_data"
  44.     }
  45.    ],
  46.    "source": [
  47.     "@interact\n",
  48.     "def plot(p=(-1, 1, 0.1)):\n",
  49.     "    plt.figure(figsize=(10, 5))\n",
  50.     "    plt.ylabel('Varianz')\n",
  51.     "    plt.xlabel('Rendite')\n",
  52.     "    plt.ylim((0, 5))\n",
  53.     "    plt.xlim((0, 0.5))\n",
  54.     "    plt.scatter([e1, e2], [s1, s2], s=300)\n",
  55.     "    es = []\n",
  56.     "    ss = []\n",
  57.     "    for k in np.linspace(0, 1, 1000):\n",
  58.     "        w1 = k\n",
  59.     "        w2 = 1-k\n",
  60.     "        e_p = w1*e1+w2*e2\n",
  61.     "        s_p = np.sqrt(w1*w1*s1*s1+w2*w2*s2*s2+2*w1*w2*s1*s2*p)\n",
  62.     "        es.append(e_p)\n",
  63.     "        ss.append(s_p)\n",
  64.     "    plt.scatter(es, ss, color='red', s=1)"
  65.    ]
  66.   },
  67.   {
  68.    "cell_type": "code",
  69.    "execution_count": null,
  70.    "metadata": {},
  71.    "outputs": [],
  72.    "source": []
  73.   }
  74.  ],
  75.  "metadata": {
  76.   "kernelspec": {
  77.    "display_name": "Python 3",
  78.    "language": "python",
  79.    "name": "python3"
  80.   },
  81.   "language_info": {
  82.    "codemirror_mode": {
  83.     "name": "ipython",
  84.     "version": 3
  85.    },
  86.    "file_extension": ".py",
  87.    "mimetype": "text/x-python",
  88.    "name": "python",
  89.    "nbconvert_exporter": "python",
  90.    "pygments_lexer": "ipython3",
  91.    "version": "3.7.3"
  92.   }
  93.  },
  94.  "nbformat": 4,
  95.  "nbformat_minor": 2
  96. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top