mergeron 2024.739097.4__py3-none-any.whl → 2024.739099.1__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/__init__.py +15 -1
- mergeron/core/damodaran_margin_data.py +3 -4
- mergeron/core/ftc_merger_investigations_data.py +8 -11
- mergeron/core/guidelines_boundaries.py +3 -4
- mergeron/core/guidelines_boundary_functions.py +5 -6
- mergeron/core/guidelines_boundary_functions_extra.py +2 -3
- mergeron/core/pseudorandom_numbers.py +5 -6
- mergeron/gen/__init__.py +37 -31
- mergeron/gen/_data_generation_functions.py +21 -22
- mergeron/gen/data_generation.py +5 -6
- mergeron/gen/enforcement_stats.py +125 -15
- mergeron/gen/upp_tests.py +17 -3
- {mergeron-2024.739097.4.dist-info → mergeron-2024.739099.1.dist-info}/METADATA +1 -24
- {mergeron-2024.739097.4.dist-info → mergeron-2024.739099.1.dist-info}/RECORD +15 -19
- mergeron/ext/__init__.py +0 -3
- mergeron/ext/proportions_tests.py +0 -518
- mergeron/ext/tol_colors.py +0 -848
- mergeron/ext/xlsxw_helper.py +0 -631
- {mergeron-2024.739097.4.dist-info → mergeron-2024.739099.1.dist-info}/WHEEL +0 -0
mergeron/__init__.py
CHANGED
|
@@ -2,12 +2,14 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import enum
|
|
4
4
|
from pathlib import Path
|
|
5
|
+
from typing import TypeAlias, TypeVar
|
|
5
6
|
|
|
6
7
|
import numpy as np
|
|
8
|
+
from numpy.typing import NBitBase, NDArray
|
|
7
9
|
|
|
8
10
|
_PKG_NAME: str = Path(__file__).parent.stem
|
|
9
11
|
|
|
10
|
-
VERSION = "2024.
|
|
12
|
+
VERSION = "2024.739099.1"
|
|
11
13
|
|
|
12
14
|
__version__ = VERSION
|
|
13
15
|
|
|
@@ -24,6 +26,18 @@ if not DATA_DIR.is_dir():
|
|
|
24
26
|
np.set_printoptions(precision=18)
|
|
25
27
|
|
|
26
28
|
|
|
29
|
+
TI = TypeVar("TI", bound=NBitBase)
|
|
30
|
+
ArrayINT = NDArray[np.integer[TI]]
|
|
31
|
+
TF = TypeVar("TF", bound=NBitBase)
|
|
32
|
+
ArrayFloat = NDArray[np.floating[TF]]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
ArrayBoolean: TypeAlias = NDArray[np.bool_]
|
|
36
|
+
|
|
37
|
+
ArrayDouble: TypeAlias = NDArray[np.float64]
|
|
38
|
+
ArrayBIGINT: TypeAlias = NDArray[np.int64]
|
|
39
|
+
|
|
40
|
+
|
|
27
41
|
@enum.unique
|
|
28
42
|
class RECConstants(enum.StrEnum):
|
|
29
43
|
"""Recapture rate - derivation methods."""
|
|
@@ -43,11 +43,10 @@ import msgpack # type:ignore
|
|
|
43
43
|
import numpy as np
|
|
44
44
|
import urllib3
|
|
45
45
|
from numpy.random import PCG64DXSM, Generator, SeedSequence
|
|
46
|
-
from numpy.typing import NDArray
|
|
47
46
|
from scipy import stats # type: ignore
|
|
48
47
|
from xlrd import open_workbook # type: ignore
|
|
49
48
|
|
|
50
|
-
from .. import _PKG_NAME, DATA_DIR, VERSION # noqa: TID252
|
|
49
|
+
from .. import _PKG_NAME, DATA_DIR, VERSION, ArrayDouble # noqa: TID252
|
|
51
50
|
|
|
52
51
|
__version__ = VERSION
|
|
53
52
|
|
|
@@ -137,7 +136,7 @@ def mgn_data_getter( # noqa: PLR0912
|
|
|
137
136
|
|
|
138
137
|
def mgn_data_builder(
|
|
139
138
|
_mgn_tbl_dict: Mapping[str, Mapping[str, float | int]] | None = None, /
|
|
140
|
-
) -> tuple[
|
|
139
|
+
) -> tuple[ArrayDouble, ArrayDouble, ArrayDouble]:
|
|
141
140
|
if _mgn_tbl_dict is None:
|
|
142
141
|
_mgn_tbl_dict = mgn_data_getter()
|
|
143
142
|
|
|
@@ -190,7 +189,7 @@ def mgn_data_resampler(
|
|
|
190
189
|
/,
|
|
191
190
|
*,
|
|
192
191
|
seed_sequence: SeedSequence | None = None,
|
|
193
|
-
) ->
|
|
192
|
+
) -> ArrayDouble:
|
|
194
193
|
"""
|
|
195
194
|
Generate draws from the empirical distribution bassed on Prof. Damodaran's margin data.
|
|
196
195
|
|
|
@@ -23,9 +23,8 @@ import re2 as re # type: ignore
|
|
|
23
23
|
import urllib3
|
|
24
24
|
from bs4 import BeautifulSoup
|
|
25
25
|
from numpy.testing import assert_array_equal
|
|
26
|
-
from numpy.typing import NDArray
|
|
27
26
|
|
|
28
|
-
from .. import _PKG_NAME, DATA_DIR, VERSION # noqa: TID252
|
|
27
|
+
from .. import _PKG_NAME, DATA_DIR, VERSION, ArrayBIGINT # noqa: TID252
|
|
29
28
|
|
|
30
29
|
__version__ = VERSION
|
|
31
30
|
|
|
@@ -93,7 +92,7 @@ CNT_FCOUNT_DICT = {
|
|
|
93
92
|
class INVTableData(NamedTuple):
|
|
94
93
|
industry_group: str
|
|
95
94
|
additional_evidence: str
|
|
96
|
-
data_array:
|
|
95
|
+
data_array: ArrayBIGINT
|
|
97
96
|
|
|
98
97
|
|
|
99
98
|
INVData: TypeAlias = Mapping[str, dict[str, dict[str, INVTableData]]]
|
|
@@ -585,12 +584,12 @@ def _identify_table_type(_tnstr: str = CONC_TABLE_ALL, /) -> tuple[str, int, str
|
|
|
585
584
|
|
|
586
585
|
def _process_table_blks_conc_type(
|
|
587
586
|
_table_blocks: Sequence[Sequence[str]], /
|
|
588
|
-
) ->
|
|
587
|
+
) -> ArrayBIGINT:
|
|
589
588
|
_conc_row_pat = re.compile(r"((?:0|\d,\d{3}) (?:- \d+,\d{3}|\+)|TOTAL)")
|
|
590
589
|
|
|
591
590
|
_col_titles_array = tuple(CONC_DELTA_DICT.values())
|
|
592
|
-
_col_totals:
|
|
593
|
-
_invdata_array:
|
|
591
|
+
_col_totals: ArrayBIGINT = np.zeros(len(_col_titles_array), np.int64)
|
|
592
|
+
_invdata_array: ArrayBIGINT = np.array(None)
|
|
594
593
|
|
|
595
594
|
for _tbl_blk in _table_blocks:
|
|
596
595
|
if _conc_row_pat.match(_blk_str := _tbl_blk[-3]):
|
|
@@ -642,13 +641,11 @@ def _process_table_blks_conc_type(
|
|
|
642
641
|
|
|
643
642
|
def _process_table_blks_cnt_type(
|
|
644
643
|
_table_blocks: Sequence[Sequence[str]], /
|
|
645
|
-
) ->
|
|
644
|
+
) -> ArrayBIGINT:
|
|
646
645
|
_cnt_row_pat = re.compile(r"(\d+ (?:to \d+|\+)|TOTAL)")
|
|
647
646
|
|
|
648
|
-
_invdata_array:
|
|
649
|
-
_col_totals:
|
|
650
|
-
3, np.int64
|
|
651
|
-
) # "enforced", "closed", "total"
|
|
647
|
+
_invdata_array: ArrayBIGINT = np.array(None)
|
|
648
|
+
_col_totals: ArrayBIGINT = np.zeros(3, np.int64) # "enforced", "closed", "total"
|
|
652
649
|
|
|
653
650
|
for _tbl_blk in _table_blocks:
|
|
654
651
|
if _cnt_row_pat.match(_blk_str := _tbl_blk[-3]):
|
|
@@ -12,9 +12,8 @@ from typing import Literal, TypeAlias
|
|
|
12
12
|
import numpy as np
|
|
13
13
|
from attrs import Attribute, field, frozen, validators
|
|
14
14
|
from mpmath import mp, mpf # type: ignore
|
|
15
|
-
from numpy.typing import NDArray
|
|
16
15
|
|
|
17
|
-
from .. import VERSION, RECConstants, UPPAggrSelector # noqa: TID252
|
|
16
|
+
from .. import VERSION, ArrayDouble, RECConstants, UPPAggrSelector # noqa: TID252
|
|
18
17
|
from . import guidelines_boundary_functions as gbfn
|
|
19
18
|
|
|
20
19
|
__version__ = VERSION
|
|
@@ -191,7 +190,7 @@ class ConcentrationBoundary:
|
|
|
191
190
|
validator=(validators.instance_of(str), _concentration_measure_name_validator),
|
|
192
191
|
)
|
|
193
192
|
|
|
194
|
-
coordinates:
|
|
193
|
+
coordinates: ArrayDouble = field(init=False, kw_only=True)
|
|
195
194
|
"""Market-share pairs as Cartesian coordinates of points on the concentration boundary."""
|
|
196
195
|
|
|
197
196
|
area: float = field(init=False, kw_only=True)
|
|
@@ -321,7 +320,7 @@ class DiversionRatioBoundary:
|
|
|
321
320
|
|
|
322
321
|
"""
|
|
323
322
|
|
|
324
|
-
coordinates:
|
|
323
|
+
coordinates: ArrayDouble = field(init=False, kw_only=True)
|
|
325
324
|
"""Market-share pairs as Cartesian coordinates of points on the diversion ratio boundary."""
|
|
326
325
|
|
|
327
326
|
area: float = field(init=False, kw_only=True)
|
|
@@ -4,9 +4,8 @@ from typing import Any, Literal, TypedDict
|
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
from mpmath import mp, mpf # type: ignore
|
|
7
|
-
from numpy.typing import NDArray
|
|
8
7
|
|
|
9
|
-
from .. import VERSION # noqa: TID252
|
|
8
|
+
from .. import VERSION, ArrayBIGINT, ArrayDouble # noqa: TID252
|
|
10
9
|
|
|
11
10
|
__version__ = VERSION
|
|
12
11
|
|
|
@@ -27,7 +26,7 @@ class ShareRatioBoundaryKeywords(TypedDict, total=False):
|
|
|
27
26
|
class GuidelinesBoundary:
|
|
28
27
|
"""Output of a Guidelines boundary function."""
|
|
29
28
|
|
|
30
|
-
coordinates:
|
|
29
|
+
coordinates: ArrayDouble
|
|
31
30
|
"""Market-share pairs as Cartesian coordinates of points on the boundary."""
|
|
32
31
|
|
|
33
32
|
area: float
|
|
@@ -718,11 +717,11 @@ def _shrratio_boundary_intcpt(
|
|
|
718
717
|
|
|
719
718
|
|
|
720
719
|
def lerp(
|
|
721
|
-
_x1: int | float | mpf |
|
|
722
|
-
_x2: int | float | mpf |
|
|
720
|
+
_x1: int | float | mpf | ArrayDouble | ArrayBIGINT = 3,
|
|
721
|
+
_x2: int | float | mpf | ArrayDouble | ArrayBIGINT = 1,
|
|
723
722
|
_r: float | mpf = 0.25,
|
|
724
723
|
/,
|
|
725
|
-
) -> float | mpf |
|
|
724
|
+
) -> float | mpf | ArrayDouble:
|
|
726
725
|
"""
|
|
727
726
|
From the function of the same name in the C++ standard [2]_
|
|
728
727
|
|
|
@@ -13,11 +13,10 @@ from typing import Literal
|
|
|
13
13
|
|
|
14
14
|
import numpy as np
|
|
15
15
|
from mpmath import mp, mpf # type: ignore
|
|
16
|
-
from numpy.typing import NDArray
|
|
17
16
|
from scipy.spatial.distance import minkowski as distance_function # type: ignore
|
|
18
17
|
from sympy import lambdify, simplify, solve, symbols # type: ignore
|
|
19
18
|
|
|
20
|
-
from .. import VERSION # noqa: TID252
|
|
19
|
+
from .. import VERSION, ArrayDouble # noqa: TID252
|
|
21
20
|
from .guidelines_boundary_functions import (
|
|
22
21
|
GuidelinesBoundary,
|
|
23
22
|
_shrratio_boundary_intcpt,
|
|
@@ -33,7 +32,7 @@ mp.trap_complex = True
|
|
|
33
32
|
|
|
34
33
|
@dataclass(slots=True, frozen=True)
|
|
35
34
|
class GuidelinesBoundaryCallable:
|
|
36
|
-
boundary_function: Callable[[
|
|
35
|
+
boundary_function: Callable[[ArrayDouble], ArrayDouble]
|
|
37
36
|
area: float
|
|
38
37
|
s_naught: float = 0
|
|
39
38
|
|
|
@@ -13,9 +13,8 @@ from typing import Literal
|
|
|
13
13
|
|
|
14
14
|
import numpy as np
|
|
15
15
|
from numpy.random import PCG64DXSM, Generator, SeedSequence
|
|
16
|
-
from numpy.typing import NDArray
|
|
17
16
|
|
|
18
|
-
from .. import VERSION # noqa: TID252
|
|
17
|
+
from .. import VERSION, ArrayDouble # noqa: TID252
|
|
19
18
|
|
|
20
19
|
__version__ = VERSION
|
|
21
20
|
|
|
@@ -134,13 +133,13 @@ class MultithreadedRNG:
|
|
|
134
133
|
|
|
135
134
|
def __init__(
|
|
136
135
|
self,
|
|
137
|
-
_out_array:
|
|
136
|
+
_out_array: ArrayDouble,
|
|
138
137
|
/,
|
|
139
138
|
*,
|
|
140
139
|
dist_type: Literal[
|
|
141
140
|
"Beta", "Dirichlet", "Gaussian", "Normal", "Random", "Uniform"
|
|
142
141
|
] = "Uniform",
|
|
143
|
-
dist_parms:
|
|
142
|
+
dist_parms: ArrayDouble | None = DIST_PARMS_DEFAULT,
|
|
144
143
|
seed_sequence: SeedSequence | None = None,
|
|
145
144
|
nthreads: int = NTHREADS,
|
|
146
145
|
):
|
|
@@ -206,8 +205,8 @@ class MultithreadedRNG:
|
|
|
206
205
|
def _fill(
|
|
207
206
|
_rng: np.random.Generator,
|
|
208
207
|
_dist_type: str,
|
|
209
|
-
_dist_parms:
|
|
210
|
-
_out:
|
|
208
|
+
_dist_parms: ArrayDouble,
|
|
209
|
+
_out: ArrayDouble,
|
|
211
210
|
_first: int,
|
|
212
211
|
_last: int,
|
|
213
212
|
/,
|
mergeron/gen/__init__.py
CHANGED
|
@@ -11,9 +11,15 @@ from typing import ClassVar, Protocol
|
|
|
11
11
|
|
|
12
12
|
import numpy as np
|
|
13
13
|
from attrs import Attribute, cmp_using, define, field, frozen, validators
|
|
14
|
-
from numpy.typing import NDArray
|
|
15
14
|
|
|
16
|
-
from .. import
|
|
15
|
+
from .. import ( # noqa: TID252
|
|
16
|
+
VERSION,
|
|
17
|
+
ArrayBIGINT,
|
|
18
|
+
ArrayBoolean,
|
|
19
|
+
ArrayDouble,
|
|
20
|
+
RECConstants,
|
|
21
|
+
UPPAggrSelector,
|
|
22
|
+
)
|
|
17
23
|
from ..core.pseudorandom_numbers import DIST_PARMS_DEFAULT # noqa: TID252
|
|
18
24
|
|
|
19
25
|
__version__ = VERSION
|
|
@@ -128,7 +134,7 @@ class ShareSpec:
|
|
|
128
134
|
dist_type: SHRConstants
|
|
129
135
|
"""See :class:`SHRConstants`"""
|
|
130
136
|
|
|
131
|
-
dist_parms:
|
|
137
|
+
dist_parms: ArrayDouble | None = field(
|
|
132
138
|
default=None, eq=cmp_using(eq=np.array_equal)
|
|
133
139
|
)
|
|
134
140
|
"""Parameters for tailoring market-share distribution
|
|
@@ -139,9 +145,9 @@ class ShareSpec:
|
|
|
139
145
|
type of Dirichlet-distribution specified.
|
|
140
146
|
|
|
141
147
|
"""
|
|
142
|
-
firm_counts_weights:
|
|
143
|
-
|
|
144
|
-
)
|
|
148
|
+
firm_counts_weights: (
|
|
149
|
+
ArrayDouble | ArrayBIGINT | ArrayDouble | ArrayBIGINT | None
|
|
150
|
+
) = field(default=None, eq=cmp_using(eq=np.array_equal))
|
|
145
151
|
"""Relative or absolute frequencies of firm counts
|
|
146
152
|
|
|
147
153
|
|
|
@@ -193,7 +199,7 @@ class PCMSpec:
|
|
|
193
199
|
dist_type: PCMConstants
|
|
194
200
|
"""See :class:`PCMConstants`"""
|
|
195
201
|
|
|
196
|
-
dist_parms:
|
|
202
|
+
dist_parms: ArrayDouble | None
|
|
197
203
|
"""Parameter specification for tailoring PCM distribution
|
|
198
204
|
|
|
199
205
|
For Uniform distribution, bounds of the distribution; defaults to `(0, 1)`;
|
|
@@ -356,39 +362,39 @@ class MarketSpec:
|
|
|
356
362
|
class MarketDataSample:
|
|
357
363
|
"""Container for generated markets data sample."""
|
|
358
364
|
|
|
359
|
-
frmshr_array:
|
|
365
|
+
frmshr_array: ArrayDouble
|
|
360
366
|
"""Merging-firm shares (with two merging firms)"""
|
|
361
367
|
|
|
362
|
-
pcm_array:
|
|
368
|
+
pcm_array: ArrayDouble
|
|
363
369
|
"""Merging-firms' prices (normalized to 1, in default specification)"""
|
|
364
370
|
|
|
365
|
-
price_array:
|
|
371
|
+
price_array: ArrayDouble
|
|
366
372
|
"""Merging-firms' price-cost margins (PCM)"""
|
|
367
373
|
|
|
368
|
-
fcounts:
|
|
374
|
+
fcounts: ArrayBIGINT
|
|
369
375
|
"""Number of firms in market"""
|
|
370
376
|
|
|
371
|
-
aggregate_purchase_prob:
|
|
377
|
+
aggregate_purchase_prob: ArrayDouble
|
|
372
378
|
"""
|
|
373
379
|
One (1) minus probability that the outside good is chosen
|
|
374
380
|
|
|
375
381
|
Converts market shares to choice probabilities by multiplication.
|
|
376
382
|
"""
|
|
377
383
|
|
|
378
|
-
nth_firm_share:
|
|
384
|
+
nth_firm_share: ArrayDouble
|
|
379
385
|
"""Market-share of n-th firm
|
|
380
386
|
|
|
381
387
|
Relevant for testing for draws the do or
|
|
382
388
|
do not meet HSR filing thresholds.
|
|
383
389
|
"""
|
|
384
390
|
|
|
385
|
-
divr_array:
|
|
391
|
+
divr_array: ArrayDouble
|
|
386
392
|
"""Diversion ratio between the merging firms"""
|
|
387
393
|
|
|
388
|
-
hhi_post:
|
|
394
|
+
hhi_post: ArrayDouble
|
|
389
395
|
"""Post-merger change in Herfindahl-Hirschmann Index (HHI)"""
|
|
390
396
|
|
|
391
|
-
hhi_delta:
|
|
397
|
+
hhi_delta: ArrayDouble
|
|
392
398
|
"""Change in HHI from combination of merging firms"""
|
|
393
399
|
|
|
394
400
|
|
|
@@ -400,16 +406,16 @@ class ShareDataSample:
|
|
|
400
406
|
and aggregate purchase probability.
|
|
401
407
|
"""
|
|
402
408
|
|
|
403
|
-
mktshr_array:
|
|
409
|
+
mktshr_array: ArrayDouble
|
|
404
410
|
"""All-firm shares (with two merging firms)"""
|
|
405
411
|
|
|
406
|
-
fcounts:
|
|
412
|
+
fcounts: ArrayBIGINT
|
|
407
413
|
"""All-firm-count for each draw"""
|
|
408
414
|
|
|
409
|
-
nth_firm_share:
|
|
415
|
+
nth_firm_share: ArrayDouble
|
|
410
416
|
"""Market-share of n-th firm"""
|
|
411
417
|
|
|
412
|
-
aggregate_purchase_prob:
|
|
418
|
+
aggregate_purchase_prob: ArrayDouble
|
|
413
419
|
"""Converts market shares to choice probabilities by multiplication."""
|
|
414
420
|
|
|
415
421
|
|
|
@@ -417,10 +423,10 @@ class ShareDataSample:
|
|
|
417
423
|
class PriceDataSample:
|
|
418
424
|
"""Container for generated price array, and related."""
|
|
419
425
|
|
|
420
|
-
price_array:
|
|
426
|
+
price_array: ArrayDouble
|
|
421
427
|
"""Merging-firms' prices"""
|
|
422
428
|
|
|
423
|
-
hsr_filing_test:
|
|
429
|
+
hsr_filing_test: ArrayBoolean
|
|
424
430
|
"""Flags draws as meeting HSR filing thresholds or not"""
|
|
425
431
|
|
|
426
432
|
|
|
@@ -428,10 +434,10 @@ class PriceDataSample:
|
|
|
428
434
|
class MarginDataSample:
|
|
429
435
|
"""Container for generated margin array and related MNL test array."""
|
|
430
436
|
|
|
431
|
-
pcm_array:
|
|
437
|
+
pcm_array: ArrayDouble
|
|
432
438
|
"""Merging-firms' PCMs"""
|
|
433
439
|
|
|
434
|
-
mnl_test_array:
|
|
440
|
+
mnl_test_array: ArrayBoolean
|
|
435
441
|
"""Flags infeasible observations as False and rest as True
|
|
436
442
|
|
|
437
443
|
Applying restrictions from Bertrand-Nash oligopoly
|
|
@@ -476,18 +482,18 @@ class UPPTestsRaw:
|
|
|
476
482
|
:func:`enforcement_stats.gen_upp_arrays`.
|
|
477
483
|
"""
|
|
478
484
|
|
|
479
|
-
guppi_test_simple:
|
|
485
|
+
guppi_test_simple: ArrayBoolean
|
|
480
486
|
"""True if GUPPI estimate meets criterion"""
|
|
481
487
|
|
|
482
|
-
guppi_test_compound:
|
|
488
|
+
guppi_test_compound: ArrayBoolean
|
|
483
489
|
"""True if both GUPPI estimate and diversion ratio estimate
|
|
484
490
|
meet criterion
|
|
485
491
|
"""
|
|
486
492
|
|
|
487
|
-
cmcr_test:
|
|
493
|
+
cmcr_test: ArrayBoolean
|
|
488
494
|
"""True if CMCR estimate meets criterion"""
|
|
489
495
|
|
|
490
|
-
ipr_test:
|
|
496
|
+
ipr_test: ArrayBoolean
|
|
491
497
|
"""True if IPR (partial price-simulation) estimate meets criterion"""
|
|
492
498
|
|
|
493
499
|
|
|
@@ -498,9 +504,9 @@ class UPPTestsCounts:
|
|
|
498
504
|
Resolution may be either :attr:`INVResolution.ENFT` or :attr:`INVResolution.CLRN`.
|
|
499
505
|
"""
|
|
500
506
|
|
|
501
|
-
by_firm_count:
|
|
502
|
-
by_delta:
|
|
503
|
-
by_conczone:
|
|
507
|
+
by_firm_count: ArrayBIGINT
|
|
508
|
+
by_delta: ArrayBIGINT
|
|
509
|
+
by_conczone: ArrayBIGINT
|
|
504
510
|
"""Zones are "unoncentrated", "moderately concentrated", and "highly concentrated"
|
|
505
511
|
"""
|
|
506
512
|
|
|
@@ -9,9 +9,8 @@ from typing import Literal
|
|
|
9
9
|
import numpy as np
|
|
10
10
|
from attrs import evolve
|
|
11
11
|
from numpy.random import SeedSequence
|
|
12
|
-
from numpy.typing import NDArray
|
|
13
12
|
|
|
14
|
-
from .. import VERSION, RECConstants # noqa: TID252
|
|
13
|
+
from .. import VERSION, ArrayBIGINT, ArrayDouble, RECConstants # noqa: TID252
|
|
15
14
|
from ..core.damodaran_margin_data import mgn_data_resampler # noqa: TID252
|
|
16
15
|
from ..core.pseudorandom_numbers import ( # noqa: TID252
|
|
17
16
|
DIST_PARMS_DEFAULT,
|
|
@@ -112,7 +111,7 @@ def _gen_share_data(
|
|
|
112
111
|
|
|
113
112
|
def _gen_market_shares_uniform(
|
|
114
113
|
_s_size: int = 10**6,
|
|
115
|
-
_dist_parms_mktshr:
|
|
114
|
+
_dist_parms_mktshr: ArrayDouble | None = DIST_PARMS_DEFAULT,
|
|
116
115
|
_mktshr_rng_seed_seq: SeedSequence | None = None,
|
|
117
116
|
_nthreads: int = 16,
|
|
118
117
|
/,
|
|
@@ -137,7 +136,7 @@ def _gen_market_shares_uniform(
|
|
|
137
136
|
"""
|
|
138
137
|
|
|
139
138
|
_frmshr_array = np.empty((_s_size, 2), dtype=np.float64)
|
|
140
|
-
_dist_parms_mktshr:
|
|
139
|
+
_dist_parms_mktshr: ArrayDouble = (
|
|
141
140
|
DIST_PARMS_DEFAULT if _dist_parms_mktshr is None else _dist_parms_mktshr
|
|
142
141
|
)
|
|
143
142
|
_mrng = MultithreadedRNG(
|
|
@@ -163,7 +162,7 @@ def _gen_market_shares_uniform(
|
|
|
163
162
|
_frmshr_array, ((0, 0), (0, 1)), "constant", constant_values=np.nan
|
|
164
163
|
)
|
|
165
164
|
|
|
166
|
-
_fcounts:
|
|
165
|
+
_fcounts: ArrayBIGINT = np.ones((_s_size, 1), np.int64) * np.nan # type: ignore
|
|
167
166
|
_nth_firm_share, _aggregate_purchase_prob = (
|
|
168
167
|
np.nan * np.ones((_s_size, 1), np.float64) for _ in range(2)
|
|
169
168
|
)
|
|
@@ -177,8 +176,8 @@ def _gen_market_shares_dirichlet_multisample(
|
|
|
177
176
|
_s_size: int = 10**6,
|
|
178
177
|
_recapture_form: RECConstants = RECConstants.INOUT,
|
|
179
178
|
_dist_type_dir: SHRConstants = SHRConstants.DIR_FLAT,
|
|
180
|
-
_dist_parms_dir:
|
|
181
|
-
_firm_count_wts:
|
|
179
|
+
_dist_parms_dir: ArrayDouble | None = None,
|
|
180
|
+
_firm_count_wts: ArrayDouble | None = None,
|
|
182
181
|
_fcount_rng_seed_seq: SeedSequence | None = None,
|
|
183
182
|
_mktshr_rng_seed_seq: SeedSequence | None = None,
|
|
184
183
|
_nthreads: int = 16,
|
|
@@ -216,7 +215,7 @@ def _gen_market_shares_dirichlet_multisample(
|
|
|
216
215
|
|
|
217
216
|
"""
|
|
218
217
|
|
|
219
|
-
_firm_count_wts:
|
|
218
|
+
_firm_count_wts: ArrayDouble = (
|
|
220
219
|
FCOUNT_WTS_DEFAULT if _firm_count_wts is None else _firm_count_wts
|
|
221
220
|
)
|
|
222
221
|
|
|
@@ -243,7 +242,7 @@ def _gen_market_shares_dirichlet_multisample(
|
|
|
243
242
|
|
|
244
243
|
if _dist_type_dir == SHRConstants.DIR_COND:
|
|
245
244
|
|
|
246
|
-
def _gen_dir_alphas(_fcv: int) ->
|
|
245
|
+
def _gen_dir_alphas(_fcv: int) -> ArrayDouble:
|
|
247
246
|
_dat = [2.5] * 2
|
|
248
247
|
if _fcv > len(_dat):
|
|
249
248
|
_dat += [1.0 / (_fcv - 2)] * (_fcv - 2)
|
|
@@ -251,7 +250,7 @@ def _gen_market_shares_dirichlet_multisample(
|
|
|
251
250
|
|
|
252
251
|
else:
|
|
253
252
|
|
|
254
|
-
def _gen_dir_alphas(_fcv: int) ->
|
|
253
|
+
def _gen_dir_alphas(_fcv: int) -> ArrayDouble:
|
|
255
254
|
return np.array(_dir_alphas_full[:_fcv], dtype=np.float64) # type: ignore
|
|
256
255
|
|
|
257
256
|
_fcounts = prng(_fcount_rng_seed_seq).choice(
|
|
@@ -312,7 +311,7 @@ def _gen_market_shares_dirichlet_multisample(
|
|
|
312
311
|
|
|
313
312
|
|
|
314
313
|
def _gen_market_shares_dirichlet(
|
|
315
|
-
_dir_alphas:
|
|
314
|
+
_dir_alphas: ArrayDouble,
|
|
316
315
|
_s_size: int = 10**6,
|
|
317
316
|
_recapture_form: RECConstants = RECConstants.INOUT,
|
|
318
317
|
_mktshr_rng_seed_seq: SeedSequence | None = None,
|
|
@@ -394,9 +393,9 @@ def _gen_market_shares_dirichlet(
|
|
|
394
393
|
|
|
395
394
|
|
|
396
395
|
def _gen_margin_price_data(
|
|
397
|
-
_frmshr_array:
|
|
398
|
-
_nth_firm_share:
|
|
399
|
-
_aggregate_purchase_prob:
|
|
396
|
+
_frmshr_array: ArrayDouble,
|
|
397
|
+
_nth_firm_share: ArrayDouble,
|
|
398
|
+
_aggregate_purchase_prob: ArrayDouble,
|
|
400
399
|
_pcm_spec: PCMSpec,
|
|
401
400
|
_price_spec: PriceConstants,
|
|
402
401
|
_hsr_filing_test_type: SSZConstants,
|
|
@@ -543,8 +542,8 @@ def _gen_margin_price_data(
|
|
|
543
542
|
|
|
544
543
|
# marked for deletion
|
|
545
544
|
def _gen_price_data(
|
|
546
|
-
_frmshr_array:
|
|
547
|
-
_nth_firm_share:
|
|
545
|
+
_frmshr_array: ArrayDouble,
|
|
546
|
+
_nth_firm_share: ArrayDouble,
|
|
548
547
|
_price_spec: PriceConstants,
|
|
549
548
|
_hsr_filing_test_type: SSZConstants,
|
|
550
549
|
_seed_seq: SeedSequence | None = None,
|
|
@@ -630,9 +629,9 @@ def _gen_price_data(
|
|
|
630
629
|
|
|
631
630
|
|
|
632
631
|
def _gen_margin_data(
|
|
633
|
-
_frmshr_array:
|
|
634
|
-
_price_array:
|
|
635
|
-
_aggregate_purchase_prob:
|
|
632
|
+
_frmshr_array: ArrayDouble,
|
|
633
|
+
_price_array: ArrayDouble,
|
|
634
|
+
_aggregate_purchase_prob: ArrayDouble,
|
|
636
635
|
_pcm_spec: PCMSpec,
|
|
637
636
|
_pcm_rng_seed_seq: SeedSequence,
|
|
638
637
|
_nthreads: int = 16,
|
|
@@ -719,8 +718,8 @@ def _gen_margin_data(
|
|
|
719
718
|
|
|
720
719
|
|
|
721
720
|
def _beta_located(
|
|
722
|
-
_mu: float |
|
|
723
|
-
) ->
|
|
721
|
+
_mu: float | ArrayDouble, _sigma: float | ArrayDouble, /
|
|
722
|
+
) -> ArrayDouble:
|
|
724
723
|
"""
|
|
725
724
|
Given mean and stddev, return shape parameters for corresponding Beta distribution
|
|
726
725
|
|
|
@@ -743,7 +742,7 @@ def _beta_located(
|
|
|
743
742
|
return np.array([_mu * _mul, (1 - _mu) * _mul], dtype=np.float64)
|
|
744
743
|
|
|
745
744
|
|
|
746
|
-
def beta_located_bound(_dist_parms:
|
|
745
|
+
def beta_located_bound(_dist_parms: ArrayDouble, /) -> ArrayDouble:
|
|
747
746
|
R"""
|
|
748
747
|
Return shape parameters for a non-standard beta, given the mean, stddev, range
|
|
749
748
|
|
mergeron/gen/data_generation.py
CHANGED
|
@@ -10,9 +10,8 @@ from typing import NamedTuple
|
|
|
10
10
|
|
|
11
11
|
import numpy as np
|
|
12
12
|
from numpy.random import SeedSequence
|
|
13
|
-
from numpy.typing import NDArray
|
|
14
13
|
|
|
15
|
-
from .. import VERSION, RECConstants # noqa: TID252
|
|
14
|
+
from .. import VERSION, ArrayDouble, RECConstants # noqa: TID252
|
|
16
15
|
from . import (
|
|
17
16
|
EMPTY_ARRAY_DEFAULT,
|
|
18
17
|
FM2Constants,
|
|
@@ -227,10 +226,10 @@ def parse_seed_seq_list(
|
|
|
227
226
|
def gen_divr_array(
|
|
228
227
|
_recapture_form: RECConstants,
|
|
229
228
|
_recapture_rate: float | None,
|
|
230
|
-
_frmshr_array:
|
|
231
|
-
_aggregate_purchase_prob:
|
|
229
|
+
_frmshr_array: ArrayDouble,
|
|
230
|
+
_aggregate_purchase_prob: ArrayDouble = EMPTY_ARRAY_DEFAULT,
|
|
232
231
|
/,
|
|
233
|
-
) ->
|
|
232
|
+
) -> ArrayDouble:
|
|
234
233
|
"""
|
|
235
234
|
Given merging-firm shares and related parameters, return diverion ratios.
|
|
236
235
|
|
|
@@ -259,7 +258,7 @@ def gen_divr_array(
|
|
|
259
258
|
|
|
260
259
|
"""
|
|
261
260
|
|
|
262
|
-
_divr_array:
|
|
261
|
+
_divr_array: ArrayDouble
|
|
263
262
|
if _recapture_form == RECConstants.FIXED:
|
|
264
263
|
_divr_array = _recapture_rate * _frmshr_array[:, ::-1] / (1 - _frmshr_array) # type: ignore
|
|
265
264
|
|