Preprocessing API¶
build_frequency_measures¶
mfdro.preprocessing.build_frequency_measures(daily_returns: pd.DataFrame, *, frequency_specs: Sequence[FrequencySpec] = DEFAULT_FREQUENCY_SPECS) -> dict[str, pd.DataFrame]
¶
Build an ordered mapping of base and compounded empirical measures.
Returns an insertion-ordered mapping whose first value is a validated copy of the base panel and whose later values are compounded measures.
Source code in src/mfdro/preprocessing.py
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 | |
compound_returns¶
mfdro.preprocessing.compound_returns(daily_returns: pd.DataFrame, rule: str, *, min_observations: int = 1, closed: Side | None = None, label: Side | None = None, origin: str = 'start_day', offset: str | None = None) -> pd.DataFrame
¶
Compound simple returns into non-overlapping calendar periods.
The final period may be incomplete, which is appropriate when the input ends on a point-in-time formation date. Empty calendar bins are removed; partially missing cross-sections are rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
daily_returns
|
DataFrame
|
Full daily simple-return panel. |
required |
rule
|
str
|
pandas offset alias such as |
required |
min_observations
|
int
|
Minimum base observations required per asset and bin. |
1
|
closed
|
Side | None
|
Explicit pandas resampling boundary conventions. |
None
|
label
|
Side | None
|
Explicit pandas resampling boundary conventions. |
None
|
origin
|
Side | None
|
Explicit pandas resampling boundary conventions. |
None
|
offset
|
Side | None
|
Explicit pandas resampling boundary conventions. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Compounded returns with the original asset order. |
Source code in src/mfdro/preprocessing.py
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 | |
validate_daily_returns¶
mfdro.preprocessing.validate_daily_returns(daily_returns: pd.DataFrame) -> pd.DataFrame
¶
Validate and copy a full, wide daily simple-return panel.
Raises :class:DataContractError for invalid dates, duplicate assets,
missing or non-finite values, and simple returns below -1.
Source code in src/mfdro/preprocessing.py
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 | |