Skip to content

Model OULogSpreadCRRASignalDemo

github-actions[bot] edited this page Oct 18, 2026 · 8 revisions

OULogSpreadCRRASignalDemo — quantitative model reference

Wiki home · Quantitative model references · Execution records

This quantitative model reference is provided for study, further research and application within the AlgoQuant framework. Read the research idea and implementation choices separately from the execution record.

Tutorials and quantitative model references · Pinned source · Javadoc

Paper introduction

Jakub W. Jurek and Halla Yang, Dynamic Portfolio Selection in Arbitrage (2007 working paper) studies how a finite-horizon investor with non-myopic preferences should allocate to a mean-reverting arbitrage opportunity, such as an equity spread. A statistical dislocation is not a riskless arbitrage: it can widen before it converges.

The key question is position size, not merely whether a spread is above or below its mean. Optimal exposure depends on the investor's preferences, remaining horizon and the modeled opportunity. A dynamic allocation can therefore differ from a fixed-notional threshold rule.

This summary is limited to the author-submitted publication abstract; the full derivation was not independently reviewed. The Java example generates and fits an OU log spread and evaluates a CRRA allocation rule. Inspect its wealth update carefully: it allocates with fixed W, so the displayed calculation should not be interpreted as a fully compounded wealth backtest or a replication of every paper assumption.

How this demo connects to the idea

The demo generates an OU path, fits it with OUFittingMLE and calls OUSpreadCRRASignal.getOptimalAllocation(price, W, tau). gamma is risk aversion, tau is remaining horizon and r*delta is the rate passed to the signal. W stays fixed while W_new records cumulative wealth, so this is not compounding allocation. Fitting and evaluation use the same generated path. The older Kim/Primbs/Boyd reference is related background, not the provenance of the Jurek-named class.

What this example teaches

This demonstrates the P&L when applying the optimal mean reversion trading strategy to an OU asset.

Using this example. Illustrates the OU log-spread trading signal and its P/L calculation using the parameters in main. Follow the modeled spread and risk-aversion inputs separately from any market-data assumptions; the theoretical model does not establish that a real pair follows an OU process.

Model and publication. The cited working paper studies finite-horizon allocation to a mean-reverting arbitrage opportunity under investor preferences. Its public abstract was verified, but full text was unavailable; the exact allocation implementation must be read in the library rather than assumed from this citation.

Implementation in this tutorial. The demo generates an OU path, fits it with OUFittingMLE and calls OUSpreadCRRASignal.getOptimalAllocation(price, W, tau). gamma is risk aversion, tau is remaining horizon and r*delta is the rate passed to the signal. W stays fixed while W_new records cumulative wealth, so this is not compounding allocation. Fitting and evaluation use the same generated path. The older Kim/Primbs/Boyd reference is related background, not the provenance of the Jurek-named class.

Verified execution record

Item Value
Status completed
Run 39114360151
UTC publication 2026-10-18 11:43 UTC
Source commit 355aa9242fc2a247b256aecc8406cbb409aa5ff3
Data mode original main defaults
Exit code 0
Elapsed seconds 4.84
Time limit seconds 180
Maximum Java heap 1200m

The original main returned successfully. Read the output and model assumptions before interpreting it.

Reproduce the calculation

Follow the repository setup for JDK 8, Maven credentials and an external NM license. From the repository root:

mvn -U -Dmaven.test.skip=true clean package
mvn exec:java -Dexec.mainClass=tech.nmfin.algoquant.demo.model.jurek2007.OULogSpreadCRRASignalDemo

The automated run uses scripts/ModelDemoRunner.java to initialize the external license before the unchanged main, save JFreeChart windows as PNGs, and exit after main returns. It uses an isolated working directory with the repository datasets/configuration linked in. Running directly may leave desktop windows open.

Observed output

