10 minute rollup

calculate the last price and sum of size of 10 minute intervals of trade
select last price, sum size by 10 xbar time.minute from trade where sym=`MSFT

hourly mean variance of some symbol
select mean:avg price, variance:var price, stdDev:dev price by date, hour:time.hh from trade where sym=`AIG

Average total trade volume over a certain week, for each 30 minute bucket for MSFT
(select sum size by 30 xbar time.minute from trade where date within 2006.08.07 2006.08.11,sym=`MSFT)% sum date within 2006.08.07 2006.08.11

Select the two heaviest traded stocks
select sym from 2# desc select sum size by sym from trade

This dyadic function shifts a vector by n elements, for example
select price-5 xprev price from trade where sym=`IBM

Generate a NBBO table for a certain month: (National best bid and offer)
nbbo: select ask: min ask,bid: max bid by date,sym,time from quote where date.month=2006.08m,asize>0,bsize>0

non-first normal form can be faster
q) \t do[10000;r1:select avg price by sym from trade where sym in `AIG`IBM] 1862
compared to
q) \t nestedtrade:select price,size by sym from trade 0 q) \t do[10000;r2:select sym,each[avg] price from nestedtrade where sym in `AIG`IBM] 180

=======

Set up a console

q trade.q -p 5001

http://localhost:5001
http://localhost:5001/?select from trade where sym=`IBM

export to excel:

http://localhost:5001/.csv?select from trade where sym=`IBM

\a set of tables
\c 20 200 how much to display
\v all global variable
\date -- operating system date ommand

========

Interlanguage access -- do excel, web, and maybe java
p. 112 of fdkdbtutorial

// build (time;sym;price;size) record
Object[]x={new Time(System.currentTimeMillis()%86400000),"xx",new
Double(93.5),new Integer(300)};
c.k("insert","trade",x);	// insert[`trade;x]
clients can also read incoming messages:
r=c.k();

for example, kdb+tick clients do:
String[]syms={"IBM","MSFT",..};
c.k(".u.sub","trade",syms);	// subscribe
while(1){Object r=c.k();..	// process incoming


p. 126 of the tutorial

import c; // That is the critical java to kdb module to import

// I don't know which of these to import
import java.awt.*; 
import java.awt.event.ActionEvent; 
import java.io.IOException;
import javax.swing.*; 
import javax.swing.table.DefaultTableModel;
// end of I don't know what

String host = "localhost";
int port = 6001;
qConn = new c(host, port); connects to a database specified by host and port

Object o = qConn.k(sSql); 
	// access the database and gets info based on sql query

c.Flip d = c.td(o); // columns are d.x and rows are d.y

int numcols = c.n(d.x); 
int numrows = c.n(d.y[0]);

Object[][] myobj = new Object[numrows][numcols];

for (int rowid = 0; rowid < numrows; rowid++) {
  for (int colid = 0; colid < numcols; colid++) {
	myobj[rowid][colid] = c.at(d.y[colid], rowid); 
		// fishes out the colid field of row rowid
  };
};



clients (see http://www.studio4kdb.com/ExcelRTDServer.htm)
