//获取指定日所有基金分类及其基金列表,并计算其份额与规模
endt:=20230930T;
r:=array();
IndexS:="TSJJ02";
setsysparam(pn_date(),endt);
bks:=getbkbydate(IndexS$".N",endt);
ret:=array();
rt:=array();
for i:=0 to length(bks)-1 do
begin
ret[i,"分类代码"]:=bks[i];
ret[i,'分类名称']:=spec(base(355002),bks[i]);
funds:=getbkbydate(bks[i],endt);//取当前分类在指定日的所有基金代码
//封闭式基金与互认基金暂不维护基金份额相关数据,不统计份额与规模
if bks[i] in array("TSJJ0209","TSJJ0210") then
begin
ret[i,'成份']:=`array("代码":funds);
continue;
end
//公募基金中同一个代码存在多个取数代码,这里做过滤处理,只统计主代码数据
grp1:=select distinct bks[i] as '分类代码',
ret[i,'分类名称'] as '分类名称',
code:=spec(base(302032),thisrow)?:thisrow as '基金代码',
spec(FundTotalShares(EndT),code) as '份额',
spec(FundScale(),code) as '规模'
from funds where spec(base(302050),thisrow)="公募基金" end;
//资产管理计划,无效主代码数据不统计,份额无效代码不统计
grp2:=select bks[i] as '分类代码',
ret[i,'分类名称'] as '分类名称',
thisrow as '基金代码',
spec(FundTotalShares(EndT),thisrow) as '份额',
spec(FundScale(),thisrow) as '规模'
from funds where spec(base(302050),thisrow)="集合资产管理计划" end;
delete from grp2 where not ["份额"] ;
grp:=grp1 union grp2;
ret[i,'成份']:=grp;
ret[i,'份额']:=sum(grp[:,"份额"])/100000000.;
ret[i,'规模']:=sum(grp[:,"规模"])/100000000.;
r&=grp;
end
ret[length(ret)]:=array("分类代码":IndexS,"分类名称":"合计","成份":r,"份额":sum(r[:,"份额"])/100000000.,"规模":sum(r[:,"规模"])/100000000.);
return ret;
结果: