コード例 #1
0
ファイル: date.cpp プロジェクト: gatgui/gcore
Date Date::Minutes(int n) {
  return Date(n * gsSecsPerMinute, true);
}
コード例 #2
0
ファイル: Date.cpp プロジェクト: SEJeff/task
Date Date::startOfYear () const
{
  return Date (1, 1, year (), 0, 0, 0);
}
コード例 #3
0
ファイル: Date.cpp プロジェクト: SEJeff/task
Date Date::operator+ (const int delta)
{
  return Date (_t + delta);
}
コード例 #4
0
void MyDayInfoPlot::DrawPricePlot(wxDC&dc){
    TotalDayInfoStru MyDays[TOTAY_DAYS_MYDAYINFO];
    double MaxSz,MinSz,MaxSh,MinSh,MaxTotal,MinTotal,MaxDelta,MinDelta;
	MaxSz=MinSz=MaxSh=MinSh=MaxTotal=MinTotal=MaxDelta=MinDelta=0;

	for (int tidx=0;tidx<TOTAY_DAYS_MYDAYINFO;tidx++){
		MyDays[tidx].Valid=false;
	}

    wxString keyPath=WStockConfig::GetMyDayInfoPath();
    wxFileName keyf(keyPath);
    keyf.MakeAbsolute();
    xmlDocPtr doc=NULL;
    if (keyf.FileExists()){
        //Load Stocks Name From file
		doc = xmlParseFile((const char*)keyf.GetFullPath().mb_str());
    }

    //If Load Fail, Create the Xml Memory
    if (doc==NULL){
        dc.DrawText(_("No Info File Found!"),10,10);
        return;
    }

    for (xmlNodePtr node=doc->children->children;node;node=node->next){
            if (xmlStrcmp(node->name,(const xmlChar*)"DayInfo")==0){
				wxString Date(wxConvUTF8.cMB2WC(
					(char*)xmlGetProp(node, (const xmlChar*)"Date")),*wxConvCurrent);
				wxString Sz(wxConvUTF8.cMB2WC(
					(char*)xmlGetProp(node, (const xmlChar*)"ShenZhen")),*wxConvCurrent);
				wxString Sh(wxConvUTF8.cMB2WC(
					(char*)xmlGetProp(node, (const xmlChar*)"ShangHai")),*wxConvCurrent);
				wxString Total(wxConvUTF8.cMB2WC(
					(char*)xmlGetProp(node, (const xmlChar*)"Total")),*wxConvCurrent);
				wxString Delta(wxConvUTF8.cMB2WC(
					(char*)xmlGetProp(node, (const xmlChar*)"TodayEarning")),*wxConvCurrent);

                wxDateTime date;
                date.ParseDate(Date);
                int idx=(wxDateTime::Today()-date).GetDays();
                if  (idx<TOTAY_DAYS_MYDAYINFO){
                    Sz.ToDouble(&MyDays[idx].sz);
                    Sh.ToDouble(&MyDays[idx].sh);
                    Total.ToDouble(&MyDays[idx].total);
                    Delta.ToDouble(&MyDays[idx].delta);
					MyDays[idx].Valid = true;
					MyDays[idx].date = date;
                }
            }
    }

	int i;
	for (i=0;i<TOTAY_DAYS_MYDAYINFO;i++){
		if (MyDays[i].Valid){
			if (MyDays[i].sz>MaxSz) MaxSz = MyDays[i].sz;
			if (MyDays[i].sz<MinSz) MinSz = MyDays[i].sz;

			if (MyDays[i].sh>MaxSh) MaxSh = MyDays[i].sh;
			if (MyDays[i].sh<MinSh) MinSh = MyDays[i].sh;

			if (MyDays[i].total>MaxTotal) MaxTotal = MyDays[i].total;
			if (MyDays[i].total<MinTotal) MinTotal = MyDays[i].total;

			if (MyDays[i].delta>MaxDelta) MaxDelta = MyDays[i].delta;
			if (MyDays[i].delta<MinDelta) MinDelta = MyDays[i].delta;

		}
	}

	dc.SetPen(wxPen(*wxBLACK,3));
	int XStart=100,YStart=10,YFree=60;
	int TotalY=dc.GetSize().y-30-YFree;
	int XTotal = dc.GetSize().x-110;
	float TotalDelta=0;
	if (MinDelta<0)	TotalDelta = MaxTotal - MinDelta+YFree;
	else TotalDelta = MaxTotal+YFree;
	if (TotalDelta<0.0003) TotalDelta = 1;
	int ZeroY = (int)(double)(TotalY/TotalDelta * MaxTotal + YStart);
	dc.DrawLine(XStart,YStart,XStart,YStart + TotalY + YFree);
	dc.DrawLine(XStart-10,ZeroY,XStart+XTotal,ZeroY);

	for (i=0;i<TOTAY_DAYS_MYDAYINFO;i++){
		if (MyDays[i].Valid){
			int MyTotalY=(int)(double)(ZeroY - TotalY/TotalDelta * MyDays[i].total);
			int MyDeltaY=(int)(double)(ZeroY - TotalY/TotalDelta * MyDays[i].delta);
			dc.SetBrush(*wxBLACK_BRUSH);
			dc.DrawRectangle(XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1)) - 5,MyTotalY,10,Abs(ZeroY-MyTotalY));
			dc.SetBrush(*wxGREEN_BRUSH);
			dc.DrawRectangle(XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1)) - 5,MyDeltaY,10,Abs(ZeroY-MyDeltaY));
			//wxLogMessage(wxT("Draw Rect at:%d %d %d %d"),(int)(XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1)) - 5),
			//MyDeltaY,10,Abs(ZeroY-MyDeltaY));
			dc.DrawText(MyDays[i].date.FormatISODate(),XStart+(i+1)*(XTotal / (TOTAY_DAYS_MYDAYINFO + 1))-30,YStart+TotalY);
		}
	}

}
コード例 #5
0
ファイル: Date.cpp プロジェクト: SEJeff/task
Date Date::startOfWeek () const
{
  Date sow (_t);
  sow -= (dayOfWeek () * 86400);
  return Date (sow.month (), sow.day (), sow.year (), 0, 0, 0);
}
コード例 #6
0
ファイル: makeois.cpp プロジェクト: 21hub/QuantLib
 MakeOIS& MakeOIS::withSettlementDays(Natural settlementDays) {
     settlementDays_ = settlementDays;
     effectiveDate_ = Date();
     return *this;
 }
