在R中进行曲线拟合以获得幂级数

时间:2015-05-20 09:51:58

标签: r power-series

我试图估算应用美元成本平均的投资计划的年度,价值增量如下所示(对不起,MathJax看起来像希腊,所以我没有使用它):

x: regular contribution, which is 1500 in my case
y: rate of return PLUS 100% (e.g 1.07 for a 7% return), which is the parameters that I want to estimate.

Time 1: xy
Time 2: (x + xy)*y
Time 3: (x + (x + xy)*y)*y
Time 4: (x + (x + (x + xy)*y)*y)*y
Time 5: (x + (x + (x + (x + xy)*y)*y)*y)*y
Time 6: (x + (x + (x + (x + (x + xy)*y)*y)*y)*y)*y

列表继续。

在简化等式后,如果我正确计算它,它应该是幂级数:

xy(1 + y + y^2 + y^3 + y^4 + y^5 +y^6)

我知道上面的等式可以用于R中的nls函数,如http://www.walkingrandomly.com/?p=5254中所述。但问题是,投资计划已经交易超过6次,交易数量是可变的,我不愿意确定公式中的交易数量。

我想知道R是否可以创建一个具有可变长度的幂级数的公式,类似函数?

更新01

感谢@Roland的评论,我的数据框dput如下所示:

structure(list(date = 1:62, value = c(1500, 3008.1048, 4279.09223337264, 
5701.16001583254, 7545.25391699441, 8883.87795645887, 11192.7249445628, 
13043.5267669473, 14396.3707754063, 16677.2027610312, 18474.8268536672, 
20225.6882177597, 21889.6372952495, 24090.0451286292, 25305.8719822623, 
26293.5164474925, 27470.5608573055, 26851.4637959011, 25610.4708389126, 
29781.3033136099, 30244.449772352, 31757.1977515, 35216.3065708333, 
38661.857424377, 40153.0021899712, 41453.1839013205, 39626.0241467687, 
42464.6515262833, 44415.7606695956, 46456.2932413184, 49539.1291983018, 
51223.0944673951, 53534.0828137635, 56511.2727118443, 60750.8112270199, 
62420.4165280642, 64561.1738159384, 67269.7609015725, 69582.2433935286, 
68461.4426685366, 72790.7668201147, 73029.1128824367, 77963.2040906503, 
81782.8304828104, 84781.7088147301, 87010.8577769314, 85461.5060309602, 
90165.7453255817, 91340.1347579196, 92918.1083054977, 96713.3387975151, 
99841.2477244806, 101538.099862003, 104946.468993318, 103233.508326534, 
106416.67466519, 109991.955526668, 110800.989092493, 112258.758666778, 
118567.887527905, 120872.966926589, 127711.586247323), expected_value = c(1511.96121064336, 
3035.97901230344, 4572.1495459301, 6120.56971911465, 7681.33721220313, 
9254.55048445835, 10840.3087802712, 12438.7121354211, 14049.861383387, 
15673.8581617081, 17310.8049183956, 18960.8049183956, 20623.9622501033, 
22300.3818319294, 23990.1694189188, 25693.4316094218, 27410.2758518191, 
29140.8104512998, 30885.1445766939, 32643.3882673588, 34415.6524401213, 
36202.0488962746, 38002.6903286308, 39817.6903286308, 41647.1633935093, 
43491.224933518, 45349.9912792063, 47223.5796887596, 49112.1083553966, 
51015.6964148254, 52934.4639527589, 54868.5320124903, 56818.0226025291, 
58783.0587042976, 60763.7642798896, 62760.2642798896, 64772.6846512559, 
66801.1523452654, 68845.7953255225, 70906.7425760312, 72984.1241093319, 
75078.0709747036, 77188.7152664305, 79316.190132135, 81460.6297811776, 
83622.169493123, 85800.9456262742, 87997.0956262742, 90210.7580347771, 
92442.0724981876, 94691.1797764704, 96958.2217520299, 99243.3414386608, 
101546.68299057, 103868.391711469, 106208.614063744, 108567.497677691, 
110945.191360831, 113341.845107297, 115757.610107297, 118192.63875665, 
120647.084666402)), .Names = c("date", "value", "expected_value"
), row.names = c("63", "62", "61", "60", "59", "58", "57", "56", 
"55", "54", "53", "52", "51", "50", "49", "48", "47", "46", "45", 
"44", "43", "42", "41", "40", "39", "38", "37", "36", "35", "34", 
"33", "32", "31", "30", "29", "28", "27", "26", "25", "24", "23", 
"22", "21", "20", "19", "18", "17", "16", "15", "14", "13", "12", 
"11", "10", "9", "8", "7", "6", "5", "4", "510", "410"), class = c("tbl_df", 
"tbl", "data.frame"))

0 个答案:

没有答案