SQL案例分析:美聯(lián)儲(chǔ)降息前后的復(fù)利差距
當(dāng)?shù)貢r(shí)間 9 月 18 日,美國(guó)聯(lián)邦儲(chǔ)備委員會(huì)宣布,將聯(lián)邦基金利率目標(biāo)區(qū)間下調(diào) 50 個(gè)基點(diǎn)到 4.75% 至 5.00% 的水平,此前的利率目標(biāo)區(qū)間為 5.25% 至 5.50%。這是美聯(lián)儲(chǔ)自 2020 年 3 月以來(lái)首次降息。
50 個(gè)基點(diǎn)不多也不少,那么具體會(huì)有多大差異呢?我們通過(guò)一個(gè) SQL 查詢(xún)計(jì)算五年期的復(fù)利給大家比較一下降息前后的差距。
復(fù)利(Compound Interest)是一種計(jì)算利息的方法,其特點(diǎn)是將前一期的本金和利息一起作為下一期的本金來(lái)計(jì)算利息。這種方式使得利息在后續(xù)期間內(nèi)產(chǎn)生額外的利息,從而實(shí)現(xiàn)資金的快速增長(zhǎng)。簡(jiǎn)單來(lái)說(shuō),復(fù)利就是“利滾利”的過(guò)程。
首先,我們通過(guò)遞歸查詢(xún)(通用表表達(dá)式)計(jì)算本金為 100 萬(wàn),年利率為 5.50% 時(shí)的復(fù)利:
WITH RECURSIVE investment(principal, total, years) AS (
SELECT 1000000.0, 1000000.0*(1+0.055), 1 -- 第一年投資收益
UNION ALL
SELECT total, total*(1+0.055), years+1 -- 第N年投資收益
FROM investment
WHERE years < 5
)
SELECT * FROM investment;
principal |total |years|
--------------------+-----------------------+-----+
1000000.0| 1055000.000| 1|
1055000.000| 1113025.000000| 2|
1113025.000000| 1174241.375000000| 3|
1174241.375000000| 1238824.650625000000| 4|
1238824.650625000000|1306960.006409375000000| 5|
其中,WITH RECURSIVE 定義了一個(gè)遞歸查詢(xún);investment 是一個(gè)臨時(shí)表,存儲(chǔ)了每年本金以及計(jì)算復(fù)利之后的本息合計(jì)。從查詢(xún)結(jié)果可以看出,年利率為 5.50% 時(shí)五年后的本息合計(jì)約為 1306960。
接下來(lái)我們比較降息前后的復(fù)利差距:
WITH RECURSIVE investment(principal_before, total_before, principal_after, total_after, years) AS (
SELECT 1000000.0, 1000000*(1+0.055), 1000000.0, 1000000*(1+0.05), 1 -- 第一年投資收益
UNION ALL
SELECT total_before, total_before*(1+0.055), total_after, total_after*(1+0.05), years+1 -- 第N年投資收益
FROM investment
WHERE years < 5
)
SELECT principal_before, total_before, principal_after, total_after, years,
total_before - total_after AS diff
FROM investment;
principal_before |total_before |principal_after |total_after |years|diff |
--------------------+-----------------------+----------------+------------------+-----+---------------------+
1000000.0| 1055000.000| 1000000.0| 1050000.00| 1| 5000.000|
1055000.000| 1113025.000000| 1050000.00| 1102500.0000| 2| 10525.000000|
1113025.000000| 1174241.375000000| 1102500.0000| 1157625.000000| 3| 16616.375000000|
1174241.375000000| 1238824.650625000000| 1157625.000000| 1215506.25000000| 4| 23318.400625000000|
1238824.650625000000|1306960.006409375000000|1215506.25000000|1276281.5625000000| 5|30678.443909375000000|
該查詢(xún)同時(shí)計(jì)算了年利率為 5.50% 和年利率為 5.00% 時(shí)的復(fù)利。投資本金 100 萬(wàn)時(shí),五年后兩者的本息合計(jì)差距約為 30678。