simulating with gamma = 1.000000
mu (estimate) = -0.379
theta / delta (estimate) = 2459.850
sigma / sqrt(delta) (estimate) = 183.593
t = 1, price = 0.251, price change = 0.000, N = -46.031, R = 1011.573, profit_{t-1} = 0.200, cumulative wealth = 1000.200
t = 2, price = 0.185, price change = -0.066, N = -41.201, R = 1007.631, profit_{t-1} = 3.249, cumulative wealth = 1003.449
t = 3, price = 0.795, price change = 0.610, N = -85.694, R = 1068.117, profit_{t-1} = -24.917, cumulative wealth = 978.532
t = 4, price = 0.077, price change = -0.718, N = -33.279, R = 1002.551, profit_{t-1} = 61.761, cumulative wealth = 1040.293
t = 5, price = 0.102, price change = 0.026, N = -35.147, R = 1003.594, profit_{t-1} = -0.651, cumulative wealth = 1039.641
t = 6, price = 0.254, price change = 0.152, N = -46.223, R = 1011.742, profit_{t-1} = -5.133, cumulative wealth = 1034.508
t = 7, price = 0.595, price change = 0.341, N = -71.107, R = 1042.309, profit_{t-1} = -15.558, cumulative wealth = 1018.950
t = 8, price = -1.142, price change = -1.737, N = 55.675, R = 1063.592, profit_{t-1} = 123.736, cumulative wealth = 1142.686
t = 9, price = -2.372, price change = -1.230, N = 145.457, R = 1345.083, profit_{t-1} = -68.279, cumulative wealth = 1074.406
t = 10, price = -2.226, price change = 0.146, N = 134.774, R = 1300.011, profit_{t-1} = 21.561, cumulative wealth = 1095.967
t = 11, price = -2.719, price change = -0.493, N = 170.753, R = 1464.283, profit_{t-1} = -66.183, cumulative wealth = 1029.784
t = 12, price = -3.443, price change = -0.724, N = 223.607, R = 1769.934, profit_{t-1} = -123.369, cumulative wealth = 906.415
t = 13, price = -3.056, price change = 0.388, N = 195.317, R = 1596.815, profit_{t-1} = 87.031, cumulative wealth = 993.446
t = 14, price = -2.511, price change = 0.544, N = 155.595, R = 1390.752, profit_{t-1} = 106.627, cumulative wealth = 1100.073
t = 15, price = -1.985, price change = 0.526, N = 117.176, R = 1232.582, profit_{t-1} = 82.189, cumulative wealth = 1182.262
t = 16, price = -2.492, price change = -0.508, N = 154.218, R = 1384.385, profit_{t-1} = -59.228, cumulative wealth = 1123.034
t = 17, price = -2.758, price change = -0.266, N = 173.619, R = 1478.896, profit_{t-1} = -40.720, cumulative wealth = 1082.313
t = 18, price = -3.253, price change = -0.495, N = 209.738, R = 1682.324, profit_{t-1} = -85.630, cumulative wealth = 996.683
t = 19, price = -3.263, price change = -0.010, N = 210.479, R = 1686.874, profit_{t-1} = -1.794, cumulative wealth = 994.889
t = 20, price = -3.422, price change = -0.158, N = 222.034, R = 1759.732, profit_{t-1} = -32.986, cumulative wealth = 961.904
t = 21, price = -4.225, price change = -0.804, N = 280.679, R = 2185.945, profit_{t-1} = -178.069, cumulative wealth = 783.835
t = 22, price = -4.038, price change = 0.187, N = 267.030, R = 2078.338, profit_{t-1} = 52.928, cumulative wealth = 836.763
t = 23, price = -3.715, price change = 0.324, N = 243.418, R = 1904.227, profit_{t-1} = 86.812, cumulative wealth = 923.576
t = 24, price = -4.245, price change = -0.531, N = 282.149, R = 2197.842, profit_{t-1} = -128.803, cumulative wealth = 794.773
t = 25, price = -4.851, price change = -0.605, N = 326.326, R = 2582.923, profit_{t-1} = -170.351, cumulative wealth = 624.421
t = 26, price = -5.016, price change = -0.165, N = 338.400, R = 2697.475, profit_{t-1} = -53.471, cumulative wealth = 570.951
... excerpt shortened; complete stdout is in the release archive ...
t = 180, price = 0.303, price change = 1.364, N = -17.189, R = 1005.208, profit_{t-1} = 24.803, cumulative wealth = 2388.272
t = 181, price = 0.689, price change = 0.386, N = -27.065, R = 1018.644, profit_{t-1} = -6.432, cumulative wealth = 2381.840
t = 182, price = 0.186, price change = -0.502, N = -14.104, R = 1002.629, profit_{t-1} = 13.803, cumulative wealth = 2395.643
t = 183, price = 0.665, price change = 0.479, N = -26.304, R = 1017.498, profit_{t-1} = -6.553, cumulative wealth = 2389.091
t = 184, price = 1.796, price change = 1.130, N = -55.036, R = 1098.818, profit_{t-1} = -29.529, cumulative wealth = 2359.562
t = 185, price = 0.995, price change = -0.801, N = -34.514, R = 1034.328, profit_{t-1} = 44.298, cumulative wealth = 2403.860
t = 186, price = 1.282, price change = 0.287, N = -41.670, R = 1053.402, profit_{t-1} = -9.696, cumulative wealth = 2394.164
t = 187, price = 1.534, price change = 0.253, N = -47.914, R = 1073.517, profit_{t-1} = -10.324, cumulative wealth = 2383.839
t = 188, price = 1.608, price change = 0.074, N = -49.607, R = 1079.778, profit_{t-1} = -3.323, cumulative wealth = 2380.517
t = 189, price = 2.250, price change = 0.642, N = -65.527, R = 1147.453, profit_{t-1} = -31.635, cumulative wealth = 2348.881
t = 190, price = 3.066, price change = 0.816, N = -85.666, R = 1262.670, profit_{t-1} = -53.236, cumulative wealth = 2295.646
t = 191, price = 4.615, price change = 1.548, N = -123.869, R = 1571.598, profit_{t-1} = -132.387, cumulative wealth = 2163.258
t = 192, price = 3.913, price change = -0.701, N = -106.012, R = 1414.873, profit_{t-1} = 87.156, cumulative wealth = 2250.414
t = 193, price = 3.965, price change = 0.052, N = -106.867, R = 1423.757, profit_{t-1} = -5.211, cumulative wealth = 2245.203
t = 194, price = 2.845, price change = -1.121, N = -78.873, R = 1224.358, profit_{t-1} = 120.055, cumulative wealth = 2365.258
t = 195, price = 3.617, price change = 0.773, N = -97.447, R = 1352.473, profit_{t-1} = -60.686, cumulative wealth = 2304.572
t = 196, price = 3.005, price change = -0.612, N = -82.098, R = 1246.689, profit_{t-1} = 59.932, cumulative wealth = 2364.505
t = 197, price = 2.875, price change = -0.130, N = -78.568, R = 1225.853, profit_{t-1} = 10.936, cumulative wealth = 2375.441
t = 198, price = 2.400, price change = -0.474, N = -66.746, R = 1160.212, profit_{t-1} = 37.512, cumulative wealth = 2412.953
t = 199, price = 1.747, price change = -0.654, N = -50.717, R = 1088.586, profit_{t-1} = 43.861, cumulative wealth = 2456.813
t = 200, price = 2.148, price change = 0.402, N = -60.067, R = 1129.041, profit_{t-1} = -20.151, cumulative wealth = 2436.663
t = 201, price = 0.944, price change = -1.205, N = -31.106, R = 1029.357, profit_{t-1} = 72.578, cumulative wealth = 2509.241
t = 202, price = 0.574, price change = -0.369, N = -22.200, R = 1012.750, profit_{t-1} = 11.698, cumulative wealth = 2520.939
t = 203, price = 0.214, price change = -0.361, N = -13.589, R = 1002.902, profit_{t-1} = 8.212, cumulative wealth = 2529.151
t = 204, price = -0.399, price change = -0.613, N = 0.830, R = 1000.332, profit_{t-1} = 8.530, cumulative wealth = 2537.681
t = 205, price = -1.111, price change = -0.711, N = 17.370, R = 1019.292, profit_{t-1} = -0.390, cumulative wealth = 2537.291
t = 206, price = -1.148, price change = -0.037, N = 18.127, R = 1020.808, profit_{t-1} = -0.443, cumulative wealth = 2536.847
t = 207, price = -1.021, price change = 0.127, N = 15.094, R = 1015.409, profit_{t-1} = 2.507, cumulative wealth = 2539.355
t = 208, price = -0.578, price change = 0.443, N = 4.885, R = 1002.823, profit_{t-1} = 6.889, cumulative wealth = 2546.243
t = 209, price = -0.244, price change = 0.334, N = -2.718, R = 999.336, profit_{t-1} = 1.831, cumulative wealth = 2548.074
t = 210, price = 0.529, price change = 0.773, N = -20.121, R = 1010.648, profit_{t-1} = -1.902, cumulative wealth = 2546.172
t = 211, price = 0.421, price change = -0.108, N = -17.563, R = 1007.396, profit_{t-1} = 2.377, cumulative wealth = 2548.549
t = 212, price = -1.189, price change = -1.610, N = 18.327, R = 1021.797, profit_{t-1} = 28.485, cumulative wealth = 2577.034
t = 213, price = -1.423, price change = -0.233, N = 23.330, R = 1033.188, profit_{t-1} = -4.070, cumulative wealth = 2572.964
t = 214, price = -2.313, price change = -0.890, N = 42.622, R = 1098.585, profit_{t-1} = -20.567, cumulative wealth = 2552.397
t = 215, price = -2.560, price change = -0.247, N = 47.649, R = 1121.998, profit_{t-1} = -10.324, cumulative wealth = 2542.073
t = 216, price = -2.917, price change = -0.357, N = 54.935, R = 1160.259, profit_{t-1} = -16.781, cumulative wealth = 2525.292
t = 217, price = -2.478, price change = 0.439, N = 45.104, R = 1111.783, profit_{t-1} = 24.344, cumulative wealth = 2549.636
t = 218, price = -3.414, price change = -0.935, N = 64.482, R = 1220.109, profit_{t-1} = -41.956, cumulative wealth = 2507.680
t = 219, price = -2.563, price change = 0.850, N = 46.076, R = 1118.093, profit_{t-1} = 55.085, cumulative wealth = 2562.765
t = 220, price = -2.906, price change = -0.343, N = 52.759, R = 1153.307, profit_{t-1} = -15.570, cumulative wealth = 2547.195
t = 221, price = -2.360, price change = 0.546, N = 41.026, R = 1096.817, profit_{t-1} = 29.033, cumulative wealth = 2576.228
t = 222, price = -3.387, price change = -1.027, N = 61.520, R = 1208.363, profit_{t-1} = -41.918, cumulative wealth = 2534.310
t = 223, price = -4.236, price change = -0.849, N = 77.984, R = 1330.330, profit_{t-1} = -51.984, cumulative wealth = 2482.326
t = 224, price = -4.818, price change = -0.582, N = 88.755, R = 1427.626, profit_{t-1} = -45.136, cumulative wealth = 2437.190
t = 225, price = -4.584, price change = 0.234, N = 83.170, R = 1381.276, profit_{t-1} = 21.035, cumulative wealth = 2458.225
t = 226, price = -4.552, price change = 0.032, N = 81.605, R = 1371.505, profit_{t-1} = 2.921, cumulative wealth = 2461.146
t = 227, price = -4.384, price change = 0.168, N = 77.410, R = 1339.397, profit_{t-1} = 13.989, cumulative wealth = 2475.135
t = 228, price = -3.024, price change = 1.360, N = 50.599, R = 1153.030, profit_{t-1} = 105.552, cumulative wealth = 2580.687
t = 229, price = -2.416, price change = 0.608, N = 38.543, R = 1093.132, profit_{t-1} = 30.998, cumulative wealth = 2611.685
t = 230, price = -2.372, price change = 0.045, N = 37.214, R = 1088.255, profit_{t-1} = 1.943, cumulative wealth = 2613.627
t = 231, price = -1.966, price change = 0.405, N = 29.302, R = 1057.614, profit_{t-1} = 15.301, cumulative wealth = 2628.928
t = 232, price = -2.433, price change = -0.466, N = 37.306, R = 1090.750, profit_{t-1} = -13.453, cumulative wealth = 2615.475
t = 233, price = -4.453, price change = -2.021, N = 72.692, R = 1323.709, profit_{t-1} = -75.162, cumulative wealth = 2540.313
t = 234, price = -3.000, price change = 1.453, N = 46.162, R = 1138.488, profit_{t-1} = 105.898, cumulative wealth = 2646.211
t = 235, price = -2.992, price change = 0.008, N = 45.319, R = 1135.603, profit_{t-1} = 0.588, cumulative wealth = 2646.799
t = 236, price = -2.238, price change = 0.754, N = 31.802, R = 1071.179, profit_{t-1} = 34.399, cumulative wealth = 2681.197
t = 237, price = -2.441, price change = -0.203, N = 34.671, R = 1084.648, profit_{t-1} = -6.250, cumulative wealth = 2674.948
t = 238, price = -2.984, price change = -0.542, N = 42.974, R = 1128.213, profit_{t-1} = -18.577, cumulative wealth = 2656.371
t = 239, price = -3.140, price change = -0.156, N = 44.730, R = 1140.433, profit_{t-1} = -6.480, cumulative wealth = 2649.890
t = 240, price = -2.190, price change = 0.949, N = 28.894, R = 1063.289, profit_{t-1} = 42.685, cumulative wealth = 2692.576
t = 241, price = -1.883, price change = 0.308, N = 23.572, R = 1044.381, profit_{t-1} = 9.100, cumulative wealth = 2701.676
t = 242, price = -2.294, price change = -0.412, N = 29.374, R = 1067.398, profit_{t-1} = -9.496, cumulative wealth = 2692.180
t = 243, price = -1.143, price change = 1.152, N = 11.608, R = 1013.267, profit_{t-1} = 34.040, cumulative wealth = 2726.220
t = 244, price = -0.233, price change = 0.910, N = -1.916, R = 999.554, profit_{t-1} = 10.766, cumulative wealth = 2736.986
t = 245, price = -0.469, price change = -0.236, N = 1.492, R = 1000.699, profit_{t-1} = 0.652, cumulative wealth = 2737.638
t = 246, price = -0.729, price change = -0.260, N = 5.090, R = 1003.712, profit_{t-1} = -0.188, cumulative wealth = 2737.449
t = 247, price = -1.469, price change = -0.739, N = 15.038, R = 1022.086, profit_{t-1} = -3.563, cumulative wealth = 2733.886
t = 248, price = -1.727, price change = -0.258, N = 18.099, R = 1031.257, profit_{t-1} = -3.681, cumulative wealth = 2730.205
t = 249, price = -1.358, price change = 0.369, N = 12.860, R = 1017.464, profit_{t-1} = 6.885, cumulative wealth = 2737.090
t = 250, price = -0.996, price change = 0.362, N = 7.957, R = 1007.924, profit_{t-1} = 4.860, cumulative wealth = 2741.950
========================================================================================================================
gamma = 5.000, initial wealth = 1000.000, mean = 6.968, SD = 58.435, Sharpe = 1.885, terminal wealth = 2741.950
========================================================================================================================

