expryDt:{[ed] (2_string ed) except "."};
// generate a formatted ticker name for an option
symbol:{[tkr;expiryDate;typ;strike]
if[not typ in `CALL`PUT`CE`PE; show "typ is not correct. it must be either CALL or PUT or CE or PE"; exit 1];
r: $[(typ=`CALL) or (typ=`CE); string `C; string `P];
"" sv (string tkr; expryDt[expiryDate]; r; string strike)
};
// test
tkr:`IBM;
expiryDate:2025.01.09;
typ:`CALL;
strike:24000i;
show symbol[tkr;expiryDate;typ;strike]; // "IBM250109C24000" OK
Meu código de teste para formatar símbolos como IBM250109C24000
funciona muito bem. No entanto, quando tento aplicá-lo na tabela t
abaixo, ele falha, pois minha função symbol
não é vetorizada. Como faço para que funcione?
t:([] ticker:`IBM`IBM`IBM;
expiryDate:2025.01.09 2025.01.09 2025.01.09;
typ:`CALL`PUT`CE;
strike:24000 24000 24000;
secType:`OPT`OPT`OPT);
show t;
t:update symbol:symbol[ticker;expiryDate;typ;strike] from t where secType=`OPT; // error
Recebo a seguinte saída ao executar o código acima:
"IBM250109C24000"
ticker expiryDate typ strike secType
-------------------------------------
IBM 2025.01.09 CALL 24000 OPT
IBM 2025.01.09 PUT 24000 OPT
IBM 2025.01.09 CE 24000 OPT
'type
[3] tv_options.q:5: symbol:{[tkr;expiryDate;typ;strike]
if[not typ in `CALL`PUT`CE`PE; show "typ is not correct. it must be either CALL or PUT or CE or PE"; exit 1];
^
r: $[(typ=`CALL) or (typ=`CE); string `C; string `P];
A maneira mais fácil é usar
'
https://code.kx.com/q/ref/maps/#caseMas uma função nativa vetorizada terá melhor desempenho. Algo como:
Em vez de
expryDt each expiryDate
se não houver muitos valores exclusivos,expiryDate
você verá uma melhoria com.Q.fu[expryDt;expiryDate]