Code and Financehttp://www.codeandfinance.com/Articles, thoughts, and notes in computational finance.enTue, 09 Sep 2014 20:14:21 GMTnikolahttp://blogs.law.harvard.edu/tech/rssFinding the implied volatilityhttp://www.codeandfinance.com/finding-implied-vol.html<div><p>Black-Scholes describes option prices as a function of the underlying price,
strike, risk-free interest rate, time to expiry and volatility:</p>
<div class="math">
\begin{equation*}
V = BS(S, K, r, T, \sigma)
\end{equation*}
</div>
<p>The volatility value used here is an estimxate of the <em>future</em> realised price volatility. (we calculated the <em>historical</em> price volatility a few articles ago.</p>
<p>Given that the stock price, the strike, risk-free interest rate, and time to expiry are all known and easily found, we can actually think of a price for an option in the market as a function of <span class="math">\(\sigma\)</span>
instead.</p>
<div class="math">
\begin{equation*}
V = BS(\sigma)
\end{equation*}
</div>
<p>The price of an option is monotonically increasing in <span class="math">\(\sigma\)</span>
, which means that as volatility increases, so does the value of the option, as shown below.</p>
<img alt="/attachments/volagainstprice.png" src="http://www.codeandfinance.com/attachments/volagainstprice.png">
<p>At the money the effect is fairly linear, and even for strikes that are ITM or OTM there's a positive effect on the price for an increase in volatility.</p>
<p class="more"><a href="http://www.codeandfinance.com/finding-implied-vol.html">Read more →</a></p></div>optionsvolatilityhttp://www.codeandfinance.com/finding-implied-vol.htmlSun, 10 Aug 2014 13:15:00 GMTBreaking even on a delta-hedged portfoliohttp://www.codeandfinance.com/option-break-even.html<p>When an options portfolio is delta-neutral, its P&L over a small time change is:</p>
<div class="math">
\begin{equation*}
P\&L = -\Theta \delta t + \frac{1}{2}\Gamma(\delta S)^2
\end{equation*}
</div>
<p>When you own options you're long gamma, so when the underlying moves it makes you money. Your option then loses some extrinsic value every day through theta.</p>
<p>Black-Scholes says that when the underlying moves by one standard deviation, your gamma profits should offset your theta losses. This known as the break even move.</p>
<p>You can use the current underlying price plus the implied volatility to work out the expected daily standard deviation. This is given by <span class="math">\(S \sigma \sqrt{\delta t}\)</span>
.</p>
<p>But, as your gamma and theta change everyday, this breakeven move can also be expressed by rearranging the equation at the top. This calculates how much the underlying needs to move <em>that day</em> to break even.</p>
<div class="math">
\begin{equation*}
\delta S = \sqrt{\frac{2\Theta}{\Gamma}}
\end{equation*}
</div>
<div class="section" id="example">
<h2>Example</h2>
<p>If we have a 1 year ATM call option on a stock where the underlying's price is currently $100.00 and the volatility is 20%.</p>
<p>Today the option has a gamma of <span class="math">\(0.028138\)</span>
and a theta of <span class="math">\(-0.01543\)</span>
, which makes our break even move</p>
<div class="math">
\begin{equation*}
\delta S = \sqrt{\frac{2\Theta}{\Gamma}} = \sqrt{\frac{2 * 0.01543}{0.028138}} = 1.047
\end{equation*}
</div>
</div>optionshedginghttp://www.codeandfinance.com/option-break-even.htmlMon, 18 Nov 2013 06:46:05 GMTMeasuring volatilityhttp://www.codeandfinance.com/measuring-volatility.html<div><p>The volatility <span class="math">\(\sigma\)</span>
of an asset is a measure of the uncertainty about the asset's returns. Volatility measures how much the price varies over time.</p>
<p>There are two types of volatility we can consider: implied and realised. Implied volatility can be extracted from option prices (it's <cite>implied</cite> from the prices). Realised volatility is the actual volatility experienced by the underlying, which could be a stock, futures contract, etc.</p>
<p>Unlike prices, volatility is not something that can be directly observed, instantaneous volatility is unobservable. Volatility requires <cite>time</cite> to manifest itself.</p>
<p class="more"><a href="http://www.codeandfinance.com/measuring-volatility.html">Read more →</a></p></div>volatilityhttp://www.codeandfinance.com/measuring-volatility.htmlTue, 03 Sep 2013 05:45:00 GMTExtending our model to price binary optionshttp://www.codeandfinance.com/extending-price-binary-options.html<div><p>Our model of <a class="reference external" href="http://codeandfinance.com/post/option-valuation-monte-carlo/">pricing European options by Monte Carlo simulations</a> can be used as the basis for pricing a variety of exotic options.</p>
<p>In our previous simulation we defined a way of distributing asset prices at maturity, and a way of assessing the value of an option at maturity with that price.</p>
<p>This simulation can be thought of generically like:</p>
<pre class="code python literal-block">
<span class="k">while</span> <span class="n">i</span> <span class="o"><</span> <span class="n">num_iterations</span><span class="p">:</span>
<span class="n">S_T</span> <span class="o">=</span> <span class="n">generate_asset_price</span><span class="p">()</span>
<span class="n">payoffs</span> <span class="o">+=</span> <span class="n">payoff_function</span><span class="p">(</span><span class="n">S_T</span><span class="p">)</span>
<span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">option_price</span> <span class="o">=</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">r</span><span class="o">*</span><span class="n">T</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">payoffs</span> <span class="o">/</span> <span class="n">num_iterations</span><span class="p">)</span>
</pre>
<p>By changing how we generate asset prices and how we assess an option's payoff, we can generate prices for some exotic options.</p>
<p class="more"><a href="http://www.codeandfinance.com/extending-price-binary-options.html">Read more →</a></p></div>monte-carlooptionsexotichttp://www.codeandfinance.com/extending-price-binary-options.htmlFri, 30 Aug 2013 05:46:05 GMTPricing options using Monte Carlo simulationshttp://www.codeandfinance.com/pricing-options-monte-carlo.html<div><p>Previously we <a class="reference external" href="http://codeandfinance.com/post/monte-carlo-pi/">introduced the concept of Monte Carlo simulations</a>, and how to build a basic model that can be sampled stochastically. We're now going to expand on our modelling and show how these simulations can be applied to some financial concepts.</p>
<p>An option is a contract that gives the buyer the <cite>right</cite> to buy or sell an asset at a particular price, at a point in the future. These contracts, known as derivatives, are traded for a number of reasons, but a common usage is to hedge away exposure to an asset's price moving in an undesirable way.</p>
<p>The option, the right to buy or sell, has a price too. The <a class="reference external" href="http://en.wikipedia.org/wiki/Black%E2%80%93Scholes">Black Scholes model</a> describes one way of determining a fair price for an option, but there are also many other methods for determining a price.</p>
<p class="more"><a href="http://www.codeandfinance.com/pricing-options-monte-carlo.html">Read more →</a></p></div>monte-carlooptionshttp://www.codeandfinance.com/pricing-options-monte-carlo.htmlThu, 29 Aug 2013 05:46:05 GMTEstimating Pi using Monte Carlo simulationshttp://www.codeandfinance.com/estimating-pi-monte-carlo.html<div><p>A <a class="reference external" href="http://en.wikipedia.org/wiki/Monte_Carlo_method">Monte Carlo simulation</a> is a method of finding an answer to a problem by repeatedly and sampling <cite>something</cite> at random. They are primarily suited to problems where a deterministic algorithm might not be practical or even feasible.</p>
<p>From a financial perspective, Monte Carlo simulations are an effective way of modelling behaviours that have a degree of uncertainty, which can range from calculating option prices to running risk simulations.</p>
<p class="more"><a href="http://www.codeandfinance.com/estimating-pi-monte-carlo.html">Read more →</a></p></div>monte-carlohttp://www.codeandfinance.com/estimating-pi-monte-carlo.htmlTue, 27 Aug 2013 12:57:30 GMT