-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathMultivariateSequenceGenerator.java.html
196 lines (171 loc) · 9.31 KB
/
MultivariateSequenceGenerator.java.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MultivariateSequenceGenerator.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">DROP</a> > <a href="index.source.html" class="el_package">org.drip.sequence.random</a> > <span class="el_source">MultivariateSequenceGenerator.java</span></div><h1>MultivariateSequenceGenerator.java</h1><pre class="source lang-java linenums">
package org.drip.sequence.random;
/*
* -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*/
/*!
* Copyright (C) 2019 Lakshmi Krishnamurthy
* Copyright (C) 2018 Lakshmi Krishnamurthy
* Copyright (C) 2017 Lakshmi Krishnamurthy
* Copyright (C) 2016 Lakshmi Krishnamurthy
* Copyright (C) 2015 Lakshmi Krishnamurthy
*
* This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
* calculations, and portfolio construction within and across fixed income, credit, commodity, equity,
* FX, and structured products.
*
* https://lakshmidrip.github.io/DROP/
*
* DROP is composed of three main modules:
*
* - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
* - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
* - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
*
* DROP Analytics Core implements libraries for the following:
* - Fixed Income Analytics
* - Asset Backed Analytics
* - XVA Analytics
* - Exposure and Margin Analytics
*
* DROP Portfolio Core implements libraries for the following:
* - Asset Allocation Analytics
* - Transaction Cost Analytics
*
* DROP Numerical Core implements libraries for the following:
* - Statistical Learning Library
* - Numerical Optimizer Library
* - Machine Learning Library
* - Spline Builder Library
*
* Documentation for DROP is Spread Over:
*
* - Main => https://lakshmidrip.github.io/DROP/
* - Wiki => https://github.com/lakshmiDRIP/DROP/wiki
* - GitHub => https://github.com/lakshmiDRIP/DROP
* - Javadoc => https://lakshmidrip.github.io/DROP/Javadoc/index.html
* - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
* - Release Versions => https://lakshmidrip.github.io/DROP/version.html
* - Community Credits => https://lakshmidrip.github.io/DROP/credits.html
* - Issues Catalog => https://github.com/lakshmiDRIP/DROP/issues
* - JUnit => https://lakshmidrip.github.io/DROP/junit/index.html
* - Jacoco => https://lakshmidrip.github.io/DROP/jacoco/index.html
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* <i>MultivariateSequenceGenerator</i> implements the Multivariate Random Sequence Generator Functionality.
*
* <br><br>
* <ul>
* <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
* <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/StatisticalLearningLibrary.md">Statistical Learning Library</a></li>
* <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sequence">Sequence</a></li>
* <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sequence/random">Random</a></li>
* </ul>
* <br><br>
*
* @author Lakshmi Krishnamurthy
*/
public class MultivariateSequenceGenerator {
<span class="fc" id="L86"> private double[][] _aadblCholesky = null;</span>
<span class="fc" id="L87"> private double[][] _aadblCorrelation = null;</span>
<span class="fc" id="L88"> private org.drip.sequence.random.UnivariateSequenceGenerator[] _aUSG = null;</span>
/**
* MultivariateSequenceGenerator Constructor
*
* @param aUSG Array of Univariate Sequence Generators
* @param aadblCorrelation The Correlation Matrix
*
* @throws java.lang.Exception Thrown if the Inputs are invalid
*/
public MultivariateSequenceGenerator (
final org.drip.sequence.random.UnivariateSequenceGenerator[] aUSG,
final double[][] aadblCorrelation)
throws java.lang.Exception
<span class="fc" id="L103"> {</span>
<span class="pc bpc" id="L104" title="2 of 4 branches missed."> if (null == (_aUSG = aUSG) || null == (_aadblCorrelation = aadblCorrelation))</span>
<span class="nc" id="L105"> throw new java.lang.Exception ("MultivariateSequenceGenerator ctr: Invalid Inputs");</span>
<span class="fc" id="L107"> _aadblCholesky = org.drip.numerical.linearalgebra.Matrix.CholeskyBanachiewiczFactorization</span>
<span class="fc" id="L108"> (aadblCorrelation);</span>
<span class="fc" id="L110"> int iNumVariate = aUSG.length;</span>
<span class="pc bpc" id="L112" title="4 of 8 branches missed."> if (null == _aadblCholesky || null == _aadblCholesky[0] || iNumVariate != _aadblCholesky.length ||</span>
iNumVariate != _aadblCholesky[0].length)
<span class="nc" id="L114"> throw new java.lang.Exception ("MultivariateSequenceGenerator ctr: Invalid Inputs");</span>
<span class="fc bfc" id="L116" title="All 2 branches covered."> for (int i = 0; i < iNumVariate; ++i) {</span>
<span class="pc bpc" id="L117" title="1 of 2 branches missed."> if (null == _aUSG[i])</span>
<span class="nc" id="L118"> throw new java.lang.Exception ("MultivariateSequenceGenerator ctr: Invalid Inputs");</span>
<span class="fc bfc" id="L120" title="All 2 branches covered."> for (int j = 0; j < iNumVariate; ++j) {</span>
<span class="pc bpc" id="L121" title="1 of 2 branches missed."> if (!org.drip.numerical.common.NumberUtil.IsValid (_aadblCorrelation[i][j]))</span>
<span class="nc" id="L122"> throw new java.lang.Exception ("MultivariateSequenceGenerator ctr: Invalid Inputs");</span>
}
}
<span class="fc" id="L125"> }</span>
/**
* Retrieve the Array of Univariate Sequence Generators
*
* @return Array of Univariate Sequence Generators
*/
public org.drip.sequence.random.UnivariateSequenceGenerator[] usg()
{
<span class="nc" id="L135"> return _aUSG;</span>
}
/**
* Retrieve the Correlation Matrix
*
* @return The Correlation Matrix
*/
public double[][] correlation()
{
<span class="nc" id="L146"> return _aadblCorrelation;</span>
}
/**
* Retrieve the Cholesky Factorial
*
* @return The Cholesky Factorial
*/
public double[][] cholesky()
{
<span class="nc" id="L157"> return _aadblCholesky;</span>
}
/**
* Retrieve the Number of Variates
*
* @return The Number of Variates
*/
public int numVariate()
{
<span class="nc" id="L168"> return _aUSG.length;</span>
}
/**
* Generate the Set of Multivariate Random Numbers according to the specified rule
*
* @return The Set of Multivariate Random Numbers
*/
public double[] random()
{
<span class="fc" id="L179"> int iNumVariate = _aUSG.length;</span>
<span class="fc" id="L180"> double[] adblRandom = new double[iNumVariate];</span>
<span class="fc" id="L181"> double[] adblUncorrelatedRandom = new double[iNumVariate];</span>
<span class="fc bfc" id="L183" title="All 2 branches covered."> for (int i = 0; i < iNumVariate; ++i)</span>
<span class="fc" id="L184"> adblUncorrelatedRandom[i] = _aUSG[i].random();</span>
<span class="fc bfc" id="L186" title="All 2 branches covered."> for (int i = 0; i < iNumVariate; ++i) {</span>
<span class="fc" id="L187"> adblRandom[i] = 0.;</span>
<span class="fc bfc" id="L189" title="All 2 branches covered."> for (int j = 0; j < iNumVariate; ++j)</span>
<span class="fc" id="L190"> adblRandom[i] += _aadblCholesky[i][j] * adblUncorrelatedRandom[j];</span>
}
<span class="fc" id="L193"> return adblRandom;</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>