OpenGamma R Windows

I can’t seem to run opengamma for R. The instructions are extremely confusing. For instance readme.txt file says this…

To run the package, the integration service from OG-Language will require a
running engine instance to connect to (e.g. run the server from OG-Examples
and use opengamma.engine.host=localhost in tests.properties).

Assuming that OG-Language builds correctly then the R package should compile
and run from Linux as long as R is in the path and R-devel headers are in the
standard include path.

…and on the opengamma doc…it says clearly R for Windows will run open gamma and no other platforms are supported. I can’t find a simple set of instructions to install opengamma package in R. The binary that came for windows also doesn’t help. There is no .zip file from which I can install the package in R. Has anyone tried using opengamma with R?

The OpenGamma R package requires a number of configuration entries in the registry, for example to locate the main OpenGamma instance, and has dependencies on other Java and native libraries. This makes it awkward to distribute as just a ZIP containing the R package files.

The easiest way to get up and running is to run the 64-bit MSI that is available on the download page: http://developers.opengamma.com/downloads

The “typical” installation option will set up an example OpenGamma server, the integration service used by the R plugin, and will register the R package. If you just want to install the R plugin (and its immediate dependencies), for example you have an OpenGamma server on another machine or are already running one you have built yourself from the source distribution, then choose the “custom” installation option and deselect the “OpenGamma Server” option.

Andrew, thanks for your reply…but still the R OpenGamma package is not recognized. I had already installed the demo version (MSI installer). I am using Windows 8 with R 2.15. I already used the typical configuration for installing everything…then rechecked today with modify option if R integration was installed.

When I say library(“OpenGamma”)

Error in library(“OpenGamma”) : there is no package called ‘OpenGamma’

Not sure if i have to do something else to dump the package inside R.

The package should have been registered with R during the installation process by running the “R CMD INSTALL” command from the R environment that the installer discovered from the registry. It is possible that this step failed, or was not executed correctly, during the installation.

As long as the remainder of the installer ran without error then the correct registry entries and configuration files will have been created along with the Windows service that hosts the Java components.

You could try manually registering the ZIP file containing the R package. This will have been written as ProgramData\OpenGamma Ltd\Tools for R\OpenGamma.zip

If this still does not work, then more detailed logging information from the installer would be helpful for me to understand exactly what is failing. Logging can be generated by running the MSI as:

msiexec /l*vx opengamma.log /i opengamma-demo-1.2.0-installer-x64.msi

To register a ZIP file containing an R package manually, open a command prompt window and navigate to the folder containing the file. Then type:

R CMD INSTALL OpenGamma.zip

You will need the R executable on the path for this to work.

Alternatively, if you are using the R Studio IDE then select “Install packages …” from the “tools” menu and browse to the zip file.

I have filed http://jira.opengamma.com/browse/RSTAT-56 within our issue tracking system to resolve the exact causes for the MSI not registering the package correctly during installation.

thanks for all your help. I was able to install the zip file using this. Now when doing the init it throws a bunch of errors

OpenGamma::Init ()
[1] “Info: Stub OG package not available”
[1] “Info: Building import package”
[1] "Info: Declaring functions"
Error in from:to : argument of length 0
In addition: Warning messages:
1: In dir.create(tmp) :
‘C:\Users\BLOOMB~1\AppData\Local\Temp\Rtmp2p1KGz\package’ already exists
2: In dir.create(man) :
‘C:\Users\BLOOMB~1\AppData\Local\Temp\Rtmp2p1KGz\package\man’ already exists
3: In dir.create® :
‘C:\Users\BLOOMB~1\AppData\Local\Temp\Rtmp2p1KGz\package\R’ already exists
4: In dir.create(tests) :
‘C:\Users\BLOOMB~1\AppData\Local\Temp\Rtmp2p1KGz\package\tests’ already exists
5: In OpenGammaCall(“Functions_count”) :
Not initialised at Entities.cpp:80

I am running the demo bloomberg service (also tried the non bloomberg service). I am running all this on bloomberg machine.

K i restarted R…and again tried…and it seems to be working! Thanks a lot andrew… :slight_smile:

also the documentation is insufficient for learning about arguments to R functions. for instance…the function details of EquityBarrierOptionSecurity. A sample syntax might have been helpful. This is a bit confusing…for someone wanting to use the function…

name

The display name or label of the security
optionType

The type of option (PUT or CALL)
strike

The strike
currency

The currency
underlyingId

The identifier of the underlying security
exerciseType

The exercise type
expiry

The expiry
pointValue

The point value
exchange

The exchange
barrierType

The barrier type
barrierDirection

The barrier direction
monitoringType

The monitoringType
samplingFrequency

The sampling frequency
barrierLevel

The barrier level

For example montitoringType …is it string or number…or what values it can take…etc…and samplingFrequency…does it take values like “Continuous”…or??

tried out some stuff…here’s my R code…shows NA for prices. It’s not able to take data from bloomberg…a one liner fix will help…thanks

