Giter Club home page Giter Club logo

af-rcpp-2023-2024's Introduction

AF-RCPP-2023-2024

This repository contains materials to the "Applied Finance" course at the University of Warsaw, Faculty of Economic Sciences in academic year 2023/2024. Materials refer to the part "Path dependent option pricing with Monte Carlo simulations and Rcpp package".

The aim of this short course is to provide techniques of incorporating c++ code into R environment. Three techniques will be discussed:

  • cppFunction() function - for short inline c++ code chunks
  • sourceCpp() function - for longer c++ code chunks located in separate *.cpp files
  • Rcpp package - for a project that consist of 2 or more files

The Rcpp package will be used to provide function defined in c++ which will be responsible for providing valuations of path-dependent option of European style using the Monte Carlo simulation technique.

To earn credits for this part of the curse, students will have to provide solutions to their individual home projects which will concentrate on valuation of a specific path-dependent option.

Schedule

Lecture #1

Slides with:

  • introduction to options,
  • option payoff profiles,
  • factors which influence option price
  • Black-Scholes-Merton (BSM) pricing formula for European options
  • elements of Monte Carlo simulations for valuation of path-depending options

To create slides/slides.pdf open slides/slides.Rmd and run knit to PDF (Beamer) by pressing Ctrl+K.

Labs #1

We will use the script scripts/intro2Rcpp.R. Following elements will be discussed:

  • introduction to the Rcpp package
  • "importing" c++ code to R using two functions: cppFunction() and sourceCpp() * simple implementations in R of functions defined in c++ code.

Lecture #2

The aim is to compare of efficiency of Monte Carlo European Call option pricing techniques. The script scripts/pricingComparison.R will be used. We will compare following techniques:

  • using loops in R
  • using vectors in R
  • using loops in C++, via Rcpp
  • using vectors in R with antithetic sampling

We also introduce a simple c++ application which runs in Command Line (Windows) or terminal (Linux/MacOS). To compile its source code into executable file you can use one of the popular IDEs (Microsoft Visual Studio, CLion, Code Blocks), code editors (VS Code, Xcode, Sublime Text, Vim, and many others) or even simple text editors (just to mention Notepad++ on Windows).

I highly recommend here trying VS Code for this. Below you will useful information how to set up VS Code for work with c++ code using the GCC compiler. Its very simple and shouldn't take your more than 5 minutes!

Labs #2

The task is to build the optionPricer2 package on the basis of code of the programs/prog2 application. Once we do this, we will then use function/functions of this package in the little playground provided inside the script scripts/optionPricer2Application.R.

Creating an R package

Below you will find steps to create an Rcpp package named optionPricer2, where code from progs/prog2 is used.

  1. In RStudio:
  • File -> New Project -> New Directory -> R Package ->
  • Type: package w/ Rcpp
  • Package name: optionPricer2
  • give appropriate path
  1. Copy your source files (*.cpp) and header files (*.h) from progs/prog2 to projects/optionsPricer2/src/ folder.

Although you may safely delete RcppExports.cpp and rcpp_hello.cpp, I would recommend to keep them, as they may serve in the next steps as hints in terms of syntax.

  1. Include necessary changes projects/optionsPricer2/src/main.cpp:
  • add before definition of your function: using namespace Rcpp;
  • add before definition of your function: #include <Rcpp.h>
  • add directly before definition of your function: // [[Rcpp::export]]
  • change the name of the main() function and type of returned value according to your needs
  • include necessary arguments for this function
  • double check the returned object at the end of the function

Repeat these actions for any other function you would like to include in the package.

  1. Fill free to edit DESCRIPTION file. However be careful! You must not change names of fields or change the inner structure of the file.

  2. Build your package: either source package or binary package, or both of them:

  • menu Build -> Build Source Package
  • menu Build -> Build Binary Package

This will create zip and/or tar.gz files with your package. By default, they will be located next to the folder with the package.

  1. This archive file (*.zip or *.tar.gz) could be then installed with:
  • install.packages("binary-package-filename.zip", type = "binaries", repos = NULL)
  • install.packages("source-package-filename.tar.gz", type = "source", repos = NULL)

See scripts/optionPricer2Application.R to examine the example.

Grading Policy

  • Each participant will get by 2023-12-10 an assignment with an individual home project.
  • The aim of the project will be to apply Monte Carlo techniques to provide an approximation of the path-dependent option.
  • The solution should be delivered in a form of a Rcpp-package, along with a short implementation of the function/functions which are provided by this package.
  • All codes from the lectures and labs can be used in the solutions.
  • A short report will be required.
  • Solutions in a form of a private Github/GitLab/Bitbucket repository will get premium points!

Happy learning! :-)

  • If you need any sort of help, feel free to message me.
  • Do not be afraid to ask question! Asking question is super important to your growth!
  • No question is a stupid question!
  • I'm available on [email protected]

af-rcpp-2023-2024's People

Contributors

pawelsakowski avatar

Stargazers

Shanth Vidyababu avatar Eachan avatar yuranus avatar Vladimir Shargin avatar  avatar EVRIM BILGEN avatar  avatar Orkhan Amrullayev avatar  avatar Kamil Korzen avatar  avatar  avatar Zimin avatar Jorge Bueno Perez avatar

Watchers

James Cloos avatar  avatar Kostas Georgiou avatar M.Saeed Pourjafar avatar  avatar Zimin avatar Artur Skowroński avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.