mergeron 2024.738963.0__py3-none-any.whl → 2024.738973.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mergeron might be problematic. Click here for more details.

mergeron/gen/upp_tests.py CHANGED
@@ -12,7 +12,6 @@ from typing import Literal, TypeAlias, TypedDict
12
12
 
13
13
  import numpy as np
14
14
  import tables as ptb # type: ignore
15
- from attrs import evolve
16
15
  from joblib import Parallel, cpu_count, delayed # type: ignore
17
16
  from numpy.random import SeedSequence
18
17
  from numpy.typing import NDArray
@@ -26,7 +25,7 @@ from . import (
26
25
  DataclassInstance,
27
26
  INVResolution,
28
27
  MarketDataSample,
29
- MarketSampleSpec,
28
+ MarketSpec,
30
29
  UPPTestRegime,
31
30
  UPPTestsCounts,
32
31
  UPPTestsRaw,
@@ -43,21 +42,27 @@ ptb.parameters.MAX_BLOSC_THREADS = 4
43
42
  SaveData: TypeAlias = Literal[False] | tuple[Literal[True], ptb.File, ptb.Group]
44
43
 
45
44
 
46
- class IVNRESCntsArgs(TypedDict, total=False):
45
+ class INVRESCntsArgs(TypedDict, total=False):
47
46
  "Keyword arguments of function, :code:`sim_invres_cnts`"
48
47
 
49
- sim_test_regime: UPPTestRegime
50
48
  saved_array_name_suffix: str
51
49
  save_data_to_file: SaveData
52
- seed_seq_list: list[SeedSequence]
50
+ sample_size: int
51
+ seed_seq_list: list[SeedSequence] | None
53
52
  nthreads: int
54
53
 
55
54
 
56
55
  def sim_invres_cnts_ll(
57
- _mkt_sample_spec: MarketSampleSpec,
56
+ _mkt_sample_spec: MarketSpec,
58
57
  _invres_parm_vec: gbl.HMGThresholds,
59
- _sim_invres_cnts_kwargs: IVNRESCntsArgs,
58
+ _sim_test_regime: UPPTestRegime,
60
59
  /,
60
+ *,
61
+ saved_array_name_suffix: str = "",
62
+ save_data_to_file: SaveData = False,
63
+ sample_size: int = 10**6,
64
+ seed_seq_list: list[SeedSequence] | None = None,
65
+ nthreads: int = 16,
61
66
  ) -> UPPTestsCounts:
62
67
  """A function to parallelize data-generation and testing
63
68
 
@@ -78,22 +83,34 @@ def sim_invres_cnts_ll(
78
83
  _mkt_sample_spec
79
84
  Configuration to use for generating sample data to test
80
85
 
81
- _sim_invres_cnts_kwargs
82
- Arguments to downstream test function `sim_invres_cnts`
86
+ _sim_test_regime
87
+ Configuration to use for testing
88
+
89
+ saved_array_name_suffix
90
+ Suffix to add to the array names in the HDF5 file
91
+
92
+ save_data_to_file
93
+ Whether to save data to an HDF5 file, and where to save it
94
+
95
+ sample_size
96
+ Number of draws to simulate
97
+
98
+ seed_seq_list
99
+ List of seed sequences, to assure independent samples in each thread
100
+
101
+ nthreads
102
+ Number of parallel processes to use
83
103
 
84
104
  Returns
85
105
  -------
86
106
  Arrays of UPPTestCounts
87
107
 
88
108
  """
89
- _sample_sz = _mkt_sample_spec.sample_size
109
+ _sample_sz = sample_size
90
110
  _subsample_sz = 10**6
91
111
  _iter_count = int(_sample_sz / _subsample_sz) if _subsample_sz < _sample_sz else 1
92
112
  _thread_count = cpu_count()
93
113
 
94
- # Crate a copy, to avoid side effects in the outer scope
95
- _mkt_sample_spec_here = evolve(_mkt_sample_spec, sample_size=_subsample_sz)
96
-
97
114
  if (
98
115
  _mkt_sample_spec.share_spec.recapture_form != RECConstants.OUTIN
99
116
  and _mkt_sample_spec.share_spec.recapture_rate != _invres_parm_vec.rec
@@ -107,26 +124,24 @@ def sim_invres_cnts_ll(
107
124
  )
108
125
 
109
126
  _rng_seed_seq_list = [None] * _iter_count
110
- if _sim_invres_cnts_kwargs:
111
- if _sseql := _sim_invres_cnts_kwargs.get("seed_seq_list"):
112
- _rng_seed_seq_list = list(
113
- zip(*[g.spawn(_iter_count) for g in _sseql], strict=True) # type: ignore
114
- )
127
+ if seed_seq_list:
128
+ _rng_seed_seq_list = list(
129
+ zip(*[g.spawn(_iter_count) for g in seed_seq_list], strict=True) # type: ignore
130
+ )
115
131
 
116
- _sim_invres_cnts_kwargs: IVNRESCntsArgs = { # type: ignore
117
- _k: _v
118
- for _k, _v in _sim_invres_cnts_kwargs.items()
119
- if _k != "seed_seq_list"
120
- }
121
- else:
122
- _sim_invres_cnts_kwargs = {}
132
+ _sim_invres_cnts_kwargs: INVRESCntsArgs = INVRESCntsArgs({
133
+ "sample_size": _subsample_sz,
134
+ "save_data_to_file": save_data_to_file,
135
+ "nthreads": nthreads,
136
+ })
123
137
 
124
138
  _res_list = Parallel(n_jobs=_thread_count, prefer="threads")(
125
139
  delayed(sim_invres_cnts)(
126
- _mkt_sample_spec_here,
140
+ _mkt_sample_spec,
127
141
  _invres_parm_vec,
142
+ _sim_test_regime,
128
143
  **_sim_invres_cnts_kwargs,
129
- saved_array_name_suffix=f"{_iter_id:0{2 + int(np.ceil(np.log10(_iter_count)))}d}",
144
+ saved_array_name_suffix=f"{saved_array_name_suffix}_{_iter_id:0{2 + int(np.ceil(np.log10(_iter_count)))}d}",
130
145
  seed_seq_list=_rng_seed_seq_list_ch,
131
146
  )
132
147
  for _iter_id, _rng_seed_seq_list_ch in enumerate(_rng_seed_seq_list)
@@ -151,19 +166,23 @@ def sim_invres_cnts_ll(
151
166
 
152
167
 
153
168
  def sim_invres_cnts(
154
- _mkt_sample_spec: MarketSampleSpec,
169
+ _mkt_sample_spec: MarketSpec,
155
170
  _upp_test_parms: gbl.HMGThresholds,
171
+ _sim_test_regime: UPPTestRegime,
156
172
  /,
157
173
  *,
158
- sim_test_regime: UPPTestRegime,
159
174
  saved_array_name_suffix: str = "",
160
175
  save_data_to_file: SaveData = False,
176
+ sample_size: int = 10**6,
161
177
  seed_seq_list: list[SeedSequence] | None = None,
162
178
  nthreads: int = 16,
163
179
  ) -> UPPTestsCounts:
164
180
  # Generate market data
165
- _market_data = dgl.gen_market_sample(
166
- _mkt_sample_spec, seed_seq_list=seed_seq_list, nthreads=nthreads
181
+ _market_data_sample = dgl.gen_market_sample(
182
+ _mkt_sample_spec,
183
+ sample_size=sample_size,
184
+ seed_seq_list=seed_seq_list,
185
+ nthreads=nthreads,
167
186
  )
168
187
 
169
188
  _invalid_array_names = (
@@ -173,28 +192,42 @@ def sim_invres_cnts(
173
192
  )
174
193
 
175
194
  save_data_to_hdf5(
176
- _market_data,
177
- saved_array_name_suffix,
178
- _invalid_array_names,
195
+ _market_data_sample,
196
+ saved_array_name_suffix=saved_array_name_suffix,
197
+ excluded_attrs=_invalid_array_names,
179
198
  save_data_to_file=save_data_to_file,
180
199
  )
181
200
 
182
- _upp_tests_data = gen_upp_arrays(
183
- _market_data,
184
- _upp_test_parms,
185
- sim_test_regime,
201
+ _upp_test_arrays = invres_cnts(
202
+ _market_data_sample, _upp_test_parms, _sim_test_regime
203
+ )
204
+
205
+ save_data_to_hdf5(
206
+ _upp_test_arrays,
186
207
  saved_array_name_suffix=saved_array_name_suffix,
187
208
  save_data_to_file=save_data_to_file,
188
209
  )
189
210
 
211
+ return _upp_test_arrays
212
+
213
+
214
+ def invres_cnts(
215
+ _market_data_sample: MarketDataSample,
216
+ _upp_test_parms: gbl.HMGThresholds,
217
+ _upp_test_regime: UPPTestRegime,
218
+ /,
219
+ ) -> UPPTestsCounts:
220
+ _upp_test_arrays = gen_upp_test_arrays(
221
+ _market_data_sample, _upp_test_parms, _upp_test_regime
222
+ )
223
+
190
224
  _fcounts, _hhi_delta, _hhi_post = (
191
- getattr(_market_data, _g) for _g in ["fcounts", "hhi_delta", "hhi_post"]
225
+ getattr(_market_data_sample, _g) for _g in ("fcounts", "hhi_delta", "hhi_post")
192
226
  )
193
- del _market_data
194
227
 
195
228
  _stats_rowlen = 6
196
229
  # Clearance/enforcement counts --- by firm count
197
- _firm_counts_weights = _mkt_sample_spec.share_spec.firm_counts_weights
230
+ _firm_counts_weights = np.unique(_fcounts)
198
231
  if _firm_counts_weights is not None and np.all(_firm_counts_weights >= 0):
199
232
  _max_firm_count = len(_firm_counts_weights)
200
233
 
@@ -210,9 +243,9 @@ def sim_invres_cnts(
210
243
  *[
211
244
  np.einsum(
212
245
  "ij->",
213
- 1 * (_firm_count_test & getattr(_upp_tests_data, _f)),
246
+ 1 * (_firm_count_test & getattr(_upp_test_arrays, _f)),
214
247
  )
215
- for _f in _upp_tests_data.__dataclass_fields__
248
+ for _f in _upp_test_arrays.__dataclass_fields__
216
249
  ],
217
250
  ]),
218
251
  ))
@@ -236,9 +269,9 @@ def sim_invres_cnts(
236
269
  np.einsum("ij->", 1 * _hhi_delta_test),
237
270
  *[
238
271
  np.einsum(
239
- "ij->", 1 * (_hhi_delta_test & getattr(_upp_tests_data, _f))
272
+ "ij->", 1 * (_hhi_delta_test & getattr(_upp_test_arrays, _f))
240
273
  )
241
- for _f in _upp_tests_data.__dataclass_fields__
274
+ for _f in _upp_test_arrays.__dataclass_fields__
242
275
  ],
243
276
  ]),
244
277
  ))
@@ -273,9 +306,9 @@ def sim_invres_cnts(
273
306
  np.einsum("ij->", 1 * _conc_test),
274
307
  *[
275
308
  np.einsum(
276
- "ij->", 1 * (_conc_test & getattr(_upp_tests_data, _f))
309
+ "ij->", 1 * (_conc_test & getattr(_upp_test_arrays, _f))
277
310
  )
278
- for _f in _upp_tests_data.__dataclass_fields__
311
+ for _f in _upp_test_arrays.__dataclass_fields__
279
312
  ],
280
313
  ]),
