Update ooo320-m1
[ooovba.git] / scaddins / source / analysis / financial.cxx
blob7064fa6df9b6f6cd036e470faf8fa3cd81608937
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: financial.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "analysis.hxx"
32 #include "analysishelper.hxx"
33 #include <rtl/math.hxx>
37 double SAL_CALL AnalysisAddIn::getAmordegrc( constREFXPS& xOpt,
38 double fCost, sal_Int32 nDate, sal_Int32 nFirstPer, double fRestVal,
39 double fPer, double fRate, const ANY& rOB ) THROWDEF_RTE_IAE
41 if( nDate > nFirstPer || fRate <= 0.0 || fRestVal > fCost )
42 THROW_IAE;
44 double fRet = GetAmordegrc( GetNullDate( xOpt ), fCost, nDate, nFirstPer, fRestVal, fPer, fRate, getDateMode( xOpt, rOB ) );
45 RETURN_FINITE( fRet );
49 double SAL_CALL AnalysisAddIn::getAmorlinc( constREFXPS& xOpt,
50 double fCost, sal_Int32 nDate, sal_Int32 nFirstPer, double fRestVal,
51 double fPer, double fRate, const ANY& rOB ) THROWDEF_RTE_IAE
53 if( nDate > nFirstPer || fRate <= 0.0 || fRestVal > fCost )
54 THROW_IAE;
56 double fRet = GetAmorlinc( GetNullDate( xOpt ), fCost, nDate, nFirstPer, fRestVal, fPer, fRate, getDateMode( xOpt, rOB ) );
57 RETURN_FINITE( fRet );
61 double SAL_CALL AnalysisAddIn::getAccrint( constREFXPS& xOpt,
62 sal_Int32 nIssue, sal_Int32 /*nFirstInter*/, sal_Int32 nSettle, double fRate,
63 const ANY &rVal, sal_Int32 nFreq, const ANY& rOB ) THROWDEF_RTE_IAE
65 double fVal = aAnyConv.getDouble( xOpt, rVal, 1000.0 );
67 if( fRate <= 0.0 || fVal <= 0.0 || CHK_Freq || nIssue >= nSettle )
68 THROW_IAE;
70 double fRet = fVal * fRate * GetYearDiff( GetNullDate( xOpt ), nIssue, nSettle, getDateMode( xOpt, rOB ) );
71 RETURN_FINITE( fRet );
75 double SAL_CALL AnalysisAddIn::getAccrintm( constREFXPS& xOpt,
76 sal_Int32 nIssue, sal_Int32 nSettle, double fRate, const ANY& rVal, const ANY& rOB ) THROWDEF_RTE_IAE
78 double fVal = aAnyConv.getDouble( xOpt, rVal, 1000.0 );
80 if( fRate <= 0.0 || fVal <= 0.0 || nIssue >= nSettle )
81 THROW_IAE;
83 double fRet = fVal * fRate * GetYearDiff( GetNullDate( xOpt ), nIssue, nSettle, getDateMode( xOpt, rOB ) );
84 RETURN_FINITE( fRet );
88 double SAL_CALL AnalysisAddIn::getReceived( constREFXPS& xOpt,
89 sal_Int32 nSettle, sal_Int32 nMat, double fInvest, double fDisc, const ANY& rOB ) THROWDEF_RTE_IAE
91 if( fInvest <= 0.0 || fDisc <= 0.0 )
92 THROW_IAE;
94 double fRet = fInvest / ( 1.0 - ( fDisc * GetYearDiff( GetNullDate( xOpt ), nSettle, nMat, getDateMode( xOpt, rOB ) ) ) );
95 RETURN_FINITE( fRet );
99 double SAL_CALL AnalysisAddIn::getDisc( constREFXPS& xOpt,
100 sal_Int32 nSettle, sal_Int32 nMat, double fPrice, double fRedemp, const ANY& rOB ) THROWDEF_RTE_IAE
102 if( fPrice <= 0.0 || fRedemp <= 0.0 || nSettle >= nMat )
103 THROW_IAE;
104 double fRet = ( 1.0 - fPrice / fRedemp ) / GetYearFrac( xOpt, nSettle, nMat, getDateMode( xOpt, rOB ) );
105 RETURN_FINITE( fRet );
109 double SAL_CALL AnalysisAddIn::getDuration( constREFXPS& xOpt,
110 sal_Int32 nSettle, sal_Int32 nMat, double fCoup, double fYield, sal_Int32 nFreq, const ANY& rOB )
111 THROWDEF_RTE_IAE
113 if( fCoup < 0.0 || fYield < 0.0 || CHK_Freq || nSettle >= nMat )
114 THROW_IAE;
116 double fRet = GetDuration( GetNullDate( xOpt ), nSettle, nMat, fCoup, fYield, nFreq, getDateMode( xOpt, rOB ) );
117 RETURN_FINITE( fRet );
121 double SAL_CALL AnalysisAddIn::getEffect( double fNominal, sal_Int32 nPeriods ) THROWDEF_RTE_IAE
123 if( nPeriods < 1 || fNominal <= 0.0 )
124 THROW_IAE;
126 double fPeriods = nPeriods;
128 double fRet = pow( 1.0 + fNominal / fPeriods, fPeriods ) - 1.0;
129 RETURN_FINITE( fRet );
133 double SAL_CALL AnalysisAddIn::getCumprinc( double fRate, sal_Int32 nNumPeriods, double fVal,
134 sal_Int32 nStartPer, sal_Int32 nEndPer, sal_Int32 nPayType ) THROWDEF_RTE_IAE
136 double fRmz, fKapZ;
138 if( nStartPer < 1 || nEndPer < nStartPer || fRate <= 0.0 || nEndPer > nNumPeriods || nNumPeriods <= 0 ||
139 fVal <= 0.0 || ( nPayType != 0 && nPayType != 1 ) )
140 THROW_IAE;
142 fRmz = GetRmz( fRate, nNumPeriods, fVal, 0.0, nPayType );
144 fKapZ = 0.0;
146 sal_uInt32 nStart = sal_uInt32( nStartPer );
147 sal_uInt32 nEnd = sal_uInt32( nEndPer );
149 if( nStart == 1 )
151 if( nPayType <= 0 )
152 fKapZ = fRmz + fVal * fRate;
153 else
154 fKapZ = fRmz;
156 nStart++;
159 for( sal_uInt32 i = nStart ; i <= nEnd ; i++ )
161 if( nPayType > 0 )
162 fKapZ += fRmz - ( GetZw( fRate, double( i - 2 ), fRmz, fVal, 1 ) - fRmz ) * fRate;
163 else
164 fKapZ += fRmz - GetZw( fRate, double( i - 1 ), fRmz, fVal, 0 ) * fRate;
167 RETURN_FINITE( fKapZ );
171 double SAL_CALL AnalysisAddIn::getCumipmt( double fRate, sal_Int32 nNumPeriods, double fVal,
172 sal_Int32 nStartPer, sal_Int32 nEndPer, sal_Int32 nPayType ) THROWDEF_RTE_IAE
174 double fRmz, fZinsZ;
176 if( nStartPer < 1 || nEndPer < nStartPer || fRate <= 0.0 || nEndPer > nNumPeriods || nNumPeriods <= 0 ||
177 fVal <= 0.0 || ( nPayType != 0 && nPayType != 1 ) )
178 THROW_IAE;
180 fRmz = GetRmz( fRate, nNumPeriods, fVal, 0.0, nPayType );
182 fZinsZ = 0.0;
184 sal_uInt32 nStart = sal_uInt32( nStartPer );
185 sal_uInt32 nEnd = sal_uInt32( nEndPer );
187 if( nStart == 1 )
189 if( nPayType <= 0 )
190 fZinsZ = -fVal;
192 nStart++;
195 for( sal_uInt32 i = nStart ; i <= nEnd ; i++ )
197 if( nPayType > 0 )
198 fZinsZ += GetZw( fRate, double( i - 2 ), fRmz, fVal, 1 ) - fRmz;
199 else
200 fZinsZ += GetZw( fRate, double( i - 1 ), fRmz, fVal, 0 );
203 fZinsZ *= fRate;
205 RETURN_FINITE( fZinsZ );
209 double SAL_CALL AnalysisAddIn::getPrice( constREFXPS& xOpt,
210 sal_Int32 nSettle, sal_Int32 nMat, double fRate, double fYield, double fRedemp, sal_Int32 nFreq,
211 const ANY& rOB ) THROWDEF_RTE_IAE
213 if( fYield < 0.0 || fRate < 0.0 || fRedemp <= 0 || CHK_Freq || nSettle >= nMat )
214 THROW_IAE;
216 double fRet = getPrice_( GetNullDate( xOpt ), nSettle, nMat, fRate, fYield, fRedemp, nFreq, getDateMode( xOpt, rOB ) );
217 RETURN_FINITE( fRet );
221 double SAL_CALL AnalysisAddIn::getPricedisc( constREFXPS& xOpt,
222 sal_Int32 nSettle, sal_Int32 nMat, double fDisc, double fRedemp, const ANY& rOB ) THROWDEF_RTE_IAE
224 if( fDisc <= 0.0 || fRedemp <= 0 || nSettle >= nMat )
225 THROW_IAE;
227 double fRet = fRedemp * ( 1.0 - fDisc * GetYearDiff( GetNullDate( xOpt ), nSettle, nMat, getDateMode( xOpt, rOB ) ) );
228 RETURN_FINITE( fRet );
232 double SAL_CALL AnalysisAddIn::getPricemat( constREFXPS& xOpt,
233 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue, double fRate, double fYield, const ANY& rOB )
234 THROWDEF_RTE_IAE
236 if( fRate < 0.0 || fYield < 0.0 || nSettle >= nMat )
237 THROW_IAE;
239 sal_Int32 nNullDate = GetNullDate( xOpt );
240 sal_Int32 nBase = getDateMode( xOpt, rOB );
242 double fIssMat = GetYearFrac( nNullDate, nIssue, nMat, nBase );
243 double fIssSet = GetYearFrac( nNullDate, nIssue, nSettle, nBase );
244 double fSetMat = GetYearFrac( nNullDate, nSettle, nMat, nBase );
246 double fRet = 1.0 + fIssMat * fRate;
247 fRet /= 1.0 + fSetMat * fYield;
248 fRet -= fIssSet * fRate;
249 fRet *= 100.0;
251 RETURN_FINITE( fRet );
255 double SAL_CALL AnalysisAddIn::getMduration( constREFXPS& xOpt,
256 sal_Int32 nSettle, sal_Int32 nMat, double fCoup, double fYield, sal_Int32 nFreq, const ANY& rOB )
257 THROWDEF_RTE_IAE
259 if( fCoup < 0.0 || fYield < 0.0 || CHK_Freq )
260 THROW_IAE;
262 double fRet = GetDuration( GetNullDate( xOpt ), nSettle, nMat, fCoup, fYield, nFreq, getDateMode( xOpt, rOB ) );
263 fRet /= 1.0 + ( fYield / double( nFreq ) );
264 RETURN_FINITE( fRet );
268 double SAL_CALL AnalysisAddIn::getNominal( double fRate, sal_Int32 nPeriods ) THROWDEF_RTE_IAE
270 if( fRate <= 0.0 || nPeriods < 0 )
271 THROW_IAE;
273 double fPeriods = nPeriods;
274 double fRet = ( pow( fRate + 1.0, 1.0 / fPeriods ) - 1.0 ) * fPeriods;
275 RETURN_FINITE( fRet );
279 double SAL_CALL AnalysisAddIn::getDollarfr( double fDollarDec, sal_Int32 nFrac ) THROWDEF_RTE_IAE
281 if( nFrac <= 0 )
282 THROW_IAE;
284 double fInt;
285 double fFrac = nFrac;
287 double fRet = modf( fDollarDec, &fInt );
289 fRet *= fFrac;
291 fRet *= pow( 10.0, -ceil( log10( fFrac ) ) );
293 fRet += fInt;
295 RETURN_FINITE( fRet );
299 double SAL_CALL AnalysisAddIn::getDollarde( double fDollarFrac, sal_Int32 nFrac ) THROWDEF_RTE_IAE
301 if( nFrac <= 0 )
302 THROW_IAE;
304 double fInt;
305 double fFrac = nFrac;
307 double fRet = modf( fDollarFrac, &fInt );
309 fRet /= fFrac;
311 fRet *= pow( 10.0, ceil( log10( fFrac ) ) );
313 fRet += fInt;
315 RETURN_FINITE( fRet );
319 double SAL_CALL AnalysisAddIn::getYield( constREFXPS& xOpt,
320 sal_Int32 nSettle, sal_Int32 nMat, double fCoup, double fPrice, double fRedemp, sal_Int32 nFreq, const ANY& rOB )
321 THROWDEF_RTE_IAE
323 if( fCoup < 0.0 || fPrice <= 0.0 || fRedemp <= 0.0 || CHK_Freq || nSettle >= nMat )
324 THROW_IAE;
326 double fRet = getYield_( GetNullDate( xOpt ), nSettle, nMat, fCoup, fPrice, fRedemp, nFreq, getDateMode( xOpt, rOB ) );
327 RETURN_FINITE( fRet );
331 double SAL_CALL AnalysisAddIn::getYielddisc( constREFXPS& xOpt,
332 sal_Int32 nSettle, sal_Int32 nMat, double fPrice, double fRedemp, const ANY& rOB ) THROWDEF_RTE_IAE
334 if( fPrice <= 0.0 || fRedemp <= 0.0 || nSettle >= nMat )
335 THROW_IAE;
337 sal_Int32 nNullDate = GetNullDate( xOpt );
339 #if 0
340 double fRet = 1.0 - fPrice / fRedemp;
341 fRet /= GetYearFrac( nNullDate, nSettle, nMat, getDateMode( xOpt, rOB ) );
342 fRet /= 0.99795; // don't know what this constant means in original
343 #endif
345 double fRet = ( fRedemp / fPrice ) - 1.0;
346 fRet /= GetYearFrac( nNullDate, nSettle, nMat, getDateMode( xOpt, rOB ) );
348 RETURN_FINITE( fRet );
352 double SAL_CALL AnalysisAddIn::getYieldmat( constREFXPS& xOpt,
353 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue, double fRate, double fPrice, const ANY& rOB )
354 THROWDEF_RTE_IAE
356 if( fRate < 0.0 || fRate <= 0.0 || nSettle >= nMat )
357 THROW_IAE;
359 double fRet = GetYieldmat( GetNullDate( xOpt ), nSettle, nMat, nIssue, fRate, fPrice, getDateMode( xOpt, rOB ) );
360 RETURN_FINITE( fRet );
364 double SAL_CALL AnalysisAddIn::getTbilleq( constREFXPS& xOpt,
365 sal_Int32 nSettle, sal_Int32 nMat, double fDisc ) THROWDEF_RTE_IAE
367 nMat++;
369 sal_Int32 nDiff = GetDiffDate360( xOpt, nSettle, nMat, sal_True );
371 if( fDisc <= 0.0 || nSettle >= nMat || nDiff > 360 )
372 THROW_IAE;
374 double fRet = ( 365 * fDisc ) / ( 360 - ( fDisc * double( nDiff ) ) );
375 RETURN_FINITE( fRet );
379 double SAL_CALL AnalysisAddIn::getTbillprice( constREFXPS& xOpt,
380 sal_Int32 nSettle, sal_Int32 nMat, double fDisc ) THROWDEF_RTE_IAE
382 if( fDisc <= 0.0 || nSettle > nMat )
383 THROW_IAE;
385 nMat++;
387 double fFraction = GetYearFrac( xOpt, nSettle, nMat, 0 ); // method: USA 30/360
389 double fDummy;
390 if( modf( fFraction, &fDummy ) == 0.0 )
391 THROW_IAE;
393 double fRet = 100.0 * ( 1.0 - fDisc * fFraction );
394 RETURN_FINITE( fRet );
398 double SAL_CALL AnalysisAddIn::getTbillyield( constREFXPS& xOpt, sal_Int32 nSettle, sal_Int32 nMat, double fPrice )
399 THROWDEF_RTE_IAE
401 sal_Int32 nDiff = GetDiffDate360( xOpt, nSettle, nMat, sal_True );
402 nDiff++;
404 if( fPrice <= 0.0 || nSettle >= nMat || nDiff > 360 )
405 THROW_IAE;
407 double fRet = 100.0;
408 fRet /= fPrice;
409 fRet--;
410 fRet /= double( nDiff );
411 fRet *= 360.0;
413 RETURN_FINITE( fRet );
417 double SAL_CALL AnalysisAddIn::getOddfprice( constREFXPS& xOpt,
418 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue, sal_Int32 nFirstCoup,
419 double fRate, double fYield, double fRedemp, sal_Int32 nFreq, const ANY& rOB ) THROWDEF_RTE_IAE
421 if( fRate < 0 || fYield < 0 || CHK_Freq || nMat <= nFirstCoup || nFirstCoup <= nSettle || nSettle <= nIssue )
422 THROW_IAE;
424 double fRet = GetOddfprice( GetNullDate( xOpt ), nSettle, nMat, nIssue, nFirstCoup, fRate, fYield, fRedemp, nFreq, getDateMode( xOpt, rOB ) );
425 RETURN_FINITE( fRet );
429 double SAL_CALL AnalysisAddIn::getOddfyield( constREFXPS& xOpt,
430 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nIssue, sal_Int32 nFirstCoup,
431 double fRate, double fPrice, double fRedemp, sal_Int32 nFreq, const ANY& rOB ) THROWDEF_RTE_IAE
433 if( fRate < 0 || fPrice <= 0 || CHK_Freq || nMat <= nFirstCoup || nFirstCoup <= nSettle || nSettle <= nIssue )
434 THROW_IAE;
436 double fRet = GetOddfyield( GetNullDate( xOpt ), nSettle, nMat, nIssue, nFirstCoup, fRate, fPrice, fRedemp, nFreq,
437 getDateMode( xOpt, rOB ) );
438 RETURN_FINITE( fRet );
442 double SAL_CALL AnalysisAddIn::getOddlprice( constREFXPS& xOpt,
443 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastInterest,
444 double fRate, double fYield, double fRedemp, sal_Int32 nFreq, const ANY& rOB ) THROWDEF_RTE_IAE
446 if( fRate < 0 || fYield < 0 || CHK_Freq || nMat <= nSettle || nSettle <= nLastInterest )
447 THROW_IAE;
449 double fRet = GetOddlprice( GetNullDate( xOpt ), nSettle, nMat, nLastInterest, fRate, fYield, fRedemp, nFreq,
450 getDateMode( xOpt, rOB ) );
451 RETURN_FINITE( fRet );
455 double SAL_CALL AnalysisAddIn::getOddlyield( constREFXPS& xOpt,
456 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nLastInterest,
457 double fRate, double fPrice, double fRedemp, sal_Int32 nFreq, const ANY& rOB ) THROWDEF_RTE_IAE
459 if( fRate < 0 || fPrice <= 0 || CHK_Freq || nMat <= nSettle || nSettle <= nLastInterest )
460 THROW_IAE;
462 double fRet = GetOddlyield( GetNullDate( xOpt ), nSettle, nMat, nLastInterest, fRate, fPrice, fRedemp, nFreq,
463 getDateMode( xOpt, rOB ) );
464 RETURN_FINITE( fRet );
468 // ============================================================================
469 // XIRR helper functions
471 #define V_(i) (*rValues.Get(i))
472 #define D_(i) (*rDates.Get(i))
474 /** Calculates the resulting amount for the passed interest rate and the given XIRR parameters. */
475 double lcl_sca_XirrResult( const ScaDoubleList& rValues, const ScaDoubleList& rDates, double fRate )
477 /* V_0 ... V_n = input values.
478 D_0 ... D_n = input dates.
479 R = input interest rate.
481 r := R+1
482 E_i := (D_i-D_0) / 365
484 n V_i n V_i
485 f(R) = SUM ------- = V_0 + SUM ------- .
486 i=0 r^E_i i=1 r^E_i
488 double D_0 = D_(0);
489 double r = fRate + 1.0;
490 double fResult = V_(0);
491 for( sal_uInt32 i = 1, nCount = rValues.Count(); i < nCount; ++i )
492 fResult += V_(i) / pow( r, (D_(i) - D_0) / 365.0 );
493 return fResult;
496 /** Calculates the first derivation of lcl_sca_XirrResult(). */
497 double lcl_sca_XirrResult_Deriv1( const ScaDoubleList& rValues, const ScaDoubleList& rDates, double fRate )
499 /* V_0 ... V_n = input values.
500 D_0 ... D_n = input dates.
501 R = input interest rate.
503 r := R+1
504 E_i := (D_i-D_0) / 365
506 n V_i
507 f'(R) = [ V_0 + SUM ------- ]'
508 i=1 r^E_i
510 n V_i n E_i V_i
511 = 0 + SUM -E_i ----------- r' = - SUM ----------- .
512 i=1 r^(E_i+1) i=1 r^(E_i+1)
514 double D_0 = D_(0);
515 double r = fRate + 1.0;
516 double fResult = 0.0;
517 for( sal_uInt32 i = 1, nCount = rValues.Count(); i < nCount; ++i )
519 double E_i = (D_(i) - D_0) / 365.0;
520 fResult -= E_i * V_(i) / pow( r, E_i + 1.0 );
522 return fResult;
525 #undef V_
526 #undef D_
529 // ----------------------------------------------------------------------------
530 // XIRR calculation
532 double SAL_CALL AnalysisAddIn::getXirr(
533 constREFXPS& xOpt, const SEQSEQ( double )& rValues, const SEQSEQ( sal_Int32 )& rDates, const ANY& rGuessRate ) THROWDEF_RTE_IAE
535 ScaDoubleList aValues, aDates;
536 aValues.Append( rValues );
537 aDates.Append( rDates );
539 if( (aValues.Count() < 2) || (aValues.Count() != aDates.Count()) )
540 THROW_IAE;
542 // result interest rate, initialized with passed guessed rate, or 10%
543 double fResultRate = aAnyConv.getDouble( xOpt, rGuessRate, 0.1 );
544 if( fResultRate <= -1 )
545 THROW_IAE;
547 // maximum epsilon for end of iteration
548 static const double fMaxEps = 1e-10;
549 // maximum number of iterations
550 static const sal_Int32 nMaxIter = 50;
552 // Newton's method - try to find a fResultRate, so that lcl_sca_XirrResult() returns 0.
553 double fNewRate, fRateEps, fResultValue;
554 sal_Int32 nIter = 0;
555 bool bContLoop;
558 fResultValue = lcl_sca_XirrResult( aValues, aDates, fResultRate );
559 fNewRate = fResultRate - fResultValue / lcl_sca_XirrResult_Deriv1( aValues, aDates, fResultRate );
560 fRateEps = fabs( fNewRate - fResultRate );
561 fResultRate = fNewRate;
562 bContLoop = (fRateEps > fMaxEps) && (fabs( fResultValue ) > fMaxEps);
564 while( bContLoop && (++nIter < nMaxIter) );
566 if( bContLoop )
567 THROW_IAE;
568 RETURN_FINITE( fResultRate );
572 // ============================================================================
574 double SAL_CALL AnalysisAddIn::getXnpv(
575 double fRate, const SEQSEQ( double )& rValues, const SEQSEQ( sal_Int32 )& rDates ) THROWDEF_RTE_IAE
577 ScaDoubleList aValList;
578 ScaDoubleList aDateList;
580 aValList.Append( rValues );
581 aDateList.Append( rDates );
583 sal_Int32 nNum = aValList.Count();
585 if( nNum != sal_Int32( aDateList.Count() ) || nNum < 2 )
586 THROW_IAE;
588 double fRet = 0.0;
589 double fNull = *aDateList.Get( 0 );
590 fRate++;
592 for( sal_Int32 i = 0 ; i < nNum ; i++ )
593 fRet += *aValList.Get( i ) / ( pow( fRate, ( *aDateList.Get( i ) - fNull ) / 365.0 ) );
595 RETURN_FINITE( fRet );
599 double SAL_CALL AnalysisAddIn::getIntrate( constREFXPS& xOpt,
600 sal_Int32 nSettle, sal_Int32 nMat, double fInvest, double fRedemp, const ANY& rOB ) THROWDEF_RTE_IAE
602 if( fInvest <= 0.0 || fRedemp <= 0.0 || nSettle >= nMat )
603 THROW_IAE;
605 double fRet = ( ( fRedemp / fInvest ) - 1.0 ) / GetYearDiff( GetNullDate( xOpt ), nSettle, nMat, getDateMode( xOpt, rOB ) );
606 RETURN_FINITE( fRet );
610 double SAL_CALL AnalysisAddIn::getCoupncd( constREFXPS& xOpt,
611 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const ANY& rOB ) THROWDEF_RTE_IAE
613 double fRet = GetCoupncd( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
614 RETURN_FINITE( fRet );
618 double SAL_CALL AnalysisAddIn::getCoupdays( constREFXPS& xOpt,
619 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const ANY& rOB ) THROWDEF_RTE_IAE
621 double fRet = GetCoupdays( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
622 RETURN_FINITE( fRet );
626 double SAL_CALL AnalysisAddIn::getCoupdaysnc( constREFXPS& xOpt,
627 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const ANY& rOB ) THROWDEF_RTE_IAE
629 double fRet = GetCoupdaysnc( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
630 RETURN_FINITE( fRet );
634 double SAL_CALL AnalysisAddIn::getCoupdaybs( constREFXPS& xOpt,
635 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const ANY& rOB ) THROWDEF_RTE_IAE
637 double fRet = GetCoupdaybs( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
638 RETURN_FINITE( fRet );
642 double SAL_CALL AnalysisAddIn::getCouppcd( constREFXPS& xOpt,
643 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const ANY& rOB ) THROWDEF_RTE_IAE
645 double fRet = GetCouppcd( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
646 RETURN_FINITE( fRet );
650 double SAL_CALL AnalysisAddIn::getCoupnum( constREFXPS& xOpt,
651 sal_Int32 nSettle, sal_Int32 nMat, sal_Int32 nFreq, const ANY& rOB ) THROWDEF_RTE_IAE
653 double fRet = GetCoupnum( GetNullDate( xOpt ), nSettle, nMat, nFreq, getDateMode( xOpt, rOB ) );
654 RETURN_FINITE( fRet );
658 double SAL_CALL AnalysisAddIn::getFvschedule( double fPrinc, const SEQSEQ( double )& rSchedule ) THROWDEF_RTE_IAE
660 ScaDoubleList aSchedList;
662 aSchedList.Append( rSchedule );
664 for( const double* p = aSchedList.First() ; p ; p = aSchedList.Next() )
665 fPrinc *= 1.0 + *p;
667 RETURN_FINITE( fPrinc );