<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE article  PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" "http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd"><article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="3.0" xml:lang="en" article-type="research article"><front><journal-meta><journal-id journal-id-type="publisher-id">JMF</journal-id><journal-title-group><journal-title>Journal of Mathematical Finance</journal-title></journal-title-group><issn pub-type="epub">2162-2434</issn><publisher><publisher-name>Scientific Research Publishing</publisher-name></publisher></journal-meta><article-meta><article-id pub-id-type="doi">10.4236/jmf.2020.102016</article-id><article-id pub-id-type="publisher-id">JMF-100148</article-id><article-categories><subj-group subj-group-type="heading"><subject>Articles</subject></subj-group><subj-group subj-group-type="Discipline-v2"><subject>Business&amp;Economics</subject><subject> Physics&amp;Mathematics</subject></subj-group></article-categories><title-group><article-title>
 
 
  A General Framework of Derivatives Pricing
 
</article-title></title-group><contrib-group><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>Liangliang</surname><given-names>Zhang</given-names></name><xref ref-type="aff" rid="aff1"><sub>1</sub></xref><xref ref-type="corresp" rid="cor1"><sup>*</sup></xref></contrib></contrib-group><aff id="aff1"><label>1</label><addr-line>101 Washington Blvd, CT 06902, Stamford, USA</addr-line></aff><pub-date pub-type="epub"><day>07</day><month>05</month><year>2020</year></pub-date><volume>10</volume><issue>02</issue><fpage>255</fpage><lpage>266</lpage><history><date date-type="received"><day>27,</day>	<month>March</month>	<year>2020</year></date><date date-type="rev-recd"><day>10,</day>	<month>May</month>	<year>2020</year>	</date><date date-type="accepted"><day>13,</day>	<month>May</month>	<year>2020</year></date></history><permissions><copyright-statement>&#169; Copyright  2014 by authors and Scientific Research Publishing Inc. </copyright-statement><copyright-year>2014</copyright-year><license><license-p>This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/</license-p></license></permissions><abstract><p>
 
 
  In this paper, we outline a general framework of derivatives pricing. The framework consists of two modules. The first is a novel simulation and machine learning based calibration module and the second one is a pricing module, which originates from 
  [1] and 
  [2]. Numerical examples show good applicability of the proposed framework. The methodology of calibration utilizes machine learning and simulation methods, combined, to deliver high quality parameter inference results and the pricing module is generic and can be applied to any financial derivatives. The machine learning based pricing methodologies can also generate prices on a future simulation grid, which facilitates XVA computations. Our methodologies can be applied to any pricing problem and the calibration routine is general and useful whenever a parametric model needs to be estimated.
 
