Serving the Quantitative Finance Community

 
User avatar
JRobinson
Topic Author
Posts: 0
Joined: March 8th, 2012, 2:54 pm

QLNet Vanilla Options with Discrete Dividends (C# port of QuantLib)

March 16th, 2012, 5:24 pm

I am trying to calculate the prices of vanilla options with discrete dividends using QLNet and I am running into some problems. QLNet is a C# port of QuantLib. I found QuantLib code for pricing vanilla options with discrete dividends here http://www.bnikolic.co.uk/blog/ql-ameri ... end.htmlMy problem is that QLNet doesn't seem to have an FDDividendAmericanEngine class. I don't know of any other pricing engines in QLNet that I can use instead. When I try FDDividendEngineMerton73 for instance, I get an exception that says "wrong engine type". The QLNet comments suggest that I can use FDDividendEngineMerton73 with discrete dividends. The QLNet solution contains plenty of test code that shows how to call its functions, but I can't find one that uses discrete dividends.If QLNet is unable to handle vanilla options with discrete dividends, what is a better way to price these products using C#? If a C# solution doesn't exist, is there an easy way I can use QuantLib in C#? I'm using Visual Studio 2010, but I'm not familiar with mixing C++ code (QuantLib) with C# code.
 
User avatar
SierpinskyJanitor
Posts: 1
Joined: March 29th, 2005, 12:55 pm

QLNet Vanilla Options with Discrete Dividends (C# port of QuantLib)

March 16th, 2012, 7:56 pm

Hello JRobinson,you can set the DividenYield in "EquityOption.cs", for example:
Last edited by SierpinskyJanitor on March 15th, 2012, 11:00 pm, edited 1 time in total.
 
User avatar
JRobinson
Topic Author
Posts: 0
Joined: March 8th, 2012, 2:54 pm

QLNet Vanilla Options with Discrete Dividends (C# port of QuantLib)

March 19th, 2012, 10:41 am

SierpinskyJanitor,I need an example that uses discrete dividends instead of an example that uses continuous dividends. Do you have one in QLNet? If not, do you know another solution coded in C#?I saw your examples in the test code that comes with QLNet. I found them helpful for showing how to call the Black-Scholes and Binomial methods. If there was a test case like that that uses discrete dividends, I would be able to use it in my code.Thanks for your reply.
 
User avatar
SierpinskyJanitor
Posts: 1
Joined: March 29th, 2005, 12:55 pm

QLNet Vanilla Options with Discrete Dividends (C# port of QuantLib)

March 19th, 2012, 10:53 am

Thanks JRobinson,we´re well aware of how different both approaches are, I was just checking out whether homework had been done. Sometimes people post exotic questions without even bothering going through the very basics, gladly, that doesn´t seem to be the case. You have surely read about using the dividendyield as an "approach" and also, under which circumstances that is valid ( basket vs single-stock ). You´re also surely read Haug´s paper on the very issue and the various numerical approaches therein suggested. So, here´s what I suggest: why don´t we actually plug this in QLNet ourselves? Most of the work has already been done, we have an engine interface in place, all we need is to do is code it accordingly. Tell me how this sounds,cheers,Serp
Last edited by SierpinskyJanitor on March 18th, 2012, 11:00 pm, edited 1 time in total.
 
User avatar
bojan
Posts: 0
Joined: August 8th, 2008, 5:35 am

QLNet Vanilla Options with Discrete Dividends (C# port of QuantLib)

March 19th, 2012, 11:54 am

You can use the C# wrap of QuantLib generated using the SWIG program. See Quantlib-SWIG part of the QuantLib repository
 
User avatar
SierpinskyJanitor
Posts: 1
Joined: March 29th, 2005, 12:55 pm

QLNet Vanilla Options with Discrete Dividends (C# port of QuantLib)

March 19th, 2012, 3:37 pm

OK, this is how far I went:Now the "setPricingEngine" method is expecting an "Engine" and if we follow the "FDDividendEngineMerton73" this is nothing but. So we must configure the "divamericanOption" using "setupArgumentsInstead"... lemme check this tomorrow...cheers,Serp
 
User avatar
JRobinson
Topic Author
Posts: 0
Joined: March 8th, 2012, 2:54 pm

QLNet Vanilla Options with Discrete Dividends (C# port of QuantLib)

March 19th, 2012, 8:45 pm

SierpinskyJanitor,Thank you again for your response. Unfortunately your code won't compile for me. I'm using QLNet v1.0.0. An object of type "FDDividendEngineMerton73" won't work in the "setPricingEngine" function because "setPricingEngine" requires an object that implements "QLNet.IPricingEngine". It is actually the code comments to the "FDDividendEngineMerton73" that suggest that this pricing engine supports discrete dividends. The Haug paper that you mention is named in the code comments I am referencing.Following bojan's advice, I'm working on using QuantLib+SWIG for an initial solution. I'm worried that the SWIG communication will degrade my program's performance however. I'll jump off that bridge when I get to it though.I may end up attempting to port the FDDividendAmericanEngine code from QuantLib to QLNet. I hope I don't have to do that though as my C++ is pretty rusty.
 
User avatar
SierpinskyJanitor
Posts: 1
Joined: March 29th, 2005, 12:55 pm

QLNet Vanilla Options with Discrete Dividends (C# port of QuantLib)

March 21st, 2012, 3:01 pm

JRobinson,it would be interesting sharing strategies - what exactly are you doing with QuantLib+SWIG in order to hack this?
Last edited by SierpinskyJanitor on March 20th, 2012, 11:00 pm, edited 1 time in total.
 
User avatar
JRobinson
Topic Author
Posts: 0
Joined: March 8th, 2012, 2:54 pm

QLNet Vanilla Options with Discrete Dividends (C# port of QuantLib)

March 23rd, 2012, 12:40 pm

SierpinskyJanitor,I'm working on coding pricing models for a risk system. We trade a lot of options here so I've been delving into option pricing models even though I'm not really a quant. I've been using Black-Scholes during my development, but I've hit a wall concerning dividends. Up to this point, I've been using QLNet for my option pricing. I'm calling its continuous-dividend binomial model fine (Cox-Ross-Rubenstein). It's the discrete-dividend models that I can't get to work.As a dividend date for a stock is approaching, I've found that the dividend yield returned from the Bloomberg API for that stock gets much too high. The stocks in the portfolio don't pay a 14% dividend yield for instance, regardless of what Bloomberg calculates. As a result, my analytics get out of whack when dividend dates are approaching and when I am using a continuous-dividend option pricing model.I then tried to use the QuantLib+SWIG solutions mentioned here, http://stackoverflow.com/questions/3334 ... or-c-sharp, specifically the binaries provided by Resolver Systems (mentioned in the comments). From here, I ran into a different problem: I was able to get prices for options using a discrete-dividend model, but the model doesn't support fractional days. Our theta decay is, of course, always changing, so we'd like to look at it intraday. Going back to the QLNet code, it was a simple task to modify the Actual365Fixed.cs code to have it support fractional days. This brought me back to my first problem: QLNet doesn't support discrete dividend option pricing.At this point, I have to choose between discrete dividends and fractional days. (I chose discrete dividends)I tried to build my own QuantLib+SWIG binaries to see if I could make changes to my copy of QuantLib and get them working in C#, but I have been running into problems doing that. I get a PInvoke error when I try to run the sample projects in the QuantLib+SWIG solution ( http://sourceforge.net/projects/quantli ... p/download ). This error was mentioned in the QuantLib mailing list here http://thread.gmane.org/gmane.comp.fina ... .user/8238 . Many thanks to Luigi Ballabio for point it out to me http://stackoverflow.com/questions/9824 ... nexception . I attempted the solution mentioned in the mailing list, but I couldn't get that to work. I was still getting the same error.For the time being, I'll be using the QuantLib+SWIG binaries provided by Resolver Systems. My models won't be able to handle intraday time changes however.
Last edited by JRobinson on March 22nd, 2012, 11:00 pm, edited 1 time in total.
 
User avatar
lballabio
Posts: 0
Joined: January 19th, 2004, 12:34 pm

QLNet Vanilla Options with Discrete Dividends (C# port of QuantLib)

March 23rd, 2012, 2:16 pm

Did you also try Hans Passant's suggestion on Stack Overflow? He added it as a comment instead of an answer, so you might have overlooked it.
 
User avatar
JRobinson
Topic Author
Posts: 0
Joined: March 8th, 2012, 2:54 pm

QLNet Vanilla Options with Discrete Dividends (C# port of QuantLib)

March 23rd, 2012, 7:33 pm

That did work for me! I changed the platform target to x86 and the target framework to ".Net Framework 4" and it worked. Thank you Luigi for your help. That QuantLib mailing list link you found really helped me out.