<div dir="ltr">Hi,<div><br></div><div>the code is take from here: <a href="http://stackoverflow.com/questions/22226195/discountcurve-example-not-working-on-rquantlib">http://stackoverflow.com/questions/22226195/discountcurve-example-not-working-on-rquantlib</a> </div><div>and I ran with recent (2h old as per time of writing) GH. It results in a segfault all the time no matter wether its in RStudio, command line R or the Mac R GUI.</div><div><br></div><div>But, the good thing is, the example(DiscountCurve) on the GH sources worked. So I will look at that code instead. Thank you!</div><div><br></div><div>Regards,</div><div>Ben</div><div><br></div><div>P.S.: Happy to test some more, but do you rather take findings on the list or as tickets?</div><div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 29, 2014 at 3:32 AM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><br>
On 29 October 2014 at 02:50, Benjamin J. J. Voigt wrote:<br>
| Hi,<br>
|<br>
| running the following example (mac 10.9.*) I get a crash, both on stable and<br>
| github sources. Is there a known reason for this and how do I prevent the<br>
| error?<br>
|<br>
| R-Code:<br>
| savepar <- par(mfrow = c(3, 3))<br>
|<br>
| params <- list(tradeDate = c(2, 15, 2002), settleDate = c(2,<br>
| 19, 2002), dt = 0.01, interpWhat = "discount", interpHow = "loglinear")<br>
|<br>
| tsQuotes <- list(d1w = 0.0382, d1m = 0.0372, fut1 = 96.2875,<br>
| fut2 = 96.7875, fut3 = 96.9875, fut4 = 96.6875, fut5 = 96.4875,<br>
| fut6 = 96.3875, fut7 = 96.2875, fut8 = 96.0875, s3y = 0.0398,<br>
| s5y = 0.0443, s10y = 0.05165, s15y = 0.055175)<br>
|<br>
| times <- seq(0, 10, 0.1)<br>
|<br>
| DiscountCurve(params, tsQuotes, times)<br>
<br>
</span>Can you detail where you got this from / what you changed? Because Gmail<br>
insists on inserting garbage into text this is a little tedious for me.<br>
<br>
When I run your code against current GH sources, I get an error on input:<br>
R> params <- list(tradeDate = c(2, 15, 2002),<br>
<span class="">+ settleDate = c(2, 19, 2002),<br>
</span>+ dt = 0.01,<br>
+ interpWhat = "discount",<br>
+ interpHow = "loglinear")<br>
R> tsQuotes <- list(d1w = 0.0382, d1m = 0.0372, fut1 = 96.2875,<br>
+ fut2 = 96.7875, fut3 = 96.9875, fut4 = 96.6875, fut5 = 96.4875,<br>
+ fut6 = 96.3875, fut7 = 96.2875, fut8 = 96.0875, s3y = 0.0398,<br>
+ s5y = 0.0443, s10y = 0.05165, s15y = 0.055175)<br>
R> times <- seq(0, 10, 0.1)<br>
R> DiscountCurve(params, tsQuotes, times)<br>
Error: expecting a single value<br>
R><br>
<br>
<br>
Now, there was a (very recent) conversation with Luigi (upstream at QL) which<br>
we had, as I recall, mostly in an issue ticket at GH. That revealed two<br>
sources of trouble: I had the wrong date, and a bad tenor -- removing the s2y<br>
point leads to better / stabler results.<br>
<br>
With that I (finally!!) reenable the discount curve examples. So from current<br>
GitHub sources you once again get a meaning 3 x 3 grid of plots. An example<br>
is below, this of course does not include the chart (which I could email<br>
you...) but you get a hint of the final values of curves via str() below.<br>
<br>
R> library(RQuantLib)<br>
R> example(DiscountCurve)<br>
<br>
DscntCR> savepar <- par(mfrow=c(3,3), mar=c(4,4,2,0.5))<br>
<br>
DscntCR> ## This data is taken from sample code shipped with QuantLib 0.9.7<br>
DscntCR> ## from the file Examples/Swap/swapvaluation<br>
DscntCR> params <- list(tradeDate=as.Date('2004-09-20'),<br>
DscntC+ settleDate=as.Date('2004-09-22'),<br>
DscntC+ dt=.25,<br>
DscntC+ interpWhat="discount",<br>
DscntC+ interpHow="loglinear")<br>
<br>
DscntCR> setEvaluationDate(as.Date("2004-09-20"))<br>
[1] TRUE<br>
<br>
DscntCR> ## We get numerical issue for the spline interpolation if we add<br>
DscntCR> ## any on of these three extra futures -- the original example<br>
DscntCR> ## creates different curves based on different deposit, fra, futures<br>
DscntCR> ## and swap data<br>
DscntCR> ## Removing s2y helps, as kindly pointed out by Luigi Ballabio<br>
DscntCR> tsQuotes <- list(d1w = 0.0382,<br>
DscntC+ d1m = 0.0372,<br>
DscntC+ d3m = 0.0363,<br>
DscntC+ d6m = 0.0353,<br>
DscntC+ d9m = 0.0348,<br>
DscntC+ d1y = 0.0345,<br>
DscntC+ fut1=96.2875,<br>
DscntC+ fut2=96.7875,<br>
DscntC+ fut3=96.9875,<br>
DscntC+ fut4=96.6875,<br>
DscntC+ fut5=96.4875,<br>
DscntC+ fut6=96.3875,<br>
DscntC+ fut7=96.2875,<br>
DscntC+ fut8=96.0875,<br>
DscntC+ # s2y = 0.037125,<br>
DscntC+ s3y = 0.0398,<br>
DscntC+ s5y = 0.0443,<br>
DscntC+ s10y = 0.05165,<br>
DscntC+ s15y = 0.055175)<br>
<br>
DscntCR> times <- seq(0,10,.1)<br>
<br>
DscntCR> # Loglinear interpolation of discount factors<br>
DscntCR> curves <- DiscountCurve(params, tsQuotes, times)<br>
<br>
DscntCR> plot(curves,setpar=FALSE)<br>
Hit <Return> to see next plot:<br>
<br>
DscntCR> # Linear interpolation of discount factors<br>
DscntCR> params$interpHow="linear"<br>
<br>
DscntCR> curves <- DiscountCurve(params, tsQuotes, times)<br>
<br>
DscntCR> plot(curves,setpar=FALSE)<br>
<br>
DscntCR> # Spline interpolation of discount factors<br>
DscntCR> params$interpHow="spline"<br>
<br>
DscntCR> curves <- DiscountCurve(params, tsQuotes, times)<br>
<br>
DscntCR> plot(curves,setpar=FALSE)<br>
<br>
DscntCR> par(savepar)<br>
R> str(curves)<br>
List of 7<br>
$ times : num [1:101] 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 ...<br>
$ discounts : num [1:101] 1 0.996 0.993 0.989 0.984 ...<br>
$ forwards : num [1:101] 0.0367 0.0404 0.0404 0.0287 0.0275 ...<br>
$ zerorates : num [1:101] 0.0392 0.0376 0.0368 0.0379 0.0402 ...<br>
$ flatQuotes: logi FALSE<br>
$ params :List of 5<br>
..$ tradeDate : Date[1:1], format: "2004-09-20"<br>
..$ settleDate: Date[1:1], format: "2004-09-22"<br>
..$ dt : num 0.25<br>
..$ interpWhat: chr "discount"<br>
..$ interpHow : chr "spline"<br>
$ table :'data.frame': 5479 obs. of 2 variables:<br>
..$ date : Date[1:5479], format: "2004-09-22" "2004-09-23" "2004-09-24" "2004-09-25" ...<br>
..$ zeroRates: num [1:5479] 0.0392 0.0392 0.0392 0.0392 0.0392 ...<br>
- attr(*, "class")= chr "DiscountCurve"<br>
R><br>
<br>
<br>
So very much no segfault here on the default example.<br>
<span class=""><br>
<br>
|<br>
|<br>
| R-Error:<br>
| *** caught segfault ***<br>
| address 0x20, cause 'memory not mapped'<br>
|<br>
| Traceback:<br>
| 1: .Call("RQuantLib_discountCurveEngine", PACKAGE = "RQuantLib", rparams,<br>
| tslist, times)<br>
| 2: discountCurveEngine(params, tsQuotes, times)<br>
| 3: DiscountCurve.default(params, tsQuotes, times)<br>
| 4: DiscountCurve(params, tsQuotes, times)<br>
|<br>
|<br>
| I am not in a hurry, just might need to think of doing this on my own, but<br>
| pricing bonds on a flat curve is not quite what regular users would like to do<br>
| when thinking about QuantLib.<br>
<br>
</span>We've just overcome this.<br>
<br>
RQuantLib is coming together. I did a bunch of work in the summer, then got<br>
sidetracked with travel and conferences and getting back to it. Michele<br>
helped with two excellent pull requests, and I think we are getting ready for<br>
a new release. The testing you are doing here is very welcome.<br>
<br>
Cheers, Dirk<br>
<span class=""><br>
|<br>
| Happy to provide more details if required.<br>
|<br>
| Regards,<br>
| Ben<br>
|<br>
| --<br>
| Ben<br>
</span>| _______________________________________________<br>
| Rquantlib-devel mailing list<br>
| <a href="mailto:Rquantlib-devel@lists.r-forge.r-project.org">Rquantlib-devel@lists.r-forge.r-project.org</a><br>
| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rquantlib-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rquantlib-devel</a><br>
<span class=""><font color="#888888"><br>
--<br>
<a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Ben</div>
</div></div>