Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upDividendVanillaOption #72
Comments
|
The QuantLib codebase is a beast! But there is some hope -- by studying the examples and particularly the (very extensive) unit tests you can often come up with something simple. Get that working standalone, and from there interfacing from R is pretty easy thanks to Rcpp. Sounds like a plan? I can help here and there... |
|
Thanks, I can try and follow that route. On the RQuantLib side, what is the type of interface that would be most appropriate? Should I go with a |
|
If |
|
If it were me, I'd do an AmericanOption and have an optional dividend argument with a default of 0 and have a single interface. |
|
@eddelbuettel Thus sounds like an easy problem for you. Why wouldn't you just do it? |
|
I'm working on a swap interface and a FRA interface. I just found unexpected behavior in the FRA results that I'm trying address. Also yield curve perturbations and then there are my 3 other clients. Sorry, another interface outside of fixed income is outside my ability to resource. Happy to advise. There's already an AmericanOption with a dividend yield, just add dividends and fork on non-zero dividend to call other quantlib dividend based method. |
|
@student-t Let's see: maybe because I have a day job, over two dozen other CRAN packages several of which I released in the last few days, well over 100 CRAN packages I maintain for Debian where I currently prep for tomorrow's first beta of R 3.3.2, and maybe also because I occasionally sleep. So, your turn: Why don't you? Jokes aside: easily contained and well-defined problems are the best to start so a case can be made that these should in fact be left as training ground for new contributors. @tleitch Point taken. I haven't looked at the class interfaces but generalizing to 'with dividend' defaulting to a value of zero and giving old behaviour sounds good to me too. |
|
@eddelbuettel I'm well aware of your enormous contributions to the community (and very grateful for them), and would love to do my part if I can wrap my head around the C++ side of things. I'm starting, as you suggested, from the unit test |
|
@hfty What I try in a case like that is to first builds a small self-contained program depending only on QuantLib. Maybe with the fewest feature. And then build up from there. What is in RQuantLib can serve as a framework for adding to it. And if you're stuck, come here and ask for help. No point in spinning the wheels... |
|
@hfty A great resource on the C++ side are the examples in Quantlib. Some of the RQuantlib functions are almost direct wraps of an example. If you know some C++ and compare an existing R/Rcpp wrap with it's matching example you can infer what your interface should look like. AmericanOption is a great start, you only need to figure out how to add the dividend input (it will be two data points, amount and time/date) and then figure out how to format that data for the method call that takes discrete dividends. The Module you want if FDDividendAmericanEngine which is related to FDAemeicanEngine. There is no example for the dividend version, but there is test suite code where it is called. I would hunt that down and compare it with the dividend yield version to help with design the call. The outputs are the same, so no work needed there. Best of luck. C++ is the easy part. Dirk is much harder to learn. |
|
Dirk is easy. Terry was referring to the fact that he also needed a crash course in how to deal with Git(Hub). |
|
Too many years in a C suite..... ;~) |
|
Thanks for the advice, @eddelbuettel and @tleitch. I'm sluggishly making my way through the code. The engine expects vectors for dividend dates and amounts, and I'm not sure what the best way to pass those as parameters with Rcpp. From the test suite:
Does that mean I can just add a For the I thought of making it a unique dividend for simplicity, but given the QuantLib function expects a vector anyway... might as well. |
|
The fixed incomes should have similar things for coupon dates and payment. In essence you are correct: vectors of dates and values. We do have Rcpp::Datevector, and that whole stack is a bit of mess in RQuantLib because it was all done before Rcpp had facilities for it. (For what it is worth I finally added something better; hopefully in the next Rcpp release.) But there should be plenty of working examples. |
|
I see. I can use some of the syntax from the bonds file, thank you. For dates, however, I guess it's a stylistic choice. Bond valuation uses actual dates, and then asks you for the |
|
Yes -- real valued 'time until' as fractional years is common. But that can happen both ways: giving QL a vector of (dividend) dates as well as a current evaluation date (today is a default), and letting it compute the time steps, or giving it the time steps. I usually follow the example and test code and try to conform to the existing class interfaces. |
|
There is no example for this, but the unit test uses fractional years from today, so I'll try to go with that. Thanks! |
|
Looks like I have a working prototype! Thank you again for your help. I did both the European and American version. However, a few questions before I submit a pull requests for your consideration:
However, no such test for the American version, and the issue is that I would need to compare to a Finite Difference benchmark. Haug uses a discrete dividend yield model (i.e. % of the spot at the ex-dividend date, if I understood that right); Hull uses a binomial tree. The values I obtain are close to Haug, but not exactly the same; they are fairly different from those of Hull, although the Greeks are very similar. I guess that it is not our job to check that the upstream results are correct, but I'd like the new functionality to be properly tested anyway...
|
|
Sounds good! Now in order:
|
|
PR merged! Thanks for your help. |
|
Ahh. Forgot we had an open issue. Will mark. (Pro-tip: Having |
I would like to get prices and Greeks for American options with discrete dividends, which seems to be implemented in QuantLib in DividendVanillaOption.
It is my understanding that this is not currently part of the code covered by RQuantLib. Is there any way I could easily interface that code from R? My C++ is fairly limited, and the QuantLib codebase looks like a beast.