split the score file into two part Parameter --------- pred : pd.DataFrame (index: ) A score file of stocks number: the number of dates for pred_left split_date: the last date of the pred_left Return ------- pred_left :
(pred, number=None, split_date=None)
| 504 | |
| 505 | |
| 506 | def split_pred(pred, number=None, split_date=None): |
| 507 | """split the score file into two part |
| 508 | Parameter |
| 509 | --------- |
| 510 | pred : pd.DataFrame (index:<instrument, datetime>) |
| 511 | A score file of stocks |
| 512 | number: the number of dates for pred_left |
| 513 | split_date: the last date of the pred_left |
| 514 | Return |
| 515 | ------- |
| 516 | pred_left : pd.DataFrame (index:<instrument, datetime>) |
| 517 | The first part of original score file |
| 518 | pred_right : pd.DataFrame (index:<instrument, datetime>) |
| 519 | The second part of original score file |
| 520 | """ |
| 521 | if number is None and split_date is None: |
| 522 | raise ValueError("`number` and `split date` cannot both be None") |
| 523 | dates = sorted(pred.index.get_level_values("datetime").unique()) |
| 524 | dates = list(map(pd.Timestamp, dates)) |
| 525 | if split_date is None: |
| 526 | date_left_end = dates[number - 1] |
| 527 | date_right_begin = dates[number] |
| 528 | date_left_start = None |
| 529 | else: |
| 530 | split_date = pd.Timestamp(split_date) |
| 531 | date_left_end = split_date |
| 532 | date_right_begin = split_date + pd.Timedelta(days=1) |
| 533 | if number is None: |
| 534 | date_left_start = None |
| 535 | else: |
| 536 | end_idx = bisect.bisect_right(dates, split_date) |
| 537 | date_left_start = dates[end_idx - number] |
| 538 | pred_temp = pred.sort_index() |
| 539 | pred_left = pred_temp.loc(axis=0)[:, date_left_start:date_left_end] |
| 540 | pred_right = pred_temp.loc(axis=0)[:, date_right_begin:] |
| 541 | return pred_left, pred_right |
| 542 | |
| 543 | |
| 544 | def time_to_slc_point(t: Union[None, str, pd.Timestamp]) -> Union[None, pd.Timestamp]: |
nothing calls this directly
no test coverage detected