AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-4555763

marital_weeping's questions

Martin Hope
marital_weeping
Asked: 2025-01-06 15:50:31 +0800 CST

与更新一起使用的矢量化函数调用

  • 5
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

我的格式化符号测试代码IBM250109C24000运行良好。但是,当我尝试将其应用于下表时,t它失败了,因为我的函数symbol未矢量化。我该如何让它工作?

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

运行上述代码后得到以下输出:

"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];
kdb+
  • 1 个回答
  • 51 Views
Martin Hope
marital_weeping
Asked: 2024-12-12 09:00:40 +0800 CST

在 kdb+ 中枚举连续的

  • 6

给定一个由 0 和 1 组成的列表,假设l: 0 0 1 1 1 0 0 1 1我想得到一个以 1 开头的序列,每个连续的 1 集都是如此。因此所需的输出应该是l: 0 0 1 2 3 0 0 1 2。如何在 kdb+ 中实现这一点?

kdb
  • 2 个回答
  • 65 Views
Martin Hope
marital_weeping
Asked: 2024-11-15 10:13:47 +0800 CST

根据 kdb 中的其他标量列筛选具有行列表的列

  • 5
w:(1 2;3 4;5 2); l:til count w; h:l+1;
show t:([] l; h; w);

l h w  
-------
0 1 1 2
1 2 3 4
2 3 5 2

我有一张表格,其中有t一列w包含行列表。我希望只保留表格中每行w位于l和值之间的元素。h

预期输出为:

l h w  
-------
0 1 ,1
1 2 ,
2 3 ,2

我尝试过

t:update w:w[where ((w>=l) and (w<=h))] from t;

但它失败了

'type
  [0]  t:update w:w[where ((w>=l) and (w<=h))] from t;

kdb
  • 1 个回答
  • 10 Views
Martin Hope
marital_weeping
Asked: 2024-10-28 22:14:09 +0800 CST

从表列中提取信息,该表列是 kdb 中的列表列表

  • 5

我有以下线性回归函数

// linear regression y vs x
// returns: intercept slope
linear:{
    if[not (count x)=(count y); show "x and y must have the same length"; exit 1];
    fit:{(enlist x) lsq y xexp/:til 1+z};
    fit[x; y; 1]
 };

// takes X and Y as a list of lists
linearLL:{[X;Y] t:([] x:X; y:Y); raze {9h$linear[x`x; x`y]} each t};

\d .

我想得到截距和斜率lr

