{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Stock Price\n",
"\n",
"Let $S_t$ represent the stock price at time $t.$ How to write a simple model for this quantity?\n",
"\n",
" - Return:\n",
"$$\n",
"\\frac{S_{t+\\delta t}-S_t}{S_t}\n",
"$$\n",
"where $S_{t+\\delta t}-S_t=\\delta S$\n",
"\n",
"In the limit $\\delta t\\rightarrow 0$, we have\n",
"$$\n",
"\\lim_{\\delta t\\rightarrow 0}\\frac{S_{t+\\delta t}-S_t}{S_t} = \\frac{dS}{S}\n",
"$$\n",
"\n",
"## Modelling Return\n",
"\n",
"Return:\n",
"$$\n",
"\\frac{dS}{S}=\\mu dt+\\sigma dW\n",
"$$\n",
"- $\\mu dt$ is a measure of the __deterministic__ expected rate of growth of the share price. In general, $\\mu =\\mu (S,t).$ In simple models $\\mu $ is taken to be constant ($\\mu =0.1 ~ \\text{yr}^{-1} =10 ~ \\%\\text{yr}^{-1} $).\n",
"- $\\sigma dW$ describes the __stochastic__ change in the share price, where $dW$ stands for $\\delta W=W_{t+\\delta t}-W_t$ as $\\delta t\\rightarrow 0$\n",
"- $W_t$ is a __Wiener process__\n",
"- $\\sigma $ is the volatility ($\\sigma =0.2 ~ \\text{yr}^{-\\frac12} = 20~\\%\\text{yr}^{-\\frac12}$)\n",
"\n",
"## Using this notebook\n",
"\n",
"The notebook contains \"cells\", and in each cell there is either information (like this) or code (they have \"In [ ]\" to the left). You can run the code in the notebook, as well as editing and rerunning it. The notebook will work best if you first run each cell in the order they appear. You can then click on a cell and run it again if you have changed anything.\n",
"\n",
"## Real Data\n",
"\n",
"We can observe $S_t$ as recorded on the stock exchange. We can plot a time series of a real stock (the actual stock is unimportant) that I've already downloaded. We now write some code to import the plot into a _variable_ __M__."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from MathFinanceWorkshop import MFW_plot\n",
"M = MFW_plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the first two cells containging code. You can see the cells with code as they have \"In [ ] \" to the left. You should see a figure appear below the second command. This plots the timeseries of $S_t$ against. The graph is split into 20 time periods and each are a different colour, the reason will become apparent in the next cell."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"M.plotRealData()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now run the third and final cell containing code. You should see a button \"Run Interact\" appear below, press it. A figure containing fours graphs will show. \n",
"\n",
"The top left contains the same real data as above but now we have 20 lines on the graph all starting at $S_0=1$, as the data has been scaled against the initial value. \n",
"\n",
"The top right contains the 20 simulations starting at $S_0=1$, using the stock model outlined above and the parameters selected for $\\mu$ and $\\sigma$.\n",
"\n",
"The bottom left contains a histogram of the historical stock returns,\n",
"$$\n",
"\\frac{S_{t+\\delta t}-S_t}{S_t}\n",
"$$\n",
"and the bottom right is a histogram of returns for the simulated stock prices. If it is a good model and properly calibrated you should expect the graphs on the left to _look_ like the graphs on the right.\n",
"\n",
"\n",
"# Task\n",
"\n",
"Try moving the sliders to different values of $\\mu$ and $\\sigma$, can you get the data on the right (our mathematical model) to look like the data on the left?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"M.f_plot_interactive()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}