コード例 #7
0
ファイル: actualactual.cpp プロジェクト: AAthresh/quantlib
    Time ActualActual::ISMA_Impl::yearFraction(const Date& d1,
                                               const Date& d2,
                                               const Date& d3,
                                               const Date& d4) const {
        if (d1 == d2)
            return 0.0;

        if (d1 > d2)
            return -yearFraction(d2,d1,d3,d4);

        // when the reference period is not specified, try taking
        // it equal to (d1,d2)
        Date refPeriodStart = (d3 != Date() ? d3 : d1);
        Date refPeriodEnd = (d4 != Date() ? d4 : d2);

        QL_REQUIRE(refPeriodEnd > refPeriodStart && refPeriodEnd > d1,
                   "invalid reference period: "
                   << "date 1: " << d1
                   << ", date 2: " << d2
                   << ", reference period start: " << refPeriodStart
                   << ", reference period end: " << refPeriodEnd);

        // estimate roughly the length in months of a period
        Integer months =
            Integer(0.5+12*Real(refPeriodEnd-refPeriodStart)/365);

        // for short periods...
        if (months == 0) {
            // ...take the reference period as 1 year from d1
            refPeriodStart = d1;
            refPeriodEnd = d1 + 1*Years;
            months = 12;
        }

        Time period = Real(months)/12.0;

        if (d2 <= refPeriodEnd) {
            // here refPeriodEnd is a future (notional?) payment date
            if (d1 >= refPeriodStart) {
                // here refPeriodStart is the last (maybe notional)
                // payment date.
                // refPeriodStart <= d1 <= d2 <= refPeriodEnd
                // [maybe the equality should be enforced, since
                // refPeriodStart < d1 <= d2 < refPeriodEnd
                // could give wrong results] ???
                return period*Real(dayCount(d1,d2)) /
                    dayCount(refPeriodStart,refPeriodEnd);
            } else {
                // here refPeriodStart is the next (maybe notional)
                // payment date and refPeriodEnd is the second next
                // (maybe notional) payment date.
                // d1 < refPeriodStart < refPeriodEnd
                // AND d2 <= refPeriodEnd
                // this case is long first coupon

                // the last notional payment date
                Date previousRef = refPeriodStart - months*Months;
                if (d2 > refPeriodStart)
                    return yearFraction(d1, refPeriodStart, previousRef,
                                        refPeriodStart) +
                        yearFraction(refPeriodStart, d2, refPeriodStart,
                                     refPeriodEnd);
                else
                    return yearFraction(d1,d2,previousRef,refPeriodStart);
            }
        } else {
            // here refPeriodEnd is the last (notional?) payment date
            // d1 < refPeriodEnd < d2 AND refPeriodStart < refPeriodEnd
            QL_REQUIRE(refPeriodStart<=d1,
                       "invalid dates: "
                       "d1 < refPeriodStart < refPeriodEnd < d2");
            // now it is: refPeriodStart <= d1 < refPeriodEnd < d2

            // the part from d1 to refPeriodEnd
            Time sum = yearFraction(d1, refPeriodEnd,
                                    refPeriodStart, refPeriodEnd);

            // the part from refPeriodEnd to d2
            // count how many regular periods are in [refPeriodEnd, d2],
            // then add the remaining time
            Integer i=0;
            Date newRefStart, newRefEnd;
            for (;;) {
                newRefStart = refPeriodEnd + (months*i)*Months;
                newRefEnd = refPeriodEnd + (months*(i+1))*Months;
                if (d2 < newRefEnd) {
                    break;
                } else {
                    sum += period;
                    i++;
                }
            }
            sum += yearFraction(newRefStart,d2,newRefStart,newRefEnd);
            return sum;
        }
    }
