Is there an easy way to pivot a table by one of its columns? Forexample, taking the canonical trade:(time:time$();sym:
symbol$();price:float$();size:
int$()), how would one create a table with 30minute buckets in each row, the list of symbols across the top and thevolume in each of the columns? I know I can probably do it bycreating a dictionary of the symbols, filling each with the results ofa query and subsequently flipping it, but if there is a more efficientway, I’d love to hear it.Thanks,Victor
charset=us-ascii;
format=flowed;
delsp=yes
Look up functional select in Q for Mortals.
Regards,
Attila
Hello Victor,Below is a example:n:1000syms:FDP
IBMMSFTstart:09:30:00.000close:16:30:00.000trade:([]time:asc start+n?(close-start);sym:n?syms;price:n?100.0;size:n?1000)pivot:exec syms!(sym!size)syms by bucket:30 xbar time.minute fromtradeThe syntax may seem a little tricky but it's based around the idea ofbuilding dictionaries from your query using !.As Attila mentions you can use functional select which you could thenpossibly wrap in a custom function for pivoting.Regards,Fintan.On Nov 20, 6:31?pm, Victor Wong <victor.w...> wrote:> Is there an easy way to pivot a table by one of its columns? ?For> example, taking the canonical trade:([]time:
time$();sym:symbol$> ();price:
float$();size:`int$()), how would one create a table with 30> minute buckets in each row, the list of symbols across the top and the> volume in each of the columns? ?I know I can probably do it by> creating a dictionary of the symbols, filling each with the results of> a query and subsequently flipping it, but if there is a more efficient> way, I’d love to hear it.>> Thanks,> Victor</victor.w…>
Thank you for the example. This is very helpful. Thanks.VictorOn Nov 23, 7:47?am, fintanq <fint…> wrote:> Hello Victor,>> Below is a example:>> n:1000> syms:FDP
IBMMSFT> start:09:30:00.000> close:16:30:00.000> trade:([]time:asc start+n?(close-start);sym:n?syms;price:n?> 100.0;size:n?1000)pivot:exec syms!(sym!size)syms by bucket:30 xbar time.minute from> trade>> The syntax may seem a little tricky but it's based around the idea of> building dictionaries from your query using !.>> As Attila mentions you can use functional select which you could then> possibly wrap in a custom function for pivoting.>> Regards,>> Fintan.>> On Nov 20, 6:31?pm, Victor Wong <victor.w...> wrote:>>>> > Is there an easy way topivota table by one of its columns? ?For> > example, taking the canonical trade:([]time:
time$();sym:symbol$> > ();price:
float$();size:`int$()), how would one create a table with 30> > minute buckets in each row, the list of symbols across the top and the> > volume in each of the columns? ?I know I can probably do it by> > creating a dictionary of the symbols, filling each with the results of> > a query and subsequently flipping it, but if there is a more efficient> > way, I’d love to hear it.>> > Thanks,> > Victor</victor.w…></fint…>