您的位置:首页 > 其它

复利计算程序

2016-02-16 17:23 169 查看
如果每个月获利6%,一年就可以翻番。。。

01 - 50211(06.18%) : 48758(03.11%) => BAD

02 - 53314(12.74%) : 55608(17.59%) => GOOD

================================== => 2.12%

03 - 56608(19.71%) : 55608(17.59%) => BAD

04 - 60107(27.11%) : 55608(17.59%) => BAD

05 - 63821(34.96%) : 55608(17.59%) => BAD

06 - 67765(43.30%) : 55608(17.59%) => BAD

07 - 71953(52.16%) : 55608(17.59%) => BAD

08 - 76400(61.56%) : 55608(17.59%) => BAD

09 - 81122(71.55%) : 55608(17.59%) => BAD

10 - 86135(82.15%) : 55608(17.59%) => BAD

11 - 91458(93.41%) : 55608(17.59%) => BAD

12 - 97110(105.36%) : 55608(17.59%) => BAD

static void Main(string[] args)
{
    double[] dataset = { 47288.15F/*2015.12*/, 48758.18F/*2016.01.31*/, 55608.18F/*2016.02.29*/ };

    CompoundInterest(dataset);
}

static void CompoundInterest(double[] dataset, float rate = 0.0618F, float N = 12)
{
    if (null == dataset || 2 > dataset.Length || 2 > N)
    {
        throw new ArgumentException();
    }

    double baseline = dataset[0];
            
    for (int i = 1; i <= N; i++)
    {
        double anticipation = Math.Pow((1.0 + rate), i);

        double actuality = i < dataset.Length ? dataset[i] / baseline : dataset[dataset.Length - 1] / baseline;

        if (i == dataset.Length)
        {
            Console.WriteLine("================================== => {0:.00}%"
                , ((anticipation - actuality) * 100));
        }

        string msg = string.Format("{0:00} - {1:00}({2:00.00}%) : {3:00}({4:00.00}%) => {5}", i
            , anticipation * baseline, (anticipation - 1.0) * 100
            , actuality * baseline, (actuality - 1.0) * 100
            , anticipation < actuality ? "GOOD" : "BAD");

        Console.WriteLine(msg);
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: