<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aroa Gomez on Medium]]></title>
        <description><![CDATA[Stories by Aroa Gomez on Medium]]></description>
        <link>https://medium.com/@aroa.gomez?source=rss-12e90fa192c7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XPgehIZ82pR20gnu.jpg</url>
            <title>Stories by Aroa Gomez on Medium</title>
            <link>https://medium.com/@aroa.gomez?source=rss-12e90fa192c7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 09:17:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aroa.gomez/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Neural Networks in finance?: Markov Chain Monte Carlo (MCMC) and Stochastic Volatility Modelling]]></title>
            <link>https://medium.com/analytics-vidhya/neural-networks-in-finance-markov-chain-monte-carlo-mcmc-and-stochastic-volatility-modelling-3f4f148c3046?source=rss-12e90fa192c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f4f148c3046</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[stochastic-process]]></category>
            <category><![CDATA[markov-chains]]></category>
            <category><![CDATA[markov-chain-monte-carlo]]></category>
            <category><![CDATA[volatility]]></category>
            <dc:creator><![CDATA[Aroa Gomez]]></dc:creator>
            <pubDate>Mon, 13 Jan 2020 14:28:16 GMT</pubDate>
            <atom:updated>2020-01-22T04:55:01.990Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>*** This post assumes basic knowledge of machine learning, econometrics modelling and options pricing . There will be no further explanation on some of the concepts below:</blockquote><blockquote><a href="https://en.wikipedia.org/wiki/Autoregressive_model">AR process</a>, <a href="https://en.wikipedia.org/wiki/Stochastic_process">Stochastic Process</a>, <a href="https://en.wikipedia.org/wiki/Autoregressive_conditional_heteroskedasticity">ARCH</a>, <a href="https://en.wikipedia.org/wiki/Black%E2%80%93Scholes_equation">Black-Scholes</a>, <a href="https://www.investopedia.com/ask/answers/062415/how-does-implied-volatility-impact-pricing-options.asp">Options pricing</a>, <a href="http://www.scholarpedia.org/article/Bayesian_statistics">Bayesian statistics</a></blockquote><p>The aim of this post is to give the reader an intuitive introduction to Markov Chain Monte Carlo (MCMC) and show a practical application in the financial sector.</p><p>In financial markets volatility is one of the key components when assessing asset returns, asset allocation and risk. Traditionally, volatility has been modelled with autoregressive conditional heteroskedasticity (ARCH) models and its variations, however, with the introduction of Black-Scholes pricing in options SV started to draw more attention in the industry. One of the main drawbacks of Black-Scholes (1973 &amp; 1976) is the assumption of constant volatility in the underlying asset which is rather unrealistic, SV models although can solve for this flaw. Considering the importance of volatility and its extensive literature, I thought it could be a good opportunity to introduce the topic as an application of MCMC.</p><p>Before we get into the math and depths of MCMC and volatility let’s start with a little bit of historical context.</p><h3><strong>Monte Carlo: the Gambling Capital of Europe</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1tv-tKg5r6bgmtvlJWdN4w.jpeg" /></figure><p><strong>When was Monte Carlo method first introduced?</strong></p><p>The Monte Carlo method was crucial for the simulations needed during the ‘Manhattan project’ during World War II to develop the first nuclear weapons.</p><p>In 1946 Von Neumman (better known as the father of Game Theory) and his colleague Ulam formalised the concept. They were investigating radiation shielding and the distance that neutrons would likely travel through various materials. Although they had enough data, the physicists in the lab were unable to solve the problem using conventional analytical math, then, Ulam had the idea of using random experiments with ‘truly random’ numbers.</p><p>At the time, this project was kept secret and they required a codename; it was Ulam who suggested the name of Monte Carlo. He got the inspiration from his uncle, who seemed to be an adept of ‘Casino de Monte-Carlo’ in Monaco where he would spend his time gambling family money.</p><h3><strong>MCMC Decomposition</strong></h3><p>MCMC is made out of two components: Markov Chain principles and Monte Carlo simulation method.</p><p><strong>Monte Carlo Method: </strong>Monte Carlo Methods are algorithms that simply repeat random samples over and over to get to an ‘answer’ when traditional math (deterministic) cannot output a single result or when the problems are too complicated to be solved analytically.</p><p><strong>Markov Chain: </strong>Markov Chain is formally an stochastic process, which is defined as a random variable that evolves through time. This process has the property that, given the present, the future is conditionally independent of the past.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*AzHi96syWn0XF3OLmawvjw.png" /></figure><p>In other words, knowing where you were in the previous period makes the rest of the chain history irrelevant. If we know Xt=j, where j is a state, then the rest of the history doesn’t add any information for predicting Xt+1; that’s why the two sides are equal, we only ‘care’ about the present state we are in Xt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*qBaXVwg_zNFEtq8swnL9ig.png" /></figure><h4>What do we need to compute MCMC?</h4><p>As you might recall from Bayesian statistics, your starting point is to be able to compute the ‘prior’ likelihood, similarly, in a Markov Chain process, for any possible point in the space we need to know the ‘prior’ probability. In simple terms, you need to know something about your parameters.</p><p>We start at a random point and calculate the prior likelihood Px, based on where we are standing at time t. Next, we take a move in the parameter space using a proposal distribution. We draw a random step towards a new position, we then compute the ‘prior likelihood’ * ‘proposal likelihood’. After thousands of iterations you will arrive to a joint posterior distribution for your large dimensional space.</p><h3>MCMC Application — Stochastic Volatility (SV)</h3><p>As mentioned in the introduction, volatility estimation is key metric in capital markets. Since the deterministic assumption is not empirically observable, a stochastic approximation is considered to be a better estimation. MCMC is very computationally expensive and it’s not widely used in the industry, however, I would like to set the framework for those interested in the topic.</p><p>The Stochastic Volatility model is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*05vJYOtWLFFhAgUtagOuaQ.png" /></figure><p>Where: y= log return; <em>h</em> = log volatility; μ= mean of log volatility; φ= persistence of volatility term; ε = white noise (error) on asset return; 𝛿 = shock on volatility at time t.</p><h4><strong>MCMC Algorithm — two steps</strong></h4><p>The main difference between ARCH and SV models is that SV considers the volatility term <em>h</em> to have an unpredictable component, while ARCH considers volatility deterministic given that it’s an autoregressive process.</p><p><strong>What does this means in computational terms?</strong></p><p>Let’s consider θ a random vector, then using Bayes’ theorem we can denote its posterior distribution as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*nofn61m3_GE3uEAHF_morw.png" /></figure><p>The volatility states <em>h</em> is based on the posterior distribution p(θ,h|y). Thus, the principle of MCMC inference is to simulate p(θ|y) with the likelihood function defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*A5D_C0gNTwl-WlqNa3Z9hA.png" /></figure><p>Since the function is a T-dimensional integral problem and is not analytically solvable an estimation is needed. It’s in the 90’s when MCMC starts to be considered a valuable technique.</p><p>The principle of MCMC bayesian inference is to simulate p(θ|y) by generating a Markov Chain random sample draw.</p><p>Firstly we deploy Markov Chain generating a sequence of random variables converging to the posterior distribution p(θ,h|y), this is done by taking samples of h, µ, φ and σ for t = 1, . . . , T in the Markov Chain space given a transition kernel.</p><p>Next, Monte Carlo computes the posterior mean of the parameters to smooth the results.</p><h3>Summary</h3><ul><li>MCMC has two components, Markov Chain process and Monte Carlo simulation.</li><li>MCMC is useful to solve integration and optimisation problems in large dimensional spaces.</li><li>Stochastic Volatility solves the problem of deterministic volatility in Black-Scholes pricing.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f4f148c3046" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/neural-networks-in-finance-markov-chain-monte-carlo-mcmc-and-stochastic-volatility-modelling-3f4f148c3046">Neural Networks in finance?: Markov Chain Monte Carlo (MCMC) and Stochastic Volatility Modelling</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An intro to Curve Interpolation: A Comparative View]]></title>
            <link>https://medium.com/@aroa.gomez/an-intro-to-curve-interpolation-a-comparative-view-fcb7b40bb31b?source=rss-12e90fa192c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcb7b40bb31b</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[interpolation]]></category>
            <category><![CDATA[data-sceince]]></category>
            <dc:creator><![CDATA[Aroa Gomez]]></dc:creator>
            <pubDate>Mon, 13 Jan 2020 14:18:50 GMT</pubDate>
            <atom:updated>2020-01-13T14:18:50.683Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article I will show how we can apply interpolation techniques in python and how to solve some of the main issues you could encounter with your data. First, we will give a short introduction about interpolation and the requirements our data must meet in order to be able to interpolate.</p><p>In this occasion we will compare quadratic and cubic spline interpolations using SciPy and sklearn Python libraries and finding what’s the best fit for our data.</p><p>To illustrate curve interpolation I will use SEK Swaps prices available <a href="https://sebgroup.com/large-corporates-and-institutions/prospectuses-and-downloads/rates/swap-rates">here</a>. This is just for the purpose of replicability. I won’t get into the theory and practice of swaps and swaps pricing. For those interested you can read more about it <a href="https://www.investopedia.com/terms/s/swap.asp">here</a>.</p><h3><strong>Definitions Time!</strong></h3><figure><img alt="One Flew Over Cuckoo’s nest (1975)" src="https://cdn-images-1.medium.com/max/500/1*39F1SPRomW3SaBEw8pVJDA.gif" /><figcaption><em>One Flew Over Cuckoo’s Nest (1975)</em></figcaption></figure><h4><strong>Interpolation</strong></h4><p>Interpolation, in math, is the estimation of f(x) from certain values of the function. If <em>x</em>0 &lt; … &lt; <em>xn</em> and <em>y</em>0 = <em>f</em>(<em>x</em>0),…, <em>yn</em> = <em>f</em>(<em>xn</em>) are known, and if <em>x</em>0 &lt; <em>x</em> &lt; <em>xn</em>, then the estimated value of <em>f</em>(<em>x</em>) is said to be an interpolation.</p><p>Interpolation techniques involve the construction of a function <em>L</em>(x), called the interpolant, which is then used to compute the desired values xi.</p><p>In other words, interpolation is the estimation of the infinite possible unknown points between two known points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*9tEeED_f_NsZ8lCYcSLjHg.png" /></figure><h4><strong>Spline Function</strong></h4><p>A spline function in math is a special category of functions used in interpolation and/or smoothing techniques. They are piecewise polynomial functions, which are functions defined on a sequence of intervals.</p><p>Spline functions minimises the overall curvature of the function we are trying to estimate.</p><h4>Cubic Spline Interpolation</h4><p>Therefore, a cubic spline is constructed of piecewise third-order polynomials which pass through a set of control points (our known <em>xi</em> points).</p><h4>Requirements For Spline Interpolation</h4><p>Before we calculate our cubic spline function we need to ensure that our known or control points meet the following requirements:</p><ul><li>Values must be real, finite and in strictly increasing order.</li><li>To achieve continuity the joint points two consecutive polynomials:<br><em>P_{i}( x) </em>and <em>P_{i+1}</em>( x) must join at <em>x{i}</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*4K_HO_gdcKPc_7WaddF-5g.png" /></figure><ul><li>To achieve smoothness they need to have the same derivatives at the point they join</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/221/1*NcNDo8bn2EFIrqNfMFo-tw.png" /></figure><p><strong>SEK Swap Curve</strong></p><p>So let’s start by taking a look at our SEK Swap data.</p><p>Our data is composed by the maturity of the swaps in years and the price in rates <em>(%).</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*GE_kkw9uRRjq0Bul307crw.png" /></figure><p>We see increasing rates (price) up until year 20 where the neighbour point (30yr) decreases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/102/1*NX96NgUG1u-njF7cEsa9hA.png" /></figure><p>This violates one of our requirements (strictly increasing order). We can solve for this in several ways:</p><ol><li>Adjust one of each pair by a small amount</li><li>Average the two points</li><li>Remove a point</li></ol><p>Depending on the case and the data you are manipulating you might me able to remove a point or adjusted by a tiny bit. In this case, since this are financial product prices at different maturities we can’t remove a point or manually adjust it. A quantitative way to tackle this problem is using isotonic regression.</p><p>An isotonic regression or monotonic regression helps to approximate the points given a restriction; i.e. given values <em>x1,</em> …, <em>xn</em> and their positive weights <em>w</em>1, …, <em>wn</em>, approximate them by <em>y</em>1, … <em>yn</em> as close as possible, subject to <em>yi</em>≥<em>yj</em> . Graphically an isotonic regression looks like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*S4dxuB6pN5PVMZF_.png" /></figure><p>The red dots in the graph above are the original points while the green dots are the isotonic solution.</p><p>In our case we only need to transform one point at the end of the curve. After applying isotonic regression our data looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/189/1*9VRa4CahXlAMEKWG0hLu2w.png" /></figure><pre>from sklearn.isotonic import IsotonicRegression</pre><pre># Setting the variables</pre><pre>x = data[&#39;Maturity&#39;]<br>y = data[&#39;Price&#39;]</pre><pre># Monotone Data: Isotonic Regression</pre><pre>ir = IsotonicRegression()<br>y_ = ir.fit_transform(x, y)</pre><p>Now we are ready to run our interpolation for SEK swap prices</p><pre>from scipy import interpolate<br>from scipy.interpolate import interp1d<br></pre><pre># Cubic Interpolation<br>tck = interpolate.splrep(x, y_)<br>interpolate.splev(x, tck, ext=3)</pre><pre>f = interp1d(x,y_, kind=&#39;cubic&#39;, fill_value=&quot;extrapolate&quot;)<br>xnew = np.linspace(0,30,1000,endpoint=True)</pre><pre># Quadratic Interpolation</pre><pre>g = interp1d(x,y_, kind=&#39;quadratic&#39;, fill_value=&quot;extrapolate&quot;)<br>xg = np.linspace(0,30,1000,endpoint=True)</pre><pre># Getting f(x) and g(x)</pre><pre>ynew = f(xnew)<br>yg = g(xg)</pre><p>In the graph below we can see our original data green dotted line, quadratic interpolation in orange and cubic in white.</p><p>As we can see, cubic line penalises on the short end and long end while the quadratic optimises (in the bad sense) the curvature. Quadratic curves are less suitable for swap prices in general given that the optimisation generates larger distance between the linear and quadratic points. This would lead in practical terms to generate ‘far from the market’ prices for SEK swaps, basically bad prices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*TYX1Qnn8PdY_9chsQTKr4g.png" /></figure><h4><strong>Summary</strong></h4><p>In this post we have seen how we can fix one of the major issues you encounter while interpolating non-monotonic points by using isotonic regression.</p><p>In this occasion we could visually identify what’s the best fit for our data. Just by looking at how far the linear points and the estimated points are from each other, i.e by minimising the distance, we can determine that cubic interpolation is more suitable than quadratic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcb7b40bb31b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>