Add preprocessing_contract.md
Browse files
preprocessing_contract.md
CHANGED
|
@@ -49,21 +49,23 @@ The convention, stated so you can check your vendor's numbers against it:
|
|
| 49 |
date before the ex-date, or that day's last bar if none is stamped that early. Pass a
|
| 50 |
`close_prior` column in the dividends table to override it. Dividends with
|
| 51 |
`amount ≥ close_prior` are skipped and the price is left under-adjusted.
|
| 52 |
-
- `amount` must be the cash per share
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
ratio.
|
| 56 |
- Two actions on the same ex-date are combined: dividend amounts are summed, split ratios
|
| 57 |
are multiplied.
|
| 58 |
- Actions dated on or before the first bar date have no effect. Actions dated on a day
|
| 59 |
with no bars (weekend, holiday, feed gap) still apply once, to every bar before that day.
|
| 60 |
|
| 61 |
-
Corporate actions must be keyed by **ex-date**. One free source is yfinance
|
|
|
|
|
|
|
| 62 |
|
| 63 |
```python
|
| 64 |
tk = yfinance.Ticker(sym)
|
| 65 |
-
splits = tk.splits.rename_axis("date").rename("ratio").reset_index()
|
| 66 |
dividends = tk.dividends.rename_axis("date").rename("amount").reset_index()
|
|
|
|
| 67 |
```
|
| 68 |
|
| 69 |
If your vendor already delivers adjusted bars, call `adjust_ohlcv(bars)` with no actions.
|
|
|
|
| 49 |
date before the ex-date, or that day's last bar if none is stamped that early. Pass a
|
| 50 |
`close_prior` column in the dividends table to override it. Dividends with
|
| 51 |
`amount ≥ close_prior` are skipped and the price is left under-adjusted.
|
| 52 |
+
- `amount` must be the cash per share on the same share basis as the bars it adjusts. A
|
| 53 |
+
feed that quotes prices on the historical basis needs dividends on that basis too. If
|
| 54 |
+
the feed reports dividends on today's split-adjusted basis, a dividend that precedes a
|
| 55 |
+
later split inside your bar range must be multiplied by that split's ratio.
|
| 56 |
- Two actions on the same ex-date are combined: dividend amounts are summed, split ratios
|
| 57 |
are multiplied.
|
| 58 |
- Actions dated on or before the first bar date have no effect. Actions dated on a day
|
| 59 |
with no bars (weekend, holiday, feed gap) still apply once, to every bar before that day.
|
| 60 |
|
| 61 |
+
Corporate actions must be keyed by **ex-date**. One free source is yfinance. Its prices,
|
| 62 |
+
volumes and dividends are all on today's split-adjusted basis even with
|
| 63 |
+
`auto_adjust=False`, so pass the dividends only and no splits:
|
| 64 |
|
| 65 |
```python
|
| 66 |
tk = yfinance.Ticker(sym)
|
|
|
|
| 67 |
dividends = tk.dividends.rename_axis("date").rename("amount").reset_index()
|
| 68 |
+
adjusted = adjust_ohlcv(bars, None, dividends)
|
| 69 |
```
|
| 70 |
|
| 71 |
If your vendor already delivers adjusted bars, call `adjust_ohlcv(bars)` with no actions.
|