<?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 Daniel Cotto on Medium]]></title>
        <description><![CDATA[Stories by Daniel Cotto on Medium]]></description>
        <link>https://medium.com/@danielcotto18?source=rss-54b8768f7d44------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Po-UrK0AuJLH4zDEePAYYQ.png</url>
            <title>Stories by Daniel Cotto on Medium</title>
            <link>https://medium.com/@danielcotto18?source=rss-54b8768f7d44------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 16:36:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danielcotto18/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 for Option Pricing]]></title>
            <link>https://medium.com/data-science/neural-networks-for-option-pricing-danielcotto-c24569ad0bb?source=rss-54b8768f7d44------2</link>
            <guid isPermaLink="false">https://medium.com/p/c24569ad0bb</guid>
            <category><![CDATA[pricing]]></category>
            <category><![CDATA[options]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Daniel Cotto]]></dc:creator>
            <pubDate>Tue, 01 Oct 2019 17:45:16 GMT</pubDate>
            <atom:updated>2019-10-01T17:45:16.588Z</atom:updated>
            <content:encoded><![CDATA[<h4>artificial neural network in finance</h4><h4>Learning in the Black &amp; Scholes World using R</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5aJ91WurWd7ouEdU" /><figcaption>Photo by <a href="https://unsplash.com/@alinnnaaaa?utm_source=medium&amp;utm_medium=referral">Alina Grubnyak</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This article is just an attempt to implement deep learning to option pricing. In particular, the main objective is to show the ability of Artificial Neural Networks to ’learn’ the model from the dataset.</p><p>Artificial neural networks (ANNs) with multiple hidden layers have become successful methods to detect patterns from a large dataset. The implementation of a ANN can be typically decompose into two separate phases: training part and test part. During the training phase, the ANN ’learn’ the model from the dataset while, in the test phase, the trained ANN can be employed to predict the results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*FsklYIOQvp-FfJyu0yQTqA.jpeg" /></figure><p>The architecture is a combination of different layers which are made by a defined number of neurons. Connecting the neuron of previous layers with those of the followers, it is possible to use the output signals coming from the previous step as an input signals for the next layer.</p><p>The activation function ψ () adds non linearity to the system. While there are many, to the purpouse of this section, I will used only the ReLu function,defined as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*jG1a_lWlugwQVd8GMYG-3Q.png" /></figure><p>To evaluate the performance the mean squared error (MSE)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*VqdlrwSe7xTybT92Dlcb4Q.png" /></figure><p>The training process try to learn the optimal weights and biases that minimize the loss function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*RzkBgOgw-QGpNbS1HfLarQ.png" /></figure><p>As the historical data of option prices are quite expensive, I have decided to simulate them.</p><p>It has been assumed that the stock prices follow a gBM to get a sufficient number of stock prices. Thus, simulated values have been got to have enough strike price, maturities, interest rates and volatilities.</p><p>From these parameters, it has been computed the price of an European Call Option by <a href="https://en.wikipedia.org/wiki/Black%E2%80%93Scholes_model#Black%E2%80%93Scholes_formula">Black Scholes formula</a>.Thus, it is assumed to be in a Black Scholes world, i.e. all assumption of the model are satisfied.</p><pre>#BS_closed formula: </pre><pre>EU_call_bs = function(S, K, r, sigma,t=0, T){<br>  d1 = (log(S/K)+(r+((sigma)^2)/2)*(T-t))/(sigma*sqrt(T-t))<br>  d2 = d1-(sigma*sqrt(T-t))<br>  return((S*pnorm(d1))-(K*exp(-r*(T-t))*pnorm(d2)))<br>}</pre><pre>#Generate Dataset<br>sample&lt;-sde::GBM(x=100,N=1000000,r = r,sigma = 0.8,T = 1)</pre><pre>mydata &lt;- NULL<br>mydata$Stock &lt;- sample<br>mydata$Strike &lt;- sample*runif(length(sample),min = 0.4,max=1)<br>mydata$Time &lt;- runif(n=length(sample))<br>mydata$sigma &lt;- runif(n=length(sample), min = 0.1, max = 0.8)<br>mydata$r &lt;-runif(n=length(sample),min = 0.01, max=0.05)<br>mydata$BS &lt;-  EU_call_bs(S = mydata$Stock, t = 0, T = mydata$Time, <br>r = mydata$r, K = mydata$Strike, sigma = as.numeric(mydata$sigma));</pre><p>Once that the dataset is built up, it has been split in two subset: training set and test set. The ANN has been trained on the training set and then evaluated on the test dataset.</p><pre>#Split dataset</pre><pre>split &lt;- rsample::initial_split(mydata, prop = .7, strata=&#39;BS&#39; )</pre><pre>train &lt;- rsample::training(split)<br>test  &lt;- rsample::testing(split)</pre><pre># Create &amp; standardize feature sets<br># training features<br>train_x &lt;- train %&gt;% dplyr::select(-BS)<br>mean    &lt;- colMeans(train_x)<br>std     &lt;- apply(train_x, 2, sd)<br>train_x &lt;- scale(train_x, center = mean, scale = std)</pre><pre># testing features<br>test_x &lt;- test %&gt;% dplyr::select(-BS)<br>test_x &lt;- scale(test_x, center = mean, scale = std)</pre><pre># Create &amp; transform response sets<br>train_y &lt;- log(train$BS)<br>test_y  &lt;- log(test$BS)</pre><p>In the following picture are reported hyper parameters used for the ANN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2OM4rOpyLGWtQ7qHEmKO9w.png" /></figure><pre>#MODEL 1<br>model_1 &lt;- keras_model_sequential() %&gt;%<br>  layer_dense(units =  200,activation = &quot;relu&quot;, input_shape = ncol(train_x)) %&gt;%<br>  layer_dense(units = 130,activation = &quot;relu&quot;) %&gt;%<br>  layer_dense(units = 50,activation = &quot;relu&quot;) %&gt;%<br>  layer_dense(units = 1)  %&gt;%<br>  <br>  # backpropagation<br>  compile(<br>    optimizer = &quot;rmsprop&quot;,<br>    loss = &quot;mse&quot;,<br>    metrics = c(&quot;mae&quot;)<br>  )</pre><pre>learn_1 &lt;- model_1 %&gt;% fit(<br>  x = train_x,<br>  y = train_y,<br>  epochs = 45,<br>  batch_size = 256,<br>  validation_split = .2,<br>  verbose = TRUE,<br>)</pre><pre>#MODEL 2</pre><pre>model_2 &lt;- keras_model_sequential() %&gt;%<br>  layer_dense(units =  200,activation = &quot;relu&quot;, input_shape = ncol(train_x),kernel_regularizer = regularizer_l2(0.001)) %&gt;%<br>  layer_batch_normalization() %&gt;%<br>  layer_dropout(rate = 0.2) %&gt;%<br>  layer_dense(units = 130,activation = &quot;relu&quot;,kernel_regularizer = regularizer_l2(0.001)) %&gt;%<br>  layer_batch_normalization() %&gt;%<br>  layer_dropout(rate = 0.2) %&gt;%<br>  layer_dense(units = 50,activation = &quot;relu&quot;,kernel_regularizer = regularizer_l2(0.001)) %&gt;%<br>  layer_batch_normalization() %&gt;%<br>  layer_dropout(rate = 0.2) %&gt;%<br>  layer_dense(units = 1)  %&gt;%<br>  <br>  compile(<br>    optimizer = &quot;rmsprop&quot;, #optimizer_adam(lr = 0.01) <br>    loss = &quot;mse&quot;,<br>    metrics = c(&quot;mae&quot;)<br>  )<br>learn_2 &lt;- model_2 %&gt;% fit(<br>  x = train_x,<br>  y = train_y,<br>  epochs = 45,<br>  batch_size = 256,<br>  validation_split = .2,<br>  verbose = TRUE,<br>  callbacks = list(<br>    #callback_early_stopping(patience = 10),<br>    callback_reduce_lr_on_plateau(patience = 5))<br>)</pre><p>During the prediction phase, the results re not so different from those got in during training phase.</p><pre>#Storing Prediction</pre><pre>risultati &lt;- NULL</pre><pre>risultati$predcted_values_model_1&lt;- model_1 %&gt;% predict(test_x)<br>risultati$true_value &lt;- test_y</pre><pre>risultati$predcted_values_model_2&lt;- model_2 %&gt;% predict(test_x)</pre><pre>risultati$pred_value_model_1_converted &lt;- exp(risultati$predcted_values_model_1)</pre><pre>risultati$true_converted &lt;- exp(risultati$true_value)</pre><pre>risultati$pred_value_model_2_converted &lt;- exp(risultati$predcted_values_model_2)</pre><pre>risultati$S_K &lt;- test[,1] / test[,2]</pre><pre>risultati$Err_model_1 &lt;- abs(risultati$true_converted - risultati$pred_value_model_1_converted )</pre><pre>risultati$Err_model_2 &lt;- abs(risultati$true_converted - risultati$pred_value_model_2_converted )</pre><p>The predicted result for the first three rows of the test set are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*VED_lRBEHDhmvs5-ZBRk5A.png" /></figure><p>The below plots are the actual price against the predicted price of each option for both models, yielding a narrow line with very few deviations.</p><pre>plot(x=risultati$true_converted, y=risultati$pred_value_model_1_converted , cex= 0.001, xlab=&#39;Actual&#39;, ylab=&#39;Predicted Model 1&#39;)</pre><pre>plot(x=risultati$true_converted, y=risultati$pred_value_model_2_converted , cex= 0.001, xlab=&#39;Actual&#39;, ylab=&#39;Predicted Model 2&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9_TdOh5Enn5bHt43qZzbmg.png" /></figure><p>To get a bettere view on the results, the absolute error which models make is shown in the graph below. It is interesting to see the different behaviours that two models have as S/K increases.</p><pre>plot(x=risultati$S_K, risultati$Err_model_1, xlab=&#39;S / K&#39;, ylab=&#39;|BS Price - Predicted model 1|&#39;,cex=0.01)</pre><pre>plot(x=risultati$S_K, risultati$Err_model_2, xlab=&#39;S / K&#39;, ylab=&#39;|BS Price - Predicted model 2|&#39;,cex=0.01)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SdQQm9oKd-9Uek8eHMuh4g.png" /></figure><p>A deeper analysis in the models and fine tuning of parameters would definitely improve the results. In general, it is possible to see how, in the Black &amp; Scholes world, the ANN provides a good method to compute the European-style derivatives.</p><blockquote>All models are wrong but some are useful.</blockquote><blockquote>-George Box, 1978-</blockquote><p>[1] R.Kristiansson, <a href="https://www.math.kth.se/matstat/seminarier/reports/M-exjobb18/180525c.pdf">Exotic Derivatives and Deep Learning </a>(2019), KTH ROYAL INSTITUTE OF TECHNOLOGY SCHOOL OF ENGINEERING SCIENCES</p><p>[2] Shuaiqiang Liu,Cornelis W. Oosterlee, Sander M.Bohte, <a href="https://arxiv.org/abs/1901.08943">Pricing options and computing implied volatilities using neural networks</a> (2018)</p><p>[3] Robert Culkin, Sanjiv R. Das, <a href="https://www.joim.com/article/machine-learning-in-finance-the-case-of-deep-learning-for-option-pricing/">Machine Learning in Finance:The Case of Deep Learning for Option Pricing </a>(2017)</p><p>[4] Jacob Michelsen Kolind, Jon Harris and Karol Przybytkowski, <a href="http://cs229.stanford.edu/proj2009/KolindHarrisPrzybytkowski.pdf">Hedging and Pricing Options using Machine Learning </a>(2009)</p><p>[5] D.Stafford, <a href="http://jultika.oulu.fi/files/nbnfioulu-201901091016.pdf">Machine Learning in Option Pricing</a> (2018), UNIVERSITY OF OULU</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c24569ad0bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/neural-networks-for-option-pricing-danielcotto-c24569ad0bb">Neural Networks for Option Pricing</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>