您的位置:首页 > 其它

p2p按年化率计算收益简单算法

2016-02-24 09:58 369 查看
p2p一般按年化率来计算投资收益,下面是一个简单的算法计算天标、月标、年标的收益。

public class Arith{

public double computeIncomeAmount(){
double incomeAmount = 0.00;// 标的收益

double apr=15 //年化率

int periodUnit =0 //-1:天标 0:月标 1:年标

int period=1  //投资期限

switch (periodUnit) {
case -1:
incomeAmount = Arith.round(apr / 100 * period * investAmount, 2);
break;
case 0:
incomeAmount = Arith.round(apr / 12 / 100 * period * investAmount,
2);
break;
case 1:
incomeAmount = Arith.round(apr / 360 / 100 * period * investAmount,
2);
break;
}
return incomeAmount;
}
/**
* 功能:提供精确的小数位四舍五入处理。
* @param v 需要四舍五入的数字
* @param scale 小数点后保留几位
* @return 四舍五入后的结果
*/
public static double round(double v, int scale) {
if (scale < 0) {
throw new IllegalArgumentException("精确度不能小于0!");

}

BigDecimal b = new BigDecimal(Double.toString(v));

return b.setScale(scale,BigDecimal.ROUND_HALF_UP).doubleValue();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  p2p 投资 算法