r"""Run an analysis for a given model and group. First, the data are loaded for each member of the analysis group. Then, the target value is lagged for the ``forecast_period``, and any ``leaders`` are lagged as well. Each frame is split along the ``predict_date`` from the ``analysis
(analysis, lag_period, forecast_period, leaders,
predict_history, splits=True)
| 135 | # |
| 136 | |
| 137 | def run_analysis(analysis, lag_period, forecast_period, leaders, |
| 138 | predict_history, splits=True): |
| 139 | r"""Run an analysis for a given model and group. |
| 140 | |
| 141 | First, the data are loaded for each member of the analysis group. |
| 142 | Then, the target value is lagged for the ``forecast_period``, and |
| 143 | any ``leaders`` are lagged as well. Each frame is split along |
| 144 | the ``predict_date`` from the ``analysis``, and finally the |
| 145 | train and test files are generated. |
| 146 | |
| 147 | Parameters |
| 148 | ---------- |
| 149 | analysis : alphapy.Analysis |
| 150 | The analysis to run. |
| 151 | lag_period : int |
| 152 | The number of lagged features for the analysis. |
| 153 | forecast_period : int |
| 154 | The period for forecasting the target of the analysis. |
| 155 | leaders : list |
| 156 | The features that are contemporaneous with the target. |
| 157 | predict_history : int |
| 158 | The number of periods required for lookback calculations. |
| 159 | splits : bool, optional |
| 160 | If ``True``, then the data for each member of the analysis |
| 161 | group are in separate files. |
| 162 | |
| 163 | Returns |
| 164 | ------- |
| 165 | analysis : alphapy.Analysis |
| 166 | The completed analysis. |
| 167 | |
| 168 | """ |
| 169 | |
| 170 | # Unpack analysis |
| 171 | |
| 172 | name = analysis.name |
| 173 | model = analysis.model |
| 174 | group = analysis.group |
| 175 | |
| 176 | # Unpack model data |
| 177 | |
| 178 | predict_file = model.predict_file |
| 179 | test_file = model.test_file |
| 180 | train_file = model.train_file |
| 181 | |
| 182 | # Unpack model specifications |
| 183 | |
| 184 | directory = model.specs['directory'] |
| 185 | extension = model.specs['extension'] |
| 186 | predict_date = model.specs['predict_date'] |
| 187 | predict_mode = model.specs['predict_mode'] |
| 188 | separator = model.specs['separator'] |
| 189 | target = model.specs['target'] |
| 190 | train_date = model.specs['train_date'] |
| 191 | |
| 192 | # Calculate split date |
| 193 | logger.info("Analysis Dates") |
| 194 | split_date = subtract_days(predict_date, predict_history) |
no test coverage detected