コード例 #8
0
ファイル: calendrier.cpp プロジェクト: clemencevaz/LO21
void FenetreProgrammerActivite::enregistrer(){
    programmation& progact = agenda::getInstance().ajouterProgrammationActivite(activite, Date(ProgDate->date().day(),ProgDate->date().month(),ProgDate->date().year()),Horaire(ProgHh->value(), ProgHm->value()));
    if(&progact!=0){
        QMessageBox msgBox;
        msgBox.setText("L'Activité a été programmée");
        msgBox.exec();
        this->close();
    }
    else
    {
        delete &progact;
        QMessageBox msgBox;
        msgBox.setText("L'Activité n'a pas été programmée");
        msgBox.exec();
    }
}
コード例 #9
0
int main()
{
	try
	{
		odb::session s; // this keeps shared pointers consistent after reloading them from the db (turns on object cache)
		std::unique_ptr<odb::database> db( new Database( "Branch_removeEmployee.test.db", true ) );

		// a set storing all employees we want to add
		std::unordered_set< std::shared_ptr<Employee> > employees;
		employees.insert( std::shared_ptr<Employee>( new Employee( "A", Date(1,1,1967) ) ) );
		employees.insert( std::shared_ptr<Employee>( new Employee( "B", Date(2,1,1968) ) ) );
		employees.insert( std::shared_ptr<Employee>( new Employee( "C", Date(3,1,1969) ) ) );

		// we will add all employees to one branch
		std::shared_ptr<Branch> b( new Branch( "Main", Address() ) );
		for( const std::shared_ptr<Employee> & e : employees )
			assert( b->addEmployee( e ) );

		// for accessing the stored branch by id
		std::string branch_id;

		// store branch and employees
		{
			odb::transaction t( db->begin() );
			for( const std::shared_ptr<Employee> & e : employees )
			{
				db->persist( e );
				std::cout << "Stored " << e->getName() << "\n";
			}
			branch_id = db->persist( b );
			t.commit();
		}

		// remove an employee from the stored branch one after the other
		for( auto i = employees.begin(); i != employees.end(); )
		{
			// retrieve the stored branch and remove an employee
			{
				odb::transaction t( db->begin() );
				std::shared_ptr<Branch> b( db->load<Branch>( branch_id ) );
				for( const odb::lazy_weak_ptr<Employee> & le : b->getEmployees() )
				{
					std::cout << "Still persistent: " << le.object_id() << "\n";
				}

				assert( (*i)->getBranch() == b ); // should be connected to branch

				// remove employee
				assert( b->removeEmployee( (*i) ) );
				assert( b->getEmployees().size() == employees.size()-1 ); // should be removed locally
				assert( (*i)->getBranch() == nullptr ); // should not be connected to any branch anymore

				// remove second time (should fail)
				assert( !b->removeEmployee( (*i) ) ); // should not be able to remove twice
				assert( b->getEmployees().size() == employees.size()-1 ); // should stay the same
				assert( (*i)->getBranch() == nullptr ); // should still not be connected to any branch

				db->update( b );
				t.commit();
			}
			// reload person from database and check if employee got removed
			{
				odb::transaction t( db->begin() );
				std::shared_ptr<Branch> b( db->load<Branch>( branch_id ) );
				assert( b->getEmployees().size() == employees.size()-1 ); // should be removed in database too
				t.commit();
			}
			std::cout << "Deleting: " << (*i) << " - " << (*i)->getName()  << "\n";
			i = employees.erase( i );
		}
	}
	catch( const odb::exception & e )
	{
		std::cerr << "Exception: " << e.what() << std::endl;
		std::exit( EXIT_FAILURE );
	}
	return 0;
}
コード例 #10
0
ファイル: Date.cpp プロジェクト: dblock/baseclasses
bool CDate::EncodeDate(
    const CString& DateString, 
    const CString& DateFormat, 
    struct tm& Result) {

  CString Date(DateString);
  
  static const char * Months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
  static const char * WeekDays[] = {"Sun", "Mon","Tue","Wed","Thu","Fri","Sat"};
  static const char * Zones[] = {"UTC", "GMT", "EDT", "EST", "CDT", "CST", "MDT", "MST", "PDT", "PST"};
  static const int ZonesHoursSkew[] = {0, 0, 4, 5, 5, 6, 6, 7, 7, 8};
	
  CString WeekDay;
  CString Month;
  CString Zone;
  
  Date.Replace('-', ' ');

  memset(&Result, 0, sizeof(Result));

  bool fScan = 
      SSScan(
          Date, 
          &DateFormat, 
          &WeekDay, 
          NULL, 
          &Result.tm_mday, 
          &Month, 
          &Result.tm_year, 
          &Result.tm_hour, 
          NULL, 
          &Result.tm_min, 
          NULL, 
          &Result.tm_sec, 
          &Zone);
  
  Trace(tagDateTime, levVerbose, 
        ("CDate:: EncodeDate - scanned %s with " \
         "WeekDay: %s " \
         "Day: %d " \
         "Month: %s " \
         "Year: %d " \
         "Hour: %d " \
         "Minute: %d " \
         "Second: %d " \
         "Zone: %s", 
         Date.GetBuffer(),
         WeekDay.GetBuffer(),
         Result.tm_mday,
         Month.GetBuffer(),
         Result.tm_year,
         Result.tm_hour,
         Result.tm_min,
         Result.tm_sec,
         Zone.GetBuffer()));
  
  if (fScan) {

		int i;
      
		if (Result.tm_year > 1900) 
			Result.tm_year-=1900;
    
		for (i = 0; i < BASE_DIM(Months); i++) {
			if (Month.Same(Months[i])) {
				Result.tm_mon = i;
				break;
			}
		}

		for (i = 0; i < BASE_DIM(WeekDays); i++) {
			// support full weekdays as well
			if (WeekDay.StartsWithSame(WeekDays[i])) {
				Result.tm_wday = i;
				break;
			}
		}

		// time zone adjustments
		int ZoneAdjustment = 0;

		if (Zone.IsInt( & ZoneAdjustment)) {
			ZoneAdjustment *= 3600;
		} else {
			for (i = 0; i < BASE_DIM(Zones); i++) {
				if (Zone.Same(Zones[i])) {
					ZoneAdjustment = ZonesHoursSkew[i] * 3600;
					break;
				}
			}
		}

		Trace(tagDateTime, levVerbose, ("CDate:: EncodeSimpleDate - ZoneAdjustment %d second(s)", ZoneAdjustment));

		Result.tm_isdst = 0;

		if (ZoneAdjustment) {
			time_t AdjustedTime;
#ifdef _UNIX
			base_gmtime(AdjustedTime, Result);
#endif
#ifdef _WIN32
			_tzset();
			AdjustedTime = mktime(&Result);
			AdjustedTime -= _timezone;
#endif
			AdjustedTime -= ZoneAdjustment;
			base_localtime(AdjustedTime, Result);
		}

		// Result.tm_gmtoff = ZoneAdjustment;    
		return true;
  }
  return false;
}
コード例 #11
0
NoArbSabrSmileSection::NoArbSabrSmileSection(
    const Date &d, Rate forward, const std::vector<Real> &sabrParams,
    const DayCounter &dc, Real shift)
    : SmileSection(d, dc, Date()), forward_(forward), params_(sabrParams), shift_(shift) {
    init();
}
コード例 #12
0
Date Grader07::getDueDate()
{
  return Date(12, 5, 2013);
}
コード例 #13
0
ファイル: date.cpp プロジェクト: gatgui/gcore
Date Date::Days(int n) {
  return Date(n * gsSecsPerDay, true);
}
コード例 #14
0
ファイル: date.cpp プロジェクト: gatgui/gcore
Date Date::Seconds(int n) {
  return Date(n, true);
}
コード例 #15
0
ファイル: Calendar.cpp プロジェクト: pepsi7959/OpenStudio
 /// constructor with year
 Calendar::Calendar(int year)
   : m_startDate(Date(MonthOfYear::Jan, 1, year)), m_endDate(Date(MonthOfYear::Dec, 31, year))
 {}
