mergeron 2024.739127.1__py3-none-any.whl → 2024.739145.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.

@@ -2,7 +2,6 @@
2
2
  Plot the empirical distribution derived using the Gaussian KDE with
3
3
  margin data downloaded from Prof. Damodaran's website at NYU.
4
4
 
5
-
6
5
  """
7
6
 
8
7
  import warnings
@@ -13,7 +12,7 @@ from matplotlib.ticker import StrMethodFormatter
13
12
  from numpy.random import PCG64DXSM, Generator, SeedSequence
14
13
  from scipy import stats # type: ignore
15
14
 
16
- import mergeron.core.damodaran_margin_data as dmgn
15
+ import mergeron.core.empirical_margin_distribution as dmgn
17
16
  from mergeron import DATA_DIR
18
17
  from mergeron.core.guidelines_boundary_functions import boundary_plot
19
18
 
@@ -46,7 +45,7 @@ with warnings.catch_warnings():
46
45
  ])
47
46
 
48
47
  mgn_kde = stats.gaussian_kde(mgn_data_obs, weights=mgn_data_wts, bw_method="silverman")
49
- mgn_kde.set_bandwidth(bw_method=mgn_kde.factor / 3.0)
48
+ mgn_kde.set_bandwidth(bw_method=mgn_kde.factor / 3.0) # pyright: ignore
50
49
 
51
50
  mgn_ax.plot(
52
51
  (_xv := np.linspace(0, BIN_COUNT, 10**5) / BIN_COUNT),
mergeron/gen/__init__.py CHANGED
@@ -25,13 +25,13 @@ from .. import ( # noqa: TID252
25
25
  RECForm,
26
26
  UPPAggrSelector,
27
27
  )
28
- from ..core.pseudorandom_numbers import DIST_PARMS_DEFAULT # noqa: TID252
28
+ from ..core.pseudorandom_numbers import DEFAULT_DIST_PARMS # noqa: TID252
29
29
 
30
30
  __version__ = VERSION
31
31
 
32
32
 
33
- EMPTY_ARRAY_DEFAULT = np.zeros(2)
34
- FCOUNT_WTS_DEFAULT = np.divide(
33
+ DEFAULT_EMPTY_ARRAY = np.zeros(2)
34
+ DEFAULT_FCOUNT_WTS = np.divide(
35
35
  (_nr := np.arange(1, 7)[::-1]), _nr.sum(), dtype=np.float64
36
36
  )
37
37
 
@@ -105,22 +105,42 @@ class ShareSpec:
105
105
 
106
106
  Notes
107
107
  -----
108
- If :attr:`mergeron.gen.ShareSpec.dist_type`:code:` == `:attr:`mergeron.gen.SHRDistribution.UNI`,
108
+ If :attr:`mergeron.gen.ShareSpec.dist_type` == :attr:`mergeron.gen.SHRDistribution.UNI`,
109
109
  then it is infeasible that
110
- :attr:`mergeron.gen.ShareSpec.recapture_form`:code:` == `:attr:`mergeron.RECForm.OUTIN`.
111
- In other words, if firm-counts are unspecified, the recapture rate cannot be
112
- estimated using outside good choice probabilities.
110
+ :attr:`mergeron.gen.ShareSpec.recapture_form` == :attr:`mergeron.RECForm.OUTIN`.
111
+ In other words, if the distribution of markets over firm-counts is unspecified,
112
+ recapture ratios cannot be estimated using outside-good choice probabilities.
113
113
 
114
- For a sample with explicit firm counts, market shares must
115
- be specified as having a supported Dirichlet distribution
116
- (see :class:`mergeron.gen.SHRDistribution`).
114
+ For a sample with explicit firm counts, market shares must be specified as
115
+ having a supported Dirichlet distribution (see :class:`mergeron.gen.SHRDistribution`).
117
116
 
118
117
  """
119
118
 
120
- dist_type: SHRDistribution
119
+ dist_type: SHRDistribution = field(default=SHRDistribution.DIR_FLAT)
121
120
  """See :class:`SHRDistribution`"""
122
121
 
