<div dir="ltr">I have tried a few things on the segmentation fault. <div><br></div><div>It's a little hard to understand what is really going on because I am not shown much information about where the error occurred. So far I have identified a few conditions when things apparently do cause an error:<div>1. No call to setEvaluationDate() supplied </div><div>2. The setEvaluationDate() date is not exactly the same date as the trade date</div><div>3. The tradeDate, and therefore the setEvaluationDate(), are set to a non-business day</div><div>4. The times argument goes right up to the time for which rates are provided e.g., a 15y swap rate is provided and times is defined as seq(0,15,0.1). It seems a save way to do this is to provide _at least_ one more rate beyond the times interval, i.e., seq(0,14,0.1) with a 15y swap rate defined</div><div><br></div><div>I am catching these conditions now.</div><div><br></div><div>Regards,</div><div>Ben</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 29, 2014 at 4:12 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 03:52, Benjamin J. J. Voigt wrote:<br>
| Hi,<br>
|<br>
</span><span class="">| the code is take from here: <a href="http://stackoverflow.com/questions/22226195/" target="_blank">http://stackoverflow.com/questions/22226195/</a><br>
| discountcurve-example-not-working-on-rquantlib <br>
| and I ran with recent (2h old as per time of writing) GH. It results in a<br>
| segfault all the time no matter wether its in RStudio, command line R or the<br>
| Mac R GUI.<br>
<br>
</span>Ok. I am in the middle of something else so I can help you with this ...<br>
<span class=""><br>
| But, the good thing is, the example(DiscountCurve) on the GH sources worked. So<br>
| I will look at that code instead. Thank you!<br>
<br>
</span>... that is exactly what I would do.<br>
<br>
My first instinct always is to a) get something in 'pure' QuantLib working<br>
and b) once that is done add the Rcpp/RQuantLib layer. By separating the two<br>
steps I find it easier to make progress.<br>
<span class=""><br>
| Regards,<br>
| Ben<br>
|<br>
| P.S.: Happy to test some more, but do you rather take findings on the list or<br>
| as tickets?<br>
<br>
</span>I am old school and tend to favour the list, but I am also getting used to<br>
having to respond to issue tickets at GH. Most folks seem to prefer the<br>
latter. I guess overall I don;t have a strong preference either. More<br>
important to get progress on code...<br>
<span class=""><font color="#888888"><br>
Dirk<br>
</font></span><div class=""><div class="h5"><br>
<br>
|<br>
| On Wed, Oct 29, 2014 at 3:32 AM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br>
|<br>
|<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<br>
| 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 =<br>
| "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>
| 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>
| + settleDate = c(2, 19, 2002),<br>
| + 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 =<br>
| 96.4875,<br>
| + fut6 = 96.3875, fut7 = 96.2875, fut8 = 96.0875, s3y =<br>
| 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)<br>
| 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<br>
| s2y<br>
| point leads to better / stabler results.<br>
|<br>
| With that I (finally!!) reenable the discount curve examples. So from<br>
| 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,<br>
| 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"<br>
| "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>
|<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", <br>
| 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,<br>
| but<br>
| | pricing bonds on a flat curve is not quite what regular users would like<br>
| to do<br>
| | when thinking about QuantLib.<br>
|<br>
| 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<br>
| for<br>
| a new release. The testing you are doing here is very welcome.<br>
|<br>
| Cheers, Dirk<br>
|<br>
| |<br>
| | Happy to provide more details if required.<br>
| |<br>
| | Regards,<br>
| | Ben<br>
| |<br>
| | --<br>
| | Ben<br>
| | _______________________________________________<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/" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/</a><br>
| rquantlib-devel<br>
|<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>
|<br>
|<br>
|<br>
|<br>
| --<br>
| Ben<br>
<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>
</div></div></blockquote></div><br><br>
</div></div></div>