|
From: Luigi B. <lui...@gm...> - 2022-10-05 20:26:37
|
Hello,
looking at your snippet, I would say you're setting the evaluation date
to 11/18/2021 but the spot curve starts at 9/30/2022. There are probably
coupons that pay between those two dates and need to be discounted, but
they're before the start of the curve so the code complains of a negative
time.
Luigi
On Mon, Oct 3, 2022 at 3:12 PM Lasha Daushvili <las...@gm...>
wrote:
> Hi I Have a problem with QuantLib C# Wrapper,
> There is code snippet,
>
> Please help me :)
>
> DateTime date = DateTime.Parse("9/30/2022");
>
> var dSettlementDate = new Date(date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy");
> Settings.instance().setEvaluationDate(dSettlementDate);
> var spot_dates = new DateVector();
> var spot_rates = new DoubleVector();
>
> //spot_dates.Add(new
> Date(DateTime.Parse("9/30/2022").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> //spot_rates.Add((double)10.6372 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("10/01/2022").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)10.6372 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("10/2/2022").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)10.6372 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("10/8/2022").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)10.6372 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("10/15/2022").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)10.6079 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("10/31/2022").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)10.5428 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("12/1/2022").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)10.4244 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("12/31/2022").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)10.3189 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("3/31/2023").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)10.0451 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("10/1/2023").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)9.6805 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("10/1/2024").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)9.3918 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("10/1/2027").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)9.6234 / 100.0);
>
> spot_dates.Add(new
> Date(DateTime.Parse("10/1/2032").Date.ToString("dd/MM/yyyy"),
> "dd/mm/yyyy"));
> spot_rates.Add((double)10.0937 / 100.0);
>
> var curveDayCounter = new Actual365Fixed();
> var curveCalendar = new NullCalendar();
> var curveInterpolation = new Linear();
> var curveCompounding = Compounding.Compounded;
> var curveFrquency = Frequency.Semiannual;
> var spot_curve = new ZeroCurve(spot_dates, spot_rates,
> curveDayCounter, curveCalendar, curveInterpolation, curveCompounding,
> curveFrquency);
> var spot_curve_handle = new
> YieldTermStructureHandle(spot_curve);
>
> var engine = new DiscountingBondEngine(spot_curve_handle);
>
> DateTime startDate = DateTime.Parse("11/18/2021");
> DateTime endDate = DateTime.Parse("9/27/2023");
> DateTime paymentDate = DateTime.Parse("9/30/2022");
>
> Settings.instance().setEvaluationDate(new
> Date(startDate.ToString("dd/MM/yyyy"), "dd/mm/yyyy"));
> Calendar calendarQ = new WeekendsOnly();
>
> Frequency frquency = Frequency.Semiannual;
>
> DayCounter dayCounter = new
> ActualActual(ActualActual.Convention.ISMA);
>
> Schedule schedule = new Schedule(new
> Date(startDate.ToString("dd/MM/yyyy"), "dd/mm/yyyy"),
> new
> Date(endDate.ToString("dd/MM/yyyy"), "dd/mm/yyyy"),
> new Period(frquency),
> calendarQ,
> BusinessDayConvention.Unadjusted,
> BusinessDayConvention.Unadjusted,
> DateGeneration.Rule.Backward,
> false);
>
> var bond = new FixedRateBond(0, //settlementDays,
> 100.0,
> schedule,
> new DoubleVector(1) { 0.07375 },
> dayCounter,
>
> BusinessDayConvention.Unadjusted,
> 100.0
>
> );
>
> bond.setPricingEngine(engine);
>
> Settings.instance().setEvaluationDate(new
> Date(paymentDate.ToString("dd/MM/yyyy"), "dd/mm/yyyy"));
> var CleanPrice = bond.NPV();
>
> Console.WriteLine(CleanPrice);
>
> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
|