I have found a strange issue in q, a possible bug I suppose. I have defined a simple function that returns a float, given a date as input:
give_dummy:{[the_date]
/// give_dummy[2013.05.10] // <- if u wanna test
:$[ the_date > 2013.01.01 ; 0.001 ; 0.002] ;
}
It works without problems if called stand-alone:
q)give_dummy[2013.05.10]
0.001
Nevertheless, if I try to call it in a query I get an error:
q)select give_dummy[date] from tab where sym = sec, i >= first_i , i < 4000
'type
If I simplify the function to just return the input date (identity function), it works in the query. If I simplify the function to just return a float, without comparing the dates, it works in the query. The problem arises when I USE the input date to compare it in the if-statement: $[ the_date > 2013.01.01 ; 0.001 ; 0.002]
The same happens if I re-define the function taking a float as input, instead than a date, and then I try to give the price as input in the query:
give_dummy:{[the_price]
/// give_dummy[12] // <- if u wanna test
:$[ the_price > 20 ; 0.001 ; 0.002] ;
}
q) give_dummy[12]
0.002
q)select give_dummy[price] from tab where sym = sec, i >= first_i , i < 4000
'type
Do you have any idea of why this happens? I tried everything. Thanks Marco