root not bracketed

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

root not bracketed

Khanh Nguyen
Hi all,

I am replicating this the first example from this page
http://www.mathworks.com/access/helpdesk/help/toolbox/finfixed/zeroyield.html

Matlab:
Example 1. Compute the yield of a short-term zero-coupon instrument.
Settle   = '24-Jun-1993';
Maturity = '1-Nov-1993';
Basis    = 0;
Price    = 95;
Yield = zeroyield(Price, Settle, Maturity, [], Basis)

Yield =
    0.1490

Code code look like this

int main() {
    double settlementDays = 1;

    Date settleDate(24, (Month)6, 1993);
    Date maturityDate(1, (Month)11, 1993);

    DayCounter dc = ActualActual();
    BusinessDayConvention bdc = ModifiedFollowing;
    double faceAmount = 100;
    double redemption = 100;

    ZeroCouponBond bond1(settlementDays,
                         UnitedStates(UnitedStates::GovernmentBond),
                         faceAmount,
                         maturityDate,
                         bdc,
                         redemption, settleDate);

    cout << bond1.yield(95, ActualActual(), Simple ,Annual);
}

it compiles, but returns "what(): root not bracketed: f[0,1] -> [nan, nan]"

Any help, please? Thanks.

-k

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables
unlimited royalty-free distribution of the report engine
for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: root not bracketed

Kim Kuen Tang
Hi Khanh,

now it works:

int main()
{
   try{
   Date settleDate(24, (Month)6, 1993);
   Integer fixingDays = 2;
   Calendar calendar=UnitedStates(UnitedStates::GovernmentBond);
   Date todaysDate = calendar.advance(settleDate, -fixingDays, Days);
   Settings::instance().evaluationDate() = todaysDate;
   Natural settlementDays = 1;

     Date maturityDate(1, (Month)11, 1993);

   DayCounter dc = ActualActual();
   BusinessDayConvention bdc = ModifiedFollowing;
   double faceAmount = 100;
   double redemption = 100;

   ZeroCouponBond bond1(settlementDays,
                        calendar,
                        faceAmount,
                        maturityDate,
                        bdc,
                        redemption, settleDate);

   std::cout << bond1.yield(95, ActualActual(), Simple ,Annual);
   }
   catch(std::exception& e)
   {
       std::cout<<e.what()<<'\n';
       return 1;
   };


return 0;
}

Best regards,
Kim

Khanh Nguyen schrieb:

> Hi all,
>
> I am replicating this the first example from this page
> http://www.mathworks.com/access/helpdesk/help/toolbox/finfixed/zeroyield.html
>
> Matlab:
> Example 1. Compute the yield of a short-term zero-coupon instrument.
> Settle   = '24-Jun-1993';
> Maturity = '1-Nov-1993';
> Basis    = 0;
> Price    = 95;
> Yield = zeroyield(Price, Settle, Maturity, [], Basis)
>
> Yield =
>     0.1490
>
> Code code look like this
>
> int main() {
>     double settlementDays = 1;
>
>     Date settleDate(24, (Month)6, 1993);
>     Date maturityDate(1, (Month)11, 1993);
>
>     DayCounter dc = ActualActual();
>     BusinessDayConvention bdc = ModifiedFollowing;
>     double faceAmount = 100;
>     double redemption = 100;
>
>     ZeroCouponBond bond1(settlementDays,
>                          UnitedStates(UnitedStates::GovernmentBond),
>                          faceAmount,
>                          maturityDate,
>                          bdc,
>                          redemption, settleDate);
>
>     cout << bond1.yield(95, ActualActual(), Simple ,Annual);
> }
>
> it compiles, but returns "what(): root not bracketed: f[0,1] -> [nan, nan]"
>
> Any help, please? Thanks.
>
> -k
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables
> unlimited royalty-free distribution of the report engine
> for externally facing server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
>  


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables
unlimited royalty-free distribution of the report engine
for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users