英文:
How to generate Cashflow dates and values automatically from a set of Data?
问题
我正在尝试创建一个用于跟踪我的保险投资回报的工具。
我在第一个表中创建了一个主列表,然后相应地在第二个表中创建了每个保单的现金流。
手动输入现金流的日期这一过程相当繁琐,我相信一定有更好的方式来管理这些信息。
请求您能否查看一下并看看如何创建这个工具?
我已经创建了两种保单,一种在保单期结束时有成熟赔付,另一种是在保险费期满后每年有赔付。
这是 Google 表格的链接 - 您可以查看并创建一个副本。
英文:
So I am trying to create a returns tracker for my Insurance investments.
I have created a master list in the first sheet and accordingly I am creating cashflow of each policy in the 2nd sheet.
This process of manually entering the dates as per the cashflow is quite tedious and I am sure there is a better way to manage this.
Requesting if you can kindly have a look and see how to create this?
I have created 2 policies, 1 with maturity payout at the end of the policy, and another with payouts every year after the premium term.
Here is the link to Google sheet - you can view and create a copy of it.
答案1
得分: 2
这是您要的翻译内容:
This process of manually entering the dates as per the cashflow is quite tedious and I am sure there is a better way to manage this.
这个手动输入现金流日期的过程相当繁琐,我相信肯定有更好的管理方式。
Example: Policy
XXXX1245S
- "Year" column is a range of dates.
- First date is the "Start Date" in
Cashflow sheet'!J5
- Dates increment by 1 year
- Final date is x years after the "Start Date" where x = "Policy term"
Cashflow sheet'!J9
- Outflow is a number based on the "Premium amount"
Cashflow sheet'!J3
- Outflow is included on the "Start Date" and for y more years, where y = "Prem. pmt term"
Cashflow sheet'!J8
示例:保单
XXXX1245S
- “年” 列是一系列日期。
- 第一个日期是
Cashflow sheet'!J5
中的 “开始日期”- 日期每年递增
- 最后的日期是 “开始日期” 后的 x 年,其中 x = “保单期限”
Cashflow sheet'!J9
- 支出是基于 “保费金额”
Cashflow sheet'!J3
的数字
- 支出包括在 “开始日期” 上,以及 y 年,其中 y = “保费支付期”
Cashflow sheet'!J8
Named Ranges
To make the formula easier to follow I've used named ranges命名范围
为了使公式更容易理解,我使用了命名范围
Formula
The following formula will dynamically create the first three columns with as many rows as is required and properly populated. If the logic for the "Inflow" column was better understood, it too could be populated in the same formula. Frankly, the entire table including the information at the top could probably be populated from one formula based solely on the "Policy No." if all the required data is stored in theMaster List
sheet.公式
以下公式将根据需要动态创建前三列,并适当填充行数。如果更好地理解了**“流入”列的逻辑,它也可以在同一个公式中填充。坦白说,整个表格,包括顶部的信息,如果所有所需数据都存储在Master List
表中,那么可能可以从一个仅基于“保单号”**的公式中填充。
Additional Info
The SEQUENCE function creates an array of specified dimensions, populated with a number sequence starting at a specified value, and incrementing (stepping) by another specified value. The only required value, however, is rows (height).附加信息
SEQUENCE 函数创建一个具有指定维度的数组,以从指定值开始的数字序列填充,并逐步增加(步进)到另一个指定值。然而,唯一必需的值是行数(高度)。
The MAP function enables mapping a set of values into a LAMBDA function. Inside the LAMBDA function, a formula can be applied iteratively to each mapped value. The LAMBDA declares one (arbitrary) name (variable) for each set of mapped values which the formula uses in order to refer to the current mapped value.
MAP 函数使一组值映射到LAMBDA函数中。在LAMBDA函数内,可以迭代地对每个映射值应用公式。LAMBDA声明一个(任意的)名称(变量)用于每组映射值,公式使用这些名称来引用当前映射值。
So, looking at the initial MAP and LAMBDA parts of the formula:
Now to build the 3 column array:
- The first row is set as { "Cashflow", "Year", "Outflow" }
- Each row has
s
in the "Cashflow" column: { 1; 2; 3; 4; 5 }- the "Start date"
start
, offset bys-1 years
, goes in column 2start
is offsets-1 years
instead ofs years
becausestart
is always the first date in the table, therefore the first calculation must bestart+0yr
notstart+1yr
: { start+0yr; start+1yr; start+2yr; start+3yr; start+4yr }- lastly, the negative "Premium amount" (
-prem
) is placed in column 3, but only if the date in column 2 falls within the "Prem. pmt term" (pmt
), otherwise a0
is placed instead现在来构建三列数组:
- 第一行设置为 { "Cashflow", "Year", "Outflow" }
- 每一行在**“Cashflow”**列中都有
s
:{ 1; 2; 3; 4; 5 }- “开始日期”
start
,通过s-1年
偏移,放在第2列start
被偏移s-1年
而不是s年
,因为start
始终是表格中的第一个日期,因此第一次计算必须是start+0年
而不是`
英文:
>This process of manually entering the dates as per the cashflow is quite tedious and I am sure there is a better way to manage this.
Example: Policy XXXX1245S
- "Year" column is a range of dates.
- First date is the "Start Date" in
Cashflow sheet'!J5
- Dates increment by 1 year
- Final date is x years after the "Start Date" where x = "Policy term"
'Cashflow sheet'!J9
- First date is the "Start Date" in
- Outflow is a number based on the "Premium amount"
'Cashflow sheet'!J3
- Outflow is included on the "Start Date" and for y more years, where y = "Prem. pmt term"
'Cashflow sheet'!J8
- Outflow is included on the "Start Date" and for y more years, where y = "Prem. pmt term"
Named Ranges
To make the formula easier to follow I've used named ranges
Name | Reference | Notes |
---|---|---|
pmt | 'Cashflow sheet'!J8 |
Prem. pmt term |
pol | 'Cashflow sheet'!J9 |
Policy term |
start | 'Cashflow sheet'!J5 |
Start date |
prem | 'Cashflow sheet'!J3 |
Premium amount |
Formula
The following formula will dynamically create the first three columns <sup><img src="https://i.stack.imgur.com/o2bPu.png" width="200" /></sup> with as many rows as is required and properly populated. If the logic for the "Inflow" column was better understood, it too could be populated in the same formula. Frankly the entire table including the information at the top could probably be populated from one formula based solely on the "Policy No." if all the required data is stored in the Master List
sheet.
={ "Cashflow", "Year", "Outflow";
MAP(SEQUENCE(pol+1), LAMBDA(s,
{ s,(EDATE(start, (s-1)*12)), IF(s<=pmt,-prem,0) })) }
<img src="https://i.stack.imgur.com/w0BOJ.png" width="600" />
- A LAMBDA function is used to create the array.
- A SEQUENCE of numbers representing policy term years is generated and MAP into the LAMBDA function which applies the formula once for each value in the SEQUENCE
- "Cashflow" column is equal to the position in the SEQUENCE, so the mapped value
s
is placed in the first column. - In the "Year" column EDATE is used to offset the "Start Date" by the number of years equal to the mapped value
(s-1)*12
. The years are multiplied by 12 because EDATE offsets in months. - Finally, the "Outflow" column is populated with the "Premium Amount" if the mapped value
s
is <= to the "Prem. pmt term". If not, the "Outflow" column is set to zero.
Additional Info
The SEQUENCE function creates an array of specified dimensions, populated with a number sequence starting at a specified value, and incrementing (stepping) by another specified value. The only required value, however, is rows (height).
Syntax: SEQUENCE(rows, [columns], [start], [step])
=SEQUENCE(5) // rows=5, cols=1, start=1, step=1
={1;2;3;4;5}
=SEQUENCE(2,4) // rows=2, cols=4, start=1, step=1
={1,2,3,4;5,6,7,8}
The MAP function enables mapping a set of values into a LAMBDA function. Inside the LAMBDA function, a formula can be applied iteratively to each mapped value. The LAMBDA declares one (arbitrary) name (variable) for each set of mapped values which the formula uses in order to refer to the current mapped value.
# one set of values mapped
=MAP(values, LAMBDA(name, formula))
# two sets of values mapped
=MAP(values1, values2, LAMBDA(name1, name2, formula))
So, looking at the initial MAP and LAMBDA parts of the formula:
# - 'pol+1' is sequenced instead of 'pol' because
# it was noted that the date list was always 1
# row longer than the number in "Policy term"
# - 's+0' is the 'formula' in this example just to
# avoid confusing the 'name' and the 'formula'
# - 'pol'=4 in this example
# - 'MAP(values, LAMBDA(name, formula))'
=MAP(SEQUENCE(pol+1), LAMBDA(s, s+0)
={ 1; 2; 3; 4; 5 }
Now to build the 3 column array:
- The first row is set as
{ "Cashflow", "Year", "Outflow" }
- Each row has
s
in the "Cashflow" column:
{ 1; 2; 3; 4; 5 }
- the "Start date"
start
, offset bys-1 years
, goes in column 2 start
is offsets-1 years
instead ofs years
becausestart
is always the first date in the table, therefore the first calculation must bestart+0yr
notstart+1yr
:
{ start+0yr; start+1yr; start+2yr; start+3yr; start+4yr }
- lastly, the negative "Premium amount" (
-prem
) is placed in column 3, but only if the date in column 2 falls within the "Prem. pmt term" (pmt
), otherwise a0
is placed instead
# - Instead of 'start+(s-1)years', as EDATE
# offsets in months (not years), the calculation
# is adapted by multiplying by 12:
# '(EDATE(start, (s-1)*12)'
# - 'pol'=4, 'start'=2/28/2021,
# 'prem'=199, `pmt`=3
={ "Cashflow", "Year", "Outflow";
MAP(SEQUENCE(pol+1), LAMBDA(s,
{ s,(EDATE(start, (s-1)*12)),
IF(s<=pmt,-prem,0) }
))
}
= { "Cashflow", "Year", "Outflow";
1, 2/28/2021, -199;
2, 2/28/2022, -199;
3, 2/28/2023, -199;
4, 2/28/2024, 0;
5, 2/28/2025, 0 }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论