Copyright © 2012 - present by OpenGamma Inc. and the OpenGamma group of companies

Please see distribution for license.

Demonstrates constructing a portfolio containing securities with different properties

(in this case FX Options with a range of strikes) to show how a single OpenGamma

engine cycle can then be used to calculate everything in parallel.

expiry <- Sys.time () + as.difftime (26, format = “%X”, units = “weeks”) # About six-months to expiry
option.strikes <- seq (1700, 2000, length.out = 50) # This can take a while - if running on a workstation, try a smaller number
notional <- 1000000

Create a portfolio containing all of the theortical securities

positions <- c ()
settlementDate <- expiry + as.difftime (2, format = “%X”, units = “days”) #2 days after expiry

for(option.strike in option.strikes)
{
security1 <- EquityIndexOptionSecurity(name=paste(“SPX Index”,option.strike),“CALL”,option.strike,“USD”,“SPX~Index~0”,exerciseType=EuropeanExerciseType(),expiry <- Sys.time () + as.difftime (26, format = “%X”, units = “weeks”),2.001,“NYSE”)
security1.id <- StoreSecurity (security1)
positions <- c (positions, PortfolioPosition (security = security1.id, quantity = 1))
}
node <- PortfolioNode (name = “EquityOptions”, positions = positions)
portfolio <- Portfolio (name = “EquityOptions Portfolio”, rootNode = node)
portfolio.id <- StorePortfolio (portfolio)

Fetch the position IDs as stored in the database - results will be keyed by these

positions <- sapply (fields.FudgeMsg (FetchPortfolio (portfolio.id)$root$positions), function (x) { x$Value$uniqueId })

Create a view on this portfolio. Note the constraints used to configure how

calculations are performed; refer to the online documentation for the full range

of parameters that can be used to control each underlying analytic model.

requirements <- list (
price = new.ValueRequirement (ValueRequirementNames.Present.Value, paste (
“CalculationMethod=LocalVolatilityPDE”,
“SmileInterpolator=Spline”,
“PDEDirection=Forward”,
sep = ", ")),
forwardDelta = new.ValueRequirement(
ValueRequirementNames.Forward.Delta, paste (
“CalculationMethod=LocalVolatilityPDE”,
“SmileInterpolator=SABR”,
“PDEDirection=Forward”,
sep = ", ")))
view <- ViewDefinition (“EquityOptionsExample”, portfolio.id, requirements)
view.id <- StoreViewDefinition (view)
calc.config <- “Default”

Create a view client attached to the snapshot and execute a cycle against current market data.

This could equally use a snapshot as shown in other examples.

view.client <- ViewClient (view.id, useSharedProcess = FALSE)
TriggerViewCycle (view.client)
view.result <- GetViewResult (viewClient = view.client, waitForResult = -1)

For each value requirement, extract the result column values and produce that in the portfolio

ordering (i.e. to correspond to option.strikes)

view.result.data <- results.ViewComputationResultModel (view.result)[[calc.config]]
results <- data.frame (
strikes = option.strikes,
lapply (requirements, function (requirement) {
columns <- columns.ViewComputationResultModel (view.result.data, requirement)
sapply (positions, function (position) {
firstValue.ViewComputationResultModel (view.result.data[position,], columns)
}, USE.NAMES = FALSE)}))

Print the results data frame

print (results)

Can anyone please answer. I always get NA in prices…some market data connection is missing!!!

changed the ticker to proper naming convention…but still same NA errors. Isin’t it supposed to automatically fetch data from bloomberg. Exact same thing is being done in FXPriceAndGreeks.R and it works fine. Is there some coding bug in EquityOption pricing. I haven’t come across any samples for Equity options…so wondering!

security1 <- EquityIndexOptionSecurity(name=paste(“SPX Index”,option.strike),“CALL”,option.strike,“USD”,“BLOOMBERG_TICKER~SPX~Index”,exerciseType=EuropeanExerciseType(),expiry <- Sys.time () + as.difftime (26, format = “%X”, units = “weeks”),2.001,“NYSE”)
security1.id <- StoreSecurity (security1)
positions <- c (positions, PortfolioPosition (security = security1.id, quantity = 1))
}

except a vanilla FX option…none of the other security types seem to be working…for instance if i change to…

security <- FXBarrierOptionSecurity(name = paste (“Long put USD,”, notional, “, call EUR”, notional / option.strike, “on”, expiry),“USD”,“EUR”,callAmount = notional / option.strike,putAmount =

notional,expiry,settlementDate,“UP”,“KNOCK_OUT”,“CONTINUOUS”,“CONTINUOUS”,4.1,long=TRUE)

instead of

security <- FXOptionSecurity (
name = paste (“Long put USD,”, notional, “, call EUR”, notional / option.strike, “on”, expiry),
callAmount = notional / option.strike,
callCurrency = “EUR”,
putCurrency = “USD”,
putAmount = notional,
expiry,
exerciseType = EuropeanExerciseType (),
long = TRUE,
settlementDate)

then I get NA in all the fields of the output.

Any suggestions???