Skip to content

Calling R from C++ application

4 messages · Alexander Kirillov, Brian Ripley, Jeff Miller +1 more

#
Hi,

I am trying to figure out if it's possible
to use R as a computational engine
for a C++-based windows application.

What I would like to do (from my C++ program)is:
- start R
- send some data from my program to R
- execute R program
- get data back to my application
(I was able to implement all this for
Matlab.)

I looked at Chapter 4 of "Modern Applied
Statistics with S-plus" by Venables and Ripley
(Springer, 1996) and stumbled on a statement:

"Note that it is only possible to call S functions
from within C functions called from S..."

Is this still true for the latest version of R?
If not, is there a place where I can look at the
sample code that calls R?

Thanks,

Alexander Kirillov



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, 6 Jun 2001, Alexander Kirillov wrote:

            
No.
Two choices:

The DCOM interface by Thomas Baier, on CRAN under
Software->Other->Non-standard packages

Use an alternative front end:  src/gnuwin32/front-ends/readme.

Both have examples in C.  The first is probably closer to what you
did in Matlab.
1 day later
#
Hi All,

    I'm wondering if there is a simple way to do the following.

    I have a dataframe, optiondata, with four columns: ticker, expdate,
strike, and spot.

    A piece of it looks like this:
sym        expdate           strike       spot
1          A           20010617       30.0         34.10
2          A           20010617       35.0         34.10
3          A           20010617       40.0         34.10
4          A           20010617       45.0         34.10
11        A           20010722       30.0         34.10
12        A           20010722       35.0         34.10
271     AAPL     20010722       27.5         20.94
272     AAPL     20010722       30.0         20.94
277     AAPL     20011021       12.5         20.94
278     AAPL     20011021       15.0         20.94

I'd like to add a fifth column to this dataframe,  moneyness.

The rule to calculate this quantity is:  take all distinct groups by ticker
and expdate,
then find the the strike closest to spot (min (abs( spot - strike))). This
has moneyness zero.
The strikes greater than this strike then have moneyness 1, 2, ...
and the strikes below are -1, -2, ...

The example above with the new column would look like
sym        expdate           strike       spot        moneyness
1          A           20010617       30.0         34.10    -1
2          A           20010617       35.0         34.10     0
3          A           20010617       40.0         34.10     1
4          A           20010617       45.0         34.10     2
11        A           20010722       30.0         34.10    -1
12        A           20010722       35.0         34.10     0
271     AAPL     20010722       27.5         20.94     0
272     AAPL     20010722       30.0         20.94     1
277     AAPL     20011021       12.5         20.94     0
278     AAPL     20011021       15.0         20.94     1

Thanks in advance for any help.

    Jeff Miller








-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
First: I'm (as usual) unsure if I understood you right
Second: The grouping thing should be trivial
Third: For the rest, this might give you a hint:

xx <- data.frame(g=sort(rep(1:3,len=20)),x=rnorm(20,10,10),y=rnorm(20,10,10))
xx <- xx[order(xx$g,xx$y-xx$x),]
xx$New <- unlist(by(xx[,c("x","y")],xx$g,function(x){
  WhichMin <- which.min(abs(x[,1]-x[,2]))
  Len <- length(x[,1])
  if(WhichMin>1) Lower <- sort(-(seq(0,WhichMin-1,1)))
  else Lower <- 0
  Upper <- seq(WhichMin+1,Len,1)-WhichMin
  c(Lower,Upper)
    
})
                 )
xx$Diff <- xx$y-xx$x
xx

Peter
On Thu, Jun 07, 2001 at 09:21:55PM -0500, Jeff Miller wrote: