Posted by
Ken Anderson-2 on
URL: http://quantlib.414.s1.nabble.com/Problem-pricing-options-in-the-past-tp4501p4502.html
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
>