Ejemplo n.º 1
0
int main (void)
{
    int year0, year1, mon0, mon1, day0, day1, dayo;
    float daysD, daysT0, daysT1;

    printf("Enter Starting YYYY,MM,DD  ");
    scanf("%d, %d, %d", &year0, &mon0, &day0);
    puts("");

    printf("Enter   Ending YYYY,MM,DD  "); 
    scanf("%d, %d, %d", &year1, &mon1, &day1);
    puts("\n");

/* temporary rem-out .....
    daysT0 = year0 * 365.2421897 + (mon0 - 1) * 30.43684914 + day0;
    daysT1 = year1 * 365.2421897 + (mon1 - 1) * 30.43684914 + day1;

    printf("Total days of daysT0 = %.10g      Total days of dayT1 = %.10g\n", daysT0, daysT1);

    daysD = (daysT1 - daysT0);

    dayo = (int)(daysD + 0.5);

    printf("\nDifference by days between dates as a 0.5 rounded-up integer = %i\n", dayo);
...... */

    dayo = daycounter(year0, year1, mon0, mon1, day0, day1);

    printf("\nA rigorous count of days (returned to the calling func) = %i\n", dayo);

    return 0;
}
        /* enregistre une jambe à taux flottant */
DLLEXPORT xloper * xlInitiateFloatLegUnitedStates (const char * objectID_,
                                                   const double * effectiveDate_,
                                                   xloper * firstCouponDate_,
                                                   xloper * lastCouponDate_,
                                                   const double * maturityDate_,
                                                   xloper * notional_,
                                                   const char * indexId_,
                                                   xloper * frequency_,
                                                   xloper * daycounter_,
                                                   xloper * spread_,
                                                   xloper * trigger_) {

    boost::shared_ptr<ObjectHandler::FunctionCall> functionCall(
        new ObjectHandler::FunctionCall("xlInitiatefloatLegUnitedStates")) ;

     try {


        QL_ENSURE(! functionCall->calledByFunctionWizard(), "") ;


            // vérification des codes erreur
        ObjectHandler::validateRange(trigger_, "trigger") ;

        ObjectHandler::validateRange(firstCouponDate_, "first Coupon Date") ;

        ObjectHandler::validateRange(lastCouponDate_, "last Coupon Date") ;

        ObjectHandler::validateRange(notional_, "notional") ;

        ObjectHandler::validateRange(frequency_, "frequency") ;

        ObjectHandler::validateRange(daycounter_, "daycounter") ;

        ObjectHandler::validateRange(spread_, "spread") ;

            // Création des oper
        ObjectHandler::ConvertOper myOper1(* firstCouponDate_),
                                   myOper2(* lastCouponDate_),
                                   myOper3(* notional_),
                                   myOper4(* frequency_),
                                   myOper5(* daycounter_),
                                   myOper6(* spread_) ;

            // création des dates et contrôles sur les dates intermédiaires
        QuantLib::Date effectiveDate(QuantLib::Date(static_cast<QuantLib::BigInteger>(* effectiveDate_))) ;

        QuantLib::Date maturityDate(QuantLib::Date(static_cast<QuantLib::BigInteger>(* maturityDate_))) ;

        QuantLib::Date firstCouponDate(myOper1.missing() ? 
            QuantLib::Date() : 
            QuantLib::Date(static_cast<QuantLib::BigInteger>(myOper1))) ;

        QuantLib::Date lastCouponDate(myOper2.missing() ? 
            QuantLib::Date() : 
            QuantLib::Date(static_cast<QuantLib::BigInteger>(myOper2))) ;

        QuantLib::Real notional(myOper3.missing() ? 
            100.0 : 
            static_cast<QuantLib::Real>(myOper3)) ;

        QuantLib::Frequency frequency(myOper4.missing() ? 
            QuantLib::Quarterly : 
            ObjectHandler::frequencyFactory()(static_cast<std::string>(myOper4))) ;

        QuantLib::DayCounter daycounter(myOper5.missing() ? 
            QuantLib::Actual360() : 
            ObjectHandler::daycountFactory()(static_cast<std::string>(myOper5))) ;

		QuantLib::Spread spread(myOper6.missing() ? 
            0.0 : 
            static_cast<QuantLib::Spread>(myOper6)) ;


            // on récupère l'index libor
        OH_GET_REFERENCE(iborIndexPtr, 
                         std::string(indexId_), 
                         QuantLibAddin::iborIndexObject,
                         QuantLib::IborIndex)    


            // Construction du value object
        boost::shared_ptr<QuantLibAddin::ValueObjects::floatLegUnitedStatesValueObject> myLegValueObject(
            new QuantLibAddin::ValueObjects::floatLegUnitedStatesValueObject(objectID_,
                                                                   true)) ;

            // instanciation de l'instrument
        boost::shared_ptr<QuantLibAddin::floatLegUnitedStatesObject> myLegObject(
            new QuantLibAddin::floatLegUnitedStatesObject(myLegValueObject,
                                                effectiveDate,
                                                firstCouponDate,
                                                lastCouponDate,
                                                maturityDate,
                                                iborIndexPtr,
                                                2,
                                                frequency,
                                                daycounter,
                                                notional,
                                                spread,
                                                QuantLib::ModifiedFollowing,
                                                QuantLib::ModifiedFollowing, 
                                                true, true)) ;


            // stockage de l'objet
        std::string returnValue =
            ObjectHandler::RepositoryXL::instance().storeObject(objectID_, 
                                                                myLegObject, 
                                                                true) ; // on force la réécriture

        static XLOPER returnOper ;

        ObjectHandler::scalarToOper(returnValue, returnOper) ;

        return & returnOper ;

    } catch (std::exception & e) {

            ObjectHandler::RepositoryXL::instance().logError(e.what(), functionCall) ;

            static XLOPER returnOper ;

            ObjectHandler::scalarToOper(e.what(), returnOper) ;

            return & returnOper ;

    }

} ;
Ejemplo n.º 3
0
int main (void)
{
    int da1, mo1, yr1,
        da2, mo2, yr2,
        len, cDays;
    float totalgal = 0,
          fuelcost = 0,
          totoilqt = 0,
          othrcost = 0,
          sodm = 0,
          fodm;
    setlocale(LC_NUMERIC, "");
    char file_name[25];
    FILE *fp;

    system("cls");
    system("dir *.csv /X");
    puts("\nQmatrix v1.06  (C) 2014 Hamal and George Winkel");
    printf("\nEnter the name of file you wish to open...\n");

    fgets(file_name, 255, stdin);

    /* Test the filename for '\n' -- fopen(below,) returns NULL unless \n is replaced with 0. */
    len = strlen(file_name);
    if(file_name[len-1] == '\n')
         file_name[len-1] = 0;

    fp = fopen(file_name,"r"); 		// file open "r", read mode

    if( fp == NULL ) {
         perror("\nError while opening the file.\n");
         printf("%s\n", file_name);
         exit(EXIT_FAILURE);
    }

    char line[1024], *tmp, 		/* This portion parses a file's lines (records) for its database fields */
         sDay[15], fDay[15];
    len = 0;
    while(fgets(line, 1024, fp)) {
         len++;
         tmp = strdup(line);
         if(len == 2) strcpy(sDay, getfield(tmp, 1)); 	// collect start date (as string)
         tmp = strdup(line);
         strcpy(fDay, getfield(tmp, 1)); 		// collect final date (as string)
         tmp = strdup(line);
         if(sodm == 0) sodm = atof(getfield(tmp, 2)); 	// collect start odometer
         tmp = strdup(line);
         fodm = atof(getfield(tmp, 2)); 		// collect final odometer
         tmp = strdup(line);
         totalgal += atof(getfield(tmp, 3)); 		// sum gallons of fuel
         tmp = strdup(line);
         fuelcost += atof(getfield(tmp, 4)); 		// sum fuel cost$
         tmp = strdup(line);
         totoilqt += atof(getfield(tmp, 5)); 		// sum qts. of oil
         tmp = strdup(line);
         othrcost += atof(getfield(tmp, 7)); 		// sum all other cost$
    }
         free(tmp);

    fclose(fp); 	// close the file.


    strcpy(line, sDay); 		/* This portion parses two string dates for six integers */
         tmp = strdup(line);
    mo1 = atoi(getfield2(tmp, 1)); 		// collect starting month
         tmp = strdup(line);
    da1 = atoi(getfield2(tmp, 2)); 		// collect starting day
         tmp = strdup(line);
    yr1 = atoi(getfield2(tmp, 3)); 		// collect starting year

    strcpy(line, fDay);
         tmp = strdup(line);
    mo2 = atoi(getfield2(tmp, 1)); 		// collect final month
         tmp = strdup(line);
    da2 = atoi(getfield2(tmp, 2)); 		// collect final day
         tmp = strdup(line);
    yr2 = atoi(getfield2(tmp, 3)); 		// collect final year
         free(tmp);

    cDays = daycounter(mo1, da1, yr1, mo2, da2, yr2);

    printf("\nThe contents of file:  %s\n", file_name);

    printf("Starting Record Date       %s\n", sDay);
    printf("Starting Odometer miles  = %.0f\n", sodm);
    printf("Total Gallons Fuel Used  = %.2f\n", totalgal);
    printf("Total Fuel Cost          =$%.2f\n", fuelcost);
    printf("Average cost per gallon  =$%.2f\n", (fuelcost / totalgal));
    printf("Subtotal of Other Costs  =$%.2f\n", othrcost);
    printf("Ending Odometer miles    = %.0f\n", fodm);
    printf("Ending Record Date         %s\n\n", fDay);

    printf("Records in this LogSheet = %d\n", len-1);
    printf("Count days this period   = %d\n", cDays);
    printf("Miles driven this period = %.0f\n", (fodm - sodm));
    printf("Tot Qts of Oil consumed  = %.0f\n", totoilqt);
    printf("Miles per gallon, Fuel   = %.2f\n", ((fodm - sodm) / totalgal));
    printf("Miles per Qt of Oil      = %.2f\n", ((fodm - sodm) / totoilqt));
    printf("Dollar cost per month    =$%.2f\n", (fuelcost + othrcost) * 30.43684914 / cDays);
    printf("Total costs this period  =$%.2f\n", (fuelcost + othrcost));
    printf("Miles driven on each $1  = %.2f\n", ((fodm - sodm) / (fuelcost + othrcost)));

    return 0;
}