知方号

知方号

基金份额参考价值 IOPV 计算

在 DolphinDB 中利用 pivot by 生成一个数据面板(矩阵),再对矩阵进行向量化运算可以提高计算速度,同时代码更为简洁。

timeSeriesValue = select tradetime, SecurityID, price * portfolio[SecurityID]/1000 as constituentValue from loadTable("dfs://LEVEL2_SZ","Trade") where SecurityID in portfolio.keys(), tradedate = 2023.12.01, price > 0iopvHist = select rowSum(ffill(constituentValue)) as IOPV from timeSeriesValue pivot by tradetime, SecurityID计算股票价值

timeSeriesValue 得到每个时间戳下的所有成分券价值,本次代码示例计算深交所 2023.12.01 这一日的逐笔成交的历史 IOPV,其中 loadTable("dfs://LEVEL2_SZ","Trade") 使用的是逐笔成交表。

上图中 constituentValue 是每一时间戳时当前股票仓位的价值。

面板数据计算 IOPV

利用 DolphinDB 中的 pivot by 数据透视功能生成一个面板数据,横轴是50只成分券,纵轴是时间戳,数据点代表每只成分券在一个时间戳上的价值。

对面板数据的纵轴(时间序列)的空置填充最近前一笔有效价值,再对横轴(成分券)汇总即可得到每个时间戳上的 IOPV 结果。

ffill会找到前一笔最近的非空值,相当于传统方法取前一股票价值。rowSum对横向行数据汇总,即把所有成分券的价值汇总得出 IOPV。

在 DolphinDB 中使用一行代码就能完成传统 IOPV 计算步骤3中的复杂逻辑;同时,DolphinDB 是向量计算,能够充分利用多线程完成高效运算。

面板数据有以下优点,参考阅读 Baltagi, Econometric Analysis of Panel Data Chapter 1 1.2 Why should we use Panel Data? The Benefits and Limitations:

Benefits

Controlling for individual heterogeneity.Panel data give more informative data, more variablility, less collinearity among the variables, more degrees of freedom and more effciency.Panel data are better able to study the dymanics of adjustment.Panel data are better able to identify and measure effects that are simply not detectable in pure cross-section or pure time-series data.Panel data models allow us to construct and test more complicated behavioral models than purely cross-section or time-series data.Micro panel data gathered on individuals, firms and households may be more accurately measured than similar variables measured at the macro level.Macro panel data on the other hand have a longer time series and unlike the problem of nonstandard distributions typical of units roots tests in time-series analysis.

Limitations

Design and data collection problems.Distortions of measurement errors.Selectivity problems.Short time-series dimensions.Cross-section dependence.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。