-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added discrete dividend interface to EuropeanOption and AmericanOption #73
Conversation
That looks like a very fine piece of work on first try -- a little hard to see all from the diff but no smoking gun yet. |
Ahh, but I spoke too soon. We do have a smoking gun in that tests failed:
|
You probably need one more cast here. Should be simple enough. I'll try to take a look on the train ride in. |
That's in the 'have TQL 1.7.* or newer and intra-day dates' branch. I didn't get it fixed on the train [1] but I'll have something for you hopefully this evening. That whole section needs some work though. You know your vector sizes, so you can allocate at once rather than push_back each. Also the 'inside the loop' additional vectors are unneeded. We'll get there... [1] I am currently making Date + Datetime vectors are little nice in Rcpp and had to roll that to the release version too. |
Thanks! For some reason it wasn't compiling when I was skipping the extra vector in the loop. I did warn you that my C++ was very limited :) But hopefully it will get better. |
Can you do me a quick favor and send me a link (maybe into the QL repo at GH) about the example you used to guide your implementation. The time duration hack with the |
This is the test unit, see (Edited: Added line numbers) |
Don't rush things. This is still wrong. Every i-th step of the loop accesses only element i, after the loop the vector is done --- no need for a vector. Just do
and use it as a temp. There are more things to fix here, and the change did not even try to address the real elephant in the room: your compilation failure. |
Sorry, I was trying to makes things better, not worse! I'm not getting the compilation failure on my machine, so it is hard for me to figure that one out. |
I already told you why (albeit in passing): you are running a QL variant not setup for intra-day times. What OS are you on? There are some ways to correct for that (and some are easier than others). |
Yes, I got that it was the reason. I'm on macOS Sierra, using homebrew. I tried to install the --HEAD version, but the recipe fails, and I've not yet figured out why. I'm going to try to install from source. |
Kewl. If and when you install from source make sure you add the required switch, approximately tar xfz Quantlib-*tar.gz
cd QuantLib-*
./configure --enable-intraday
make
make install |
Ok. Try these halfes for the two European exercise case#ifdef QL_HIGH_RESOLUTION_DATE
QuantLib::Date exDate(today.dateTime() + length);
if(discreteDividends[0] != 0) {
boost::posix_time::time_duration discreteDividendLength;
for (int i = 0; i < n; i++) {
discreteDividendLength = boost::posix_time::minutes(discreteDividendsTimeUntil[i] * 360 * 24 * 60);
QuantLib::Date dt(today.dateTime() + discreteDividendLength);
discreteDividendDates.push_back(dt);
}
}
#else American exercise case#ifdef QL_HIGH_RESOLUTION_DATE
QuantLib::Date exDate(today.dateTime() + length);
if(discreteDividends[0] != 0) {
boost::posix_time::time_duration discreteDividendLength;
for (int i = 0; i < n; i++) {
discreteDividendLength = boost::posix_time::minutes(discreteDividendsTimeUntil[i] * 360 * 24 * 60);
QuantLib::Date dt(today.dateTime() + discreteDividendLength);
discreteDividendDates.push_back(dt);
}
}
#else |
Will you be able to apply those two changes to repair the pull request? |
Sure, thank you. I'll do that after lunch, I'm teaching this morning. |
Perfect, was just worried as I hadn't heard from you. Maybe we can square this this evening (North American time). |
Yeah, sorry. I spend some time on compiling quantlib from source last night, but I have some unusual errors that I still can't figure out. But that shouldn't stop me from including your changes! |
I can't help much with OS X. I am subscribed to the two main QL mailing list, and that topic (of woes on OS X) seems to be recurring. I don't read each and every post on the list though -- but maybe you will a nugget there or can ask. On Linux things "just work". Also, while I have you here, we tend to have contributors 'unmasked'. Can you please provide a name and email address? |
I did a (long overdue) clean install of macOS Sierra, and Quantlib has been compiling for the last hour, no more error, it seems. I'll test the changes as soon as that's done and submit an updated PR. |
Great. Also:
|
Sure. I sent you an email about that on your Debian address. |
Now vanilla RQuantLib does not compile with the Quantlib I compiled from source... Bear with me while I figure that out. |
If you show error messages I may be able to help you. |
Thanks. Here's a partial gist. I was using RStudio so the error messages have been truncated. I'm doing it again from the command line and will update the gist when it's done. Unless you have a better suggestion, I might try to recompile quantlib not from the github repository, but from the latest release, and see if that makes a difference. |
Ah, yes, I would recommend the releases. I maintain them for Debian and Ubuntu too -- never had an issue with snapshots. "Random" git syncs are not my favourite way to get software. |
Sounds good. It took a good couple of hours to compile last time, so I'm going to launch it tonight and report back in the morning. If it still doesn't work, I'll just do it on a Linux VM. |
All checks passed! Do I need to fix anything else? |
Not right now. I had a really casual first look when I had your branch checked out. I will do two things 'for polish':
But what would always help are more real-world examples. Can you punch up something either from Haug, or from John Hull's book, or some other standard? |
For the dates, sure, but then won't that be inconsistent with the maturity date being in fractional years? Could you detect the type of I'll dig through some books and try to find more examples. I think |
(Rcpp) Dates are internally all doubles so you can be as fractional as you want: R> as.numeric(difftime( as.Date(ISOdatetime(2016,10,16,10,0,0)), as.Date(ISOdatetime(2016,10,12,14,0,0))))
[1] 4
R> as.numeric(difftime( ISOdatetime(2016,10,16,10,0,0), ISOdatetime(2016,10,12,14,0,0)))
[1] 3.83333
R> I am a bit surprised by the first answer---but it does not limit us. Rcpp and QuantLib dates are more fine grained: R> class(Sys.Date())
[1] "Date"
R> storage.mode(Sys.Date())
[1] "double"
R> Example cleanups and extensions are always welcome too. |
But then there's the question of the day counting convention. I guess we should move this discussion to the issue tracker, anyway. Thanks for the merge! |
Day count conventions are covered at length in QL -- which is why I like to follow their examples. Ie the one you worked off just add 'two months' and 'five months'. That is pretty clean, and users can (as they should be able to) do that in R. But yes, new issue for new examples? |
@hfty: Ok, I gave it one quick do-over using It may still be interesting to try to use actual dates, But it doesn't fit the current paradigm so it needs some thought. |
No description provided.