コード例 #16
0
void
MonthDayRuleTest::test_utilities()
{
	int yearIndex;
	SetDate date;
	Year year ( DateUtil::year());

	Date newYearDate (year, Month(1), DayOfMonth(1));
	Date july4Date (year, Month(7), DayOfMonth(4));
	Date christmasDate(year, Month(12), DayOfMonth(25));


	//test: MontDayRule::virtual Date calcDate(const Year& year) const ;
	MonthDayRule newYearRule ("Rule", Month(1), DayOfMonth(1));
	date = newYearRule.calcDate(year);
	CPPUNIT_ASSERT(newYearDate == *date.begin());
	for (yearIndex = year.getValue(); yearIndex <= year.getValue() + 50; ++yearIndex){
		date = newYearRule.calcDate(Year(yearIndex));
		CPPUNIT_ASSERT(newYearDate == *date.begin());
		newYearDate.addYear(1);
	}
	
	MonthDayRule july4Rule ("July4Rule", Month(7), DayOfMonth(4));
	date = july4Rule.calcDate(year);
	CPPUNIT_ASSERT(july4Date == *date.begin());

	MonthDayRule christmasRule("ChristmasRule", Month(12), DayOfMonth(25));
	date = christmasRule.calcDate(year);
	CPPUNIT_ASSERT(christmasDate == *date.begin());

	//Test for weekendAdjustment
	WeekendRuleSharedPtr weekendRulePtr(new WeekendRule("WeekendRule"));
	weekendRulePtr->addDay(WeekDay::Saturday);
	weekendRulePtr->addDay(WeekDay::Sunday);
	MonthDayRule adjustingNewYearRule ("AdjustingNewYear", Month(1), DayOfMonth(1));
	adjustingNewYearRule.setStartEffectiveDate(20110101);
	adjustingNewYearRule.setWeekendAdjustment(WeekendAdjustment::ClosestWeekDay);
	adjustingNewYearRule.setWeekendRule(weekendRulePtr);

	//First check for Saturday -> prior Friday
	date = adjustingNewYearRule.calcDate(Year(2011));
	CPPUNIT_ASSERT(Date(20101231) == *date.begin());

	//First check for Sunday -> next Monday
	date = adjustingNewYearRule.calcDate(Year(2012));
	CPPUNIT_ASSERT(Date(20120102) == *date.begin());

	//Check for no adjustment is required
	date = adjustingNewYearRule.calcDate(Year(2013));
	CPPUNIT_ASSERT(Date(20130101) == *date.begin());


	//Rule is disabled
	try{
		newYearRule.setEnabledFlag(false);
		newYearRule.calcDate(year);
	}
	catch (BaseException& ex){
		CAUGHT_EXCEPTION(ex,"Calculation called on disabled rule");
	}
	newYearRule.setEnabledFlag(true);
	 

	//Rule start date year > calc year
	try{
		newYearRule.calcDate(Year(2010));
	}
	catch (BaseException& ex){
		CAUGHT_EXCEPTION(ex,"Calculation called for year before  rule is in effect");
	}

	//Rule calc year >  rule end date year
	try{
		newYearRule.setEndEffectiveDate(20121231);
		newYearRule.calcDate(Year(2030));
	}
	catch (BaseException& ex){
		CAUGHT_EXCEPTION(ex,"Calculation called for year after  rule is in effect");
	}

}
コード例 #17
0
ファイル: Value.cpp プロジェクト: open2cerp/Open2C-ERP
void CValue::SetDate(CString s)
{
	Copy(Date(s));
}
コード例 #18
0
ファイル: makecms.cpp プロジェクト: AlexJiaeHwang/quantlib
    MakeCms::operator boost::shared_ptr<Swap>() const {

        Date startDate;
        if (effectiveDate_ != Date())
            startDate = effectiveDate_;
        else {
            Natural fixingDays = iborIndex_->fixingDays();
            Date referenceDate = Settings::instance().evaluationDate();
            Date spotDate = floatCalendar_.advance(referenceDate,
                                                   fixingDays*Days);
            startDate = spotDate+forwardStart_;
        }

        Date terminationDate = startDate+swapTenor_;

        Schedule cmsSchedule(startDate, terminationDate,
                             cmsTenor_, cmsCalendar_,
                             cmsConvention_,
                             cmsTerminationDateConvention_,
                             cmsRule_, cmsEndOfMonth_,
                             cmsFirstDate_, cmsNextToLastDate_);

        Schedule floatSchedule(startDate, terminationDate,
                               floatTenor_, floatCalendar_,
                               floatConvention_,
                               floatTerminationDateConvention_,
                               floatRule_ , floatEndOfMonth_,
                               floatFirstDate_, floatNextToLastDate_);

        Leg cmsLeg = CmsLeg(cmsSchedule, swapIndex_)
            .withNotionals(nominal_)
            .withPaymentDayCounter(cmsDayCount_)
            .withPaymentAdjustment(cmsConvention_)
            .withFixingDays(swapIndex_->fixingDays())
            .withGearings(cmsGearing_)
            .withSpreads(cmsSpread_)
            .withCaps(cmsCap_)
            .withFloors(cmsFloor_);
        if (couponPricer_)
            setCouponPricer(cmsLeg, couponPricer_);

        Rate usedSpread = iborSpread_;
        if (useAtmSpread_) {
            QL_REQUIRE(!iborIndex_->forwardingTermStructure().empty(),
                       "null term structure set to this instance of " <<
                       iborIndex_->name());
            QL_REQUIRE(!swapIndex_->forwardingTermStructure().empty(),
                       "null term structure set to this instance of " <<
                       swapIndex_->name());
            QL_REQUIRE(couponPricer_,
                       "no CmsCouponPricer set (yet)");
            Leg floatLeg = IborLeg(floatSchedule, iborIndex_)
                .withNotionals(nominal_)
                .withPaymentDayCounter(floatDayCount_)
                .withPaymentAdjustment(floatConvention_)
                .withFixingDays(iborIndex_->fixingDays());

            Swap temp(cmsLeg, floatLeg);
            temp.setPricingEngine(engine_);

            Real npv = temp.legNPV(0)+temp.legNPV(1);

            usedSpread = -npv/temp.legBPS(1)*1e-4;
        } else {
            QL_REQUIRE(usedSpread != Null<Spread>(),
                       "null spread set");
        }

        Leg floatLeg = IborLeg(floatSchedule, iborIndex_)
            .withNotionals(nominal_)
            .withPaymentDayCounter(floatDayCount_)
            .withPaymentAdjustment(floatConvention_)
            .withFixingDays(iborIndex_->fixingDays())
            .withSpreads(usedSpread);

        boost::shared_ptr<Swap> swap;
        if (payCms_)
            swap = boost::shared_ptr<Swap>(new Swap(cmsLeg, floatLeg));
        else
            swap = boost::shared_ptr<Swap>(new Swap(floatLeg, cmsLeg));
        swap->setPricingEngine(engine_);
        return swap;
    }