123
- dist_parms: ArrayDouble | None = field(
122
+ @dist_type.validator # pyright: ignore
123
+ def __dtv(
124
+ _i: ShareSpec, _a: Attribute[SHRDistribution], _v: SHRDistribution
125
+ ) -> None:
126
+ if _v == SHRDistribution.UNI:
127
+ if _i.firm_counts_weights is not None:
128
+ raise ValueError(
129
+ "The specified value is incompatible with "
130
+ " :code:`distypte`=:attr`:`SHRDistribution.UNI`. "
131
+ "Set value to None or Consider revising the "
132
+ r"distribution type to :attr:`SHRDistribution.DIR_FLAT`, which gives "
133
+ "uniformly distributed draws on the :math:`n+1` simplex "
134
+ "for firm-count, :math:`n`. "
135
+ ""
136
+ )
137
+ elif _i.recapture_form == RECForm.OUTIN:
138
+ raise ValueError(
139
+ "Market share specification requires estimation of recapture ratio from "
140
+ "generated data. Either delete recapture ratio specification or set it to None."
141
+ )
142
+
143
+ dist_parms: ArrayFloat | ArrayINT | None = field(
124
144
  default=None, eq=cmp_using(eq=np.array_equal)
125
145
  )
126
146
  """Parameters for tailoring market-share distribution
@@ -131,49 +151,47 @@ class ShareSpec:
131
151
  type of Dirichlet-distribution specified.
132
152
 
133
153
  """
154
+
155
+ @dist_parms.validator # pyright: ignore
156
+ def __dpv(
157
+ _i: ShareSpec,
158
+ _a: Attribute[ArrayFloat | ArrayINT | None],
159
+ _v: ArrayFloat | ArrayINT | None,
160
+ ) -> None:
161
+ if (
162
+ _i.firm_counts_weights is not None
163
+ and _v is not None
164
+ and len(_v) < 1 + len(_i.firm_counts_weights)
165
+ ):
166
+ raise ValueError(
167
+ "If specified, the number of distribution parameters must be at least "
168
+ "the maximum firm-count premerger, which is 1 plus the length of the "
169
+ "vector specifying firm-count weights."
170
+ )
171
+
134
172
  firm_counts_weights: ArrayFloat | ArrayINT | None = field(
135
- default=None, eq=cmp_using(eq=np.array_equal)
173
+ default=DEFAULT_FCOUNT_WTS, eq=cmp_using(eq=np.array_equal)
136
174
  )
137
175
  """Relative or absolute frequencies of firm counts
138
176
 
139
177
  Given frequencies are exogenous to generated market data sample;
140
- for Dirichlet-type distributions, defaults to FCOUNT_WTS_DEFAULT, which specifies
178
+ for Dirichlet-type distributions, defaults to DEFAULT_FCOUNT_WTS, which specifies
141
179
  firm-counts of 2 to 6 with weights in descending order from 5 to 1.
142
180
 
143
181
  """
144
182
 
145
- @firm_counts_weights.validator
146
- def _check_fcw(_i: ShareSpec, _a: Attribute[ArrayDouble], _v: ArrayDouble) -> None:
147
- if _v is not None and _i.dist_type == SHRDistribution.UNI:
148
- raise ValueError(
149
- "Generated data for markets with specified firm-counts or "
150
- "varying firm counts are not feasible for market shares "
151
- "with Uniform distribution. Consider revising the "
152
- r"distribution type to {SHRDistribution.DIR_FLAT}, which gives "
153
- "uniformly distributed draws on the :math:`n+1` simplex "
154
- "for firm-count, :math:`n`."
155
- )
156
-
157
183
  recapture_form: RECForm = field(default=RECForm.INOUT)
158
184
  """See :class:`mergeron.RECForm`"""
159
185
 
160
- @recapture_form.validator
161
- def _check_rf(_i: ShareSpec, _a: Attribute[RECForm], _v: RECForm) -> None:
162
- if _v == RECForm.OUTIN and _i.dist_type == SHRDistribution.UNI:
163
- raise ValueError(
164
- "Market share specification requires estimation of recapture rate from "
165
- "generated data. Either delete recapture rate specification or set it to None."
166
- )
167
-
168
- recapture_rate: float | None = field(default=DEFAULT_REC_RATE)
186
+ recapture_ratio: float | None = field(default=DEFAULT_REC_RATE)
169
187
  """A value between 0 and 1.
170
188
 
171
189
  :code:`None` if market share specification requires direct generation of
172
190
  outside good choice probabilities (:attr:`mergeron.RECForm.OUTIN`).
173
191
 
174
- The recapture rate is usually calibrated to the numbers-equivalent of the
192
+ The recapture ratio is usually calibrated to the numbers-equivalent of the
175
193
  HHI threshold for the presumtion of harm from unilateral competitive effects
176
- in published merger guidelines. Accordingly, the recapture rate rounded to
194
+ in published merger guidelines. Accordingly, the recapture ratio rounded to
177
195
  the nearest 5% is:
178
196
 
179
197
  * 0.85, **7-to-6 merger from symmetry**; US Guidelines, 1992, 2023
@@ -188,14 +206,14 @@ class ShareSpec:
188
206
 
189
207
  """
190
208
 
191
- @recapture_rate.validator
192
- def _check_rr(_i: ShareSpec, _a: Attribute[float], _v: float) -> None:
209
+ @recapture_ratio.validator # pyright: ignore
210
+ def __rrv(_i: ShareSpec, _a: Attribute[float], _v: float) -> None:
193
211
  if _v and not (0 < _v <= 1):
194
- raise ValueError("Recapture rate must lie in the interval, [0, 1).")
212
+ raise ValueError("Recapture ratio must lie in the interval, [0, 1).")
195
213
  elif _v is None and _i.recapture_form != RECForm.OUTIN:
196
214
  raise ValueError(
197
215
  f"Recapture specification, {_i.recapture_form!r} requires that "
198
- "the market sample specification inclues a recapture rate in the "
216
+ "the market sample specification inclues a recapture ratio in the "
199
217
  "interval [0, 1)."
200
218
  )
201
219
 
@@ -248,16 +266,16 @@ class PCMSpec:
248
266
 
249
267
  """
250
268
 
251
- @dist_parms.validator
252
- def _check_dp(
269
+ @dist_parms.validator # pyright: ignore
270
+ def __dpv(
253
271
  _i: PCMSpec, _a: Attribute[ArrayDouble | None], _v: ArrayDouble | None
254
272
  ) -> None:
255
273
  if _i.dist_type.name.startswith("BETA"):
256
274
  if _v is None:
257
275
  pass
258
- elif np.array_equal(_v, DIST_PARMS_DEFAULT):
276
+ elif np.array_equal(_v, DEFAULT_DIST_PARMS):
259
277
  raise ValueError(
260
- f"The distribution parameters, {DIST_PARMS_DEFAULT!r} "
278
+ f"The distribution parameters, {DEFAULT_DIST_PARMS!r} "
261
279
  "are not valid with margin distribution, {_dist_type_pcm!r}"
262
280
  )
263
281
  elif (
@@ -85,8 +85,8 @@ class MarketSample:
85
85
  )
86
86
  """Margin specification, see :class:`PCMSpec`"""
87
87
 
88
- @pcm_spec.validator
89
- def _check_pcm(self, _a: Attribute[PCMSpec], _v: PCMSpec, /) -> None:
88
+ @pcm_spec.validator # pyright: ignore
89
+ def __psv(self, _a: Attribute[PCMSpec], _v: PCMSpec, /) -> None:
90
90
  if (
91
91
  self.share_spec.recapture_form == RECForm.FIXED
92
92
  and _v.firm2_pcm_constraint == FM2Constraint.MNL
@@ -113,7 +113,7 @@ class MarketSample:
113
113
 
114
114
  enf_counts: UPPTestsCounts = field(default=None)
115
115
 
116
- def _gen_market_sample(
116
+ def __gen_market_sample(
117
117
  self,
118
118
  /,
119
119
  *,
@@ -134,7 +134,7 @@ class MarketSample:
134
134
  """
135
135
 
136
136
  _recapture_form = self.share_spec.recapture_form
137
- _recapture_rate = self.share_spec.recapture_rate
137
+ _recapture_ratio = self.share_spec.recapture_ratio
138
138
  _dist_type_mktshr = self.share_spec.dist_type
139
139
  _dist_firm2_pcm = self.pcm_spec.firm2_pcm_constraint
140
140
  _hsr_filing_test_type = self.hsr_filing_test_type
@@ -208,7 +208,7 @@ class MarketSample:
208
208
  # Calculate diversion ratios
209
209
  _divr_array = gen_divr_array(
210
210
  _recapture_form,
211
- _recapture_rate,
211
+ _recapture_ratio,
212
212
  _mktshr_array[:, :2],
213
213
  _aggregate_purchase_prob,
214
214
  )
@@ -256,7 +256,7 @@ class MarketSample:
256
256
 
257
257
  """
258
258
 
259
- self.data = self._gen_market_sample(
259
+ self.data = self.__gen_market_sample(
260
260
  sample_size=sample_size, seed_seq_list=seed_seq_list, nthreads=nthreads
261
261
  )
262
262
 
@@ -273,14 +273,14 @@ class MarketSample:
273
273
  save_data_to_file=save_data_to_file,
274
274
  )
275
275
 
276
- def _sim_enf_cnts(
276
+ def __sim_enf_cnts(
277
277
  self,
278
278
  _upp_test_parms: gbl.HMGThresholds,
279
279
  _sim_test_regime: UPPTestRegime,
280
280
  /,
281
281
  *,
282
282
  sample_size: int = 10**6,
283
- seed_seq_list: list[SeedSequence] | None = None,
283
+ seed_seq_list: Sequence[SeedSequence] | None = None,
284
284
  nthreads: int = 16,
285
285
  save_data_to_file: SaveData = False,
286
286
  saved_array_name_suffix: str = "",
@@ -320,7 +320,7 @@ class MarketSample:
320
320
 
321
321
  """
322
322
 
323
- _market_data_sample = self._gen_market_sample(
323
+ _market_data_sample = self.__gen_market_sample(
324
324
  sample_size=sample_size, seed_seq_list=seed_seq_list, nthreads=nthreads
325
325
  )
326
326
 
@@ -349,14 +349,14 @@ class MarketSample:
349
349
 
350
350
  return _upp_test_arrays
351
351
 
352
- def _sim_enf_cnts_ll(
352
+ def __sim_enf_cnts_ll(
353
353
  self,
354
354
  _enf_parm_vec: gbl.HMGThresholds,
355
355
  _sim_test_regime: UPPTestRegime,
356
356
  /,
357
357
  *,
358
358
  sample_size: int = 10**6,
359
- seed_seq_list: list[SeedSequence] | None = None,
359
+ seed_seq_list: Sequence[SeedSequence] | None = None,
360
360
  nthreads: int = 16,
361
361
  save_data_to_file: SaveData = False,
362
362
  saved_array_name_suffix: str = "",
@@ -410,11 +410,11 @@ class MarketSample:
410
410
 
411
411
  if (
412
412
  self.share_spec.recapture_form != RECForm.OUTIN
413
- and self.share_spec.recapture_rate != _enf_parm_vec.rec
413
+ and self.share_spec.recapture_ratio != _enf_parm_vec.rec
414
414
  ):
415
415
  raise ValueError(
416
416
  "{} {} {}".format(
417
- f"Recapture rate from market sample spec, {self.share_spec.recapture_rate}",
417
+ f"Recapture ratio from market sample spec, {self.share_spec.recapture_ratio}",
418
418
  f"must match the value, {_enf_parm_vec.rec}",
419
419
  "the guidelines thresholds vector.",
420
420
  )
@@ -433,12 +433,12 @@ class MarketSample:
433
433
  })
434
434
 
435
435
  _res_list = Parallel(n_jobs=_thread_count, prefer="threads")(
436
- delayed(self._sim_enf_cnts)(
436
+ delayed(self.__sim_enf_cnts)(
437
437
  _enf_parm_vec,
438
438
  _sim_test_regime,
439
439
  **_sim_enf_cnts_kwargs,
440
- saved_array_name_suffix=f"{saved_array_name_suffix}_{_iter_id:0{2 + int(np.ceil(np.log10(_iter_count)))}d}",
441
- seed_seq_list=_rng_seed_seq_list_ch,
440
+ saved_array_name_suffix=f"{saved_array_name_suffix}_{_iter_id:0{2 + int(np.ceil(np.log10(_iter_count)))}d}", # pyright: ignore
441
+ seed_seq_list=_rng_seed_seq_list_ch, # pyright: ignore
442
442
  )
443
443
  for _iter_id, _rng_seed_seq_list_ch in enumerate(_rng_seed_seq_list)
444
444
  )
@@ -508,7 +508,7 @@ class MarketSample:
508
508
  """
509
509
 
510
510
  if self.data is None:
511
- self.enf_counts = self._sim_enf_cnts_ll(
511
+ self.enf_counts = self.__sim_enf_cnts_ll(
512
512
  _enf_parm_vec,
513
513
  _upp_test_regime,
514
514
  sample_size=sample_size,
@@ -11,22 +11,16 @@ import numpy as np
11
11
  from attrs import evolve
12
12
  from numpy.random import SeedSequence
13
13
 
14
- from .. import ( # noqa: TID252
15
- DEFAULT_REC_RATE,
16
- VERSION,
17
- ArrayBIGINT,
18
- ArrayDouble,
19
- RECForm,
20
- )
21
- from ..core.damodaran_margin_data import mgn_data_resampler # noqa: TID252
14
+ from .. import DEFAULT_REC_RATE, VERSION, ArrayDouble, RECForm # noqa: TID252
15
+ from ..core.empirical_margin_distribution import mgn_data_resampler # noqa: TID252
22
16
  from ..core.pseudorandom_numbers import ( # noqa: TID252
23
- DIST_PARMS_DEFAULT,
17
+ DEFAULT_DIST_PARMS,
24
18
  MultithreadedRNG,
25
19
  prng,
26
20
  )
27
21
  from . import (
28
- EMPTY_ARRAY_DEFAULT,
29
- FCOUNT_WTS_DEFAULT,
22
+ DEFAULT_EMPTY_ARRAY,
23
+ DEFAULT_FCOUNT_WTS,
30
24
  FM2Constraint,
31
25
  MarginDataSample,
32
26
  PCMDistribution,
@@ -106,7 +100,7 @@ def gen_share_data(
106
100
 
107
101
  # If recapture_form == "inside-out", recalculate _aggregate_purchase_prob
108
102
  _frmshr_array = _mkt_share_sample.mktshr_array[:, :2]
109
- _r_bar = _share_spec.recapture_rate or DEFAULT_REC_RATE
103
+ _r_bar = _share_spec.recapture_ratio or DEFAULT_REC_RATE
110
104
  if _recapture_form == RECForm.INOUT:
111
105
  _mkt_share_sample = ShareDataSample(
112
106
  _mkt_share_sample.mktshr_array,
@@ -120,7 +114,7 @@ def gen_share_data(
120
114
 
121
115
  def gen_market_shares_uniform(
122
116
  _s_size: int = 10**6,
123
- _dist_parms_mktshr: ArrayDouble | None = DIST_PARMS_DEFAULT,
117
+ _dist_parms_mktshr: ArrayDouble | None = DEFAULT_DIST_PARMS,
124
118
  _mktshr_rng_seed_seq: SeedSequence | None = None,
125
119
  _nthreads: int = 16,
126
120
  /,
@@ -145,9 +139,8 @@ def gen_market_shares_uniform(
145
139
  """
146
140
 
147
141
  _frmshr_array = np.empty((_s_size, 2), dtype=np.float64)
148
- _dist_parms_mktshr: ArrayDouble = (
149
- DIST_PARMS_DEFAULT if _dist_parms_mktshr is None else _dist_parms_mktshr
150
- )
142
+
143
+ _dist_parms_mktshr = _dist_parms_mktshr or DEFAULT_DIST_PARMS
151
144
  _mrng = MultithreadedRNG(
152
145
  _frmshr_array,
153
146
  dist_type="Uniform",
@@ -164,6 +157,7 @@ def gen_market_shares_uniform(
164
157
  ))
165
158
 
166
159
  # Keep only share combinations representing feasible mergers
160
+ # This is a no-op for 64-bit floats, but is necessary for 32-bit floats
167
161
  _frmshr_array = _frmshr_array[_frmshr_array.min(axis=1) > 0]
168
162
 
169
163
  # Let a third column have values of "np.nan", so HHI calculations return "np.nan"
@@ -171,11 +165,18 @@ def gen_market_shares_uniform(
171
165
  _frmshr_array, ((0, 0), (0, 1)), "constant", constant_values=np.nan
172
166
  )
173
167
 
174
- _fcounts: ArrayBIGINT = np.ones((_s_size, 1), np.int64) * np.nan # type: ignore
168
+ _fcounts = np.empty((_s_size, 1), np.int64)
175
169
  _nth_firm_share, _aggregate_purchase_prob = (
176
- np.nan * np.ones((_s_size, 1), np.float64) for _ in range(2)
170
+ np.empty(_fcounts.shape, np.float64)
171
+ for _ in ("nth_firm_share", "aggregate_purchase_prob")
177
172
  )
178
173
 
174
+ # This array is meant to be ignored, so a sentinel value is fine
175
+ _fcounts.fill(-9999)
176
+
177
+ _nth_firm_share.fill(np.nan)
178
+ _aggregate_purchase_prob.fill(np.nan)
179
+
179
180
  return ShareDataSample(
180
181
  _mktshr_array, _fcounts, _nth_firm_share, _aggregate_purchase_prob
181
182
  )
@@ -228,9 +229,10 @@ def gen_market_shares_dirichlet_multimarket(
228
229
 
229
230
  """
230
231
 
231
- _firm_count_wts: ArrayDouble = (
232
- FCOUNT_WTS_DEFAULT if _firm_count_wts is None else _firm_count_wts
233
- )
232
+ # _firm_count_wts: ArrayDouble = (
233
+ # DEFAULT_FCOUNT_WTS if _firm_count_wts is None else _firm_count_wts
234
+ # )
235
+ _firm_count_wts = DEFAULT_FCOUNT_WTS if _firm_count_wts is None else _firm_count_wts
234
236
 
235
237
  _min_choice_wt = 0.03 if _dist_type_dir == SHRDistribution.DIR_FLAT_CONSTR else 0.00
236
238
  _fcount_keys, _choice_wts = zip(
@@ -394,7 +396,8 @@ def gen_market_shares_dirichlet(
394
396
  )
395
397
 
396
398
  # If recapture_form == 'inside_out', further calculations downstream
397
- _aggregate_purchase_prob = np.nan * np.empty((_s_size, 1))
399
+ _aggregate_purchase_prob = np.empty((_s_size, 1), dtype=np.float64)
400
+ _aggregate_purchase_prob.fill(np.nan)
398
401
  if _recapture_form == RECForm.OUTIN:
399
402
  _aggregate_purchase_prob = 1 - _mktshr_array[:, [-1]]
400
403
  _mktshr_array = _mktshr_array[:, :-1] / _aggregate_purchase_prob
@@ -409,9 +412,9 @@ def gen_market_shares_dirichlet(
409
412
 
410
413
  def gen_divr_array(
411
414
  _recapture_form: RECForm,
412
- _recapture_rate: float | None,
415
+ _recapture_ratio: float | None,
413
416
  _frmshr_array: ArrayDouble,
414
- _aggregate_purchase_prob: ArrayDouble = EMPTY_ARRAY_DEFAULT,
417
+ _aggregate_purchase_prob: ArrayDouble = DEFAULT_EMPTY_ARRAY,
415
418
  /,
416
419
  ) -> ArrayDouble:
417
420
  """
@@ -425,8 +428,8 @@ def gen_divr_array(
425
428
  _recapture_form
426
429
  Enum specifying Fixed (proportional), Inside-out, or Outside-in
427
430
 
428
- _recapture_rate
429
- If recapture is proportional or inside-out, the recapture rate
431
+ _recapture_ratio
432
+ If recapture is proportional or inside-out, the recapture ratio
430
433
  for the firm with the smaller share.
431
434
 
432
435
  _frmshr_array
@@ -450,7 +453,7 @@ def gen_divr_array(
450
453
 
451
454
  _divr_array: ArrayDouble
452
455
  if _recapture_form == RECForm.FIXED:
453
- _divr_array = _recapture_rate * _frmshr_array[:, ::-1] / (1 - _frmshr_array) # type: ignore
456
+ _divr_array = _recapture_ratio * _frmshr_array[:, ::-1] / (1 - _frmshr_array) # type: ignore
454
457
 
455
458
  else:
456
459
  _purchprob_array = _aggregate_purchase_prob * _frmshr_array
@@ -525,6 +528,10 @@ def gen_margin_price_data(
525
528
  Simulated margin- and price-data arrays for mergers in the sample.
526
529
  """
527
530
 
531
+ _margin_data = MarginDataSample(
532
+ np.empty_like(_frmshr_array), np.ones(len(_frmshr_array)) == 0
533
+ )
534
+
528
535
  _price_array, _price_ratio_array = (
529
536
  np.ones_like(_frmshr_array, np.float64),
530
537
  np.empty_like(_frmshr_array, np.float64),
@@ -673,7 +680,6 @@ def _gen_margin_data(
673
680
  for _f in ("dist_type", "firm2_pcm_constraint", "dist_parms")
674
681
  )
675
682
 
676
- _dist_type: Literal["Beta", "Uniform"]
677
683
  _pcm_array = (
678
684
  np.empty((len(_frmshr_array), 1), dtype=np.float64)
679
685
  if _pcm_spec.firm2_pcm_constraint == FM2Constraint.SYM
@@ -683,23 +689,27 @@ def _gen_margin_data(
683
689
  _beta_min, _beta_max = [None] * 2 # placeholder
684
690
  if _dist_type_pcm == PCMDistribution.EMPR:
685
691
  _pcm_array = mgn_data_resampler(
686
- _pcm_array.shape, # type: ignore
687
- seed_sequence=_pcm_rng_seed_seq,
692
+ _pcm_array.shape, seed_sequence=_pcm_rng_seed_seq
688
693
  )
689
694
  else:
690
- _dist_type = "Uniform" if _dist_type_pcm == PCMDistribution.UNI else "Beta"
691
- if _dist_type_pcm == PCMDistribution.BETA:
692
- if _dist_parms_pcm is None:
693
- _dist_parms_pcm = np.ones(2, np.float64)
694
-
695
- elif _dist_type_pcm == PCMDistribution.BETA_BND: # Bounded beta
696
- if _dist_parms_pcm is None:
697
- _dist_parms_pcm = np.array([0, 1, 0, 1], np.float64)
698
- _dist_parms = beta_located_bound(_dist_parms_pcm)
695
+ _dist_type: Literal["Beta", "Uniform"]
696
+ if _dist_type_pcm in (PCMDistribution.BETA, PCMDistribution.BETA_BND):
697
+ _dist_type = "Beta"
698
+ _dist_parms_pcm = (
699
+ (
700
+ np.array([0, 1, 0, 1], np.float64)
701
+ if _dist_parms_pcm == PCMDistribution.BETA_BND
702
+ else np.ones(2, np.float64)
703
+ )
704
+ if _dist_parms_pcm is None
705
+ else _dist_parms_pcm
706
+ )
707
+ _dist_parms = beta_located_bound(_dist_parms_pcm)
708
+
699
709
  else:
700
- # _dist_type_pcm == PCMDistribution.UNI
710
+ _dist_type = "Uniform"
701
711
  _dist_parms = (
702
- DIST_PARMS_DEFAULT if _dist_parms_pcm is None else _dist_parms_pcm
712
+ DEFAULT_DIST_PARMS if _dist_parms_pcm is None else _dist_parms_pcm
703
713
  )
704
714
 
705
715
  _pcm_rng = MultithreadedRNG(
@@ -838,29 +848,29 @@ def parse_seed_seq_list(
838
848
  Seed sequence data
839
849
 
840
850
  """
851
+ _seed_count = 2 if _mktshr_dist_type == SHRDistribution.UNI else 3
852
+ _seed_count += 1 if _price_spec == PriceSpec.ZERO else 0
853
+
841
854
  _fcount_rng_seed_seq: SeedSequence | None = None
842
855
  _pr_rng_seed_seq: SeedSequence | None = None
843
856
 
844
- if _price_spec == PriceSpec.ZERO:
845
- _sseq_list, _pr_rng_seed_seq = (
846
- (_sseq_list[:-1], _sseq_list[-1])
847
- if _sseq_list
848
- else (None, SeedSequence(pool_size=8))
849
- )
850
-
851
- _seed_count = 2 if _mktshr_dist_type == SHRDistribution.UNI else 3
857
+ _sseq_list = (
858
+ _sseq_list
859
+ if _sseq_list
860
+ else tuple(SeedSequence(pool_size=8) for _ in range(_seed_count))
861
+ )
852
862
 
853
- if _sseq_list:
854
- if len(_sseq_list) < _seed_count:
855
- raise ValueError(
856
- f"seed sequence list must contain {_seed_count} seed sequences"
857
- )
858
- else:
859
- _sseq_list = tuple(SeedSequence(pool_size=8) for _ in range(_seed_count))
863
+ if (_l := len(_sseq_list)) < _seed_count:
864
+ raise ValueError(
865
+ f"Seed sequence list must contain {_seed_count} seed sequences; "
866
+ f"only {_l} given."
867
+ )
860
868
 
861
- (_mktshr_rng_seed_seq, _pcm_rng_seed_seq, _fcount_rng_seed_seq) = (
862
- _sseq_list if _seed_count == 3 else (*_sseq_list, None) # type: ignore
869
+ _mktshr_rng_seed_seq, _pcm_rng_seed_seq = _sseq_list[:2]
870
+ _fcount_rng_seed_seq = (
871
+ None if _mktshr_dist_type == SHRDistribution.UNI else _sseq_list[2]
863
872
  )
873
+ _pr_rng_seed_seq = _sseq_list[-1] if _price_spec == PriceSpec.ZERO else None
864
874
 
865
875
  return SeedSequenceData(
866
876
  _mktshr_rng_seed_seq, _pcm_rng_seed_seq, _fcount_rng_seed_seq, _pr_rng_seed_seq
mergeron/gen/upp_tests.py CHANGED
@@ -26,7 +26,7 @@ from .. import ( # noqa
26
26
  )
27
27
  from ..core import guidelines_boundaries as gbl # noqa: TID252
28
28
  from . import (
29
- EMPTY_ARRAY_DEFAULT,
29
+ DEFAULT_EMPTY_ARRAY,
30
30
  DataclassInstance,
31
31
  INVResolution,
32
32
  MarketDataSample,
@@ -38,9 +38,6 @@ from . import enforcement_stats as esl
38
38
 
39
39
  __version__ = VERSION
40
40
 
41
- ptb.parameters.MAX_NUMEXPR_THREADS = 8
42
- ptb.parameters.MAX_BLOSC_THREADS = 4
43
-
44
41
  type SaveData = Literal[False] | tuple[Literal[True], ptb.File, ptb.Group]
45
42
 
46
43
 
@@ -48,7 +45,7 @@ class INVRESCntsArgs(TypedDict, total=False):
48
45
  "Keyword arguments of function, :code:`sim_enf_cnts`"
49
46
 
50
47
  sample_size: int
51
- seed_seq_list: list[SeedSequence] | None
48
+ seed_seq_list: Sequence[SeedSequence] | None
52
49
  nthreads: int
53
50
  save_data_to_file: SaveData
54
51
  saved_array_name_suffix: str
@@ -282,7 +279,7 @@ def _compute_test_array_seq(
282
279
  UPPAggrSelector.OSA,
283
280
  UPPAggrSelector.OSD,
284
281
  )
285
- else EMPTY_ARRAY_DEFAULT
282
+ else DEFAULT_EMPTY_ARRAY
286
283
  )
287
284
 
288
285
  match _aggregator:
@@ -335,10 +332,10 @@ def initialize_hd5(
335
332
  if _h5_path.is_file():
336
333
  _h5_path.unlink()
337
334
  _h5_file = ptb.open_file(_h5_path, mode="w", title=_h5_title)
338
- _save_data_to_file: tuple[Literal[True], ptb.File, str] = (True, _h5_file, "/")
335
+ _save_data_to_file: SaveData = (True, _h5_file, _h5_file.root)
339
336
  _next_subgroup_name_root = "enf_{}_{}_{}_{}".format(
340
337
  _hmg_pub_year,
341
- *(getattr(_test_regime, _f.name).name for _f in _test_regime.__attrs_attrs__),
338
+ *(getattr(_test_regime, _f.name).name for _f in _test_regime.__attrs_attrs__), # pyright: ignore
342
339
  )
343
340
  return _save_data_to_file, _next_subgroup_name_root
344
341
 
@@ -386,7 +383,7 @@ def save_array_to_hdf5(
386
383
  _h5_array_name,
387
384
  atom=ptb.Atom.from_dtype(_array_obj.dtype),
388
385
  shape=_array_obj.shape,
389
- filters=ptb.Filters(complevel=3, complib="blosc:lz4hc", fletcher32=True),
386
+ filters=ptb.Filters(complevel=3, complib="blosc:lz4hc", fletcher32=True), # pyright: ignore
390
387
  )
391
388
  _h5_array[:] = _array_obj
392
389