</p></abstract><kwd-group><kwd>Clustering</kwd><kwd> Machine Learning</kwd><kwd> Calibration</kwd><kwd> Asset Pricing</kwd><kwd> Curve Fitting</kwd></kwd-group></article-meta></front><body><sec id="s1"><title>1. Introduction</title><p>Despite recent advancement in model-free reinforcement learning based derivatives pricing methods and market scenario generating schemes, parametric models remain an important aspect of financial modeling for OTC and exchange traded financial derivatives, because parametric models are well-understood and can be easily interpreted. Moreover, the sensitivity measures are easy to obtain. However, in today’s banking practice, the parametric calibration and asset pricing are still ad-hoc, in that, different trading desks might use different models for the same set of risk factors. Moreover, models are of low dimensions in nature, because a joint calibration is time consuming and numerical optimization routines are often unstable and return boundary solutions. In addition, products involving complex dynamics are often treated with approximations that are not accurate or convergent.</p><p>Recent literature on machine learning calibration includes [<xref ref-type="bibr" rid="scirp.100148-ref3">3</xref>], in which the author proposes a deep learning and simulation based approach to calibrate option pricing models. In addition, [<xref ref-type="bibr" rid="scirp.100148-ref4">4</xref>] proposes a similar approach.</p><p>In this paper, we propose a novel framework to alleviate the mentioned difficulties in derivatives calibration and pricing. First, we propose a simulation-based calibration method, without the need to use numerical optimization routines to minimize the sum of squares, i.e., the L<sup>2</sup> distance, between the model and the observed prices. The intermediate simulation results can be stored and re-used. Therefore, the proposed methodology is efficient: we only need initial simulation and calibration can be done in a fast manner in an on-going basis. Second, the calibration method does not need many evaluations of derivative prices, as opposed to a standard optimization routine, which might require thousands of iterations. Third, we leverage the methods proposed in [<xref ref-type="bibr" rid="scirp.100148-ref1">1</xref>] and [<xref ref-type="bibr" rid="scirp.100148-ref2">2</xref>] for the pricing of complex financial derivatives, potentially involving optimal stopping features or other exotic properties such as a breakable swap, where both parties can terminate the contract to the best of their interest (and therefore a stochastic Nash equilibrium has to be found in order for us to obtain the price of this product). Clustering method, as an unsupervised learning method, was first applied to yield nonlinear regression computations in [<xref ref-type="bibr" rid="scirp.100148-ref5">5</xref>] and [<xref ref-type="bibr" rid="scirp.100148-ref2">2</xref>]. In this paper, we apply this approach to calibration of financial derivatives. To the best of our knowledge, our paper is the first to propose such a method. The algorithm is very easy to implement, fast and accurate. Numerical experiments show that it can give an accurate estimate to the speed of mean reversion parameter of a CIR process, which is thought to be very difficult to infer using either bond or bond option data. The calibration methodology has the potential to support joint inference using derivatives from different asset classes using data from both P and Q measures.</p><p>The organization of this paper is as follows. Section 2 introduces the main methodologies. Section 3 contains numerical experiments and Section 4 concludes. All the source code can be found in Appendix.</p></sec><sec id="s2"><title>2. The Methodology</title><p>In what follows, we will assume that a pricing model (and equivalently, the model prices) is denoted by M ( X , ϑ , θ , C ) , where X is a set of state variables described by the model, ϑ is the model parameters related to X and θ is the parameters related to the financial product. C, defined as the set of control parameters, is related to a numerical method that solves the model. We denote M θ m k t the market observed prices for product θ . We use risk neutral derivatives pricing as an example to illustrate ideas, with the understanding that the method is generic and applies to all the asset pricing problems.</p><sec id="s2_1"><title>2.1. Calibration</title><p>The calibration method first simulates N uniform samples of parameter ϑ . Usually, N increases with the dimension of ϑ . For each simulated parameter ϑ n , we can evaluate the model price M ( X , ϑ , ϑ n , C ) and define ϑ * = arg min n ‖ M ( X , ϑ , ϑ n , C ) − M θ m k t ‖ 2 , i.e., the specific simulated parameter ϑ n that minimizes the distance between model produced prices and market observed prices. As we expect, when N → ∞ , the estimated parameter ϑ * → ϑ , the true parameter value.</p><p>The above methodology works theoretically. However, it is difficult, or often time consuming to implement in practice. The reason is that, even for a European type product, with long time to maturity and no closed-form solution, it might take a long time for the pricer to produce even one sufficiently accurate price, let alone the American products. Often, ϑ is in high dimension, given a portfolio of financial derivatives, and N is large. This often implies an unreasonably large amount of time needed for the estimation.</p><p>An improvement utilizes clustering method on the simulated parameter space Θ = { ϑ n } n = 1 N . For example, we can divide the Θ into K clusters { Θ k } k = 1 K , such that for each 1 ≤ k ≤ K , we have ‖ Θ k ‖ ≤ ϵ , where ‖   ⋅   ‖ is the radius operator of a finite set and ϵ &gt; 0 is a small positive number. In each of the cluster Θ k ,</p><p>denote its centroid by Θ k &#175; , valuate the model at each Θ k &#175; : M ( X , ϑ , Θ k &#175; , C ) and obtain K prices { M ( X , ϑ , Θ k &#175; , C ) } k = 1 K . Find k * = arg min k { M ( X , ϑ , Θ k &#175; , C ) } k = 1 K .</p><p>Next, let us focus on cluster Θ k * . As long as | Θ k * | ≥ K , i.e., the number of elements in Θ k * is no less than K, we can repeat the above operations, until we find a k ^ such that | Θ k ^ | &lt; K . Then, use the centroid Θ k ^ &#175; as the estimator of ϑ .</p><p>The complexity of the algorithm grows in a logarithm manner with respect to N. Assume that α = ⌊ l o g K N ⌋ , the integer part of l o g K N , then, the total number of evaluation times is K &#215; α . The method ensures that we can find the optimal parameter values quickly without the need to evaluate the pricer at each simulated value of the model parameter.</p><p>The choice of the numerical method to implement the pricer is open to the preference of each user of our framework. It can be brute-force Monte Carlo simulation, analytical expansion, asymptotic expansion or other approximation methodologies.</p></sec><sec id="s2_2"><title>2.2. Pricing</title><p>We use the pricing of financial derivatives as an example to illustrate ideas. Under no arbitrage framework and some sufficient condition, the present value of all marketed cash flows is martingales under a so-called risk-neutral measure, or Q measure. In general, derivatives pricing follows a reduce-form approach that assumes an underlying price distribution and compute the conditional expected value of the discounted payoff function. The underlying can be modeled by a discrete time-series or a system of stochastic differential equations. The simulated-based numerical methods for the latter case are discussed in [<xref ref-type="bibr" rid="scirp.100148-ref1">1</xref>] and [<xref ref-type="bibr" rid="scirp.100148-ref2">2</xref>]. We refer the readers to those references for more details.</p></sec><sec id="s2_3"><title>2.3. XVA</title><p>The proposed methodologies in [<xref ref-type="bibr" rid="scirp.100148-ref1">1</xref>] and [<xref ref-type="bibr" rid="scirp.100148-ref2">2</xref>] enable evaluation in a future simulation grid and this is the foundation for XVA evaluations.</p></sec></sec><sec id="s3"><title>3. Numerical Experiments</title><p>In this paper, we will mainly test the calibration method, with the pricing component already validated in the reference of [<xref ref-type="bibr" rid="scirp.100148-ref1">1</xref>] and [<xref ref-type="bibr" rid="scirp.100148-ref2">2</xref>]. Due to the constraint on the computational budget, we focus on simple products to illustrate ideas. The method we adopt for the pricer is Monte Carlo simulation, which is relatively more time consuming than semi closed-form solutions.</p><sec id="s3_1"><title>3.1. Heston European Equity Option Pricing Model</title><p>Assume that under the risk neutral measure, the stock price follows a Heston- type stochastic volatility model, with parameter values described in <xref ref-type="table" rid="table1">Table 1</xref> below.</p><p>In order to estimate the true values, we generate 75,000 uniform samples of ( κ , θ , σ , ρ ) in interval [ 0.0000 , 1.5000 ] &#215; [ 0.0000 , 0.0900 ] &#215; [ 0.0000 , 0.5000 ] &#215; [ − 1.0000 , 1.0000 ] . Using the methodology outlined in Section 2.1, we have the following estimates. Risk free rate is 1.00%, time to maturity is 0.50 years and the option prices are evaluated via Monte Carlo simulation method with 75,000 sample paths and 50 time discretization points. <xref ref-type="fig" rid="fig1">Figure 1</xref> shows the price fit for case 1. Blue curve is the true price<sup>1</sup> and the orange curve represents the calibrated prices at maturity date across different strikes. We choose 250 clusters for the estimation. <xref ref-type="table" rid="table2">Table 2</xref> contains the results.</p></sec><sec id="s3_2"><title>3.2. CIR Bond Pricing Model</title><p>In this section, we study a zero-coupon bond pricing problem, where the short rate process follows a Cox-Ingersoll-Ross model. The parametrization of the problem is listed in <xref ref-type="table" rid="table3">Table 3</xref> and inference result is in <xref ref-type="table" rid="table4">Table 4</xref>. We use a whole term structure of bond prices to calibrate the model. For more details, we refer the interested readers to the sample code in the Appendix. The pricing fit is in <xref ref-type="fig" rid="fig2">Figure 2</xref>.</p><table-wrap id="table1" ><label><xref ref-type="table" rid="table1">Table 1</xref></label><caption><title> Parameter Values. ( κ , θ , σ , ρ ) are speed of mean reversion, long term mean, volatility of volatility and correlation parameters</title></caption><table><tbody><thead><tr><th align="center" valign="middle" >Index</th><th align="center" valign="middle" >κ</th><th align="center" valign="middle" >θ</th><th align="center" valign="middle" >σ</th><th align="center" valign="middle" >ρ</th></tr></thead><tr><td align="center" valign="middle" >1</td><td align="center" valign="middle" >1.1000</td><td align="center" valign="middle" >0.0400</td><td align="center" valign="middle" >0.2500</td><td align="center" valign="middle" >−0.2500</td></tr><tr><td align="center" valign="middle" >2</td><td align="center" valign="middle" >0.5000</td><td align="center" valign="middle" >0.0225</td><td align="center" valign="middle" >0.1500</td><td align="center" valign="middle" >−0.5000</td></tr><tr><td align="center" valign="middle" >3</td><td align="center" valign="middle" >1.2500</td><td align="center" valign="middle" >0.0750</td><td align="center" valign="middle" >0.3000</td><td align="center" valign="middle" >−0.7500</td></tr></tbody></table></table-wrap><table-wrap id="table2" ><label><xref ref-type="table" rid="table2">Table 2</xref></label><caption><title> Estimated parameter values</title></caption><table><tbody><thead><tr><th align="center" valign="middle" >Index</th><th align="center" valign="middle" >κ</th><th align="center" valign="middle" >θ</th><th align="center" valign="middle" >σ</th><th align="center" valign="middle" >ρ</th></tr></thead><tr><td align="center" valign="middle" >1</td><td align="center" valign="middle" >1.0078</td><td align="center" valign="middle" >0.0400</td><td align="center" valign="middle" >0.2324</td><td align="center" valign="middle" >−0.1919</td></tr><tr><td align="center" valign="middle" >2</td><td align="center" valign="middle" >0.1179</td><td align="center" valign="middle" >0.0234</td><td align="center" valign="middle" >0.1340</td><td align="center" valign="middle" >−0.4600</td></tr><tr><td align="center" valign="middle" >3</td><td align="center" valign="middle" >1.2763</td><td align="center" valign="middle" >0.0695</td><td align="center" valign="middle" >0.3245</td><td align="center" valign="middle" >−0.6665</td></tr></tbody></table></table-wrap><table-wrap id="table3" ><label><xref ref-type="table" rid="table3">Table 3</xref></label><caption><title> CIR short rate parameter table</title></caption><table><tbody><thead><tr><th align="center" valign="middle" >Index</th><th align="center" valign="middle" >κ</th><th align="center" valign="middle" >θ</th><th align="center" valign="middle" >σ</th><th align="center" valign="middle" >r 0</th></tr></thead><tr><td align="center" valign="middle" >1</td><td align="center" valign="middle" >0.6000</td><td align="center" valign="middle" >0.0150</td><td align="center" valign="middle" >0.1500</td><td align="center" valign="middle" >0.0100</td></tr><tr><td align="center" valign="middle" >2</td><td align="center" valign="middle" >0.4000</td><td align="center" valign="middle" >0.0225</td><td align="center" valign="middle" >0.1500</td><td align="center" valign="middle" >0.0100</td></tr><tr><td align="center" valign="middle" >3</td><td align="center" valign="middle" >1.2500</td><td align="center" valign="middle" >0.0350</td><td align="center" valign="middle" >0.3000</td><td align="center" valign="middle" >0.0100</td></tr></tbody></table></table-wrap><table-wrap id="table4" ><label><xref ref-type="table" rid="table4">Table 4</xref></label><caption><title> Inference table</title></caption><table><tbody><thead><tr><th align="center" valign="middle" >Index</th><th align="center" valign="middle" >κ</th><th align="center" valign="middle" >θ</th><th align="center" valign="middle" >σ</th><th align="center" valign="middle" >r 0</th></tr></thead><tr><td align="center" valign="middle" >1</td><td align="center" valign="middle" >0.6514</td><td align="center" valign="middle" >0.0151</td><td align="center" valign="middle" >0.2172</td><td align="center" valign="middle" >0.0100</td></tr><tr><td align="center" valign="middle" >2</td><td align="center" valign="middle" >0.3230</td><td align="center" valign="middle" >0.0264</td><td align="center" valign="middle" >0.2845</td><td align="center" valign="middle" >0.0100</td></tr><tr><td align="center" valign="middle" >3</td><td align="center" valign="middle" >1.3929</td><td align="center" valign="middle" >0.0336</td><td align="center" valign="middle" >0.2845</td><td align="center" valign="middle" >0.0100</td></tr></tbody></table></table-wrap></sec><sec id="s3_3"><title>3.3. Vasicek Bond Option Pricing Model</title><p>The results are listed in the <xref ref-type="table" rid="table5">Table 5</xref> and <xref ref-type="table" rid="table6">Table 6</xref>, and <xref ref-type="fig" rid="fig3">Figure 3</xref>. Details of this exercise can be found in the source code.</p></sec></sec><sec id="s4"><title>4. Conclusion</title><p>The main contribution of this paper is a general framework of financial asset pricing and calibration, where the calibration module consists of a novel simulation and clustering-based methodology. The simulated numbers and intermediate</p><table-wrap id="table5" ><label><xref ref-type="table" rid="table5">Table 5</xref></label><caption><title> True parameters</title></caption><table><tbody><thead><tr><th align="center" valign="middle" >Index</th><th align="center" valign="middle" >κ</th><th align="center" valign="middle" >θ</th><th align="center" valign="middle" >σ</th><th align="center" valign="middle" >r 0</th></tr></thead><tr><td align="center" valign="middle" >1</td><td align="center" valign="middle" >0.6000</td><td align="center" valign="middle" >0.0150</td><td align="center" valign="middle" >0.1500</td><td align="center" valign="middle" >0.0100</td></tr><tr><td align="center" valign="middle" >2</td><td align="center" valign="middle" >0.4000</td><td align="center" valign="middle" >0.0225</td><td align="center" valign="middle" >0.1500</td><td align="center" valign="middle" >0.0100</td></tr><tr><td align="center" valign="middle" >3</td><td align="center" valign="middle" >1.2500</td><td align="center" valign="middle" >0.0350</td><td align="center" valign="middle" >0.3000</td><td align="center" valign="middle" >0.0100</td></tr></tbody></table></table-wrap><table-wrap id="table6" ><label><xref ref-type="table" rid="table6">Table 6</xref></label><caption><title> Inference results</title></caption><table><tbody><thead><tr><th align="center" valign="middle" >Index</th><th align="center" valign="middle" >κ</th><th align="center" valign="middle" >θ</th><th align="center" valign="middle" >σ</th><th align="center" valign="middle" >r 0</th></tr></thead><tr><td align="center" valign="middle" >1</td><td align="center" valign="middle" >0.5461</td><td align="center" valign="middle" >0.0133</td><td align="center" valign="middle" >0.1469</td><td align="center" valign="middle" >0.0100</td></tr><tr><td align="center" valign="middle" >2</td><td align="center" valign="middle" >0.3490</td><td align="center" valign="middle" >0.0226</td><td align="center" valign="middle" >0.1450</td><td align="center" valign="middle" >0.0100</td></tr><tr><td align="center" valign="middle" >3</td><td align="center" valign="middle" >1.0868</td><td align="center" valign="middle" >0.0385</td><td align="center" valign="middle" >0.2844</td><td align="center" valign="middle" >0.0100</td></tr></tbody></table></table-wrap><p>pricing results can be re-used and are therefore very efficient. The methodology potentially applies to any problem that requires curve fitting, i.e., minimizing a parametric objective function and obtaining the optimal parameters.</p></sec><sec id="s5"><title>Conflicts of Interest</title><p>The author declares no conflicts of interest regarding the publication of this paper.</p></sec><sec id="s6"><title>Cite this paper</title><p>Zhang, L.L. (2020) A General Framework of Derivatives Pricing. Journal of Mathematical Finance, 10, 255-266. https://doi.org/10.4236/jmf.2020.102016</p></sec><sec id="s7"><title>Appendix: Sample Source Code</title>A1. Heston Option Pricing<p># Python Code for Calibration</p><p>import numpy as np</p><p>import matplotlib.pyplot as plt</p><p>from sklearn.cluster import MiniBatchKMeans</p><p># Parameters</p><p>r = 0.01</p><p>kappa = 1.25</p><p>theta = 0.075</p><p>sigma = 0.30</p><p>rho = -0.75</p><p>H = 0.50</p><p>N = 50</p><p>h = H / N</p><p>MUnif = 75000</p><p>MNorm = 75000</p><p>S0 = 1.00</p><p>v0 = 0.15 ** 2</p><p>TimeNode = np.array([5, 7, 10, 12, 15, 17, 20, 22, 25, 27, 30, 32, 35, 37, 40, 42, 45, 47, 50])</p><p>Clusters = 250</p><p>StrikeLen = 25</p><p># Rrandom Numbers</p><p>dWt = np.random.normal(0, np.sqrt(h), [N, MNorm])</p><p>dBt = np.random.normal(0, np.sqrt(h), [N, MNorm])</p><p>KappaRnd = np.random.uniform(0.000, 1.50, MUnif)</p><p>ThetaRnd = np.random.uniform(0.000, 0.30 ** 2, MUnif)</p><p>SigmaRnd = np.random.uniform(0.000, 0.50, MUnif)</p><p>RhoRnd = np.random.uniform(-1.00, 1.00, MUnif)</p><p>Y = np.transpose(np.array([KappaRnd, ThetaRnd, SigmaRnd, RhoRnd]))</p><p># Pricer Definition</p><p>def StrikeFunc(x, y, z):</p><p>Upper = S0 * (1 + 0.6 * x / y * z * np.sqrt(v0))</p><p>Lower = np.maximum(0, S0 * (1 - 0.6 * x / y * z * np.sqrt(v0)))</p><p>return(np.linspace(Lower, Upper, StrikeLen))</p><p>def HestonPrice(x, y, z, w):</p><p>S = S0 * np.ones([N+1, MNorm])</p><p>V = v0 * np.ones([N+1, MNorm])</p><p>for i in range(N):</p><p>S[i + 1, :] = S[i, :] * (1 + r * h + V[i, :] * dWt[i, :])</p><p>V[i + 1, :] = V[i, :] + x * (y - V[i, :]) * h + \</p><p>z * np.sqrt(np.abs(V[i, :])) * (w * dWt[i, :] + np.sqrt(1 - w ** 2) * dBt[i, :])</p><p>Price = np.zeros([len(TimeNode), StrikeLen])</p><p>for j in range(len(TimeNode)):</p><p>Strike = StrikeFunc(TimeNode[j] + 1, N, H)</p><p>for k in range(len(Strike)):</p><p>Price[j, k] = np.mean(np.maximum(0, S[TimeNode[j], :] - Strike[k]))</p><p>return(np.exp(-r * H) * Price)</p><p># True Solution</p><p>PriceTrue = HestonPrice(kappa, theta, sigma, rho)</p><p># Clustering</p><p>Div = MUnif / Clusters</p><p>while(Div &gt;= Clusters):</p><p>kmeans = MiniBatchKMeans(n_clusters = Clusters,</p><p>random_state = 0,</p><p>batch_size = 256,</p><p>max_iter = 20000).fit(Y)</p><p>YCenters = kmeans.cluster_centers_</p><p>LSE = np.zeros(Clusters)</p><p>Prices = np.zeros([Clusters, len(TimeNode), StrikeLen])</p><p>for j in range(Clusters):</p><p>Prices[j, :, :] = HestonPrice(YCenters[j][<xref ref-type="bibr" rid="scirp.100148-ref0">0</xref>], YCenters[j][<xref ref-type="bibr" rid="scirp.100148-ref1">1</xref>], YCenters[j][<xref ref-type="bibr" rid="scirp.100148-ref2">2</xref>], YCenters[j][<xref ref-type="bibr" rid="scirp.100148-ref3">3</xref>])</p><p>LSE[j] = np.sqrt(np.mean((Prices[j, :, :] - PriceTrue) ** 2 / 1 ** 2))</p><p>Idx = np.argmin(LSE)</p><p>KmIdx = np.where(kmeans.labels_ == Idx)[<xref ref-type="bibr" rid="scirp.100148-ref0">0</xref>]</p><p>PricesFit = Prices[Idx, :, :]</p><p>Y = Y[KmIdx, :]</p><p>Div = Y.shape[<xref ref-type="bibr" rid="scirp.100148-ref0">0</xref>]</p><p>Params = YCenters[Idx]</p><p># Plots</p><p>plt.plot(PricesFit[-1, :])</p><p>plt.plot(PriceTrue[-1, :])</p><p>print('Mean Squared Error: ', np.sqrt(np.mean((PricesFit - PriceTrue) ** 2)))</p><p>print('Params Fitted: ', Params)</p><p>print('Params True', [kappa, theta, sigma, rho])</p>A2. CIR Bond Pricing Model<p># Python Code for Calibration</p><p>import numpy as np</p><p>import matplotlib as plt</p><p>from sklearn.cluster import MiniBatchKMeans</p><p>from matplotlib.pyplot import plot</p><p># Parameters</p><p>r0 = 0.010</p><p>kappa = 0.600</p><p>theta = 0.015</p><p>sigma = 0.150</p><p>H = 7.50</p><p>N = 250</p><p>h = H / N</p><p>MUnif = 50000</p><p>MNorm = 100000</p><p>Clusters = 200</p><p># Rrandom Numbers</p><p>dWt = np.random.normal(0, np.sqrt(h), [N, MNorm])</p><p>KappaRnd = np.random.uniform(0.000, 1.50, MUnif)</p><p>ThetaRnd = np.random.uniform(0.000, 0.03, MUnif)</p><p>SigmaRnd = np.random.uniform(0.000, 0.30, MUnif)</p><p>Y = np.transpose(np.array([KappaRnd, ThetaRnd, SigmaRnd]))</p><p># Pricer Definition</p><p>def BondPrice(x, y, z):</p><p>V = r0 * np.ones([N+1, MNorm])</p><p>C = r0 * np.ones([N+1, MNorm])</p><p>for i in range(N):</p><p>V[i + 1, :] = V[i, :] + x * (y - V[i, :]) * h + z * np.sqrt(np.abs(V[i, :])) * dWt[i, :]</p><p>C[i + 1, :] = C[i, :] + V[i + 1, :]</p><p>Price = np.mean(np.exp(-C * h), 1)</p><p>return(Price)</p><p># True Solution</p><p>PriceTrue = BondPrice(kappa, theta, sigma)</p><p># Clustering</p><p>Div = MUnif</p><p>while(Div &gt;= Clusters):</p><p>kmeans = MiniBatchKMeans(n_clusters = Clusters,</p><p>random_state = 0,</p><p>batch_size = 256,</p><p>init_size = 256,</p><p>max_iter = 20000).fit(Y)</p><p>YCenters = kmeans.cluster_centers_</p><p>LSE = np.zeros(Clusters)</p><p>Prices = np.zeros([Clusters, N+1])</p><p>for j in range(Clusters):</p><p>Prices[j, :] = BondPrice(YCenters[j][<xref ref-type="bibr" rid="scirp.100148-ref0">0</xref>], YCenters[j][<xref ref-type="bibr" rid="scirp.100148-ref1">1</xref>], YCenters[j][<xref ref-type="bibr" rid="scirp.100148-ref2">2</xref>])</p><p>LSE[j] = np.sqrt(np.mean((Prices[j, :] - PriceTrue) ** 2))</p><p>Idx = np.argmin(LSE)</p><p>KmIdx = np.where(kmeans.labels_ == Idx)[<xref ref-type="bibr" rid="scirp.100148-ref0">0</xref>]</p><p>PricesFit = Prices[Idx, :]</p><p>Y = Y[KmIdx, :]</p><p>Div = Y.shape[<xref ref-type="bibr" rid="scirp.100148-ref0">0</xref>]</p><p>print('Cluster Length: ', Div)</p><p>Params = YCenters[Idx]</p><p># Plots</p><p>plt.pyplot.plot(PricesFit)</p><p>plt.pyplot.plot(PriceTrue)</p><p>print('Mean Squared Error: ', np.sqrt(np.mean((PricesFit - PriceTrue) ** 2)))</p><p>print('Params Fitted: ', Params)</p><p>print('Params True', [kappa, theta, sigma])</p>A3. Vasicek Bond Option Pricing Model<p># Python Code for Calibration</p><p>import numpy as np</p><p>import matplotlib as plt</p><p>from sklearn.cluster import MiniBatchKMeans</p><p>from matplotlib.pyplot import plot</p><p>from sklearn.linear_model import LinearRegression</p><p># Parameters</p><p>r0 = 0.0100</p><p>kappa = 0.4000</p><p>theta = 0.0225</p><p>sigma = 0.1500</p><p>HBond = 1.0000</p><p>HOption = 0.5000</p><p>N = 50</p><p>h = HBond / N</p><p>LookBack = int((HBond - HOption) / h)</p><p>K = [0.90, 0.925, 0.95, 0.975, 1.00, 1.025, 1.05, 1.075, 1.10]</p><p>MUnif = 75000</p><p>MNorm = 75000</p><p>Clusters = 250</p><p># Rrandom Numbers</p><p>dWt = np.random.normal(0, np.sqrt(h), [N, MNorm])</p><p>KappaRnd = np.random.uniform(0.000, 1.50, MUnif)</p><p>ThetaRnd = np.random.uniform(0.000, 0.05, MUnif)</p><p>SigmaRnd = np.random.uniform(0.000, 0.30, MUnif)</p><p>Y = np.transpose(np.array([KappaRnd, ThetaRnd, SigmaRnd]))</p><p># Pricer Definition</p><p>def FutureBondPrice(x, y, z):</p><p>V = r0 * np.ones([N+1, MNorm])</p><p>C = r0 * np.ones([N+1, MNorm])</p><p>for i in range(N):</p><p>V[i + 1, :] = V[i, :] + x * (y - V[i, :]) * h + z * dWt[i, :]</p><p>Regression = LinearRegression().fit(np.array(V[N-LookBack, :]).reshape(-1, 1),</p><p>-np.array(np.sum(V[(N-LookBack):(N+1), :], 0) * h).reshape(-1, 1))</p><p>Price = np.exp(-Regression.predict(np.array(V[N-LookBack, :]).reshape(-1, 1)))</p><p>return(Price)</p><p>def BondOptionPrice(x, y, z):</p><p>FutureBond = FutureBondPrice(x, y, z)</p><p>PriceTemp = np.zeros(len(K))</p><p>for i in range(len(K)):</p><p>PriceTemp[i] = np.mean(np.maximum(FutureBond - K[i], 0))</p><p>return(PriceTemp)</p><p># True Solution</p><p>PriceTrue = BondOptionPrice(kappa, theta, sigma)</p><p># Clustering</p><p>Div = MUnif</p><p>while(Div &gt;= Clusters):</p><p>kmeans = MiniBatchKMeans(n_clusters = Clusters,</p><p>random_state = 0,</p><p>batch_size = 256,</p><p>init_size = 256,</p><p>max_iter = 20000).fit(Y)</p><p>YCenters = kmeans.cluster_centers_</p><p>LSE = np.zeros(Clusters)</p><p>Prices = np.zeros([Clusters, len(K)])</p><p>for j in range(Clusters):</p><p>Prices[j, :] = BondOptionPrice(YCenters[j][<xref ref-type="bibr" rid="scirp.100148-ref0">0</xref>], YCenters[j][<xref ref-type="bibr" rid="scirp.100148-ref1">1</xref>], YCenters[j][<xref ref-type="bibr" rid="scirp.100148-ref2">2</xref>])</p><p>LSE[j] = np.sqrt(np.mean((Prices[j, :] - PriceTrue) ** 2))</p><p>Idx = np.argmin(LSE)</p><p>KmIdx = np.where(kmeans.labels_ == Idx)[<xref ref-type="bibr" rid="scirp.100148-ref0">0</xref>]</p><p>PricesFit = Prices[Idx, :]</p><p>Y = Y[KmIdx, :]</p><p>Div = Y.shape[<xref ref-type="bibr" rid="scirp.100148-ref0">0</xref>]</p><p>print('Cluster Length: ', Div)</p><p>Params = YCenters[Idx]</p><p># Plots</p><p>plt.pyplot.plot(PricesFit)</p><p>plt.pyplot.plot(PriceTrue)</p><p>print('Mean Squared Error: ', np.sqrt(np.mean((PricesFit - PriceTrue) ** 2)))</p><p>print('Params Fitted: ', Params)</p><p>print('Params True', [kappa, theta, sigma])</p></sec><sec id="s8"><title>NOTES</title></sec></body><back><ref-list><title>References</title><ref id="scirp.100148-ref1"><label>1</label><mixed-citation publication-type="other" xlink:type="simple">Ye, T. and Zhang, L. (2019) Derivatives Pricing via Machine Learning. Journal of Mathematical Finance, 9, 561-589. https://doi.org/10.4236/jmf.2019.93029</mixed-citation></ref><ref id="scirp.100148-ref2"><label>2</label><mixed-citation publication-type="other" xlink:type="simple">Zhang, L. (2020) A Clustering Method to Solve Backward Stochastic Differential Equations with Jumps. Journal of Mathematical Finance, 10, 1-9. https://doi.org/10.4236/jmf.2020.101001</mixed-citation></ref><ref id="scirp.100148-ref3"><label>3</label><mixed-citation publication-type="other" xlink:type="simple">Itkin, A. (2019) Deep Learning Calibration of Option Pricing Models: Some Pitfalls and Solutions.</mixed-citation></ref><ref id="scirp.100148-ref4"><label>4</label><mixed-citation publication-type="other" xlink:type="simple">Li, S., Borovykh, A., Grzelak, L.A. and Oosterlee, C. (2019) A Neural Network-Based Framework for Financial Model Calibration.</mixed-citation></ref><ref id="scirp.100148-ref5"><label>5</label><mixed-citation publication-type="other" xlink:type="simple">Zhang, L. (2019) Asset Return Prediction via Machine Learning. Journal of Mathematical Finance, 9, 691-697. https://doi.org/10.4236/jmf.2019.94035</mixed-citation></ref></ref-list></back></article>