コード例 #19
0
ファイル: makeois.cpp プロジェクト: 21hub/QuantLib
    MakeOIS::operator shared_ptr<OvernightIndexedSwap>() const {

        Date startDate;
        if (effectiveDate_ != Date())
            startDate = effectiveDate_;
        else {
            Date refDate = Settings::instance().evaluationDate();
            // if the evaluation date is not a business day
            // then move to the next business day
            refDate = calendar_.adjust(refDate);
            Date spotDate = calendar_.advance(refDate,
                                              settlementDays_*Days);
            startDate = spotDate+forwardStart_;
            if (forwardStart_.length()<0)
                startDate = calendar_.adjust(startDate, Preceding);
            else
                startDate = calendar_.adjust(startDate, Following);
        }

        // OIS end of month default
        bool usedEndOfMonth = 
            isDefaultEOM_ ? calendar_.isEndOfMonth(startDate) : endOfMonth_;

        Date endDate = terminationDate_;
        if (endDate == Date()) {
            if (usedEndOfMonth)
                endDate = calendar_.advance(startDate,
                                            swapTenor_,
                                            ModifiedFollowing,
                                            usedEndOfMonth);
            else
                endDate = startDate + swapTenor_;
        }

        Schedule schedule(startDate, endDate,
                          Period(paymentFrequency_),
                          calendar_,
                          ModifiedFollowing,
                          ModifiedFollowing,
                          rule_,
                          usedEndOfMonth);

        Rate usedFixedRate = fixedRate_;
        if (fixedRate_ == Null<Rate>()) {
            OvernightIndexedSwap temp(type_, nominal_,
                                      schedule,
                                      0.0, // fixed rate
                                      fixedDayCount_,
                                      overnightIndex_, overnightSpread_);
            if (engine_ == 0) {
                Handle<YieldTermStructure> disc =
                                    overnightIndex_->forwardingTermStructure();
                QL_REQUIRE(!disc.empty(),
                           "null term structure set to this instance of " <<
                           overnightIndex_->name());
                bool includeSettlementDateFlows = false;
                shared_ptr<PricingEngine> engine(new
                    DiscountingSwapEngine(disc, includeSettlementDateFlows));
                temp.setPricingEngine(engine);
            } else
                temp.setPricingEngine(engine_);

            usedFixedRate = temp.fairRate();
        }

        shared_ptr<OvernightIndexedSwap> ois(new
            OvernightIndexedSwap(type_, nominal_,
                                 schedule,
                                 usedFixedRate, fixedDayCount_,
                                 overnightIndex_, overnightSpread_));

        if (engine_ == 0) {
            Handle<YieldTermStructure> disc =
                                overnightIndex_->forwardingTermStructure();
            bool includeSettlementDateFlows = false;
            shared_ptr<PricingEngine> engine(new
                DiscountingSwapEngine(disc, includeSettlementDateFlows));
            ois->setPricingEngine(engine);
        } else
            ois->setPricingEngine(engine_);

        return ois;
    }
