Add intraday volatility risk research#81
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 24daf5f3df
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if intraday_close is None or intraday_close.empty: | ||
| return returns.copy(), pd.DataFrame() | ||
|
|
||
| pre_execution = _slot_pre_execution_returns(intraday_close, prices, slot).reindex(returns.index) |
There was a problem hiding this comment.
Skip dates with no intraday execution bar
When the return window extends beyond the 15-minute data coverage or has a missing session, this reindex creates an all-NaN row for every such date; the later fillna(0.0) then treats missing intraday prices as a flat pre-execution move and records turnover days as execution events with zero adjustment. This inflates the reported event counts and can silently dilute execution-timing results unless the caller happens to trim returns exactly to complete intraday coverage.
Useful? React with 👍 / 👎.
| if pre_execution.empty: | ||
| return returns.copy(), pd.DataFrame() | ||
|
|
||
| previous_weights = weights.shift(1).reindex(returns.index).fillna(0.0) |
There was a problem hiding this comment.
Preserve the prior weight at the start of a sliced window
For research windows that start after the backtest has already been running, weights has already been reindexed to returns.index, so the first row's shifted previous weight is filled as zero even if the strategy held a position on the prior trading day. The first intraday date is therefore treated as a new trade from cash, causing a spurious execution adjustment/event; compute the shift from the full normalized weight history before trimming to the return window, or keep the prior row when slicing.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 755522df22
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| normalized = pd.DataFrame( | ||
| { | ||
| "symbol": frame[symbol_column].astype(str).str.upper().str.strip(), | ||
| "time": pd.to_datetime(frame[time_column], errors="coerce").dt.tz_localize(None), |
There was a problem hiding this comment.
Handle timezone-aware IBKR timestamps before stripping tz
When the intraday CSV uses timezone-aware timestamps (the new research doc says the IBKR pulls used formatDate=2, which produces UTC-aware datetimes), this expression raises TypeError: Already tz-aware, use tz_convert to convert. before any research can run. The reproducible --hourly-prices / --intraday-15m-prices commands therefore fail on the documented IBKR files; parse with utc=True and then convert/drop the timezone, or branch between tz_convert(None) and tz_localize(None).
Useful? React with 👍 / 👎.
Summary
Validation
Note: pytest is not installed in the local venv, so I used direct invocation for the new focused tests.