13"double GetPMT( double fRate, double fNper, double fPv, double fFv, bool bPayInAdvance);\n";
 
   16"double GetPMT( double fRate, double fNper, double fPv, double fFv, bool bPayInAdvance )\n" 
   20"        fPayment = (fPv + fFv) / fNper;\n" 
   23"        if (bPayInAdvance)\n" 
   24"            fPayment = (fFv + fPv * exp( fNper * log1p(fRate) ) ) * fRate\n" 
   25"                / (expm1( (fNper + 1) * log1p(fRate) ) - fRate);\n" 
   27"            fPayment = (fFv + fPv * exp(fNper * log1p(fRate) ) ) * fRate\n" 
   28"                / expm1( fNper * log1p(fRate) );\n" 
   34"double GetIpmt(double fRate, double fPer, double fNper, double fPv,\n" 
   35"    double fFv, bool bPayInAdvance, double* fPmt);\n";
 
   38"double GetIpmt(double fRate, double fPer, double fNper, double fPv,\n" 
   39"    double fFv, bool bPayInAdvance, double* fPmt)\n" 
   41"    *fPmt = GetPMT(fRate, fNper, fPv, fFv, bPayInAdvance);\n" 
   45"        if (bPayInAdvance)\n" 
   52"        if (bPayInAdvance)\n" 
   53"            fIpmt = GetFV(fRate, fPer-2.0, *fPmt, fPv, true) - *fPmt;\n" 
   55"            fIpmt = GetFV(fRate, fPer-1.0, *fPmt, fPv, false);\n" 
   57"    return fIpmt * fRate;\n" 
   61"double GetFV( double fRate, double fNper, double fPmt," 
   62"    double fPv, bool bPayInAdvance );\n";
 
   65"double GetFV( double fRate, double fNper, double fPmt," 
   66"    double fPv, bool bPayInAdvance )\n" 
   70"        fFv = fPv + fPmt * fNper;\n" 
   73"        double fTerm = pow(1.0 + fRate, fNper);\n" 
   74"        if (bPayInAdvance)\n" 
   75"            fFv = fPv * fTerm + fPmt*(1.0 + fRate)*(fTerm - 1.0)/fRate;\n" 
   77"            fFv = fPv * fTerm + fPmt*(fTerm - 1.0)/fRate;\n" 
   83"bool IsLeapYear( int n );\n";
 
   86"bool IsLeapYear( int n )\n" 
   88"    return ( (( ( n % 4 ) == 0 ) && ( ( n % 100 ) != 0)) || ( ( n % 400 ) == " 
   93"int DaysInMonth( int nMonth, int nYear );\n";
 
   96"int DaysInMonth( int nMonth, int nYear )\n" 
  117"        if ( IsLeapYear(nYear)==1)\n" 
  127"int  DateToDays( int nDay, int nMonth, int nYear );\n";
 
  130"int  DateToDays( int nDay, int nMonth, int nYear )\n" 
  132"    int nDays = (nYear-1) * 365;\n" 
  133"    nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400);\n" 
  134"    for( int i = 1; i < nMonth; i++ )\n" 
  135"        nDays += DaysInMonth(i,nYear);\n" 
  142"int GetNullDate();\n";
 
  147"    return DateToDays(30,12,1899 );\n" 
  151"void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, " 
  152"int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay," 
  153"int *b30Days,int *bUSMode,int *nDay);\n";
 
  156"void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, " 
  157"int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay," 
  158"int *b30Days,int *bUSMode,int *nDay)\n" 
  160"    DaysToDate( nNullDate + nDate, nOrigDay, nMonth, nYear );\n" 
  161"    *bLastDayMode = (nBase != 5);\n" 
  162"    *bLastDay = (*nOrigDay >= DaysInMonth( *nMonth, *nYear ));\n" 
  163"    *b30Days = (nBase == 0) || (nBase == 4);\n" 
  164"    *bUSMode = (nBase == 0);\n" 
  167"        *nDay = min( *nOrigDay, 30);\n" 
  168"        if( *bLastDay || (*nDay >=DaysInMonth( *nMonth, *nYear )) )\n" 
  173"        int nLastDay = DaysInMonth( *nMonth, *nYear );\n" 
  174"        *nDay = *bLastDay ? nLastDay : min( *nOrigDay, nLastDay );\n" 
  179"int lcl_GetCouppcd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
 
  182"int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n" 
  184"    int aDate = nMat;\n" 
  185"    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0," 
  186"rbUSMode=0,rnDay=0;\n" 
  187"    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0," 
  188"sbUSMode=0,snDay=0;\n" 
  189"    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode," 
  190"&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n" 
  191"    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode," 
  192"&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n" 
  194"    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  195"    if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay," 
  196"sbLastDay,rDay,sDay))\n" 
  199"        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  201"    while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay," 
  202"rbLastDay,sDay,rDay))\n" 
  204"        double d = -1*(12/nFreq);\n" 
  205"        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n" 
  207"    int nLastDay = DaysInMonth( rMonth, rYear );\n" 
  208"    int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :" 
  209"min( nLastDay, rDay );\n" 
  210"    return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n" 
  214"int lcl_GetCoupncd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
 
  217"int lcl_GetCoupncd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n" 
  219"    int aDate = nMat;\n" 
  220"    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0," 
  221"rbUSMode=0,rnDay=0;\n" 
  222"    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0," 
  223"sbUSMode=0,snDay=0;\n" 
  224"    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode," 
  225"&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n" 
  226"    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode," 
  227"&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n" 
  229"    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  230"    if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay" 
  234"        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  236"    while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay," 
  237"rbLastDay,sDay,rDay))\n" 
  239"      addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n" 
  241"    int nLastDay = DaysInMonth( rMonth, rYear );\n" 
  242"    int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :" 
  243"min( nLastDay, rDay );\n" 
  244"    return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n" 
  248"void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay," 
  249"int *nMonth,int nMonthCount,int *year);\n";
 
  252"void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay," 
  253"int *nMonth,int nMonthCount,int *year)\n" 
  255"    int nNewMonth = nMonthCount + *nMonth;\n" 
  256"    if( nNewMonth > 12 )\n" 
  259"        *year+=nNewMonth / 12 ;\n" 
  260"        *nMonth = ( nNewMonth % 12 ) + 1;\n" 
  262"    else if( nNewMonth < 1 )\n" 
  264"        *year+= nNewMonth / 12 - 1 ;\n" 
  265"        *nMonth =  nNewMonth % 12 + 12 ;\n" 
  268"        *nMonth = nNewMonth ;\n" 
  271"        *nDay = min( nOrigDay, 30);\n" 
  272"        if( bLastDay || (*nDay >= DaysInMonth( *nMonth, *year )) )\n" 
  277"        int nLastDay = DaysInMonth( *nMonth, *year );\n" 
  278"        *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n" 
  283"int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year);\n";
 
  286"int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year)\n" 
  288"    if( nFrom > nTo )\n" 
  292"        nRet = (nTo - nFrom + 1) * 30;\n" 
  295"        for( int nMonthIx = nFrom; nMonthIx <= nTo; ++nMonthIx )\n" 
  296"            nRet += b30Days ? 30 : DaysInMonth( nMonthIx, year );\n" 
  302"int GetDaysInYears( int nYear1, int nYear2 );\n";
 
  305"int GetDaysInYears( int nYear1, int nYear2 )\n" 
  308"    for( int n = nYear1 ; n <= nYear2 ; n++ )\n" 
  310"        if( IsLeapYear( n ) )\n" 
  322"int GetDaysInYear( int nNullDate, int nDate, int nMode );\n";
 
  325"int GetDaysInYear( int nNullDate, int nDate, int nMode )\n" 
  335"            int  nD=0, nM=0, nY=0;\n" 
  336"            nDate += nNullDate;\n" 
  337"            DaysToDate( nDate, &nD, &nM, &nY );\n" 
  338"            return IsLeapYear( nY )? 366 : 365;\n" 
  346"int getDaysInYearRange( int nFrom, int nTo,int b30Days );\n";
 
  349"int getDaysInYearRange( int nFrom, int nTo,int b30Days )\n" 
  351"    if( nFrom > nTo )\n" 
  353"    return b30Days ? ((nTo - nFrom + 1) * 360) : GetDaysInYears( nFrom, nTo)" 
  358"int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode," 
  359"int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth," 
  360"int tYear,int tbLastDayMode,int tbLastDay,int tb30Days," 
  361"int tbUSMode,int tnDay);\n";
 
  364"int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode," 
  365"int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth," 
  366"int tYear,int tbLastDayMode,int tbLastDay,int tb30Days," 
  367"int tbUSMode,int tnDay)\n" 
  371"        int d=fDay;fDay=tDay;tDay=d;\n" 
  372"        int m=fMonth;fMonth=tMonth;tMonth=m;\n" 
  373"        int y=fYear;fYear=tYear;tYear=y;\n" 
  374"        int a=fbLastDayMode;fbLastDayMode=tbLastDayMode;tbLastDayMode=a;\n" 
  375"        int b=fbLastDay;fbLastDay=tbLastDay;tbLastDay=b;\n" 
  376"        int c=fb30Days;fb30Days=tb30Days;tb30Days=c;\n" 
  377"        int e=fbUSMode;fbUSMode=tbUSMode;tbUSMode=e;\n" 
  378"        int f=fnDay;fnDay=tnDay;tnDay=f;\n" 
  385"            if( ((fMonth == 2) || (fnDay < 30)) && (tDay == 31) )\n" 
  387"            else if( (tMonth == 2) && tbLastDay )\n" 
  388"                tnDay = DaysInMonth( 2, tYear );\n" 
  392"            if( (fMonth == 2) && (fnDay == 30) )\n" 
  393"                fnDay = DaysInMonth( 2, fYear );\n" 
  394"            if( (tMonth == 2) && (tnDay == 30) )\n" 
  395"                tnDay = DaysInMonth( 2, tYear );\n" 
  398"    if( (fYear < tYear) || ((fYear == tYear) && (fMonth < tMonth)) )\n" 
  400"        int d = fb30Days ? 30:DaysInMonth(fMonth,fYear);\n" 
  401"        nDiff = d- fnDay + 1;\n" 
  402"        fDay = fnDay = 1;\n" 
  404"        addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,1,&fYear);\n" 
  405"        if( fYear < tYear )\n" 
  407"            nDiff += getDaysInMonthRange( fMonth, 12,fb30Days,fYear);\n" 
  408"            addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,13-fMonth,&fYear" 
  410"            nDiff += getDaysInYearRange( fYear, tYear - 1,fb30Days);\n" 
  411"            fYear+=tYear - fYear;\n" 
  413"        nDiff += getDaysInMonthRange(fMonth, tMonth - 1,fb30Days ,fYear );\n" 
  414"        addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,tMonth-fMonth,&fYear" 
  417"    nDiff += tnDay - fnDay;\n" 
  418"    return nDiff > 0 ? nDiff : 0;\n" 
  422"int lcl_Getcoupdaybs(int nNullDate,int nSettle,int nMat,int nFreq," 
  426"int lcl_Getcoupdaybs(int nNullDate,int nSettle,int nMat,int nFreq," 
  429"    int aDate = nMat;\n" 
  430"    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0," 
  431"rbUSMode=0,rnDay=0;\n" 
  432"    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0," 
  433"sbUSMode=0,snDay=0;\n" 
  434"    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode," 
  435"&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n" 
  436"    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode," 
  437"&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n" 
  439"    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  440"    aDate=DateToDays( rnDay,rMonth,rYear);\n" 
  441"    if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay," 
  442"sbLastDay,rDay,sDay))\n" 
  445"        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  446"        aDate=DateToDays( rnDay,rMonth,rYear );\n" 
  448"    while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay," 
  449"rbLastDay,sDay,rDay))\n" 
  451"        double d = -1*(12/nFreq);\n" 
  452"        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n" 
  453"        aDate=DateToDays( rnDay,rMonth,rYear );\n" 
  455"    return getDiff( aDate,nSettle+nNullDate,rDay,rMonth,rYear,rbLastDayMode," 
  456"rbLastDay,rb30Days,rbUSMode,rnDay,sDay,sMonth,sYear,sbLastDayMode,sbLastDay," 
  457"sb30Days,sbUSMode, snDay);\n" 
  461"int lcl_Getcoupdays(int nNullDate,int nSettle, " 
  462"int nMat,int nFreq,int nBase);\n";
 
  465"int lcl_Getcoupdays(int nNullDate,int nSettle, " 
  466"int nMat,int nFreq,int nBase)\n" 
  468"    int aDate = nMat;\n" 
  469"    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0," 
  470"rbUSMode=0,rnDay=0;\n" 
  471"    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0," 
  472"sbUSMode=0,snDay=0;\n" 
  473"    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode," 
  474"&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n" 
  475"    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode," 
  476"&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n" 
  478"    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  479"    aDate=DateToDays( rnDay,rMonth,rYear);\n" 
  480"    if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay," 
  481"sbLastDay,rDay,sDay))\n" 
  484"        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  485"        aDate=DateToDays( rnDay,rMonth,rYear );\n" 
  487"    while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay," 
  488"rbLastDay,sDay,rDay))\n" 
  490"        double d = -1*12/(double)nFreq;\n" 
  491"        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n" 
  492"        aDate=DateToDays( rnDay,rMonth,rYear );\n" 
  494"    int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n" 
  495"    int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days," 
  496"abUSMode=rbUSMode,anDay=rnDay;\n" 
  497"    int tmp = (int)(12/(double)nFreq);\n" 
  498"    addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,tmp,&aYear);\n" 
  499"    return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, " 
  500"rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode," 
  501"abLastDay, ab30Days, abUSMode, anDay);\n" 
  505"double lcl_Getcoupnum(int nNullDate,int nSettle,int nMat,int nFreq,int" 
  508"double lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq,int" 
  511"    int aDate = nMat;\n" 
  512"    int mDay=0,mMonth=0, mYear=0;\n" 
  513"    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0," 
  514"rbUSMode=0,rnDay=0;\n" 
  515"    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0," 
  516"sbUSMode=0,snDay=0;\n" 
  517"    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode," 
  518"&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n" 
  519"    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode," 
  520"&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n" 
  521"    mMonth = rMonth, mYear = rYear;\n" 
  523"    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  524"    if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay," 
  525"sbLastDay,rDay,sDay))\n" 
  528"        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  530"    int m= checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay," 
  531"rbLastDay,sDay,rDay);\n" 
  534"        double d = -1*(12/nFreq);\n" 
  535"        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n" 
  536"        m = checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay," 
  537"rbLastDay,sDay,rDay);\n" 
  539"    int n=(mYear-rYear)*12+mMonth-rMonth;\n" 
  540"    double tmp = (double)(n*nFreq)/12.0;\n" 
  545"void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days," 
  548"void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days," 
  553"        *nDay = min( nOrigDay, 30);\n" 
  554"        if( bLastDay || (*nDay >= DaysInMonth( nMonth, nYear )) )\n" 
  559"        int nLastDay = DaysInMonth( nMonth, nYear );\n" 
  560"        *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n" 
  565"double coupdays(int nSettle,int nMat,int nFreq,int nBase);\n";
 
  568"double coupdays(int nSettle,int nMat,int nFreq,int nBase)\n" 
  570"    int nNullDate=693594;\n" 
  572"        return lcl_Getcoupdays(nNullDate, nSettle, nMat,nFreq, nBase);\n" 
  574"        return (double)GetDaysInYear(0,0,nBase)/(double)nFreq;\n" 
  578"double coupdaybs( int nSettle,int nMat,int nFreq,int nBase);\n";
 
  581"double coupdaybs( int nSettle,int nMat,int nFreq,int nBase)\n" 
  583"    int nNullDate=693594;\n" 
  584"    return lcl_Getcoupdaybs(nNullDate, nSettle, nMat,nFreq, nBase);\n" 
  588"double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase);\n";
 
  591"double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase)\n" 
  593"    int nNullDate=693594;\n" 
  594"    if((nBase != 0) && (nBase != 4))\n" 
  596"    int aDate = nMat;\n" 
  597"    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0," 
  598"rbUSMode=0,rnDay=0;\n" 
  599"    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0," 
  600"sbUSMode=0,snDay=0;\n" 
  601"    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode," 
  602"&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n" 
  603"    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode," 
  604"&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n" 
  606"    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  607"    aDate=DateToDays( rnDay,rMonth,rYear);\n" 
  608"    if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay" 
  612"        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" 
  613"        aDate=DateToDays( rnDay,rMonth,rYear );\n" 
  615"    while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay," 
  616"rbLastDay,sDay,rDay))\n" 
  618"      addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n" 
  619"      aDate=DateToDays( rnDay,rMonth,rYear );\n" 
  621"    return getDiff( nSettle+nNullDate,aDate,sDay,sMonth,sYear,sbLastDayMode, " 
  622"sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, " 
  623"rbLastDay, rb30Days, rbUSMode, rnDay);\n" 
  626"        return coupdays(nSettle,nMat,nFreq,nBase)- coupdaybs( nSettle," 
  627"nMat,nFreq,nBase);\n" 
  631"int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int " 
  632"bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay);\n";
 
  634"int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int " 
  635"bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay)\n" 
  637"    if( aYear != bYear )\n" 
  638"        return aYear < bYear;\n" 
  639"    if( aMonth != bMonth )\n" 
  640"        return aMonth < bMonth;\n" 
  641"    if( anDay != bnDay )\n" 
  642"        return anDay < bnDay;\n" 
  643"    if( abLastDay || bbLastDay )\n" 
  644"        return !abLastDay && bbLastDay;\n" 
  645"    return anOrigDay < bnOrigDay;\n" 
  649"double coupnum( int nSettle,int nMat,int nFreq,int nBase);\n";
 
  652"double coupnum( int nSettle,int nMat,int nFreq,int nBase)\n" 
  654"    int nNullDate=693594;\n" 
  655"    return lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq,nBase);\n" 
  659"double getPrice(int nSettle, int nMat, double fRate, double fYield,\n" 
  660    "double fRedemp, int nFreq, int nBase );\n";
 
  663"double getPrice(int nSettle, int nMat, double fRate, double fYield,\n" 
  664    "double fRedemp, int nFreq, int nBase )\n" 
  666"    double      fFreq = nFreq;\n" 
  667"    double      fE = coupdays( nSettle, nMat, nFreq, nBase );\n" 
  668"    double      fDSC_E = coupdaysnc(  nSettle, nMat, nFreq, nBase ) / fE;\n" 
  669"    double      fN = coupnum( nSettle, nMat, nFreq, nBase );\n" 
  670"    double      fA = coupdaybs( nSettle, nMat, nFreq, nBase );\n" 
  671"    double      fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + " 
  673"    fRet -= 100.0 * fRate / fFreq * fA / fE;\n" 
  674"    double      fT1 = 100.0 * fRate / fFreq;\n" 
  675"    double      fT2 = 1.0 + fYield / fFreq;\n" 
  676"    for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n" 
  677"        fRet += fT1 / pow( fT2, fK + fDSC_E );\n" 
  682"double getYield_( int nNullDate, int nSettle, int nMat, double fCoup," 
  683"double fPrice,double fRedemp, int nFreq, int nBase);\n";
 
  686"double getYield_( int nNullDate, int nSettle, int nMat, double fCoup," 
  687"double fPrice,double fRedemp, int nFreq, int nBase )\n" 
  689"    double      fRate = fCoup;\n" 
  690"    double      fPriceN = 0.0;\n" 
  691"    double      fYield1 = 0.0;\n" 
  692"    double      fYield2 = 1.0;\n" 
  693"    double      fPrice1 = getPrice(nSettle, nMat, fRate, fYield1, fRedemp, " 
  695"    double      fPrice2 = getPrice(nSettle, nMat, fRate, fYield2, fRedemp, " 
  697"    double      fYieldN = ( fYield2 - fYield1 ) * 0.5;\n" 
  698"    for( unsigned int nIter = 0 ; nIter < 100 && fPriceN != fPrice ; nIter++ " 
  701"        fPriceN = getPrice(nSettle, nMat, fRate, fYieldN, fRedemp, nFreq, " 
  703"        if( fPrice == fPrice1 )\n" 
  705"        else if( fPrice == fPrice2 )\n" 
  707"        else if( fPrice == fPriceN )\n" 
  709"        else if( fPrice < fPrice2 )\n" 
  712"            fPrice2 = getPrice(nSettle, nMat, fRate, fYield2, fRedemp, nFreq" 
  714"            fYieldN = ( fYield2 - fYield1 ) * 0.5;\n" 
  718"            if( fPrice < fPriceN )\n" 
  720"                fYield1 = fYieldN;\n" 
  721"                fPrice1 = fPriceN;\n" 
  725"                fYield2 = fYieldN;\n" 
  726"                fPrice2 = fPriceN;\n" 
  728"            fYieldN = fYield2 - ( fYield2 - fYield1 ) * ( ( fPrice - fPrice2 " 
  729") / ( fPrice1 - fPrice2 ) );\n" 
  736    "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n" 
  737        "double fRate, double fPrice, int nBase );\n";
 
  740    "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n" 
  741        "double fRate, double fPrice, int nBase )\n" 
  743"    double      fIssMat = GetYearFrac( nNullDate, nIssue, nMat, nBase );\n" 
  744"    double      fIssSet = GetYearFrac( nNullDate, nIssue, nSettle, nBase );\n" 
  745"    double      fSetMat = GetYearFrac( nNullDate, nSettle, nMat, nBase );\n" 
  746"    double      y = 1.0 + fIssMat * fRate;\n" 
  747"    y =y / (fPrice / 100.0 + fIssSet * fRate);\n" 
  754"int GetDiffDate360_(\n" 
  755"                int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n" 
  756"                int nDay2, int nMonth2, int nYear2,\n" 
  757"                bool bUSAMethod );\n";
 
  760"int GetDiffDate360_(\n" 
  761"                int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n" 
  762"                int nDay2, int nMonth2, int nYear2,\n" 
  763"                bool bUSAMethod )\n" 
  765"    if( nDay1 == 31 )\n" 
  767"    else if( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 " 
  768"&& !bLeapYear1 ) ) ) )\n" 
  770"    if( nDay2 == 31 )\n" 
  772"        if( bUSAMethod && nDay1 != 30 )\n" 
  775"            if( nMonth2 == 12 )\n" 
  786"    return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - " 
  791"int GetDiffDate360( int nNullDate, int nDate1, int nDate2," 
  792"bool bUSAMethod);\n";
 
  795"int GetDiffDate360( int nNullDate, int nDate1, int nDate2," 
  798"    nDate1 += nNullDate;\n" 
  799"    nDate2 += nNullDate;\n" 
  800"    int nDay1, nMonth1, nYear1, nDay2, nMonth2, nYear2;\n" 
  801"    DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n" 
  802"    DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n" 
  803"    return GetDiffDate360_( nDay1, nMonth1, nYear1, IsLeapYear( nYear1 ), " 
  804"nDay2, nMonth2, nYear2, bUSAMethod );\n" 
  808"double GetDuration( \n" 
  809"                int nNullDate, int nSettle, int nMat, double fCoup,\n" 
  810"                double fYield, int nFreq, int nBase );\n";
 
  813"double GetDuration( \n" 
  814"                int nNullDate, int nSettle, int nMat, double fCoup,\n" 
  815"                double fYield, int nFreq, int nBase )\n" 
  817"        double fYearfrac = GetYearFrac(nNullDate,nSettle,nMat,nBase);\n" 
  818"        double fNumOfCoups = lcl_Getcoupnum(nNullDate,nSettle,nMat," 
  820"        double fDur = 0.0;\n" 
  821"        fCoup = fCoup * 100.0 / nFreq;\n" 
  822"        fYield = fYield / nFreq;\n" 
  824"        double nDiff = fYearfrac * nFreq - fNumOfCoups;\n" 
  826"        double tmp0 = 0, tmp1 = 0, tmp2 = 0;\n" 
  827"        for( t = 1 ; t < fNumOfCoups ; t++ ){\n" 
  828"            tmp0 = (t + nDiff) * ( fCoup ) ;\n" 
  829"            tmp1 = pow( fYield, t + nDiff ) ;\n" 
  830"            tmp2 = tmp0 / tmp1;\n" 
  833"        fDur += (fNumOfCoups + nDiff) * (fCoup + 100.0) * pow(pow(fYield," 
  834" fNumOfCoups + nDiff ),-1);\n" 
  836"        for( t = 1 ; t < fNumOfCoups ; t++ ){\n" 
  837"            tmp0 = pow( fYield, t + nDiff );\n" 
  838"            p += fCoup / tmp0;}\n" 
  839"        p += (fCoup + 100.0) / pow(fYield, fNumOfCoups + nDiff);\n" 
  841"        fDur = fDur / nFreq;\n" 
  846"double ScGetDDB(double fCost, double fSalvage, double fLife, double fPeriod," 
  850"double ScGetDDB(double fCost, double fSalvage, double fLife, double fPeriod," 
  853"    double fDdb, fRate, fOldValue, fNewValue;\n" 
  854"    fRate = fFactor / fLife;\n" 
  855"    if (fRate >= 1.0)\n" 
  858"        if (fPeriod == 1.0)\n" 
  859"            fOldValue = fCost;\n" 
  864"        fOldValue = fCost * pow(1.0 - fRate, fPeriod - 1.0);\n" 
  865"    fNewValue = fCost * pow(1.0 - fRate, fPeriod);\n" 
  867"    if (fNewValue < fSalvage)\n" 
  868"        fDdb = fOldValue - fSalvage;\n" 
  870"        fDdb = fOldValue - fNewValue;\n" 
  877"double ScInterVDB(double fCost, double fSalvage, double fLife, double fLife1," 
  878"double fPeriod, double fFactor);\n";
 
  881"double ScInterVDB(double fCost, double fSalvage, double fLife, double fLife1," 
  882"double fPeriod, double fFactor)\n" 
  885"    double fIntEnd   = ceil(fPeriod);\n" 
  886"    int nLoopEnd   = fIntEnd;\n" 
  888"    double fTerm, fSln;\n" 
  889"    double fSalvageValue = fCost - fSalvage;\n" 
  894"    for ( i = 1; i <= nLoopEnd; i++)\n" 
  898"            fDdb = ScGetDDB(fCost, fSalvage, fLife, (double) i, fFactor);\n" 
  899"            fSln = fSalvageValue/ (fLife1 - (double) (i-1));\n" 
  908"                fSalvageValue =fSalvageValue- fDdb;\n" 
  916"        if ( i == nLoopEnd)\n" 
  917"            fTerm *= ( fPeriod + 1.0 - fIntEnd );\n" 
  925"double VDBImplement(double fCost, double fSalvage, double fLife, double fStart" 
  926", double fEnd, double fFactor, bool bNoSwitch);\n";
 
  929"double VDBImplement(double fCost, double fSalvage, double fLife, double fStart" 
  930", double fEnd, double fFactor, bool bNoSwitch)\n" 
  932"    double fIntStart = floor(fStart);\n" 
  933"    double fIntEnd   = ceil(fEnd);\n" 
  934"    long nLoopStart = (long)(fIntStart);\n" 
  935"    long nLoopEnd   = (long)(fIntEnd);\n" 
  937"    double fVdb = 0.0;\n" 
  940"        for (long i = nLoopStart + 1; i <= nLoopEnd; i++)\n" 
  942"            double fTerm = ScGetDDB(fCost, fSalvage, fLife, i, fFactor);\n" 
  944"            if ( i == nLoopStart+1 )\n" 
  945"                fTerm *= ( min( fEnd, fIntStart + 1.0 ) - fStart );\n" 
  946"            else if ( i == nLoopEnd )\n" 
  947"                fTerm *= ( fEnd + 1.0 - fIntEnd );\n" 
  954"        double fPart = 0.0;\n" 
  955"        if ( !approx_equal( fStart, fIntStart ) ||\n" 
  956"             !approx_equal( fEnd, fIntEnd ) )\n" 
  958"            if ( !approx_equal( fStart, fIntStart ) )\n" 
  960"                double fTempIntEnd = fIntStart + 1.0;\n" 
  961"                double fTempValue = fCost -\n" 
  962"                    ScInterVDB( fCost, fSalvage, fLife, fLife, fIntStart, fFactor );\n" 
  963"                fPart += ( fStart - fIntStart ) *\n" 
  964"                    ScInterVDB( fTempValue, fSalvage, fLife, fLife - fIntStart,\n" 
  965"                    fTempIntEnd - fIntStart, fFactor);\n" 
  967"            if ( !approx_equal( fEnd, fIntEnd ) )\n" 
  969"                double fTempIntStart = fIntEnd - 1.0;\n" 
  970"                double fTempValue = fCost -\n" 
  971"                    ScInterVDB( fCost, fSalvage, fLife, fLife, fTempIntStart, fFactor );\n" 
  972"                fPart += ( fIntEnd - fEnd ) *\n" 
  973"                    ScInterVDB( fTempValue, fSalvage, fLife, fLife - fTempIntStart,\n" 
  974"                    fIntEnd - fTempIntStart, fFactor);\n" 
  977"        fCost -= ScInterVDB( fCost, fSalvage, fLife, fLife, fIntStart, fFactor );\n" 
  978"        fVdb = ScInterVDB( fCost, fSalvage, fLife, fLife - fIntStart,\n" 
  979"            fIntEnd - fIntStart, fFactor);\n" 
  986"double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n" 
  987"    double fRate, double fYield, double fRedemp, int nFreq, int nBase );\n";
 
  990"double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n" 
  991"    double fRate, double fYield, double fRedemp, int nFreq, int nBase )\n" 
  993"    double   fFreq =  nFreq ;\n" 
  994"    double   fDCi = GetYearFrac( nNullDate, nLastCoup," 
  995"nMat, nBase ) * fFreq;\n" 
  996"    double   fDSCi = GetYearFrac( nNullDate, nSettle," 
  997"nMat, nBase ) * fFreq;\n" 
  998"    double   fAi = GetYearFrac( nNullDate, nLastCoup," 
  999"nSettle, nBase ) * fFreq;\n" 
 1000"    double   p = fRedemp + fDCi * 100.0 * fRate / fFreq;\n" 
 1001"    p /= fDSCi * fYield / fFreq + 1.0;\n" 
 1002"    p -= fAi * 100.0 * fRate / fFreq;\n" 
 1007"double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n" 
 1008"    double fRate, double fPrice, double fRedemp, int nFreq, int nBase );\n";
 
 1011"double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n" 
 1012"    double fRate, double fPrice, double fRedemp, int nFreq, int nBase ) \n" 
 1014"    double fFreq =  nFreq ;\n" 
 1015"    double fDCi= GetYearFrac( nNullDate, nLastCoup, nMat, nBase ) * fFreq;\n" 
 1016"    double fDSCi= GetYearFrac( nNullDate, nSettle, nMat, nBase ) * fFreq;\n" 
 1017"    double fAi= GetYearFrac( nNullDate, nLastCoup, nSettle, nBase )*fFreq;\n" 
 1018"    double y = fRedemp + fDCi * 100.0 * fRate / fFreq;\n" 
 1019"    y /= fPrice + fAi * 100.0 * fRate / fFreq;\n" 
 1021"    y *= fFreq / fDSCi;\n" 
 1026"double GetYearFrac( int nNullDate, int nStartDate, int nEndDate," 
 1030"double GetYearFrac( int nNullDate, int nStartDate, int nEndDate," 
 1033"    if( nStartDate == nEndDate )\n" 
 1035"   if( nStartDate > nEndDate )\n" 
 1037"       int   n = nEndDate;\n" 
 1038"       nEndDate = nStartDate;\n" 
 1041"  int nDate1 = nStartDate + nNullDate;\n" 
 1042"  int nDate2 = nEndDate + nNullDate;\n" 
 1043"  int  nDay1, nDay2;\n" 
 1044"  int  nMonth1, nMonth2;\n" 
 1045"  int  nYear1, nYear2;\n" 
 1046"  DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n" 
 1047"  DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n" 
 1052"          if ( nDay1 == 31 )\n" 
 1056"          if ( nDay1 == 30 && nDay2 == 31 )\n" 
 1062"              if ( nMonth1 == 2 && nDay1 == " 
 1063"( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n" 
 1066"                  if ( nMonth2 == 2 && nDay2 == " 
 1067"( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n" 
 1073"          nDayDiff = ( nYear2 - nYear1 ) * 360 + " 
 1074"( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n" 
 1079"         nDayDiff = nDate2 - nDate1;\n" 
 1082"          if ( nDay1 == 31 )\n" 
 1086"          if ( nDay2 == 31 )\n" 
 1090"          nDayDiff = ( nYear2 - nYear1 ) * 360 + " 
 1091"( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n" 
 1094"  double nDaysInYear;\n" 
 1100"          nDaysInYear = 360;\n" 
 1104"              bool isYearDifferent = ( nYear1 != nYear2 );\n" 
 1105"              if ( isYearDifferent &&\n" 
 1106"                   ( ( nYear2 != nYear1 + 1 ) ||\n" 
 1107"                     ( nMonth1 < nMonth2 ) ||\n" 
 1108"                     ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n" 
 1110"                  int nDayCount = 0;\n" 
 1111"                 for ( int i = nYear1; i <= nYear2; i++ )\n" 
 1112"                      nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n" 
 1113"                  nDaysInYear = ( double ) nDayCount / " 
 1114"( double ) ( nYear2 - nYear1 + 1 );\n" 
 1118"                  if ( isYearDifferent && IsLeapYear( nYear1 ) )\n" 
 1120"                      nDaysInYear = 366;\n" 
 1124"                      if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 " 
 1125"&& nDay1 <= 29 ) ||\n" 
 1126"                           ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || " 
 1127"( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n" 
 1129"                         nDaysInYear = 366;\n" 
 1133"                          nDaysInYear = 365;\n" 
 1134"                           for ( int i = nYear1; i <= nYear2; i++ )\n" 
 1136"                             if ( IsLeapYear( i ) )\n" 
 1138"                                  nDaysInYear = 366;\n" 
 1148"          nDaysInYear = 365;\n" 
 1151"  return (double)( nDayDiff ) / (nDaysInYear);\n" 
 1155"void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n";
 
 1158"void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n" 
 1165"        nTempDays = nDays;\n" 
 1166"        *rYear = (int)((nTempDays / 365) - i);\n" 
 1167"        nTempDays -= ((int) *rYear -1) * 365;\n" 
 1168"        nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)" 
 1171"        if ( nTempDays < 1 )\n" 
 1178"            if ( nTempDays > 365 )\n" 
 1180"                if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n" 
 1188"    while ( bCalc );\n" 
 1189"    if(nTempDays != 0){\n" 
 1190"        for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );" 
 1193"            nTempDays -= DaysInMonth( *rMonth, *rYear ); \n" 
 1195"        *rDay = (int)nTempDays;\n" 
 1200"void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n";
 
 1203"void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n" 
 1210"        nTempDays = nDays;\n" 
 1211"        *rYear = (int)((nTempDays / 365) - i);\n" 
 1212"        nTempDays -= ((int) *rYear -1) * 365;\n" 
 1213"        nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)" 
 1216"        if ( nTempDays < 1 )\n" 
 1223"            if ( nTempDays > 365 )\n" 
 1225"                if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n" 
 1233"    while ( bCalc );\n" 
 1234"    barrier(CLK_LOCAL_MEM_FENCE);\n" 
 1235"    if(nTempDays != 0){\n" 
 1236"        for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );" 
 1239"            nTempDays -= DaysInMonth( *rMonth, *rYear ); \n" 
 1241"        *rDay = (int)nTempDays;\n" 
 1246"double GetYearDiff( int nNullDate, int nStartDate, int nEndDate," 
 1250"double GetYearDiff( int nNullDate, int nStartDate, int nEndDate," 
 1253"    int   nDays1stYear;\n" 
 1254"    int   nTotalDays = GetDiffDate( nNullDate, nStartDate, nEndDate," 
 1257"    return (double)(nTotalDays) / (double)nDays1stYear;\n" 
 1261"int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode," 
 1262"    int* pOptDaysIn1stYear );\n";
 
 1265"int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode," 
 1266"    int* pOptDaysIn1stYear )\n" 
 1268"    bool    bNeg = nStartDate > nEndDate;\n" 
 1271"        int   n = nEndDate;\n" 
 1272"        nEndDate = nStartDate;\n" 
 1281"        int      nD1, nM1, nY1, nD2, nM2, nY2;\n" 
 1282"        nStartDate += nNullDate;\n" 
 1283"        nEndDate += nNullDate;\n" 
 1284"        DaysToDate( nStartDate, &nD1, &nM1, &nY1 );\n" 
 1285"        DaysToDate( nEndDate, &nD2, &nM2, &nY2 );\n" 
 1286"        bool        bLeap = IsLeapYear( nY1 );\n" 
 1287"        int       nDays, nMonths;\n" 
 1288"        nMonths = nM2 - nM1;\n" 
 1289"        nDays = nD2 - nD1;\n" 
 1290"        nMonths += ( nY2 - nY1 ) * 12;\n" 
 1291"        nRet = nMonths * 30 + nDays;\n" 
 1292"        if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n" 
 1293"            nRet -= bLeap? 1 : 2;\n" 
 1294"        if( pOptDaysIn1stYear )\n" 
 1295"            *pOptDaysIn1stYear = 360;\n" 
 1299"        if( pOptDaysIn1stYear )\n" 
 1302"            DaysToDate( nStartDate + nNullDate, &nD, &nM, &nY );\n" 
 1303"            *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n" 
 1305"        nRet = nEndDate - nStartDate;\n" 
 1308"        nRet = nEndDate - nStartDate;\n" 
 1309"        if( pOptDaysIn1stYear )\n" 
 1310"            *pOptDaysIn1stYear = 360;\n" 
 1313"        nRet = nEndDate - nStartDate;\n" 
 1314"        if( pOptDaysIn1stYear )\n" 
 1315"            *pOptDaysIn1stYear = 365;\n" 
 1318"    return bNeg? -nRet : nRet;\n" 
 1322"bool RateIteration( double fNper, double fPayment, double fPv," 
 1323"                    double fFv, bool bPayType, double* fGuess );\n";
 
 1326"bool RateIteration( double fNper, double fPayment, double fPv," 
 1327"                    double fFv, bool bPayType, double* fGuess )\n" 
 1329"#define SCdEpsilon                1.0E-7\n" 
 1330"    bool bValid = true, bFound = false;\n" 
 1331"    double fX, fXnew, fTerm, fTermDerivation;\n" 
 1332"    double fGeoSeries, fGeoSeriesDerivation;\n" 
 1333"    const int nIterationsMax = 150;\n" 
 1335"    const double fEpsilonSmall = 1.0E-14;\n" 
 1338"        fFv = fFv - fPayment;\n" 
 1339"        fPv = fPv + fPayment;\n" 
 1341"    if (fNper == round( fNper ))\n" 
 1344"        while (!bFound && nCount < nIterationsMax)\n" 
 1346"            double fPowN, fPowNminus1;\n" 
 1347"            fPowNminus1 = pow( 1.0+fX, fNper-1.0);\n" 
 1348"            fPowN = fPowNminus1 * (1.0+fX);\n" 
 1351"                fGeoSeries = fNper;\n" 
 1352"                fGeoSeriesDerivation = fNper * (fNper-1.0)/2.0;\n" 
 1356"                fGeoSeries = (fPowN-1.0)/fX;\n" 
 1357"                fGeoSeriesDerivation = fNper * fPowNminus1 / fX - fGeoSeries / fX;\n" 
 1359"            fTerm = fFv + fPv *fPowN+ fPayment * fGeoSeries;\n" 
 1360"            fTermDerivation = fPv * fNper * fPowNminus1 + fPayment * fGeoSeriesDerivation;\n" 
 1361"            if (fabs(fTerm) < fEpsilonSmall)\n" 
 1365"                if (fTermDerivation == 0.0)\n" 
 1366"                    fXnew = fX + 1.1 * SCdEpsilon;\n" 
 1368"                    fXnew = fX - fTerm / fTermDerivation;\n" 
 1370"                bFound = (fabs(fXnew - fX) < SCdEpsilon);\n" 
 1374"        bValid = (fX > -1.0);\n" 
 1378"        fX = (*fGuess < -1.0) ? -1.0 : *fGuess;\n" 
 1379"        while (bValid && !bFound && nCount < nIterationsMax)\n" 
 1383"                fGeoSeries = fNper;\n" 
 1384"                fGeoSeriesDerivation = fNper * (fNper-1.0)/2.0;\n" 
 1388"                fGeoSeries = (pow( 1.0+fX, fNper) - 1.0) / fX;\n" 
 1389"                fGeoSeriesDerivation = fNper * pow( 1.0+fX, fNper-1.0) / fX - fGeoSeries / fX;\n" 
 1391"            fTerm = fFv + fPv *pow(1.0 + fX,fNper)+ fPayment * fGeoSeries;\n" 
 1392"            fTermDerivation = fPv * fNper * pow( 1.0+fX, fNper-1.0) + fPayment * fGeoSeriesDerivation;\n" 
 1393"            if (fabs(fTerm) < fEpsilonSmall)\n" 
 1397"                if (fTermDerivation == 0.0)\n" 
 1398"                    fXnew = fX + 1.1 * SCdEpsilon;\n" 
 1400"                    fXnew = fX - fTerm / fTermDerivation;\n" 
 1402"                bFound = (fabs(fXnew - fX) < SCdEpsilon);\n" 
 1404"                bValid = (fX >= -1.0);\n" 
 1409"    return bValid && bFound;\n" 