コード例 #20
0
ファイル: FixingCurves.cpp プロジェクト: daveysj/sjd
 bool MonthlyFixingCurve::containsARateSetOn(QuantLib::Date date) const
 {
     return FixingRateSource::containsARateSetOn(Date(1, date.month(), date.year()));
 }
コード例 #21
0
void __fastcall TRegPac::FormCreate(TObject *Sender)
{
        fechNac->Date=Date()-366;        
}
コード例 #22
0
ファイル: FixingCurves.cpp プロジェクト: daveysj/sjd
 double MonthlyFixingCurve::getRateSetOn(QuantLib::Date date) const
 {
     return FixingRateSource::getRateSetOn(Date(1, date.month(), date.year()));
 }
コード例 #23
0
ファイル: Date.cpp プロジェクト: SEJeff/task
Date Date::startOfDay () const
{
  return Date (month (), day (), year (), 0, 0, 0);
}
コード例 #24
0
ファイル: china.cpp プロジェクト: grantathon/nquantlib64
    bool China::IbImpl::isBusinessDay(const Date& date) const {
        static const Date working_weekends[] = {
            // 2005
            Date(5, February, 2005),
            Date(6, February, 2005),
            Date(30, April, 2005),
            Date(8, May, 2005),
            Date(8, October, 2005),
            Date(9, October, 2005),
            Date(31, December, 2005),
            //2006
            Date(28, January, 2006),
            Date(29, April, 2006),
            Date(30, April, 2006),
            Date(30, September, 2006),
            Date(30, December, 2006),
            Date(31, December, 2006),
            // 2007
            Date(17, February, 2007),
            Date(25, February, 2007),
            Date(28, April, 2007),
            Date(29, April, 2007),
            Date(29, September, 2007),
            Date(30, September, 2007),
            Date(29, December, 2007),
            // 2008
            Date(2, February, 2008),
            Date(3, February, 2008),
            Date(4, May, 2008),
            Date(27, September, 2008),
            Date(28, September, 2008),
            // 2009
            Date(4, January, 2009),
            Date(24, January, 2009),
            Date(1, February, 2009),
            Date(31, May, 2009),
            Date(27, September, 2009),
            Date(10, October, 2009),
            // 2010
            Date(20, February, 2010),
            Date(21, February, 2010),
            Date(12, June, 2010),
            Date(13, June, 2010),
            Date(19, September, 2010),
            Date(25, September, 2010),
            Date(26, September, 2010),
            Date(9, October, 2010),
            // 2011
            Date(30, January, 2011),
            Date(12, February, 2011),
            Date(2, April, 2011),
            Date(8, October, 2011),
            Date(9, October, 2011),
            Date(31, December, 2011),
            // 2012
            Date(21, January, 2012),
            Date(29, January, 2012),
            Date(31, March, 2012),
            Date(1, April, 2012),
            Date(28, April, 2012),
            Date(29, September, 2012),
            // 2013
            Date(5,January,2013),
            Date(6,January,2013),
            Date(16,February,2013),
            Date(17,February,2013),
            Date(7,April,2013),
            Date(27,April,2013),
            Date(28,April,2013),
            Date(8,June,2013),
            Date(9,June,2013),
            Date(22,September,2013),
            Date(29,September,2013),
            Date(12,October,2013),
            // 2014
            Date(26,January,2014),
            Date(8,February,2014),
            Date(4,May,2014),
            Date(28,September,2014),
            Date(11,October,2014),
            // 2015
            Date(4,January,2015),
            Date(15,February,2015),
            Date(28,February,2015),
            Date(6,September,2015),
            Date(10,October,2015),
            // 2016
            Date(6,February,2016),
            Date(14,February,2016),
            Date(12,June,2016),
            Date(18,September,2016),
            Date(8,October,2016),
            Date(9,October,2016)
        };
        static const Size n =
            sizeof(working_weekends)/sizeof(working_weekends[0]);
        static const std::set<Date> workingWeekends(working_weekends+0,
                                                    working_weekends+n);

        // If it is already a SSE business day, it must be a IB business day
        return sseImpl->isBusinessDay(date) ||
            (workingWeekends.find(date) != workingWeekends.end());
    }
