q / KDB+ 如何用列表中的随机符号填充 table?
q / KDB+ How to populate table with random symbols from the list?
我正在尝试使用以下语法创建 table:
rows: 100
syms:(`VOD.L;`APPL;`AZ.L;`FB)
values:([] timestamp: rand each rows#.z.t; sym:rand syms; quote:rand each rows#1000; bid:rand each rows#1000; ask:rand each rows#1000; price:rand each rows#1000)
values
它返回以下内容:
timestamp sym quote bid ask price
-------------------------------------
08:08:00.050 APPL 466 498 263 657
10:09:27.205 APPL 464 240 176 898
04:47:18.085 APPL 191 407 105 990
09:54:58.651 APPL 876 96 429 699
02:19:09.967 APPL 60 227 333 954
04:16:32.491 APPL 29 454 574 757
00:04:47.977 APPL 945 607 559 666
00:01:38.306 APPL 185 52 298 745
07:41:15.101 APPL 96 397 261 924
05:58:57.757 APPL 267 845 114 584
04:28:41.917 APPL 20 320 300 418
07:24:54.913 APPL 188 614 83 335
07:03:28.536 APPL 248 20 831 565
02:32:59.849 APPL 435 485 274 27
08:24:16.294 APPL 831 66 810 418
10:31:42.552 APPL 876 19 147 586
10:40:04.843 APPL 539 752 351 194
03:16:53.847 APPL 6 600 905 321
03:55:59.228 APPL 376 288 427 645
08:08:32.805 APPL 350 742 126 942
..
问题是所有符号都相同 - APPL:
select from values where sym<>`APPL
timestamp sym quote bid ask price
---------------------------------
我无法将它们随机化。我尝试使用与随机化时间戳或数值相同的方法,就像这样...
values:([] timestamp: rand each rows#.z.t; sym:rand each rows#syms; quote:rand each rows#1000; bid:rand each rows#1000; ask:rand each rows#1000; price:rand each rows#1000)
...但随后出现以下错误:
评价错误:
VOD.L
[3] (<q>)
[2] (.q.rand)
[1] (.q.each)
[0] values:([] timestamp: rand each rows#.z.t; sym:rand each rows#syms; quote:rand each rows#1000; bid:rand each rows#1000; ask:rand each rows#1000; price:rand each rows#1000)
很明显,我一定是被困在了一些愚蠢的事情上,但对我来说,它可能是什么并不明显。请帮忙。
提前致谢。
使用一卷 ?
而不是 rand
:
q)([]timestamp:rows?.z.t;sym:rows?syms;quote:rows?1000;bid:rows?1000;ask:rows?1000;price:rows?1000)
timestamp sym quote bid ask price
--------------------------------------
00:28:43.630 AZ.L 181 879 501 394
00:13:16.346 APPL 421 555 529 52
04:33:06.881 APPL 379 386 914 259
01:55:03.027 FB 198 399 684 990
05:23:18.919 AZ.L 728 318 641 264
...
详情在这里:https://code.kx.com/q/ref/deal/
Roll/deal 更适合列表,rand
(https://code.kx.com/q/ref/rand/) 只适合选择一个值。如文档中所述:
"rand 正好等同于{first 1?x}。如果需要列表结果,使用Roll"
我正在尝试使用以下语法创建 table:
rows: 100
syms:(`VOD.L;`APPL;`AZ.L;`FB)
values:([] timestamp: rand each rows#.z.t; sym:rand syms; quote:rand each rows#1000; bid:rand each rows#1000; ask:rand each rows#1000; price:rand each rows#1000)
values
它返回以下内容:
timestamp sym quote bid ask price
-------------------------------------
08:08:00.050 APPL 466 498 263 657
10:09:27.205 APPL 464 240 176 898
04:47:18.085 APPL 191 407 105 990
09:54:58.651 APPL 876 96 429 699
02:19:09.967 APPL 60 227 333 954
04:16:32.491 APPL 29 454 574 757
00:04:47.977 APPL 945 607 559 666
00:01:38.306 APPL 185 52 298 745
07:41:15.101 APPL 96 397 261 924
05:58:57.757 APPL 267 845 114 584
04:28:41.917 APPL 20 320 300 418
07:24:54.913 APPL 188 614 83 335
07:03:28.536 APPL 248 20 831 565
02:32:59.849 APPL 435 485 274 27
08:24:16.294 APPL 831 66 810 418
10:31:42.552 APPL 876 19 147 586
10:40:04.843 APPL 539 752 351 194
03:16:53.847 APPL 6 600 905 321
03:55:59.228 APPL 376 288 427 645
08:08:32.805 APPL 350 742 126 942
..
问题是所有符号都相同 - APPL:
select from values where sym<>`APPL
timestamp sym quote bid ask price
---------------------------------
我无法将它们随机化。我尝试使用与随机化时间戳或数值相同的方法,就像这样...
values:([] timestamp: rand each rows#.z.t; sym:rand each rows#syms; quote:rand each rows#1000; bid:rand each rows#1000; ask:rand each rows#1000; price:rand each rows#1000)
...但随后出现以下错误:
评价错误:
VOD.L
[3] (<q>)
[2] (.q.rand)
[1] (.q.each)
[0] values:([] timestamp: rand each rows#.z.t; sym:rand each rows#syms; quote:rand each rows#1000; bid:rand each rows#1000; ask:rand each rows#1000; price:rand each rows#1000)
很明显,我一定是被困在了一些愚蠢的事情上,但对我来说,它可能是什么并不明显。请帮忙。
提前致谢。
使用一卷 ?
而不是 rand
:
q)([]timestamp:rows?.z.t;sym:rows?syms;quote:rows?1000;bid:rows?1000;ask:rows?1000;price:rows?1000)
timestamp sym quote bid ask price
--------------------------------------
00:28:43.630 AZ.L 181 879 501 394
00:13:16.346 APPL 421 555 529 52
04:33:06.881 APPL 379 386 914 259
01:55:03.027 FB 198 399 684 990
05:23:18.919 AZ.L 728 318 641 264
...
详情在这里:https://code.kx.com/q/ref/deal/
Roll/deal 更适合列表,rand
(https://code.kx.com/q/ref/rand/) 只适合选择一个值。如文档中所述:
"rand 正好等同于{first 1?x}。如果需要列表结果,使用Roll"