2

I am trying to extend the functionality of a package and therefore trying to access the entire code behind one of the functions.

The package in question is RQuantLib and I am trying to see the entire code used in the function "DiscountCurve"

The result I get is simply:

function (params, tsQuotes, times = seq(0, 10, 0.1), legparams = list(dayCounter = "Thirty360", 
  fixFreq = "Annual", floatFreq = "Semiannual")) 
{
  UseMethod("DiscountCurve")
}

I have tried quite a few solutions as posted in this thread with no luck: How can I view the source code for a function?

UseMethod("DiscountCurve") does not tell me much. As far as I understand this is a translated package from C++. I am rather new to coding so it is possible that I have just not implemented the correct solution in the thread above correctly.

Edit for more detial on methods used so far: Results from methods: > methods("DiscountCurve") 1 DiscountCurve.default*

When checking methods(Class="default") I get 184 results. Due to space I will post screenshots of the code: prnt.sc/tws98x

Further using getAnywhere: prnt.sc/tws9rq

Phil
  • 7,287
  • 3
  • 36
  • 66
Qfin
  • 39
  • 1
  • 7
  • 1
    please tell us a little more about the solutions you've tried. I would expect you to have gotten somewhere with `methods()` and `getAnywhere()` from the accepted answer ... can you edit your question to include the results of following these steps? (Just running `methods()` won't get you anywhere, you have to follow the steps from the linked answer ...) – Ben Bolker Aug 09 '20 at 20:20
  • Here are the results > methods("DiscountCurve") [1] DiscountCurve.default* When checking methods(Class="default") I get 184 results. Due to space I will post screenshots of the code: https://prnt.sc/tws98x Further using getAnywhere: https://prnt.sc/tws9rq – Qfin Aug 09 '20 at 20:41

1 Answers1

3

If you do:

RQuantLib:::DiscountCurve.default

You will see the actual code that runs when the generic calls UseMethod("DiscountCurve") . However, you are likely to be disappointed, because essentially that function is a glorified type-checker which passes your parameters safely to another unexported function called discountCurveEngine, which looks like this:

RQuantLib:::discountCurveEngine
function (rparams, tslist, times, legParams) 
{
    .Call(`_RQuantLib_discountCurveEngine`, rparams, tslist, 
        times, legParams)
}

Which, you will see, is actually a thin wrapper for the C++ code that actually does the calculation. It is written in Rcpp-flavoured C++ and you can read the source code here. However, this in turn calls functions from another C++ library called Quantlib.

Depending on how keen you are, and how proficient you are in C++, you may find this enjoyably challenging or dishearteningly baffling, but at least you know where to find the source code.

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
  • Thank you very much. I have not coded in C++ at all so I guess it will be a challenge, but this is a big step forwards after a long time being stuck so that is great. Very quick and thorough reply as well so thank you for that @Allan Cameron – Qfin Aug 09 '20 at 21:03
  • You're welcome @Qfin . From reviewing the code, this is very nicely written C++ and because it uses Rcpp, you should get a good idea of what it is doing. Good luck! – Allan Cameron Aug 09 '20 at 21:11