Skip to content

Instantly share code, notes, and snippets.

@meg-codes
Last active March 12, 2018 15:13
Show Gist options
  • Save meg-codes/c5adc97161842c3bc2e3b13a0d0819f7 to your computer and use it in GitHub Desktop.
Save meg-codes/c5adc97161842c3bc2e3b13a0d0819f7 to your computer and use it in GitHub Desktop.
Instructions for RQuantLib and Brew with OpenMP

Installing QuantLib

Follow the instructions here to install Quantlib.

Make especially sure that you use the --with-intraday flag for QuantLib.

Install an up-to-date clang with OpenMP support

The default MacOS clang++ for High Sierra does not include support for OpenMP, so you'll need to install a version that does and then set R to use it for compiling libraries.

First run brew update to make sure you have the most up to date formulae. After that, run: brew install --with-toolchain llvm. As of the time of writing, this will install llvm-6.0.0. This will vary as new versions are released.

This will compile and take some considerable time, roughly ~90 minutes on a 2017 Macbook Pro.

Setting R to use the newly installed clang and libraries

Homebrew by default does not add the newly installed clang to your path, in preference to the system version. This is a good thing that avoids conflicts. R includes a mechanism for specifying a non-system compiler that works around this. Create a file in the directory ~/.R/ called Makevars, i.e. from the terminal:

mkdir ~/.R
touch Makevars

In that file, add the following lines with one substitution explained below:

CC=/usr/local/opt/llvm/bin/clang
CXX=/usr/local/opt/llvm/bin/clang++
CXX11=$CXX
CXX14=$CXX
CXX17=$CXX
CXX1X=$CXX
LDFLAGS=-L/usr/local/opt/llvm/lib

You will need to add the appropriate prefix before bin and lib to make all of this work. You can get this for the version of llvm you installed by typing: brew --prefix llvm. Change everything before /bin/ in the CC, CXX, and LD lines with your result for this command.

Install RQuantLib

Now you should be able to install R quantlib using OpenMP and the command provided in the link above via the R console: install.packages("RQuantLib", configure.args = "--with-boost-include=/usr/local/include/ --with-boost-lib=/usr/local/lib/", type = "source") `

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment