php rdemo jan2006

Upload: alonso-ruelas

Post on 04-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Php Rdemo Jan2006

    1/1

    Analysing options in R

    This is a demonstration of thebasic features of R for fi-nance, prepared for students in the UNISA Programmein Mathematical Modelling of Derivatives.

    What is R ?

    R is a computer language for statistical and mathemat-ical analysis. It is similar to the commercial system S,developed at Bell Laboratories . R is available for theoperating systems AIX, FreeBSD, GNU/Linux, HPUX,Irix, MacOS X, Solaris, as well as for Microsoft Windows(9x, ME, NT4, 2000, XP).http://www.r-project.org/

    What is QuantLib?

    QuantLib is a free and open-source library for finance.It aims to provide a comprehensive software frameworkfor numerical finance by providing a standard free/opensource library for modeling, trading, and risk manage-ment of financial assets. http://www.quantlib.org/

    Why free and open-source software?

    Open-source software is not only free but may also bemodified, installed on arbitrarily many machines, studiedand maintained by anyone.

    Starting RQuantLib

    In Linux the R environment, if installed, is invoked bysimply typing R and pressing the Enter key in a a ter-minal window. In order to use the QuantLib functionsthat have been ported toR , the library should be loadedwith the command library(RQuantLib) from inside theR environment.

    European options in R

    The Black-Scholes formula is implemented in R and canbe used right away for the pricing of European options on

    non-dividend paying assets. Simply pricing an option isaccomplished by a command like

    EuropeanOption("call", underlying = 100,

    strike = 100, dividendYield = 0.00,

    riskFreeRate = 0.07, maturity = 1,

    volatility = 0.35)

    for an at-the-money call option, or an abbreviated versionof this command,

    EuropeanOption("call",100,100,0.00,0.07,1,0.35)

    and the output of either command is

    Concise summary of valuation for EuropeanOption

    value delta gamma vega theta rho divRho

    17.0675 0.6462 0.0106 37.1855 -9.8359 47.5495 -64.6170

    which gives quite a bit of information about the option!One can also build arrays of values

    und