/ sliding window from https://code.kx.com/q/kb/programming-idioms/
swin:{[f;w;s] f each {1_x,y}\[w#0; s]}

p:1 2 3 0N 0N 0N 4 5 0N 6 0N 0N 0N 7 8 9;
p:1f*p;
time:2024.01.01+til count p;
n:4;
t:([] p: p; time: time);

t:update c:til count t from t;
t:select from t where p>0;
t:update x:swin[::;n;c] from t;
t:update y:swin[::;n;p] from t;
/t:update y:swin[::;n;p] from t;
t:update x:1f*({distinct x} each x) from t;
t:update y:({x except 0} each y) from t;
t:update y:({x except 0N} each y) from t;
t:delete c from t;
show t:update lr:.regression.linearLL[x;y] from t;

其结果(正如预期):

p time       x           y        lr      
------------------------------------------
1 2024.01.01 ,0f         ,1f              
2 2024.01.02 0 1f        1 2f     -1   1  
3 2024.01.03 0 1 2f      1 2 3f   -1   1  
4 2024.01.07 0 1 2 6f    1 2 3 4f -2.5 1.9
5 2024.01.08 1 2 6 7f    2 3 4 5f -3.7 2.2
6 2024.01.10 2 6 7 9f    3 4 5 6f -3.9 2.2
7 2024.01.14 6 7 9 13f   4 5 6 7f -3.9 2.3
8 2024.01.15 7 9 13 14f  5 6 7 8f -5.5 2.5
9 2024.01.16 9 13 14 15f 6 7 8 9f -1.5 1.9

但是我'length在调​​用时出现错误:

show t:update intercept:lr[0], slope:lr[1] from t;

我假设的元素lr是一对元素的列表,但不知何故事实并非如此。我如何提取截距和斜率信息?

kdb
  • 1 个回答
  • 26 Views
Martin Hope
marital_weeping
Asked: 2024-10-13 20:03:45 +0800 CST

在 kdb 中获取不重叠的交易

  • 5

我有一张t桌子

q)trades: ([]
    signalTime: 2024.01.05 2024.01.12 2024.01.19 2024.01.25 2024.02.02 2024.02.09 2024.02.16 2024.02.23 2024.03.01 2024.03.07;
    exitTime: 2024.01.25 2024.02.01 2024.02.08 2024.02.15 2024.02.22 2024.02.29 2024.03.07 2024.03.14 2024.03.21 2024.03.28
 );
signalTime exitTime
----------------------
2024.01.05 2024.01.25
2024.01.12 2024.02.01
2024.01.19 2024.02.08
2024.01.25 2024.02.15
2024.02.02 2024.02.22
2024.02.09 2024.02.29
2024.02.16 2024.03.07
2024.02.23 2024.03.14
2024.03.01 2024.03.21
2024.03.07 2024.03.28

我希望只保留中间日期(介于signalTime和 之间exitTime)不与其他任何交易(行)重叠的交易。或者,任何给定日期内应该只有一笔交易。预期输出应为

signalTime exitTime
----------------------
2024.01.05 2024.01.25
2024.02.02 2024.02.22
2024.02.23 2024.03.14

虽然我能够使用do循环来构思解决方案,但如何以更有效、更惯用的方式实现这一目标q?

这是我使用循环解决问题的微薄尝试,do尽管它并不完全正确。

removeOverlappingTrades:{[t]
    n: count t;
    accept: n#0b;          
    accept[0]: 1b;         
    lastExitTime: t[`exitTime][0]; 
    do[n-1; {[t;lastExitTime;accept;x]
        i: x+1;  // Current index
        if[t[`signalTime][i] >= lastExitTime;
           accept[i]: 1b;
           lastExitTime: t[`exitTime][i];
          ];
    }[t;lastExitTime;accept] each til n-1];
    t where accept
 };
kdb
  • 1 个回答
  • 49 Views
Martin Hope
marital_weeping
Asked: 2024-10-01 22:35:34 +0800 CST

重新缩放功能有问题

  • 5

我有一张桌子t

t:([] x: 1 2 3 4 5; y: 5.1 2.4 3.3 4.5 1.5);
x y  
-----
1 5.1
2 2.4
3 3.3
4 4.5
5 1.5

并且我正在尝试重新缩放x和y行,t使得较大的一个变为 1,另一个取ceiling max(x;y)%min(x;y)如下值:

rescaledUnits:{[t]
    t:update l:max(x;y), s:min(x;y) from t;
    t:update a:ceiling l%s, ones:1 from t;
    t:update uc:ones, up:a where x>=y from t;
    t:update uc:a, up:ones where x<y from t;
    t
 };

但当我调用它时我得到了

show rescaledUnits[t]

q)

'length
    t:update a:ceiling l%s, one:1 from t;
    t:update uc:one, up:a where x>=y from t;
      ^
    t:update uc:a, up:one where x<y from t;

我该如何修复上述功能?

kdb
  • 2 个回答
  • 35 Views
Martin Hope
marital_weeping
Asked: 2024-07-15 08:43:24 +0800 CST

KDB 中 N 个后续元素的列表

  • 5

给定表格t: ([] a: 1 2 3 4),如何获取b例如以下列:

n=2

a b
-----
1 1 2
2 2 3
3 3 4
4 ,4

n=3

a b
-------
1 1 2 3
2 2 3 4
3 3 4
4 ,4

其中是要包含在 中的后续元素(包括)n的数量。aab

kdb
  • 2 个回答
  • 48 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve