-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathSlice.java.html
708 lines (584 loc) · 35.8 KB
/
Slice.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
<?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>Slice.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.execution.discrete</a> > <span class="el_source">Slice.java</span></div><h1>Slice.java</h1><pre class="source lang-java linenums">
package org.drip.execution.discrete;
/*
* -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*/
/*!
* Copyright (C) 2020 Lakshmi Krishnamurthy
* Copyright (C) 2019 Lakshmi Krishnamurthy
* Copyright (C) 2018 Lakshmi Krishnamurthy
* Copyright (C) 2017 Lakshmi Krishnamurthy
* Copyright (C) 2016 Lakshmi Krishnamurthy
*
* This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
* asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
* analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
* equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
* numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
* and computational support.
*
* https://lakshmidrip.github.io/DROP/
*
* DROP is composed of three modules:
*
* - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
* - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
* - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
*
* DROP Product Core implements libraries for the following:
* - Fixed Income Analytics
* - Loan Analytics
* - Transaction Cost Analytics
*
* DROP Portfolio Core implements libraries for the following:
* - Asset Allocation Analytics
* - Asset Liability Management Analytics
* - Capital Estimation Analytics
* - Exposure Analytics
* - Margin Analytics
* - XVA Analytics
*
* DROP Computational Core implements libraries for the following:
* - Algorithm Support
* - Computation Support
* - Function Analysis
* - Model Validation
* - Numerical Analysis
* - Numerical Optimizer
* - Spline Builder
* - Statistical Learning
*
* 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
* - Repo Layout Taxonomy => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
* - 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>Slice</i> implements the Arithmetic Dynamics of the Price/Cost Movements exhibited by an Asset owing to
* the Volatility and the Market Impact Factors on a Trajectory Slice. The References are:
*
* <br><br>
* <ul>
* <li>
* Almgren, R., and N. Chriss (1999): Value under Liquidation <i>Risk</i> <b>12 (12)</b>
* </li>
* <li>
* Almgren, R., and N. Chriss (2000): Optimal Execution of Portfolio Transactions <i>Journal of
* Risk</i> <b>3 (2)</b> 5-39
* </li>
* <li>
* Bertsimas, D., and A. W. Lo (1998): Optimal Control of Execution Costs <i>Journal of Financial
* Markets</i> <b>1</b> 1-50
* </li>
* <li>
* Chan, L. K. C., and J. Lakonishak (1995): The Behavior of Stock Prices around Institutional
* Trades <i>Journal of Finance</i> <b>50</b> 1147-1174
* </li>
* <li>
* Keim, D. B., and A. Madhavan (1997): Transaction Costs and Investment Style: An Inter-exchange
* Analysis of Institutional Equity Trades <i>Journal of Financial Economics</i> <b>46</b>
* 265-292
* </li>
* </ul>
*
* <br><br>
* <ul>
* <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
* <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/TransactionCostAnalyticsLibrary.md">Transaction Cost Analytics</a></li>
* <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/execution/README.md">Optimal Impact/Capture Based Trading Trajectories - Deterministic, Stochastic, Static, and Dynamic</a></li>
* <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/execution/discrete/README.md">Trajectory Slice Execution Cost Distribution</a></li>
* </ul>
*
* @author Lakshmi Krishnamurthy
*/
public class Slice implements org.drip.execution.sensitivity.ControlNodesGreekGenerator {
<span class="fc" id="L121"> private double _dblTimeInterval = java.lang.Double.NaN;</span>
<span class="fc" id="L122"> private double _dblLeftHoldings = java.lang.Double.NaN;</span>
<span class="fc" id="L123"> private double _dblRightHoldings = java.lang.Double.NaN;</span>
/**
* Slice Constructor
*
* @param dblLeftHoldings The Left-of-Slice Holdings
* @param dblRightHoldings The Right-of-Slice Holdings
* @param dblTimeInterval The Discrete Time Interval
*
* @throws java.lang.Exception Thrown if the Inputs are Invalid
*/
public Slice (
final double dblLeftHoldings,
final double dblRightHoldings,
final double dblTimeInterval)
throws java.lang.Exception
<span class="fc" id="L140"> {</span>
<span class="pc bpc" id="L141" title="1 of 2 branches missed."> if (!org.drip.numerical.common.NumberUtil.IsValid (_dblLeftHoldings = dblLeftHoldings) ||</span>
<span class="pc bpc" id="L142" title="1 of 2 branches missed."> !org.drip.numerical.common.NumberUtil.IsValid (_dblRightHoldings = dblRightHoldings) ||</span>
<span class="pc bpc" id="L143" title="2 of 4 branches missed."> !org.drip.numerical.common.NumberUtil.IsValid (_dblTimeInterval = dblTimeInterval) || 0. >=</span>
_dblTimeInterval)
<span class="nc" id="L145"> throw new java.lang.Exception ("Slice Constructor => Invalid Inputs!");</span>
<span class="fc" id="L146"> }</span>
/**
* Retrieve the Left-of-Slice Holdings
*
* @return The Left-of-Slice Holdings
*/
public double leftHoldings()
{
<span class="nc" id="L156"> return _dblLeftHoldings;</span>
}
/**
* Retrieve the Right Holdings
*
* @return The Right Holdings
*/
public double rightHoldings()
{
<span class="nc" id="L167"> return _dblRightHoldings;</span>
}
/**
* Retrieve the Evolution Time Interval of the Arithmetic Dynamics
*
* @return The Evolution Time Interval of the Arithmetic Dynamics
*/
public double timeInterval()
{
<span class="nc" id="L178"> return _dblTimeInterval;</span>
}
/**
* Indicate if the Slice is a Sell
*
* @return TRUE - The Slice is a Sell
*/
public boolean isSell()
{
<span class="nc bnc" id="L189" title="All 2 branches missed."> return _dblLeftHoldings - _dblRightHoldings > 0.;</span>
}
/**
* Generate the Price Evolution Increment Unit Realization given the Walk Realization
*
* @param dblPreviousEquilibriumPrice The Previous Equilibrium Price
* @param ws Realized Walk Suite
* @param apep The Arithmetic Price Walk Evolution Parameters
*
* @return The Realized Price Evolution Increment Unit given the Walk Realization
*/
public org.drip.execution.discrete.PriceIncrement priceIncrementRealization (
final double dblPreviousEquilibriumPrice,
final org.drip.execution.dynamics.WalkSuite ws,
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
<span class="nc bnc" id="L207" title="All 4 branches missed."> if (null == ws || null == apep) return null;</span>
<span class="nc" id="L209"> org.drip.execution.parameters.ArithmeticPriceDynamicsSettings apds =</span>
<span class="nc" id="L210"> apep.arithmeticPriceDynamicsSettings();</span>
<span class="nc" id="L212"> double dblSerialCorrelation = apds.serialCorrelation();</span>
<span class="nc" id="L214"> double dblTimeUnitSQRT = java.lang.Math.sqrt (_dblTimeInterval);</span>
<span class="nc" id="L216"> double dblExecutionRate = (_dblRightHoldings - _dblLeftHoldings) / _dblTimeInterval;</span>
try {
<span class="nc" id="L219"> double dblMarketCoreJumpUnit = apds.epochVolatility() * dblTimeUnitSQRT;</span>
<span class="nc" id="L221"> return new org.drip.execution.discrete.PriceIncrement (</span>
dblPreviousEquilibriumPrice,
new org.drip.execution.evolution.MarketImpactComponent (
<span class="nc" id="L224"> _dblTimeInterval * apds.drift(),</span>
0.,
<span class="nc" id="L226"> _dblTimeInterval * apep.permanentExpectation().epochImpactFunction().evaluate (dblExecutionRate),</span>
<span class="nc" id="L227"> apep.temporaryExpectation().epochImpactFunction().evaluate (dblExecutionRate)</span>
),
new org.drip.execution.evolution.MarketImpactComponent (
<span class="nc" id="L230"> dblMarketCoreJumpUnit * java.lang.Math.sqrt (1. + dblSerialCorrelation * dblSerialCorrelation) *</span>
<span class="nc" id="L231"> ws.currentWanderer(),</span>
<span class="nc" id="L232"> dblMarketCoreJumpUnit * dblSerialCorrelation * ws.previousWanderer(),</span>
<span class="nc" id="L233"> dblTimeUnitSQRT * apep.permanentVolatility().epochImpactFunction().evaluate (dblExecutionRate) *</span>
<span class="nc" id="L234"> ws.permanentImpactWanderer(),</span>
<span class="nc" id="L235"> dblTimeUnitSQRT * apep.temporaryVolatility().epochImpactFunction().evaluate (dblExecutionRate) *</span>
<span class="nc" id="L236"> ws.temporaryImpactWanderer()</span>
)
);
<span class="nc" id="L239"> } catch (java.lang.Exception e) {</span>
<span class="nc" id="L240"> e.printStackTrace();</span>
}
<span class="nc" id="L243"> return null;</span>
}
/**
* Generate the Cost Evolution Increment Unit Realization given the Walk Realization
*
* @param dblPreviousEquilibriumPrice The Previous Equilibrium Price
* @param ws Realized Walk Suite
* @param apep The Arithmetic Price Walk Evolution Parameters
*
* @return The Cost Evolution Increment Unit Realization given the Walk Realization
*/
public org.drip.execution.discrete.ShortfallIncrement costIncrementRealization (
final double dblPreviousEquilibriumPrice,
final org.drip.execution.dynamics.WalkSuite ws,
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
<span class="nc" id="L261"> return org.drip.execution.discrete.ShortfallIncrement.Standard (</span>
<span class="nc" id="L262"> priceIncrementRealization (dblPreviousEquilibriumPrice, ws, apep),</span>
_dblLeftHoldings,
_dblRightHoldings - _dblLeftHoldings
);
}
/**
* Generate the R^1 Normal Cost Increment Distribution
*
* @param apep The Arithmetic Price Walk Evolution Parameters
*
* @return The R^1 Normal Cost Increment Distribution
*/
public org.drip.execution.discrete.ShortfallIncrementDistribution costIncrementDistribution (
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
<span class="pc bpc" id="L279" title="1 of 2 branches missed."> double dblTradeAmount = _dblRightHoldings > _dblLeftHoldings ? _dblRightHoldings - _dblLeftHoldings :</span>
_dblLeftHoldings - _dblRightHoldings;
<span class="fc" id="L281"> double dblExecutionRate = dblTradeAmount / _dblTimeInterval;</span>
<span class="fc" id="L283"> org.drip.execution.parameters.ArithmeticPriceDynamicsSettings apds =</span>
<span class="fc" id="L284"> apep.arithmeticPriceDynamicsSettings();</span>
try {
<span class="fc" id="L287"> double dblMarketCoreVolatility = apds.epochVolatility();</span>
<span class="fc" id="L289"> double dblTemporaryVolatility = apep.temporaryVolatility().epochImpactFunction().evaluate</span>
<span class="fc" id="L290"> (dblTradeAmount, _dblTimeInterval);</span>
<span class="fc" id="L292"> return new org.drip.execution.discrete.ShortfallIncrementDistribution (</span>
<span class="fc" id="L293"> _dblTimeInterval * _dblRightHoldings * apep.permanentExpectation().epochImpactFunction().evaluate</span>
<span class="fc" id="L294"> (dblExecutionRate),</span>
<span class="fc" id="L295"> dblTradeAmount * apep.temporaryExpectation().epochImpactFunction().evaluate (dblExecutionRate),</span>
<span class="fc" id="L296"> -1. * _dblRightHoldings * apds.drift() * _dblTimeInterval,</span>
0.,
dblExecutionRate * dblExecutionRate * dblTemporaryVolatility * dblTemporaryVolatility *
_dblTimeInterval,
_dblRightHoldings * _dblRightHoldings * dblMarketCoreVolatility * dblMarketCoreVolatility *
_dblTimeInterval
);
<span class="nc" id="L303"> } catch (java.lang.Exception e) {</span>
<span class="nc" id="L304"> e.printStackTrace();</span>
}
<span class="nc" id="L307"> return null;</span>
}
@Override public org.drip.execution.sensitivity.ControlNodesGreek permanentImpactExpectation (
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
<span class="pc bpc" id="L313" title="1 of 2 branches missed."> if (null == apep) return null;</span>
<span class="fc" id="L315"> double dblTradeAmount = _dblRightHoldings - _dblLeftHoldings;</span>
<span class="fc bfc" id="L316" title="All 2 branches covered."> double dblSign = _dblRightHoldings < _dblLeftHoldings ? -1. : 1.;</span>
<span class="fc" id="L318"> org.drip.execution.impact.TransactionFunction tfPermanentDrift =</span>
<span class="fc" id="L319"> apep.permanentExpectation().epochImpactFunction();</span>
try {
<span class="fc" id="L322"> double dblPermanentDrift = tfPermanentDrift.evaluate (dblTradeAmount, _dblTimeInterval);</span>
<span class="fc" id="L324"> double dblPermanentDriftLeftJacobian = tfPermanentDrift.leftHoldingsDerivative (dblTradeAmount,</span>
_dblTimeInterval, 1);
<span class="fc" id="L327"> double dblPermanentDriftRightJacobian = tfPermanentDrift.rightHoldingsDerivative (dblTradeAmount,</span>
_dblTimeInterval, 1);
<span class="fc" id="L330"> double dblPermanentDriftLeftHessian = tfPermanentDrift.leftHoldingsDerivative (dblTradeAmount,</span>
_dblTimeInterval, 2);
<span class="fc" id="L333"> double dblPermanentDriftRightHessian = tfPermanentDrift.rightHoldingsDerivative (dblTradeAmount,</span>
_dblTimeInterval, 2);
<span class="fc" id="L336"> double dblPermanentDriftCrossHessian = tfPermanentDrift.crossHoldingsDerivative (dblTradeAmount,</span>
_dblTimeInterval);
<span class="fc" id="L339"> double dblPermanentDriftImpact = dblSign * _dblTimeInterval * _dblRightHoldings *</span>
dblPermanentDrift;
<span class="fc" id="L341"> double dblPermanentDriftImpactLeftJacobian = dblSign * _dblTimeInterval * _dblRightHoldings *</span>
dblPermanentDriftLeftJacobian;
<span class="fc" id="L343"> double dblPermanentDriftImpactRightJacobian = dblSign * _dblTimeInterval * _dblRightHoldings *</span>
dblPermanentDriftRightJacobian + dblSign * _dblTimeInterval * dblPermanentDrift;
<span class="fc" id="L345"> double dblPermanentDriftImpactLeftHessian = dblSign * _dblTimeInterval * _dblRightHoldings *</span>
dblPermanentDriftLeftHessian;
<span class="fc" id="L347"> double dblPermanentDriftImpactRightHessian = dblSign * _dblTimeInterval * _dblRightHoldings *</span>
dblPermanentDriftRightHessian + 2. * dblSign * _dblTimeInterval *
dblPermanentDriftRightJacobian;
<span class="fc" id="L350"> double dblPermanentDriftImpactCrossHessian = dblSign * _dblTimeInterval *</span>
dblPermanentDriftLeftJacobian + dblSign * _dblTimeInterval * _dblRightHoldings *
dblPermanentDriftCrossHessian;
<span class="fc" id="L354"> return new org.drip.execution.sensitivity.ControlNodesGreek (</span>
dblPermanentDriftImpact,
new double[] {
dblPermanentDriftImpactLeftJacobian,
dblPermanentDriftImpactRightJacobian
},
new double[][] {
{dblPermanentDriftImpactLeftHessian, dblPermanentDriftImpactCrossHessian},
{dblPermanentDriftImpactCrossHessian, dblPermanentDriftImpactRightHessian}
}
);
<span class="nc" id="L365"> } catch (java.lang.Exception e) {</span>
<span class="nc" id="L366"> e.printStackTrace();</span>
}
<span class="nc" id="L369"> return null;</span>
}
@Override public org.drip.execution.sensitivity.ControlNodesGreek permanentImpactVariance (
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
try {
<span class="fc" id="L376"> return new org.drip.execution.sensitivity.ControlNodesGreek (0., new double[] {0., 0.}, new</span>
double[][] {{0., 0.}, {0., 0.}});
<span class="nc" id="L378"> } catch (java.lang.Exception e) {</span>
<span class="nc" id="L379"> e.printStackTrace();</span>
}
<span class="nc" id="L382"> return null;</span>
}
@Override public org.drip.execution.sensitivity.ControlNodesGreek temporaryImpactExpectation (
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
<span class="pc bpc" id="L388" title="1 of 2 branches missed."> if (null == apep) return null;</span>
<span class="fc" id="L390"> double dblTradeAmount = _dblRightHoldings - _dblLeftHoldings;</span>
<span class="fc" id="L392"> org.drip.execution.impact.TransactionFunction tfTemporaryDrift =</span>
<span class="fc" id="L393"> apep.temporaryExpectation().epochImpactFunction();</span>
try {
<span class="fc" id="L396"> double dblTemporaryDrift = tfTemporaryDrift.evaluate (dblTradeAmount, _dblTimeInterval);</span>
<span class="fc" id="L398"> double dblTemporaryDriftLeftJacobian = tfTemporaryDrift.leftHoldingsDerivative (dblTradeAmount,</span>
_dblTimeInterval, 1);
<span class="fc" id="L401"> double dblTemporaryDriftRightJacobian = tfTemporaryDrift.rightHoldingsDerivative</span>
<span class="fc" id="L402"> (dblTradeAmount, _dblTimeInterval, 1);</span>
<span class="fc" id="L404"> double dblTemporaryDriftLeftHessian = tfTemporaryDrift.leftHoldingsDerivative (dblTradeAmount,</span>
_dblTimeInterval, 2);
<span class="fc" id="L407"> double dblTemporaryDriftRightHessian = tfTemporaryDrift.rightHoldingsDerivative (dblTradeAmount,</span>
_dblTimeInterval, 2);
<span class="fc" id="L410"> double dblTemporaryDriftCrossHessian = tfTemporaryDrift.crossHoldingsDerivative (dblTradeAmount,</span>
_dblTimeInterval);
<span class="fc" id="L413"> double dblTemporaryDriftImpact = dblTradeAmount * dblTemporaryDrift;</span>
<span class="fc" id="L415"> double dblTemporaryDriftImpactLeftJacobian = -1. * dblTemporaryDrift + dblTradeAmount *</span>
dblTemporaryDriftLeftJacobian;
<span class="fc" id="L417"> double dblTemporaryDriftImpactRightJacobian = dblTemporaryDrift + dblTradeAmount *</span>
dblTemporaryDriftRightJacobian;
<span class="fc" id="L419"> double dblTemporaryDriftImpactLeftHessian = -2. * dblTemporaryDriftLeftJacobian + dblTradeAmount</span>
* dblTemporaryDriftLeftHessian;
<span class="fc" id="L421"> double dblTemporaryDriftImpactRightHessian = 2. * dblTemporaryDriftRightJacobian + dblTradeAmount</span>
* dblTemporaryDriftRightHessian;
<span class="fc" id="L423"> double dblTemporaryDriftImpactCrossHessian = -1. * dblTemporaryDriftRightJacobian +</span>
dblTemporaryDriftLeftJacobian + dblTradeAmount * dblTemporaryDriftCrossHessian;
<span class="fc" id="L426"> return new org.drip.execution.sensitivity.ControlNodesGreek (</span>
dblTemporaryDriftImpact,
new double[] {
dblTemporaryDriftImpactLeftJacobian,
dblTemporaryDriftImpactRightJacobian
},
new double[][] {
{dblTemporaryDriftImpactLeftHessian, dblTemporaryDriftImpactCrossHessian},
{dblTemporaryDriftImpactCrossHessian, dblTemporaryDriftImpactRightHessian}
}
);
<span class="nc" id="L437"> } catch (java.lang.Exception e) {</span>
<span class="nc" id="L438"> e.printStackTrace();</span>
}
<span class="nc" id="L441"> return null;</span>
}
@Override public org.drip.execution.sensitivity.ControlNodesGreek temporaryImpactVariance (
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
<span class="pc bpc" id="L447" title="1 of 2 branches missed."> if (null == apep) return null;</span>
<span class="fc" id="L449"> double dblTradeAmount = _dblRightHoldings - _dblLeftHoldings;</span>
<span class="fc" id="L450"> double dblTradeAmountSquared = dblTradeAmount * dblTradeAmount;</span>
<span class="fc" id="L452"> org.drip.execution.impact.TransactionFunction tfTemporaryVolatility =</span>
<span class="fc" id="L453"> apep.temporaryVolatility().epochImpactFunction();</span>
try {
<span class="pc bpc" id="L456" title="1 of 2 branches missed."> if (null == tfTemporaryVolatility)</span>
<span class="nc" id="L457"> return new org.drip.execution.sensitivity.ControlNodesGreek (0., new double[] {0., 0.}, new</span>
double[][] {{0., 0.}, {0., 0.}});
<span class="fc" id="L460"> double dblTemporaryVolatility = tfTemporaryVolatility.evaluate (dblTradeAmount,</span>
_dblTimeInterval);
<span class="fc" id="L463"> double dblTemporaryVolatilityLeftJacobian = tfTemporaryVolatility.leftHoldingsDerivative</span>
<span class="fc" id="L464"> (dblTradeAmount, _dblTimeInterval, 1);</span>
<span class="fc" id="L466"> double dblTemporaryVolatilityRightJacobian = tfTemporaryVolatility.rightHoldingsDerivative</span>
<span class="fc" id="L467"> (dblTradeAmount, _dblTimeInterval, 1);</span>
<span class="fc" id="L469"> double dblTemporaryVolatilityLeftHessian = tfTemporaryVolatility.leftHoldingsDerivative</span>
<span class="fc" id="L470"> (dblTradeAmount, _dblTimeInterval, 2);</span>
<span class="fc" id="L472"> double dblTemporaryVolatilityRightHessian = tfTemporaryVolatility.rightHoldingsDerivative</span>
<span class="fc" id="L473"> (dblTradeAmount, _dblTimeInterval, 2);</span>
<span class="fc" id="L475"> double dblTemporaryVolatilityCrossHessian = tfTemporaryVolatility.crossHoldingsDerivative</span>
<span class="fc" id="L476"> (dblTradeAmount, _dblTimeInterval);</span>
<span class="fc" id="L478"> double dblTemporaryVolatilitySquared = dblTemporaryVolatility * dblTemporaryVolatility;</span>
<span class="fc" id="L480"> double dblTemporaryVarianceCrossHessian =</span>
2. * dblTradeAmountSquared * dblTemporaryVolatilityLeftJacobian * dblTemporaryVolatilityRightJacobian * _dblTimeInterval
+ 2. * dblTradeAmountSquared * dblTemporaryVolatility * dblTemporaryVolatilityCrossHessian * _dblTimeInterval
+ 4. * dblTradeAmount * dblTemporaryVolatility * dblTemporaryVolatilityLeftJacobian * _dblTimeInterval
- 4. * dblTradeAmount * dblTemporaryVolatility * dblTemporaryVolatilityRightJacobian * _dblTimeInterval
- 2. * dblTemporaryVolatilitySquared * _dblTimeInterval;
<span class="fc" id="L487"> return new org.drip.execution.sensitivity.ControlNodesGreek (</span>
dblTradeAmountSquared * dblTemporaryVolatilitySquared * _dblTimeInterval,
new double[] {
2. * dblTradeAmountSquared * dblTemporaryVolatility * dblTemporaryVolatilityLeftJacobian * _dblTimeInterval
- 2. * dblTradeAmount * dblTemporaryVolatilitySquared * _dblTimeInterval,
2. * dblTradeAmountSquared * dblTemporaryVolatility * dblTemporaryVolatilityRightJacobian * _dblTimeInterval
+ 2. * dblTradeAmount * dblTemporaryVolatilitySquared * _dblTimeInterval
},
new double[][] {
{
2. * dblTradeAmountSquared * dblTemporaryVolatilityLeftJacobian * dblTemporaryVolatilityLeftJacobian * _dblTimeInterval
+ 2. * dblTradeAmountSquared * dblTemporaryVolatility * dblTemporaryVolatilityLeftHessian * _dblTimeInterval
- 8. * dblTradeAmount * dblTemporaryVolatility * dblTemporaryVolatilityLeftJacobian * _dblTimeInterval
+ 2. * dblTemporaryVolatilitySquared * _dblTimeInterval,
dblTemporaryVarianceCrossHessian
}, {
dblTemporaryVarianceCrossHessian,
2. * dblTradeAmountSquared * dblTemporaryVolatilityRightJacobian * dblTemporaryVolatilityRightJacobian * _dblTimeInterval
+ 2. * dblTradeAmountSquared * dblTemporaryVolatility * dblTemporaryVolatilityRightHessian * _dblTimeInterval
+ 8. * dblTradeAmount * dblTemporaryVolatility * dblTemporaryVolatilityRightJacobian * _dblTimeInterval
+ 2. * dblTemporaryVolatilitySquared * _dblTimeInterval
}
}
);
<span class="nc" id="L511"> } catch (java.lang.Exception e) {</span>
<span class="nc" id="L512"> e.printStackTrace();</span>
}
<span class="nc" id="L515"> return null;</span>
}
@Override public org.drip.execution.sensitivity.ControlNodesGreek marketDynamicsExpectation (
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
<span class="pc bpc" id="L521" title="1 of 2 branches missed."> if (null == apep) return null;</span>
<span class="fc" id="L523"> double dblDrift = apep.arithmeticPriceDynamicsSettings().drift();</span>
try {
<span class="fc" id="L526"> return new org.drip.execution.sensitivity.ControlNodesGreek (</span>
-1. * _dblTimeInterval * dblDrift * _dblRightHoldings,
new double[] {
0.,
-1. * _dblTimeInterval * dblDrift
}, new
double[][] {
{0., 0.},
{0., 0.}
}
);
<span class="nc" id="L537"> } catch (java.lang.Exception e) {</span>
<span class="nc" id="L538"> e.printStackTrace();</span>
}
<span class="nc" id="L541"> return null;</span>
}
@Override public org.drip.execution.sensitivity.ControlNodesGreek marketDynamicsVariance (
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
<span class="pc bpc" id="L547" title="1 of 2 branches missed."> if (null == apep) return null;</span>
try {
<span class="fc" id="L550"> double dblVolatility = apep.arithmeticPriceDynamicsSettings().epochVolatility();</span>
<span class="fc" id="L552"> return new org.drip.execution.sensitivity.ControlNodesGreek (</span>
_dblTimeInterval * dblVolatility * dblVolatility * _dblRightHoldings * _dblRightHoldings,
new double[] {
0.,
2. * _dblTimeInterval * dblVolatility * dblVolatility * _dblRightHoldings
}, new double[][] {
{0., 0.},
{0., 2. * _dblTimeInterval * dblVolatility * dblVolatility}
}
);
<span class="nc" id="L562"> } catch (java.lang.Exception e) {</span>
<span class="nc" id="L563"> e.printStackTrace();</span>
}
<span class="nc" id="L566"> return null;</span>
}
@Override public org.drip.execution.sensitivity.ControlNodesGreek expectationContribution (
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
<span class="fc" id="L572"> org.drip.execution.sensitivity.ControlNodesGreek cngPermanentImpact = permanentImpactExpectation</span>
<span class="fc" id="L573"> (apep);</span>
<span class="pc bpc" id="L575" title="1 of 2 branches missed."> if (null == cngPermanentImpact) return null;</span>
<span class="fc" id="L577"> org.drip.execution.sensitivity.ControlNodesGreek cngTemporaryImpact = temporaryImpactExpectation</span>
<span class="fc" id="L578"> (apep);</span>
<span class="pc bpc" id="L580" title="1 of 2 branches missed."> if (null == cngTemporaryImpact) return null;</span>
<span class="fc" id="L582"> org.drip.execution.sensitivity.ControlNodesGreek cngMarketCore = marketDynamicsExpectation (apep);</span>
<span class="pc bpc" id="L584" title="1 of 2 branches missed."> if (null == cngMarketCore) return null;</span>
<span class="fc" id="L586"> double[][] aadblPermanentImpactExpectationHessian = cngPermanentImpact.hessian();</span>
<span class="fc" id="L588"> double[][] aadblTemporaryImpactExpectationHessian = cngTemporaryImpact.hessian();</span>
<span class="fc" id="L590"> double[] adblPermanentImpactExpectationJacobian = cngPermanentImpact.jacobian();</span>
<span class="fc" id="L592"> double[] adblTemporaryImpactExpectationJacobian = cngTemporaryImpact.jacobian();</span>
<span class="fc" id="L594"> double[][] aadblMarketCoreExpectationHessian = cngMarketCore.hessian();</span>
<span class="fc" id="L596"> double[] adblMarketCoreExpectationJacobian = cngMarketCore.jacobian();</span>
<span class="fc" id="L598"> int iNumSliceNode = adblMarketCoreExpectationJacobian.length;</span>
<span class="fc" id="L599"> double[][] aadblHessian = new double[iNumSliceNode][iNumSliceNode];</span>
<span class="fc" id="L600"> double[] adblJacobian = new double[iNumSliceNode];</span>
<span class="fc bfc" id="L602" title="All 2 branches covered."> for (int i = 0; i < iNumSliceNode; ++i) {</span>
<span class="fc" id="L603"> adblJacobian[i] = adblPermanentImpactExpectationJacobian[i] +</span>
adblTemporaryImpactExpectationJacobian[i] + adblMarketCoreExpectationJacobian[i];
<span class="fc bfc" id="L606" title="All 2 branches covered."> for (int j = 0; j < iNumSliceNode; ++j)</span>
<span class="fc" id="L607"> aadblHessian[i][j] = aadblPermanentImpactExpectationHessian[i][j] +</span>
aadblTemporaryImpactExpectationHessian[i][j] + aadblMarketCoreExpectationHessian[i][j];
}
try {
<span class="fc" id="L612"> return new org.drip.execution.sensitivity.ControlNodesGreek (cngPermanentImpact.value() +</span>
<span class="fc" id="L613"> cngTemporaryImpact.value() + cngMarketCore.value(), adblJacobian, aadblHessian);</span>
<span class="nc" id="L614"> } catch (java.lang.Exception e) {</span>
<span class="nc" id="L615"> e.printStackTrace();</span>
}
<span class="nc" id="L618"> return null;</span>
}
@Override public org.drip.execution.sensitivity.ControlNodesGreek varianceContribution (
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
<span class="fc" id="L624"> org.drip.execution.sensitivity.ControlNodesGreek cngPermanentImpact = permanentImpactVariance (apep);</span>
<span class="pc bpc" id="L626" title="1 of 2 branches missed."> if (null == cngPermanentImpact) return null;</span>
<span class="fc" id="L628"> org.drip.execution.sensitivity.ControlNodesGreek cngTemporaryImpact = temporaryImpactVariance (apep);</span>
<span class="pc bpc" id="L630" title="1 of 2 branches missed."> if (null == cngTemporaryImpact) return null;</span>
<span class="fc" id="L632"> org.drip.execution.sensitivity.ControlNodesGreek cngMarketCore = marketDynamicsVariance (apep);</span>
<span class="pc bpc" id="L634" title="1 of 2 branches missed."> if (null == cngMarketCore) return null;</span>
<span class="fc" id="L636"> double[][] aadblPermanentImpactExpectationHessian = cngPermanentImpact.hessian();</span>
<span class="fc" id="L638"> double[][] aadblTemporaryImpactExpectationHessian = cngTemporaryImpact.hessian();</span>
<span class="fc" id="L640"> double[] adblPermanentImpactExpectationJacobian = cngPermanentImpact.jacobian();</span>
<span class="fc" id="L642"> double[] adblTemporaryImpactExpectationJacobian = cngTemporaryImpact.jacobian();</span>
<span class="fc" id="L644"> double[][] aadblMarketCoreExpectationHessian = cngMarketCore.hessian();</span>
<span class="fc" id="L646"> double[] adblMarketCoreExpectationJacobian = cngMarketCore.jacobian();</span>
<span class="fc" id="L648"> int iNumSliceNode = adblMarketCoreExpectationJacobian.length;</span>
<span class="fc" id="L649"> double[][] aadblHessian = new double[iNumSliceNode][iNumSliceNode];</span>
<span class="fc" id="L650"> double[] adblJacobian = new double[iNumSliceNode];</span>
<span class="fc bfc" id="L652" title="All 2 branches covered."> for (int i = 0; i < iNumSliceNode; ++i) {</span>
<span class="fc" id="L653"> adblJacobian[i] = adblPermanentImpactExpectationJacobian[i] +</span>
adblTemporaryImpactExpectationJacobian[i] + adblMarketCoreExpectationJacobian[i];
<span class="fc bfc" id="L656" title="All 2 branches covered."> for (int j = 0; j < iNumSliceNode; ++j)</span>
<span class="fc" id="L657"> aadblHessian[i][j] = aadblPermanentImpactExpectationHessian[i][j] +</span>
aadblTemporaryImpactExpectationHessian[i][j] + aadblMarketCoreExpectationHessian[i][j];
}
try {
<span class="fc" id="L662"> return new org.drip.execution.sensitivity.ControlNodesGreek (cngPermanentImpact.value() +</span>
<span class="fc" id="L663"> cngTemporaryImpact.value() + cngMarketCore.value(), adblJacobian, aadblHessian);</span>
<span class="nc" id="L664"> } catch (java.lang.Exception e) {</span>
<span class="nc" id="L665"> e.printStackTrace();</span>
}
<span class="nc" id="L668"> return null;</span>
}
/**
* Estimate the Optimal Adjustment Attributable to the Serial Correlation
*
* @param apep The Arithmetic Price Walk Parameters
*
* @return The Optimal Adjustment Attributable to the Serial Correlation
*/
public org.drip.execution.discrete.OptimalSerialCorrelationAdjustment serialCorrelationAdjustment (
final org.drip.execution.dynamics.ArithmeticPriceEvolutionParameters apep)
{
<span class="pc bpc" id="L682" title="1 of 2 branches missed."> if (null == apep) return null;</span>
<span class="fc" id="L684"> org.drip.execution.parameters.ArithmeticPriceDynamicsSettings apds =</span>
<span class="fc" id="L685"> apep.arithmeticPriceDynamicsSettings();</span>
<span class="fc" id="L687"> double dblTradeRate = (_dblRightHoldings - _dblLeftHoldings) / _dblTimeInterval;</span>
<span class="fc" id="L689"> org.drip.execution.impact.TransactionFunction miTemporary =</span>
<span class="fc" id="L690"> apep.temporaryExpectation().epochImpactFunction();</span>
try {
<span class="fc" id="L693"> double dblRhoSigma = apds.serialCorrelation() * apds.epochVolatility();</span>
<span class="fc" id="L695"> double dblDenominator = 1. / (dblTradeRate * miTemporary.derivative (dblTradeRate, 2) + 2. *</span>
<span class="fc" id="L696"> miTemporary.derivative (dblTradeRate, 1));</span>
<span class="fc" id="L698"> return new org.drip.execution.discrete.OptimalSerialCorrelationAdjustment (dblDenominator *</span>
<span class="fc" id="L699"> dblRhoSigma * java.lang.Math.pow (_dblTimeInterval, 1.5), 0.5 * dblDenominator * dblRhoSigma</span>
* dblRhoSigma * _dblTimeInterval * _dblTimeInterval);
<span class="nc" id="L701"> } catch (java.lang.Exception e) {</span>
<span class="nc" id="L702"> e.printStackTrace();</span>
}
<span class="nc" id="L705"> return null;</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>