Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": null,
  6. "metadata": {
  7. "collapsed": true
  8. },
  9. "outputs": [],
  10. "source": []
  11. },
  12. {
  13. "cell_type": "markdown",
  14. "metadata": {},
  15. "source": [
  16. "# Black-Scholes option pricing theory\n",
  17. "\n",
  18. "## Hedging and the partial differential equation\n",
  19. "\n",
  20. "The original derivation of the Black-Scholes partial differential equation was via stochastic calculus, Ito's lemma and a simple hedging argument (Black & Scholes, 1973).\n",
  21. "\n",
  22. "Assume that the underlying follows a lognormal random walk\n",
  23. "$$\n",
  24. "\tdS = \\mu S dt + \\sigma S dX.\n",
  25. "$$\n",
  26. "Use $\\Pi$ to denote the value of a portfolio of one long option position and a short position in some quantity $\\Delta$ of the underlying:\n",
  27. "$$ \n",
  28. "\t\\Pi = V(S,t) - \\Delta S.\n",
  29. "$$\n",
  30. "\n",
  31. "The first term on the right is the option and the second term is the short asset position.\n",
  32. "\n",
  33. "Ask .... $t$ to $t+dt$.\n",
  34. "$$\n",
  35. "\td\\Pi = dV -\n",
  36. "$$\n",
  37. "\n",
  38. "From Ito's lemma we have\n",
  39. "$$\n",
  40. "\td\\Pi = \\frac{\\partial V}{\\partial t}dt + \\frac{\\partial V}{\\partial S}dS +\n",
  41. "\t\\frac{1}{2} \\sigma^2 S^2 \\frac{\\partial^2 V}{\\partial S^2}dt -\n",
  42. "$$\n",
  43. "\n",
  44. ".....\n",
  45. "\n",
  46. "$$\n",
  47. "\td\\Pi = \\Big( \\frac{\\partial V}{\\partial t} + ...\\Big)dt.\n",
  48. "$$\n",
  49. "\n",
  50. "$$\n",
  51. "\tV(S,T)=\\max(S-K,0)\n",
  52. "$$"
  53. ]
  54. },
  55. {
  56. "cell_type": "code",
  57. "execution_count": 1,
  58. "metadata": {},
  59. "outputs": [
  60. {
  61. "name": "stdout",
  62. "output_type": "stream",
  63. "text": [
  64. "8.916035060662303\n"
  65. ]
  66. }
  67. ],
  68. "source": [
  69. "from math import *\n",
  70. "# Cumulative normal distribution\n",
  71. "\n",
  72. "def CND(X):\n",
  73. "\n",
  74. " (a1,a2,a3,a4,a5) = (0.31938153, -0.356563782, 1.781477937, \n",
  75. "\n",
  76. " -1.821255978, 1.330274429)\n",
  77. " L = abs(X)\n",
  78. "\n",
  79. " K = 1.0 / (1.0 + 0.2316419 * L)\n",
  80. "\n",
  81. " w = 1.0 - 1.0 / sqrt(2*pi)*exp(-L*L/2.) * (a1*K + a2*K*K + a3*pow(K,3) +\n",
  82. "\n",
  83. " a4*pow(K,4) + a5*pow(K,5))\n",
  84. " if X<0:\n",
  85. "\n",
  86. " w = 1.0-w\n",
  87. "\n",
  88. " return w\n",
  89. "# Black Sholes Function\n",
  90. "\n",
  91. "def BlackSholes(CallPutFlag,S,X,T,r,v):\n",
  92. "\n",
  93. " d1 = (log(S/X)+(r+v*v/2.)*T)/(v*sqrt(T))\n",
  94. "\n",
  95. " d2 = d1-v*sqrt(T)\n",
  96. " if CallPutFlag=='c':\n",
  97. "\n",
  98. " return S*CND(d1)-X*exp(-r*T)*CND(d2)\n",
  99. "\n",
  100. " else:\n",
  101. "\n",
  102. " return X*exp(-r*T)*CND(-d2)-S*CND(-d1)\n",
  103. " \n",
  104. "call = BlackSholes('c',100,100,1,0.02,0.2)\n",
  105. "\n",
  106. "print (call)"
  107. ]
  108. },
  109. {
  110. "cell_type": "code",
  111. "execution_count": null,
  112. "metadata": {
  113. "collapsed": true
  114. },
  115. "outputs": [],
  116. "source": []
  117. }
  118. ],
  119. "metadata": {
  120. "kernelspec": {
  121. "display_name": "Python 3",
  122. "language": "python",
  123. "name": "python3"
  124. },
  125. "language_info": {
  126. "codemirror_mode": {
  127. "name": "ipython",
  128. "version": 3
  129. },
  130. "file_extension": ".py",
  131. "mimetype": "text/x-python",
  132. "name": "python",
  133. "nbconvert_exporter": "python",
  134. "pygments_lexer": "ipython3",
  135. "version": "3.6.1"
  136. }
  137. },
  138. "nbformat": 4,
  139. "nbformat_minor": 2
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement