本文整理汇总了C#中Date类的典型用法代码示例。如果您正苦于以下问题:C# Date类的具体用法?C# Date怎么用?C# Date使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Date类属于命名空间,在下文中一共展示了Date类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FixedRateCoupon
// constructors
public FixedRateCoupon(double nominal, Date paymentDate, double rate, DayCounter dayCounter,
Date accrualStartDate, Date accrualEndDate,
Date refPeriodStart = null, Date refPeriodEnd = null,double? amount = null)
: base(nominal, paymentDate, accrualStartDate, accrualEndDate, refPeriodStart, refPeriodEnd, amount)
{
rate_ = new InterestRate(rate, dayCounter, Compounding.Simple,Frequency.Annual);
}
示例2: CanAddZeroYears
public void CanAddZeroYears()
{
var dt = new Date(2000, 1, 1);
var actual = dt.AddYears(0);
var expected = new Date(2000, 1, 1);
Assert.Equal(expected, actual);
}
示例3: CanAddPositiveYears_FromLeapDay_ToLeapYear
public void CanAddPositiveYears_FromLeapDay_ToLeapYear()
{
var dt = new Date(2000, 2, 29);
var actual = dt.AddYears(4);
var expected = new Date(2004, 2, 29);
Assert.Equal(expected, actual);
}
示例4: FixedRateBond
//! fixed-rate bond
/*! \ingroup instruments
\test calculations are tested by checking results against
cached values.
*/
//! simple annual compounding coupon rates
public FixedRateBond(int settlementDays, double faceAmount, Schedule schedule,List<double> coupons,
DayCounter accrualDayCounter, BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
double redemption = 100, Date issueDate = null,Calendar paymentCalendar = null,
Period exCouponPeriod = null,
Calendar exCouponCalendar = null,
BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted,
bool exCouponEndOfMonth = false)
: base(settlementDays, paymentCalendar == null ? schedule.calendar() : paymentCalendar,
issueDate)
{
frequency_ = schedule.tenor().frequency();
dayCounter_ = accrualDayCounter;
maturityDate_ = schedule.endDate();
cashflows_ = new FixedRateLeg(schedule)
.withCouponRates(coupons, accrualDayCounter)
.withExCouponPeriod(exCouponPeriod,
exCouponCalendar,
exCouponConvention,
exCouponEndOfMonth)
.withPaymentCalendar(calendar_)
.withNotionals(faceAmount)
.withPaymentAdjustment(paymentConvention);
addRedemptionsToCashflows(new List<double>() { redemption });
if (cashflows().Count == 0)
throw new ApplicationException("bond with no cashflows!");
if (redemptions_.Count != 1)
throw new ApplicationException("multiple redemptions created");
}
示例5: CanAddPositiveYears
public void CanAddPositiveYears()
{
var dt = new Date(2000, 1, 1);
var actual = dt.AddYears(1);
var expected = new Date(2001, 1, 1);
Assert.Equal(expected, actual);
}
示例6: AmericanExercise
public AmericanExercise(Date latest, bool payoffAtExpiry)
: base(Type.American, payoffAtExpiry)
{
dates_ = new InitializedList<Date>(2);
dates_[0] = Date.minDate();
dates_[1] = latest;
}
示例7: SwaptionVolatilityDiscrete
public SwaptionVolatilityDiscrete(List<Period> optionTenors,
List<Period> swapTenors,
int settlementDays,
Calendar cal,
BusinessDayConvention bdc,
DayCounter dc)
: base(settlementDays, cal, bdc, dc)
{
nOptionTenors_ = optionTenors.Count;
optionTenors_ = optionTenors;
optionDates_ = new InitializedList<Date>(nOptionTenors_);
optionTimes_ = new InitializedList<double>(nOptionTenors_);
optionDatesAsReal_ = new InitializedList<double>(nOptionTenors_);
nSwapTenors_ = swapTenors.Count;
swapTenors_ = swapTenors;
swapLengths_ = new InitializedList<double>(nSwapTenors_);
checkOptionTenors();
initializeOptionDatesAndTimes();
checkSwapTenors();
initializeSwapLengths();
optionInterpolator_ = new LinearInterpolation(optionTimes_,
optionTimes_.Count,
optionDatesAsReal_);
optionInterpolator_.update();
optionInterpolator_.enableExtrapolation();
evaluationDate_ = Settings.evaluationDate();
Settings.registerWith(update);
}
示例8: isBusinessDay
public override bool isBusinessDay(Date date)
{
DayOfWeek w = date.DayOfWeek;
int d = date.Day, dd = date.DayOfYear;
Month m = (Month)date.Month;
int y = date.Year;
int em = easterMonday(y);
if (isWeekend(w)
// Holy Thursday
|| (dd == em-4)
// Good Friday
|| (dd == em-3)
// Easter Monday
|| (dd == em)
// Ascension Thursday
|| (dd == em+38)
// Whit Monday
|| (dd == em+49)
// New Year's Day
|| (d == 1 && m == Month.January)
// May Day
|| (d == 1 && m == Month.May)
// National Independence Day
|| (d == 17 && m == Month.May)
// Christmas
|| (d == 25 && m == Month.December)
// Boxing Day
|| (d == 26 && m == Month.December))
return false;
return true;
}
示例9: testAmortizingBond1
public void testAmortizingBond1()
{
// Input Values
double faceValue = 40000;
double marketValue = 43412;
double couponRate = 0.06;
Date issueDate = new Date(1, Month.January, 2001);
Date maturirtyDate = new Date(1, Month.January, 2005);
Date tradeDate = new Date(1, Month.January, 2004);
Frequency paymentFrequency = Frequency.Semiannual;
DayCounter dc = new Thirty360(Thirty360.Thirty360Convention.USA);
// Build Bond
AmortizingBond bond = BondFactory.makeAmortizingBond(faceValue, marketValue, couponRate,
issueDate, maturirtyDate, tradeDate, paymentFrequency, dc, AmortizingMethod.EffectiveInterestRate);
// Amortizing Yield ( Effective Rate )
double y1 = bond.Yield();
Assert.AreEqual(-0.0236402, y1, 0.001, "Amortizing Yield is different");
// Amortized Cost at Date
double Amort1 = bond.AmortizationValue(new Date(31, Month.August, 2004));
Assert.AreEqual(41126.01, Amort1, 100, "Amortized Cost at 08/31/2004 is different");
double Amort2 = bond.AmortizationValue(new Date(30, Month.September, 2004));
Assert.AreEqual(40842.83, Amort2, 100, "Amortized Cost at 09/30/2004 is different");
}
示例10: FloatingRateBond
public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter,
BusinessDayConvention paymentConvention, int fixingDays, List<double> gearings, List<double> spreads,
List<double> caps, List<double> floors, bool inArrears, double redemption, Date issueDate)
: base(settlementDays, schedule.calendar(), issueDate) {
maturityDate_ = schedule.endDate();
cashflows_ = new IborLeg(schedule, index)
.withPaymentDayCounter(paymentDayCounter)
.withFixingDays(fixingDays)
.withGearings(gearings)
.withSpreads(spreads)
.withCaps(caps)
.withFloors(floors)
.inArrears(inArrears)
.withNotionals(faceAmount)
.withPaymentAdjustment(paymentConvention);
addRedemptionsToCashflows(new List<double>() { redemption });
if (cashflows().Count == 0)
throw new ApplicationException("bond with no cashflows!");
if (redemptions_.Count != 1)
throw new ApplicationException("multiple redemptions created");
index.registerWith(update);
}
示例11: CommonVars
// todo
// cleanup
// SavedSettings backup;
// setup
public CommonVars()
{
calendar = new TARGET();
today = calendar.adjust(Date.Today);
Settings.setEvaluationDate(today);
faceAmount = 1000000.0;
}
示例12: dates
//! \name Volatility
/*! by default, inflation is observed with the lag
of the term structure.
Because inflation is highly linked to dates (for
interpolation, periods, etc) time-based overload of the
methods are not provided.
*/
//@{
//! Returns the volatility for a given maturity date and strike rate.
double volatility(Date maturityDate, double strike,
Period obsLag = null,
bool extrapolate = false)
{
if (obsLag == null)
obsLag = new Period(-1, TimeUnit.Days);
Period useLag = obsLag;
if (obsLag == new Period(-1, TimeUnit.Days))
{
useLag = observationLag();
}
if (indexIsInterpolated())
{
checkRange(maturityDate - useLag, strike, extrapolate);
double t = timeFromReference(maturityDate - useLag);
return volatilityImpl(t, strike);
}
else
{
KeyValuePair<Date, Date> dd = Utils.inflationPeriod(maturityDate - useLag, frequency());
checkRange(dd.Key, strike, extrapolate);
double t = timeFromReference(dd.Key);
return volatilityImpl(t, strike);
}
}
示例13: WriteRawValueWritesDate
public void WriteRawValueWritesDate()
{
RawValueWriter target = new RawValueWriter(this.settings, this.stream, new UTF32Encoding());
Date value = new Date(2014, 9, 18);
target.WriteRawValue(value);
this.StreamAsString(target).Should().Be("2014-09-18");
}
示例14: CalculateDifference_ShouldNotChangePeriod
public void CalculateDifference_ShouldNotChangePeriod()
{
var period = new Date(2000, 1, 1);
var period1 = new Date(2001, 1, 1);
period.CalculateDifference(period1);
Assert.AreEqual(period, new Date(2000,1,1));
}
示例15: CallableBondConstantVolatility
public CallableBondConstantVolatility(Date referenceDate, double volatility, DayCounter dayCounter)
:base(referenceDate)
{
volatility_ = new Handle<Quote>(new SimpleQuote(volatility));
dayCounter_ = dayCounter;
maxBondTenor_ = new Period(100,TimeUnit.Years);
}