希望获得一系列每日收益的连续累积收益?我知道可以使用exp和sum来解决此问题,但是我的返回序列不是使用LN来计算的。
希望在不使用循环的情况下解决此问题,因为它们在sql中效率很低。重要的是要使其快速运行。
资料集:
理想的结果
这是你想要的吗?
select t.*,
(select exp(sum(log(1 + return))) - 1
from table t2
where t2.date <= t.date
) as cumereturn
from table t;
您正在使用的数据库中用于exp()
和的功能log()
可能有所不同。在许多数据库中,您还可以使用:
select t.*, exp(sum(log(1 + return) over (order by date)) - 1
from table t;
我认为任何数据库都没有内置的product()
聚合功能。唉。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句