Historical data queries  TAQ data queries

Chapter 3: Sample Queries

Historical market query examples

Query description: hist_qry1 Get the closing price of a set of 10 stocks for a 10-year period and group into weekly, monthly and yearly aggregates. For each aggregate period determine the low, high and average closing price value. The output is sorted by id (INSTRUMENT_ID) and trade date.

INSTRUMENT_ID   YEAR   MON   WEEK   MAX_PRICE   MIN_PRICE             AVG_PRICE
            1   2005     2       8      75.39      70.36      72.78800000000000000000000
            1   2005     2       9      76.13      74.62      75.22600000000000000000000
            1   2005     2      10      73.87      73.87      73.87000000000000000000000
            1   2005     2  (NULL)      76.13      70.36      73.75000000000000000000000
            1   2005     3      10      78.37      75.35      76.66750000000000000000000
            1   2005     3      11      85.68      79.94      82.70200000000000000000000
            1   2005     3      12      87.34      83.12      84.97000000000000000000000
            1   2005     3      13      90.83      87.30      88.72200000000000000000000
            1   2005     3      14      91.74      89.01      90.59750000000000000000000
            1   2005     3  (NULL)      91.74      75.35      84.82739130434782608695652
            1   2005     4      14      87.23      87.23      87.23000000000000000000000
            1   2005     4      15      87.17      84.63      85.64000000000000000000000
            1   2005     4      16      87.13      85.39      86.26200000000000000000000
            1   2005     4      17      92.45      87.97      89.92800000000000000000000
            1   2005     4      18      94.29      92.40      93.72000000000000000000000
            1   2005     4  (NULL)      94.29      84.63      88.80857142857142857142857
            1   2005     5      19      97.05      90.55      94.23000000000000000000000
            1   2005     5      20      96.07      94.12      94.90600000000000000000000
            1   2005     5      21      95.06      93.16      94.47400000000000000000000
            1   2005     5      22      92.19      87.65      89.81200000000000000000000
            1   2005     5      23      89.40      87.65      88.52500000000000000000000
            1   2005     5  (NULL)      97.05      87.65      92.91636363636363636363636
            1   2005     6      23      92.09      92.09      92.09000000000000000000000
           ...

NoteThe hist_qry1 query uses the ROLLUP operator. The NULL values for month and week are subtotals. A NULL value in the week column is a subtotal for the month. A NULL value in the month and week column is a subtotal for the year.

Query description: hist_qry4 Calculate the value of the S&P 500 and Russell 2000 index for a specified day using unadjusted prices and the index composition of the two indexes on the specified day.

INDEX_NAME      AVERAGE_CLOSE_PRICE
Russell 2000    49.47026052104208416833667
S&P 500         54.44644000000000000000000

Query description: hist_qry7 Determine the value of $100,000 now if 1 year ago it was invested equally in 10 specified stocks (that is, allocation for each stock is $10,000). The trading strategy is: When the 20-day moving average crosses over the 5-month moving average the complete allocation for that stock is invested and when the 20-day moving average crosses below the 5-month moving average the entire position is sold. The trades happen on the closing price of the trading day.

STOCK_VALUE
60299.133021




Copyright © 2005. Sybase Inc. All rights reserved. TAQ data queries

View this book as PDF