Commit 50b93469 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

исправлены функции MDURATION и DURATION

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55618 954022d7-b5bf-4e40-9824-e11837661b57
parent bdae7d32
...@@ -332,29 +332,33 @@ ...@@ -332,29 +332,33 @@
} }
function _duration( settlement, maturity, coupon, yld, frequency, basis ){ function _duration( settlement, maturity, coupon, yld, frequency, basis ){
var dbc = getcoupdaybs(new Date( settlement ),new Date( maturity ),frequency,basis),
coupD = getcoupdays(new Date( settlement ),new Date( maturity ),frequency,basis),
numCoup = getcoupnum(new Date( settlement ),new Date( maturity ),frequency);
var yearfrac = _yearFrac( new Date( settlement ), new Date( maturity ), basis ); var duration = 0, p = 0;
var numOfCoups = _coupnum( new Date( settlement ), new Date( maturity ), frequency );
var duration = 0, f100 = 100;
coupon *= f100 / frequency;
yld /= frequency;
yld += 1;
var nDiff = yearfrac * frequency - numOfCoups; var dsc = coupD - dbc;
var diff = dsc / coupD - 1;
yld = yld / frequency + 1;
var p = 0;
for ( var i = 1; i < numOfCoups; i++ ) { coupon *= 100/frequency;
duration += ( i + nDiff ) * ( coupon ) / Math.pow( yld, i + nDiff );
p += coupon / Math.pow( yld, i + nDiff ); for(var index = 1; index <= numCoup; index++ ){
} var di = index + diff;
var yldPOW = Math.pow( yld, di);
duration += ( numOfCoups + nDiff ) * ( coupon + f100 ) / Math.pow( yld, numOfCoups + nDiff ); duration += di * coupon / yldPOW;
p += ( coupon + f100 ) / Math.pow( yld, numOfCoups + nDiff );
p += coupon / yldPOW;
}
duration = duration / p / frequency; duration += (diff + numCoup) * 100 / Math.pow( yld, diff + numCoup);
p += 100 / Math.pow( yld, diff + numCoup);
return duration; return duration / p / frequency ;
} }
var ver = 2; var ver = 2;
......
...@@ -262,28 +262,34 @@ function getyieldmat( settle, mat, issue, rate, price, base ){ ...@@ -262,28 +262,34 @@ function getyieldmat( settle, mat, issue, rate, price, base ){
function getduration( settlement, maturity, coupon, yld, frequency, basis ){ function getduration( settlement, maturity, coupon, yld, frequency, basis ){
var yearfrac = yearFrac( new Date( settlement ), new Date( maturity ), basis ).getValue(); var dbc = getcoupdaybs(new Date( settlement ),new Date( maturity ),frequency,basis),
var numOfCoups = getcoupnum( new Date( settlement ), new Date( maturity ), frequency ); coupD = getcoupdays(new Date( settlement ),new Date( maturity ),frequency,basis),
var duration = 0, f100 = 100; numCoup = getcoupnum(new Date( settlement ),new Date( maturity ),frequency);
coupon *= f100 / frequency;
yld /= frequency;
yld += 1;
var nDiff = yearfrac * frequency - numOfCoups; var duration = 0, p = 0;
var p = 0; var dsc = coupD - dbc;
var diff = dsc / coupD - 1;
yld = yld / frequency + 1;
for ( var i = 1; i < numOfCoups; i++ ) {
duration += ( i + nDiff ) * ( coupon ) / Math.pow( yld, i + nDiff ); coupon *= 100/frequency;
p += coupon / Math.pow( yld, i + nDiff );
for(var index = 1; index <= numCoup; index++ ){
var di = index + diff;
var yldPOW = Math.pow( yld, di);
duration += di * coupon / yldPOW;
p += coupon / yldPOW;
} }
duration += ( numOfCoups + nDiff ) * ( coupon + f100 ) / Math.pow( yld, numOfCoups + nDiff ); duration += (diff + numCoup) * 100 / Math.pow( yld, diff + numCoup);
p += ( coupon + f100 ) / Math.pow( yld, numOfCoups + nDiff ); p += 100 / Math.pow( yld, diff + numCoup);
duration = duration / p / frequency; return duration / p / frequency ;
return duration;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment