Data and Primitives¶
Where every expression starts: prices, fields from the data, and the returns, volatility and volume built from them. The panels run on the toy data.
Prices and fields¶
close¶
close() open() high() low()
Each stock's daily prices, adjusted for splits and dividends. Use them for returns and for a stock's own history; to
compare stocks with each other, or with a dollar amount, use an as-traded field such as field('price')
(Adjusted Data and Look-Ahead).
close()| A | B | C | D | |
|---|---|---|---|---|
| Jan 02 | 10.0 | 20.0 | 30.0 | 40.0 |
| Jan 03 | 11.0 | 19.0 | 30.5 | 42.0 |
| Jan 04 | 12.0 | 18.0 | · | 41.0 |
| Jan 05 | 11.0 | 18.5 | 31.0 | 43.0 |
| Jan 08 | 13.0 | 17.0 | 32.0 | 44.0 |
| Jan 09 | 14.0 | 16.0 | 31.5 | 46.0 |
field¶
field('name')
Any field of the data, by name, read as numbers. A field given once per day (an index level, a rate) is given to every
stock. Labels such as a sector are read with group('name') instead.
field('surprise')| A | B | C | D | |
|---|---|---|---|---|
| Jan 02 | · | · | · | · |
| Jan 03 | 0.05 | · | · | · |
| Jan 04 | · | · | · | · |
| Jan 05 | · | · | −0.02 | · |
| Jan 08 | · | −0.01 | · | 0.03 |
| Jan 09 | · | · | · | · |
field('mcap') # market capitalization, if the data has it
1 / field('price_to_book') # book-to-price
market¶
market()
The market's price level: the data's market series, the same for every stock. It is whatever market the data
supplies, such as an index's total-return close or an equal-weight index of the universe.
market()| A | B | C | D | |
|---|---|---|---|---|
| Jan 02 | 100.0 | 100.0 | 100.0 | 100.0 |
| Jan 03 | 101.0 | 101.0 | 101.0 | 101.0 |
| Jan 04 | 100.5 | 100.5 | 100.5 | 100.5 |
| Jan 05 | 102.0 | 102.0 | 102.0 | 102.0 |
| Jan 08 | 103.0 | 103.0 | 103.0 | 103.0 |
| Jan 09 | 102.5 | 102.5 | 102.5 | 102.5 |
Returns, risk and volume¶
returns¶
returns(period[, 'field'])
The return over period days: today's price over the last price at or before period days ago, minus 1,
The price is close unless another field is named; returns(1, 'market') is the market's daily return.
On a day with no price there is no return, so a halted stock drops out of rank and the group operators instead of
counting as 0%. The day it trades again carries the whole move since its last price: below, C on Jan 05 is
31 / 30.5 − 1, measured from Jan 03. A price more than 10 days old no longer counts.
close()| A | B | C | D | |
|---|---|---|---|---|
| Jan 02 | 10.0 | 20.0 | 30.0 | 40.0 |
| Jan 03 | 11.0 | 19.0 | 30.5 | 42.0 |
| Jan 04 | 12.0 | 18.0 | · | 41.0 |
| Jan 05 | 11.0 | 18.5 | 31.0 | 43.0 |
| Jan 08 | 13.0 | 17.0 | 32.0 | 44.0 |
| Jan 09 | 14.0 | 16.0 | 31.5 | 46.0 |
returns(1)| A | B | C | D | |
|---|---|---|---|---|
| Jan 02 | · | · | · | · |
| Jan 03 | 0.100 | −0.050 | 0.017 | 0.050 |
| Jan 04 | 0.091 | −0.053 | · | −0.024 |
| Jan 05 | −0.083 | 0.028 | 0.016 | 0.049 |
| Jan 08 | 0.182 | −0.081 | 0.032 | 0.023 |
| Jan 09 | 0.077 | −0.059 | −0.016 | 0.045 |
returns(20) # one month
returns(1, 'market') # the market's daily return
-returns(5) # last week, reversed: a reversal signal
volatility¶
volatility(period[, 'field'])
Annualized volatility: the standard deviation of daily returns over period days, times √252,
Daily returns follow the rule above. Part of the window (window rules).
volume¶
volume(period)
Average daily volume over period days, in shares; volume(1) is the day's volume. Part of the window.
volume(1)| A | B | C | D | |
|---|---|---|---|---|
| Jan 02 | 100 | 300 | 200 | 400 |
| Jan 03 | 120 | 280 | 210 | 380 |
| Jan 04 | 150 | 260 | · | 500 |
| Jan 05 | 110 | 300 | 260 | 420 |
| Jan 08 | 200 | 250 | 240 | 440 |
| Jan 09 | 180 | 240 | 230 | 600 |
adv¶
adv(period)
Average daily dollar volume, close × volume, over period days. Part of the window. Dollar volume compares across
stocks; share volume does not.