gamma = 0.800000, number of sims = 10000, min Sharpe = -1.441, mean Sharpe = 1.134, max Sharpe = 3.269
gamma = 1.000000, number of sims = 10000, min Sharpe = 0.695, mean Sharpe = 2.016, max Sharpe = 4.781
gamma = 5.000000, number of sims = 10000, min Sharpe = -1.912, mean Sharpe = 1.788, max Sharpe = 4.725
gamma = 50.000000, number of sims = 10000, min Sharpe = 0.589, mean Sharpe = 2.277, max Sharpe = 5.970
gamma = 10000.000000, number of sims = 10000, min Sharpe = 7.209, mean Sharpe = 73.363, max Sharpe = 798.734

Charts from this run

OU diagnostic path 1

Generated-path diagnostics; fixed-W sizing in the source is retained. These are printed observations, not a reconstructed self-financing backtest.

Derived from stdout.log using the precision available in that file. Download plotted data. Undefined or malformed cells are omitted, never replaced by zero.

Chart 1

OU diagnostic path 2

Generated-path diagnostics; fixed-W sizing in the source is retained. These are printed observations, not a reconstructed self-financing backtest.

Derived from stdout.log using the precision available in that file. Download plotted data. Undefined or malformed cells are omitted, never replaced by zero.

Chart 2

Reported Monte Carlo Sharpe summary

Uses printed Monte Carlo summaries and the demo’s Sharpe convention; not independently annualized or validated.

Derived from stdout.log using the precision available in that file. Download plotted data. Undefined or malformed cells are omitted, never replaced by zero.

Chart 3

Downloadable evidence

Download OULogSpreadCRRASignalDemo.zip contains stdout, stderr, the execution record, checksums and any exported CSV/chart files.

Export Bytes
files/derived-charts/charts.json 1587
files/derived-charts/derived-01.csv 26293
files/derived-charts/derived-01.png 180001
files/derived-charts/derived-02.csv 26130
files/derived-charts/derived-02.png 169750
files/derived-charts/derived-03.csv 675
files/derived-charts/derived-03.png 110744

Interpreting the result

Read the reported units: optimizer weights, model-fit coefficients, forecast correlations and simulated P/L are different outputs. Synthetic runs demonstrate the API rather than historical market returns. Inspect undefined values and open positions instead of replacing them with zero. Chart exports visualize exactly this run.

For model assumptions, original publications and adaptation limits, use the literature guide.

Clone this wiki locally