281
314
  ))
@@ -293,19 +326,26 @@ def sim_invres_cnts(
293
326
  )
294
327
 
295
328
 
296
- def gen_upp_arrays(
329
+ def gen_upp_test_arrays(
297
330
  _market_data: MarketDataSample,
298
331
  _upp_test_parms: gbl.HMGThresholds,
299
332
  _sim_test_regime: UPPTestRegime,
300
333
  /,
301
- *,
302
- saved_array_name_suffix: str = "",
303
- save_data_to_file: SaveData = False,
304
334
  ) -> UPPTestsRaw:
305
335
  """
306
336
  Generate UPP tests arrays for given configuration and market sample
307
337
 
308
338
  Given a standards vector, market
339
+
340
+ Parameters
341
+ ----------
342
+ _market_data
343
+ market data sample
344
+ _upp_test_parms
345
+ guidelines thresholds for testing UPP and related statistics
346
+ _sim_test_regime
347
+ configuration to use for generating UPP tests
348
+
309
349
  """
310
350
  _g_bar, _divr_bar, _cmcr_bar, _ipr_bar = (
311
351
  getattr(_upp_test_parms, _f) for _f in ("guppi", "divr", "cmcr", "ipr")
@@ -407,29 +447,21 @@ def gen_upp_arrays(
407
447
  _divr_test_vector = _market_data.divr_array.max(axis=1, keepdims=True)
408
448
 
409
449
  if _invres_resolution == INVResolution.ENFT:
410
- _upp_tests_data = UPPTestsRaw(
450
+ _upp_test_arrays = UPPTestsRaw(
411
451
  _guppi_test_vector >= _g_bar,
412
452
  (_guppi_test_vector >= _g_bar) | (_divr_test_vector >= _divr_bar),
413
453
  _cmcr_test_vector >= _cmcr_bar,
414
454
  _ipr_test_vector >= _ipr_bar,
415
455
  )
416
456
  else:
417
- _upp_tests_data = UPPTestsRaw(
457
+ _upp_test_arrays = UPPTestsRaw(
418
458
  _guppi_test_vector < _g_bar,
419
459
  (_guppi_test_vector < _g_bar) & (_divr_test_vector < _divr_bar),
420
460
  _cmcr_test_vector < _cmcr_bar,
421
461
  _ipr_test_vector < _ipr_bar,
422
462
  )
423
- del _guppi_test_vector, _divr_test_vector, _cmcr_test_vector, _ipr_test_vector
424
-
425
- save_data_to_hdf5(
426
- _upp_tests_data,
427
- saved_array_name_suffix,
428
- (),
429
- save_data_to_file=save_data_to_file,
430
- )
431
463
 
432
- return _upp_tests_data
464
+ return _upp_test_arrays
433
465
 
434
466
 
435
467
  def initialize_hd5(
@@ -449,24 +481,25 @@ def initialize_hd5(
449
481
 
450
482
  def save_data_to_hdf5(
451
483
  _dclass: DataclassInstance,
452
- _saved_array_name_suffix: str = "",
453
- _excl_attrs: Sequence[str] = (),
454
484
  /,
455
485
  *,
486
+ saved_array_name_suffix: str | None = "",
487
+ excluded_attrs: Sequence[str] | None = (),
456
488
  save_data_to_file: SaveData = False,
457
489
  ) -> None:
458
490
  if save_data_to_file:
459
491
  _, _h5_file, _h5_group = save_data_to_file
460
492
  # Save market data arrays
493
+ excluded_attrs = excluded_attrs or ()
461
494
  for _array_name in _dclass.__dataclass_fields__:
462
- if _array_name in _excl_attrs:
495
+ if _array_name in excluded_attrs:
463
496
  continue
464
497
  save_array_to_hdf5(
465
498
  getattr(_dclass, _array_name),
466
499
  _array_name,
467
500
  _h5_group,
468
501
  _h5_file,
469
- saved_array_name_suffix=_saved_array_name_suffix,
502
+ saved_array_name_suffix=saved_array_name_suffix,
470
503
  )
471
504
 
472
505
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mergeron
3
- Version: 2024.738963.0
3
+ Version: 2024.738973.0
4
4
  Summary: Analysis of standards defined in Horizontal Merger Guidelines
5
5
  License: MIT
6
6
  Keywords: merger policy analysis,merger guidelines,merger screening,policy presumptions,concentration standards,upward pricing pressure,GUPPI
@@ -1,22 +1,24 @@
1
1
  mergeron/License.txt,sha256=7iX-y0EyjkbVJKJLS4ZKzuuE1wd0lryfsD_IytLG8lQ,1246
2
2
  mergeron/__init__.py,sha256=_0Bt2k2P8MPlF_WagQKGspaSODn-pkqib0uvSd4gys4,1019
3
3
  mergeron/core/InCommon RSA Server CA cert chain.pem,sha256=W8TqydgY8jphQ4fr6WMdT6jLwqFjHLpx8fFr3LXub4s,4292
4
- mergeron/core/__init__.py,sha256=MWnGSHui-3SpgZ_0Mc84NIpx2sEkCRx3G1cVAMRwpQI,2110
4
+ mergeron/core/__init__.py,sha256=9_FKQ5f8hJhmv6BfaSNrjKr8dEw8Twd4X3j3i6NvHOs,2257
5
5
  mergeron/core/damodaran_margin_data.py,sha256=DHTQdFjuZ5Yl3Dbq0db0QR4FHUqJpZj4yi5zdUncLtg,8166
6
6
  mergeron/core/excel_helper.py,sha256=XfdKNOEdB5zNJl8LguVyAcDjr5y2wapKDbNgAx6r-es,7831
7
7
  mergeron/core/ftc_invdata.msgpack,sha256=WBFHgi7Ld4R-h2zL2Zc3TOIlKqVrbVFMH1LoI4-T-M0,264664
8
8
  mergeron/core/ftc_merger_investigations_data.py,sha256=wHF1dKAqWlh1hMvaQv2uOCAKAHnuPvCGnmaOB3CJO9I,26929
9
- mergeron/core/guidelines_boundaries.py,sha256=UiB1Jf32IhgQZbWNiSq5FiMequf5W0DCDxLFA32D9KE,37393
10
- mergeron/core/guidelines_boundaries_specialized_functions.py,sha256=xqiNGbka9PUZ6xWanyWfYNhA-2ONg211ksnK5IdMcyM,10377
9
+ mergeron/core/guidelines_boundaries.py,sha256=haMNATCWKkAjFCQTChHPqfgKq4DTM5SZb9R9RIXoCT0,12542
10
+ mergeron/core/guidelines_boundary_functions.py,sha256=Pmg73eXu1HUh4UW8s-wgep8udWXZqX3t266Yp3uSi70,25313
11
+ mergeron/core/guidelines_boundary_functions_extra.py,sha256=NOdxBgoP32RdXwY41vjGuo9VH80hCIv7jRYi5UhFgxQ,11423
11
12
  mergeron/core/proportions_tests.py,sha256=tCrbya1el5u1OFOXphODP6yWOGywuNY6z9LBTsNRKzM,15320
12
13
  mergeron/core/pseudorandom_numbers.py,sha256=uBK_fnhkOSkqnK4gEU8b3r_9B6r-vKmXZ64HViraTK8,9446
13
14
  mergeron/ext/__init__.py,sha256=iyfxkX3-SoMS4ZQZKHKPn8JEMN536vpty9oSZf0LHv8,115
14
15
  mergeron/ext/tol_colors.py,sha256=wFOHZXWZonbp9mhmSGu9mVujBYhdTsvx9_WikMpoCmo,22229
15
- mergeron/gen/__init__.py,sha256=3W3EZH934f65msQY0LDY4cjSKE04cGeznF6Bqa5IND8,16554
16
- mergeron/gen/_data_generation_functions_nonpublic.py,sha256=J6f5l3Kiuv5aqThOrj1evT6vrYxpNf7qZ-6gckmSNbw,21364
17
- mergeron/gen/data_generation.py,sha256=29o-XuSI760JSY8Hq1QVB9ibJRjmzGPLnU2UOJT7KKc,8887
16
+ mergeron/gen/__init__.py,sha256=-yewgOkVtKpXmc6HhGwJjbMkpWOk9ODYd_DEmoYnS50,16022
17
+ mergeron/gen/_data_generation_functions.py,sha256=QLxeS35D3bqQjjDabq1QncqwptMaHBrtmZ-_JUo6SG4,23202
18
+ mergeron/gen/data_generation.py,sha256=7teP8OKgKp08riX2Yu7flMEvN6a_eNXJllv_Hdkt7W8,8842
18
19
  mergeron/gen/investigations_stats.py,sha256=4-AY_zhqKSlGE8sQciuYxzg2U4efQs2014dydmWUFz4,22802
19
- mergeron/gen/upp_tests.py,sha256=nAdcejRH5BnSw32tkAYfkYL_yOofHK3m3kqx3zPDVs0,16521
20
+ mergeron/gen/market_sample.py,sha256=HQbdmzAEub9vZDXjwPzZOZrTRHDLwn5fDhcTgeOwSlQ,2399
21
+ mergeron/gen/upp_tests.py,sha256=OaEEo1ARSza2-PFsZaFArC2bOdo2qKG3k1jubhg-ccQ,17217
20
22
  mergeron/jinja_LaTex_templates/clrrate_cis_summary_table_template.tex.jinja2,sha256=ae4JiciU-pt8YAM8mRbsmt4W6ePuN1y1NPCWD95oXIo,4833
21
23
  mergeron/jinja_LaTex_templates/ftcinvdata_byhhianddelta_table_template.tex.jinja2,sha256=ODEurkC0UHuWpjRUiQpeW85njSeUEUJYRdYg8gqoEq0,3642
22
24
  mergeron/jinja_LaTex_templates/ftcinvdata_summary_table_template.tex.jinja2,sha256=h8_DEE0iskT9tnga5lZtxcoevN7pY4iKF-maErt4UU4,2906
@@ -25,6 +27,6 @@ mergeron/jinja_LaTex_templates/mergeron.cls,sha256=AV2mk4-uERvAuMkE95Ka7el6LZsb0
25
27
  mergeron/jinja_LaTex_templates/mergeron_table_collection_template.tex.jinja2,sha256=nr6xUI0_2KHG4Sz9k1JFVQjs2h9qS9BGt1MeE6Tygs8,2429
26
28
  mergeron/jinja_LaTex_templates/setup_tikz_tables.tex.jinja2,sha256=WKVxtp3eoMchfGliQAJMj4w2FtBkWG5z2V3-hBYUYUQ,3292
27
29
  mergeron/py.typed,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
28
- mergeron-2024.738963.0.dist-info/METADATA,sha256=mlWYt8srM1_7wpJAkUBUFA9aouiELbCpLQzldksbl0E,6925
29
- mergeron-2024.738963.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
30
- mergeron-2024.738963.0.dist-info/RECORD,,
30
+ mergeron-2024.738973.0.dist-info/METADATA,sha256=VCkVedkcxNum0AjN3whp7lnAE3cJit1fAzOVh5OTxrU,6925
31
+ mergeron-2024.738973.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
+ mergeron-2024.738973.0.dist-info/RECORD,,