Problem pricing options in the past?

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

Problem pricing options in the past?

Ken Anderson-2
I'm using the SWIG for Java of the latest download, and I have a problem with pricing options in the past.  If I use current or future dates, it works fine, but the value is always zero in the past.  Here's the code:


Date todaysDate = new Date(17,Month.February, 2006);
Date settlementDate = new Date(21, Month.February, 2006);
Date exerciseDate = new Date(24, Month.May, 2006);

DayCounter fixed365 = new Actual365Fixed();
EuropeanExercise exercise = new EuropeanExercise(exerciseDate);
PlainVanillaPayoff payoff = new PlainVanillaPayoff(Option.Type.Call, 58.0);
SimpleQuote underlyingQuote = new SimpleQuote(60.0);
FlatForward flatDividentTS = new FlatForward(settlementDate, 0.0, fixed365);
FlatForward flatTermStructure = new FlatForward(settlementDate, .06, fixed365);
BlackConstantVol flatVolTS = new BlackConstantVol(settlementDate, .20, fixed365);


BlackScholesProcess process = new BlackScholesProcess(new QuoteHandle(underlyingQuote), 
new YieldTermStructureHandle(flatDividentTS),
new YieldTermStructureHandle(flatTermStructure),
new BlackVolTermStructureHandle(flatVolTS));


VanillaOption euroOption = new VanillaOption(process, payoff, exercise, new AnalyticEuropeanEngine());


System.out.println("Value: "+euroOption.NPV());
System.out.println("Delta: "+euroOption.delta());

The code above works OK, but if you change the dates to be 2005, it fails with 0.0 NPV and 0.0 delta.  Any ideas?

Thanks,
Ken

Reply | Threaded
Open this post in threaded view
|

Re: Problem pricing options in the past?

Ken Anderson-2
Luigi,

Sorry - I thought I had replied to the list when Ari sent the  
question about setting the evaluation date, but I guess I hadn't.  My  
problem was exactly that - somehow in my testing, the evaluation date  
code got commented out.

Thanks,
Ken

On Feb 23, 2006, at 3:39 PM, Luigi Ballabio wrote:

>
> On Feb 17, 2006, at 8:53 PM, Ken Anderson wrote:
>> I'm using the SWIG for Java of the latest download, and I have a  
>> problem with pricing options in the past.  If I use current or  
>> future dates, it works fine, but the value is always zero in the  
>> past.  Here's the code:
>>
>>
>>                       Date todaysDate = new Date
>> (17,Month.February, 2006);
>>                    Date settlementDate = new Date(21,  
>> Month.February, 2006);
>>                   Date exerciseDate = new Date(24, Month.May, 2006);
>>
>>                   DayCounter fixed365 = new Actual365Fixed();
>>                     EuropeanExercise exercise = new  
>> EuropeanExercise(exerciseDate);
>>                     PlainVanillaPayoff payoff = new  
>> PlainVanillaPayoff(Option.Type.Call, 58.0);
>>                    SimpleQuote underlyingQuote = new SimpleQuote
>> (60.0);
>>                     FlatForward flatDividentTS = new FlatForward
>> (settlementDate, 0.0, fixed365);
>>                   FlatForward flatTermStructure = new FlatForward
>> (settlementDate, .06, fixed365);
>>                   BlackConstantVol flatVolTS = new BlackConstantVol
>> (settlementDate, .20, fixed365);
>>
>>                         BlackScholesProcess process = new  
>> BlackScholesProcess(new QuoteHandle(underlyingQuote),
>>                                    new YieldTermStructureHandle
>> (flatDividentTS),
>>                                        new YieldTermStructureHandle
>> (flatTermStructure),
>>                                        new  
>> BlackVolTermStructureHandle(flatVolTS));
>>
>>                         VanillaOption euroOption = new  
>> VanillaOption(process, payoff, exercise, new AnalyticEuropeanEngine
>> ());
>>
>>                         System.out.println("Value: "+euroOption.NPV
>> ());
>>                        System.out.println("Delta:  
>> "+euroOption.delta());
>
> Ken,
> just declaring a variable called todaysDate to be in the past does  
> not change QuantLib's today's date. You have to set it with a line  
> that in C++ would be
>
> Settings::instance().evaluationDate() = todaysDate;
>
> I'm not sure how that would spell in Java, though. It's probably  
> something like
>
> Settings.instance().setEvaluationDate(todaysDate);
>
> Hope this helps,
> Luigi
>