コード例 #25
0
ファイル: Date.cpp プロジェクト: SEJeff/task
Date Date::startOfMonth () const
{
  return Date (month (), 1, year (), 0, 0, 0);
}
コード例 #26
0
    CatBond::results MonteCarloCatBondEngine::npv(bool includeSettlementDateFlows, 
												  Date settlementDate, 
									              Date npvDate) const
    {
	    const size_t MAX_PATHS = 10000; //TODO
		CatBond::results result;
		result.reset();

        double lossProbability =  0.0;
        double exhaustionProbability = 0.0;
        double expectedLoss = 0.0;
		//GenericRiskStatistics<GeneralStatistics> statistics;
		GeneralStatistics statistics;
        if (arguments_.cashflows.empty()) {
			 return result;
		}

        if (settlementDate == Date())
            settlementDate = Settings::instance().evaluationDate();

        if (npvDate == Date())
            npvDate = settlementDate;

        Real totalNPV = 0.0;
        Date effectiveDate = std::max(arguments_.startDate, settlementDate);
        Date maturityDate = (*arguments_.cashflows.rbegin())->date();
        auto catSimulation = catRisk_->newSimulation(effectiveDate, maturityDate);
        std::vector<std::pair<Date, Real> > eventsPath;
        NotionalPath notionalPath;
        Real riskFreeNPV = pathNpv(includeSettlementDateFlows, settlementDate, notionalPath);
        size_t pathCount=0;
        while(catSimulation->nextPath(eventsPath) && pathCount<MAX_PATHS)
        {
            arguments_.notionalRisk->updatePath(eventsPath, notionalPath);
            if(notionalPath.loss()>0) { //optimization, most paths will not include any loss
				double thisNpv = pathNpv(includeSettlementDateFlows, settlementDate, notionalPath);
                totalNPV += thisNpv;
                lossProbability+=1;
                if (notionalPath.loss()==1) 
                    exhaustionProbability+=1;
                expectedLoss+=notionalPath.loss();
				statistics.add(thisNpv, 1.0);
            } else {
                totalNPV += riskFreeNPV;
				statistics.add(riskFreeNPV, 1.0);
            }
            pathCount++;
        }
        lossProbability/=pathCount;
        exhaustionProbability/=pathCount;
        expectedLoss/=pathCount;

		result.valuationDate = settlementDate;

		result.value = totalNPV/(pathCount*discountCurve_->discount(npvDate));
		result.settlementValue = result.value;
		result.lossProbability = lossProbability;
		result.exhaustionProbability = exhaustionProbability;
		result.expectedLoss = expectedLoss;

		if(Null<Real>()!=varLevel_) {
			result.var = result.value - statistics.percentile(1.0-varLevel_);
			result.stdDev = statistics.standardDeviation();
			result.skew = statistics.skewness();
			result.kurtosis = statistics.kurtosis();
		}
        return result;
    }
コード例 #27
0
ファイル: Date.cpp プロジェクト: SEJeff/task
Date Date::operator- (const int delta)
{
  return Date (_t - delta);
}
コード例 #28
0
ファイル: Calendar.cpp プロジェクト: pepsi7959/OpenStudio
 /// default constructor, uses assumed year
 Calendar::Calendar()
   :  m_startDate(Date(MonthOfYear::Jan, 1, YearDescription().assumedYear())), 
   m_endDate(Date(MonthOfYear::Dec, 31, YearDescription().assumedYear()))
 {}
コード例 #29
0
ファイル: UTCStamp.cpp プロジェクト: JohnDNoodle/JDNRepo
Date UTCStamp::getDate() const
{
	struct tm tStamp = createTMStruct();
	return Date(tStamp.tm_mday, tStamp.tm_mon + 1, tStamp.tm_year + 1900);
}
コード例 #30
0
ファイル: date.cpp プロジェクト: gatgui/gcore
Date Date::Hours(int n) {
  return Date(n * gsSecsPerHour, true);
}