Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
R Object-oriented Programming

You're reading from   R Object-oriented Programming A practical guide to help you learn and understand the programming techniques necessary to exploit the full power of R

Arrow left icon
Product type Paperback
Published in Oct 2014
Publisher
ISBN-13 9781783986682
Length 190 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Kelly Black Kelly Black
Author Profile Icon Kelly Black
Kelly Black
Arrow right icon
View More author details
Toc

Examples

We will now provide a brief example to demonstrate how to use the Simulation and MonteCarlo classes described in the previous sections. We focus on the discrete simulation class, but additional examples can be found in the code that accompanies this text. In this example, we assume that the definitions for the simulation and MonteCarlo classes are contained in two files, simulationS3.R and monteCarloS3.R.

The Monte-Carlo simulations can be created by first creating an object from the MontyCarlo class and setting the values of the parameters as follows:

> source('simulationS3.R')
> source('monteCarloS3.R')

> monty <- MonteCarlo()
> monty$setParams(100,1,
                1.0,2.0,
                1.2,-0.3,0.65,0.2,
                0.03,0.04)

Now that an object from the MonteCarlo class is defined, an object from the DiscreteSimulation class is created, and the simulation object is used to generate the results from 500 simulations:

> a <- DiscreteSimulation...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image