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

Добавлены функции: PPMT, MIRR, IPMT, DB, DDB, SLN.

исправлена ошибка при переносе ячеек с формулами.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55377 954022d7-b5bf-4e40-9824-e11837661b57
parent fea5960a
This diff is collapsed.
......@@ -279,6 +279,43 @@
}
function _coupnum( settlement, maturity, frequency, basis ) {
basis = ( basis !== undefined ? basis : 0 );
var n = new Date(maturity);
_lcl_GetCouppcd( settlement, n, frequency );
var nMonths = (maturity.getFullYear() - n.getFullYear()) * 12 + maturity.getMonth() - n.getMonth();
return nMonths * frequency / 12 ;
}
function _duration( settlement, maturity, coupon, yld, frequency, basis ){
var yearfrac = _yearFrac( new Date( settlement ), new Date( maturity ), basis );
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 p = 0;
for ( var i = 1; i < numOfCoups; i++ ) {
duration += ( i + nDiff ) * ( coupon ) / Math.pow( yld, i + nDiff );
p += coupon / Math.pow( yld, i + nDiff );
}
duration += ( numOfCoups + nDiff ) * ( coupon + f100 ) / Math.pow( yld, numOfCoups + nDiff );
p += ( coupon + f100 ) / Math.pow( yld, numOfCoups + nDiff );
duration = duration / p / frequency;
return duration;
}
var ver = 2;
var oParser, wb, ws, date1, date2, dif = 1e-9,
......@@ -4032,20 +4069,9 @@
test( "Test: \"COUPNUM\"", function () {
function coupnum( settlement, maturity, frequency, basis ) {
basis = ( basis !== undefined ? basis : 0 );
var n = new Date(maturity);
_lcl_GetCouppcd( settlement, n, frequency );
var nMonths = (maturity.getFullYear() - n.getFullYear()) * 12 + maturity.getMonth() - n.getMonth();
return nMonths * frequency / 12 ;
}
oParser = new parserFormula( "COUPNUM(DATE(2007,1,25),DATE(2008,11,15),2,1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), coupnum( new Date(2007,0,25), new Date(2008,10,15), 2, 1 ) );
strictEqual( oParser.calculate().getValue(), _coupnum( new Date(2007,0,25), new Date(2008,10,15), 2, 1 ) );
} )
......@@ -4090,9 +4116,9 @@
function pricemat( settl, matur, iss, rate, yld, basis ) {
var fIssMat = yearFrac( new Date(iss), new Date(matur), basis );
var fIssSet = yearFrac( new Date(iss), new Date(settl), basis );
var fSetMat = yearFrac( new Date(settl), new Date(matur), basis );
var fIssMat = _yearFrac( new Date(iss), new Date(matur), basis );
var fIssSet = _yearFrac( new Date(iss), new Date(settl), basis );
var fSetMat = _yearFrac( new Date(settl), new Date(matur), basis );
var res = 1.0 + fIssMat * rate;
res /= 1.0 + fSetMat * yld;
......@@ -4132,7 +4158,6 @@
} )
test( "Test: \"YIELDMAT\"", function () {
oParser = new parserFormula( "YIELDMAT(DATE(2008,3,15),DATE(2008,11,3),DATE(2007,11,8),0.0625,100.0123,0)", "A2", ws );
......@@ -4166,9 +4191,9 @@
function oddlyield( settlement, maturity, last_interest, rate, pr, redemption, frequency, basis ){
var fDCi = yearFrac( last_interest, maturity, basis ) * frequency;
var fDSCi = yearFrac( settlement, maturity, basis ) * frequency;
var fAi = yearFrac( last_interest, settlement, basis ) * frequency;
var fDCi = _yearFrac( last_interest, maturity, basis ) * frequency;
var fDSCi = _yearFrac( settlement, maturity, basis ) * frequency;
var fAi = _yearFrac( last_interest, settlement, basis ) * frequency;
var res = redemption + fDCi * 100.0 * rate / frequency;
res /= pr + fAi * 100.0 * rate / frequency;
......@@ -4184,6 +4209,28 @@
} )
test( "Test: \"DURATION\"", function () {
oParser = new parserFormula( "DURATION(DATE(2008,1,1),DATE(2016,1,1),0.08,0.09,2,1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), _duration( new Date(2008,0,1), new Date(2016,0,1), 0.08, 0.09, 2, 1 ) );
} )
test( "Test: \"MDURATION\"", function () {
function mduration(settl, matur, coupon, yld, frequency, basis){
return _duration( settl, matur, coupon, yld, frequency, basis ) / (1 + yld/frequency);
}
oParser = new parserFormula( "MDURATION(DATE(2008,1,1),DATE(2016,1,1),0.08,0.09,2,1)", "A2", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), mduration( new Date(2008,0,1), new Date(2016,0,1), 0.08, 0.09, 2, 1 ) );
} )
test( "Test: \"SYD\"", function () {
function syd( cost, salvage, life, per ){
......@@ -4213,5 +4260,4 @@
} )
} );
"use strict";
function ConvertToDec( aStrSource, nBase, nCharLim ){
if ( nBase < 2 || nBase > 36 )
return "Error #1";
var nStrLen = aStrSource.length;
if( nStrLen > nCharLim )
return "Error #2";
else if( !nStrLen )
return 0;
var fVal = 0;
var p = aStrSource;
var nFirstDig = 0;
var bFirstDig = true;
var fBase = nBase;
for(var i=0; i < p.length; i++)
{
var n;
if( '0' <= p[i] && p[i] <= '9' )
n = p[i].charCodeAt() - '0'.charCodeAt();
else if( 'A' <= p[i] && p[i] <= 'Z' )
n = 10 + ( p[i].charCodeAt() - 'A'.charCodeAt() );
else if ( 'a' <= p[i] && p[i] <= 'z' )
n = 10 + ( p[i].charCodeAt() - 'a'.charCodeAt() );
else
n = nBase;
if( n < nBase )
{
if( bFirstDig )
{
bFirstDig = false;
nFirstDig = n;
}
fVal = fVal * fBase + n;
}
else
return "Error #3"
}
if( nStrLen == nCharLim && !bFirstDig && (nFirstDig >= nBase / 2) )
{ // handling negativ values
fVal = ( Math.pow( nBase, nCharLim ) - fVal ); // complement
fVal *= -1.0;
}
return fVal;
}
/**
* Created with JetBrains WebStorm.
* User: Dmitry.Shahtanov
......
......@@ -4101,9 +4101,7 @@ RangeDataManager.prototype = {
},
move : function(from, to)
{
//убираем fChange, чтобы потом послать его только на одну операцию, а не 2
var fOldChange = this.fChange;
this.fChange = null;
var fOldChange = this.fChange;
var nOffsetRow = to.r1 - from.r1;
var nOffsetCol = to.c1 - from.c1;
var oGetRes = this.get(from);
......@@ -4113,10 +4111,13 @@ RangeDataManager.prototype = {
var oNewBBox = new Asc.Range(elem.bbox.c1 + nOffsetCol, elem.bbox.r1 + nOffsetRow, elem.bbox.c2 + nOffsetCol, elem.bbox.r2 + nOffsetRow);
if(null != fOldChange)
fOldChange.call(this, elem.data, elem.bbox, oNewBBox);
//убираем fChange, чтобы потом послать его только на одну операцию, а не 2
this.fChange = null;
this.removeElement(elem);
this.add(oNewBBox, elem.data);
this.fChange = fOldChange;
}
this.fChange = fOldChange;
},
getAll : function()
{
......@@ -4312,9 +4313,7 @@ CellArea.prototype = {
},
move : function(from, to)
{
//убираем fChange, чтобы потом послать его только на одну операцию, а не 2
var fOldChange = this.fChange;
this.fChange = null;
var fOldChange = this.fChange;
var nOffsetRow = to.r1 - from.r1;
var nOffsetCol = to.c1 - from.c1;
var oGetRes = this.get(from);
......@@ -4324,10 +4323,12 @@ CellArea.prototype = {
var oNewBBox = new Asc.Range(elem.bbox.c1 + nOffsetCol, elem.bbox.r1 + nOffsetRow, elem.bbox.c2 + nOffsetCol, elem.bbox.r2 + nOffsetRow);
if(null != fOldChange)
fOldChange.call(this, elem.data, elem.bbox, oNewBBox);
//убираем fChange, чтобы потом послать его только на одну операцию, а не 2
this.fChange = null;
this.removeElement(elem);
this.add(oNewBBox.r1, oNewBBox.c1, elem.data);
this.fChange = fOldChange;
}
this.fChange = fOldChange;
},
getAll : function(){
var aRes = [];
......
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