我试图估计一个应用美元成本平均的投资计划的年度,其价值增量如下所列(抱歉,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 中的函数,如http://www.walkingrandomly.com/?p=5254nls
中所建议的那样。但问题是,投资方案已经交易了 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"))