help with VWAP function

https://learninghub.kx.com/forums/topic/help-with-vwap-function

Hi, as a small exercise, i am trying to compute the VWAP over the different depths of the order book.The simplest way is select timestamp, depth_vwap1: (bq0; bq1; aq0; aq1) wavg (bp0; bp1; ap0; ap1) from data now i am trying to abstract i in a function so that we can pass the max depth the vwap goes to as a parameter:

[!data;
();
0b;
(enlist$ "vwap_d", string max_depth)!(enlist(wavg;(enlist;bq0;bq1;aq0; aq1 );
(enlist;bp0;bp1;ap0; ap1 )))]

now, i need to abstract the

(enlist;bp0;bp1;ap0;ap1)
part.I thought of doing :

quantities: raze(("bq"; "aq"),/::string til maxDepth)
prices : raze(("bp"; "ap"),/::string til maxDepth)

but then i dont understand how to use them within the parse request.Would really appreciate is someone could help!Thank youPaul

edit: sorry for the formatting i dont know what causes that

Sample table for testing:
q)data:([] timestamp:til 10;bq0:til 10;bq1:til 10;bq2:til 10;bp0:til 10;bp1:til 10;bp2:til 10;aq0:til 10;aq1:til 10;aq2:til 10;ap0:til 10;ap1:til 10;ap2:til 10) 
q)data 
timestamp bq0 bq1 bq2 bp0 bp1 bp2 aq0 aq1 aq2 ap0 ap1 ap2 
--------------------------------------------------------- 
0         0   0   0   0   0   0   0   0   0   0   0   0 
1         1   1   1   1   1   1   1   1   1   1   1   1 
2         2   2   2   2   2   2   2   2   2   2   2   2 
3         3   3   3   3   3   3   3   3   3   3   3   3 
4         4   4   4   4   4   4   4   4   4   4   4   4 
5         5   5   5   5   5   5   5   5   5   5   5   5 
6         6   6   6   6   6   6   6   6   6   6   6   6 
7         7   7   7   7   7   7   7   7   7   7   7   7 
8         8   8   8   8   8   8   8   8   8   8   8   8 
9         9   9   9   9   9   9   9   9   9   9   9   9
Test provided query:
q)select timestamp, depth_vwap1: (bq0; bq1; aq0; aq1) wavg (bp0; bp1; ap0; ap1) from data 
timestamp depth_vwap1 
--------------------- 
0 
1         1 
2         2 
3         3 
4         4 
5         5 
6         6 
7         7 
8         8 
9         9
parse query to functional form:
q)parse"select timestamp, depth_vwap1: (bq0; bq1; aq0; aq1) wavg (bp0; bp1; ap0; ap1) from data" 
? 
`data 
() 
0b 
`timestamp`depth_vwap1!(`timestamp;(wavg;
(enlist;`bq0;`bq1;`aq0;`aq1);
(enlist;`bp0;`bp1;`ap0;`ap1)))
Test functional query:
q)?[data;();0b;`timestamp`depth_vwap1!(`timestamp;(wavg;
(enlist;`bq0;`bq1;`aq0;`aq1);
(enlist;`bp0;`bp1;`ap0;`ap1)))] 
timestamp depth_vwap1 
--------------------- 
0 
1         1 
2         2 
3         3 
4         4 
5         5 
6         6 
7         7 
8         8 
9         9
Set up variables:
q)maxDepth:2 
q)quantities: `$raze(("bq"; "aq"),/:\:string til maxDepth) // Note `$ to convert strings to symbols 
q)prices : `$raze(("bp"; "ap"),/:\:string til maxDepth) // Note `$ to convert strings to symbols
Create needed list to pass to functional query:
q)enlist,quantities 
enlist 
`bq0 
`bq1 
`aq0 
`aq1 
q)-1 .Q.s1 enlist,quantities; //.Q.s1 very useful to show full structure of object 
(enlist;`bq0;`bq1;`aq0;`aq1)
Test new dynamic functional select:
q)?[data;();0b;`timestamp`depth_vwap1!(`timestamp;
(wavg;enlist,quantities;enlist,prices))] 
timestamp depth_vwap1 
--------------------- 
0 
1         1 
2         2 
3         3 
4         4 
5         5 
6         6 
7         7 
8         8 
9         9

thank you for such a complete answer! I was far from having the complete solution!
Best,
PF