1
$\begingroup$

I've been tracing back through bond.cpp and find the following in FloatingBond() :

double dayCounter = Rcpp::as<double>(datemisc["dayCounter"]);

$\mathrm{datemisc[]}$ is passed (traced back to) from FloatingBond.default in bond.R as

dateparams=list(....
                dayCounter='Thirty360',
                ....)

which is a string, so I would assume that it would be a pointer to a string in c++.

Looking downstream to $\mathrm{dayCounter()}$ in util.cpp I see

QuantLib::DayCounter getDayCounter(const double n){
    if (n==0)
        return QuantLib::Actual360();
    else if (n==1)
        return QuantLib::Actual365Fixed();
    .......
}

So downstream agrees with the type passed but the upstream in bond.R seems incorrect. I do not see where the text string is translated into a double.

What am I missing?

$\endgroup$
  • $\begingroup$ I should add this is true for the other parameters in "dataparams", the functions expect doubles but I see string pointers passed. $\endgroup$ – terry leitch Mar 14 '16 at 18:37
1
$\begingroup$

You probably have already figured out. It's very common in computer science that all the primary data types get converted into a string for interfacing. Rcpp simply did the conversion for you. You shouldn't worry about the conversion and just focus only on the algorithm.

| improve this answer | |
$\endgroup$
  • $\begingroup$ this is not automaticly generated code. this is not an answer and it is wrong. $\endgroup$ – terry leitch Jun 12 '16 at 14:33
  • $\begingroup$ @terryleitch Maybe you can write your answer? $\endgroup$ – HelloWorld Jun 12 '16 at 14:34
  • $\begingroup$ The conversion is performed by R code matchParams() which is in the bond.R source prior to calling the c++ code. It's confusing as the name is reused in the call (e.g. dateparams<-matchParams(dateparams) ) so when looking at the code above you see the character strings. Would be better if the result was assigned to something more meaningful like "mappedparams". $\endgroup$ – terry leitch Jun 15 '16 at 15:43
0
$\begingroup$

The conversion is performed by matchParams() which is in the bond.R source prior to calling the c++ code. It's confusing as the name is reused in the call (e.g. dateparams<-matchParams(dateparams) ) so when looking at the code above you see the character strings. Would be better if the result was assigned to something more meaningful like "mappedparams".

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.