const char ScInterVDBDecl[]
const char IsLeapYearDecl[]
const char DaysInMonthDecl[]
const char DaysToDateDecl[]
const char coupdaysncDecl[]
const char GetOddlpriceDecl[]
const char GetNullDateDecl[]
const char lcl_GetcoupdaysDecl[]
const char VDBImplementDecl[]
const char DaysToDate_LocalBarrierDecl[]
const char checklessthan[]
const char RateIteration[]
const char GetDiffDate360_[]
const char getYield_Decl[]
const char GetDiffDate360Decl[]
const char checklessthanDecl[]
const char GetDiffDate360_Decl[]
const char GetOddlyieldDecl[]
const char GetDurationDecl[]
const char GetDiffDateDecl[]
const char lcl_Getcoupdaybs[]
const char getDaysInMonthRange[]
const char GetDiffDate360[]
const char RateIterationDecl[]
const char DateToDaysDecl[]
const char lcl_Getcoupdays[]
const char lcl_GetCoupncdDecl[]
const char getDaysInYearRange[]
const char addMonthsDecl[]
const char VDBImplement[]
const char lcl_GetCoupncd[]
const char GetDaysInYears[]
const char GetOddlyield[]
const char lcl_GetcoupnumDecl[]
const char GetYieldmatDecl[]
const char GetDaysInYearsDecl[]
const char coupdaysDecl[]
const char lcl_GetcoupdaybsDecl[]
const char GetDaysInYearDecl[]
const char GetOddlprice[]
const char GetYearFracDecl[]
const char lcl_GetCouppcd[]
const char getPriceDecl[]
const char getDaysInYearRangeDecl[]
const char getDaysInMonthRangeDecl[]
const char lcl_Getcoupnum[]
const char coupdaybsDecl[]
const char ScGetDDBDecl[]
const char GetDaysInYear[]
const char lcl_GetCouppcdDecl[]
const char DaysToDate_LocalBarrier[]
const char GetYearDiffDecl[]