dポイントプレゼントキャンペーン実施中!

Excel関数のRATEと同様な処理を
Javaで実装したいのですが、どのように実装すれば良いのでしょうか。

具体的なソースを教えて頂けると大変助かります。
よろしくお願いします。

A 回答 (1件)

public class Rate{


double F,P,N,p;
double off=0.1/*利率初期推測値*/;
int t;/*支払期日 期末0 期首1*/

/**
*@param F 将来価値
*@param P 現在価値
*@param N 支払回数
*@param p 定期支払額
*/
Rate(double F,double P,int N,int p){
this.F=F;this.P=P;this.N=N;this.p=p;
}

/**
*利率を算出する.
*@return 利率
*/
public double calculate(){
double p1=off,p2;int c=0;
while(true){
c++;p2=n(p1);
if(c>20){if(Math.abs(p2-p1)>1E-7)p1=Double.NaN;break;}
p1=p2;
}
return p1;
}

double n(double r){
return r-(P*p(1+r,N)+p*(1+r*t)*(p(1+r,N)-1)/r+F)/(P*N*p(1+r,N-1)
+p*(r*(t*(p(1+r,N)-1)+N*(1+r*t)*p(1+r,N-1))-(1+r*t)*(p(1+r,N)-1))/p(r,2));
}

double p(double a,double b){return Math.pow(a,b);}

public static void main(String[] args){
/*使用例*/
int F=Integer.parseInt(args[0]);
int P=Integer.parseInt(args[1]);
int N=Integer.parseInt(args[2]);
int p=Integer.parseInt(args[3]);

Rate rate=new Rate(F,P,N,p);
System.out.println(rate.calculate());
}
}

参考URL:http://excel.onushi.com/function/rate.htm
    • good
    • 0
この回答へのお礼

kacchannさま

大変参考になります。
どうもありがとうございました。

お礼日時:2007/09/26 19:14

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!