问题描述
我下面有一个10期费用曲线表.我如何以编程方式将其折叠/压缩/缩小到4个周期.我正在使用VBA,但我应该能够使用其他语言.该例程应在您经历的任何时间段都起作用.例如,如果我将其传递为7,则应将百分比压缩为7个周期.如果我通过24,则将百分比扩展到24个周期,并根据原始曲线扩展百分比.任何帮助或示例,将不胜感激.谢谢...
I have a 10 period cost curve table below. How do I programmatically collapse/condense/shrink this to 4 periods. I'm using VBA but I should be able to follow other languages. The routine should work for whatever period you pass to it. For example, if I pass it a 7 it should condense the percentages to 7 periods. If I pass it 24 then expand the percentages to 24 periods, spreading the percentages based on the original curve. Any help or example will be appreciated. Thanks...
ORIGINAL
Period Pct
1 10.60%
2 19.00%
3 18.30%
4 14.50%
5 10.70%
6 8.90%
7 6.50%
8 3.10%
9 3.00%
10 5.40%
COLLAPSED
Period Pct
1 38.75%
2 34.35%
3 16.95%
4 9.95%
我已经在下面添加了到目前为止的示例代码.它仅在1、2、3、5、9、10期间有效.也许有人可以帮助修改它以在任何时期内正常工作.免责声明,我不是程序员,所以我的编码不好.另外,我不知道自己在做什么.
EDITED: I've added sample code below as to what I have so far. It only works for periods 1, 2, 3, 5, 9, 10. Maybe someone can help modify it to work for any period. Disclaimer, I'm not a programmer so my coding is bad. Plus, I have no clue as to what I'm doing.
Sub Collapse_Periods()
Dim aPct As Variant
Dim aPer As Variant
aPct = Array(0.106, 0.19, 0.183, 0.145, 0.107, 0.089, 0.065, 0.031, 0.03, 0.054)
aPer = Array(1, 2, 3, 5, 9, 10)
For i = 0 To UBound(aPer)
pm = 10 / aPer(i)
pct1 = 1
p = 0
ttl = 0
For j = 1 To aPer(i)
pct = 0
k = 1
Do While k <= pm
pct = pct + aPct(p) * pct1
pct1 = 1
p = p + 1
If k <> pm And k = Int(pm) Then
pct1 = (pm - Int(pm)) * j
pct = pct + (pct1 * aPct(p))
pct1 = 1 - pct1
End If
k = k + 1
Loop
Debug.Print aPer(i) & " : " & j & " : " & pct
ttl = ttl + pct
Next j
Debug.Print "Total: " & ttl
Next i
End Sub
推荐答案
这篇关于将10个周期的曲线折叠为4个周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!