Applications of Stochastic Processes in Asset Price Modeling

Similar documents
Continuous Processes. Brownian motion Stochastic calculus Ito calculus

Energy Price Processes

23 Stochastic Ordinary Differential Equations with Examples from Finance

One note for Session Two

STEX s valuation analysis, version 0.0

Market Volatility and Risk Proxies

King s College London

Question from Session Two

Monte Carlo Simulations

Economics 883: The Basic Diffusive Model, Jumps, Variance Measures. George Tauchen. Economics 883FS Spring 2015

Math 239 Homework 1 solutions

Computational Finance Improving Monte Carlo

Modeling via Stochastic Processes in Finance

INVESTMENTS Class 2: Securities, Random Walk on Wall Street

3.1 Itô s Lemma for Continuous Stochastic Variables

FINANCIAL MATHEMATICS WITH ADVANCED TOPICS MTHE7013A

Attempt QUESTIONS 1 and 2, and THREE other questions. Do not turn over until you are told to do so by the Invigilator.

1. What is Implied Volatility?

Economics 883: The Basic Diffusive Model, Jumps, Variance Measures, and Noise Corrections. George Tauchen. Economics 883FS Spring 2014

FINANCIAL MATHEMATICS WITH ADVANCED TOPICS MTHE7013A

Attempt QUESTIONS 1 and 2, and THREE other questions. Do not turn over until you are told to do so by the Invigilator.

Dr. Maddah ENMG 625 Financial Eng g II 10/16/06

Module 10:Application of stochastic processes in areas like finance Lecture 36:Black-Scholes Model. Stochastic Differential Equation.

STOCHASTIC CALCULUS AND BLACK-SCHOLES MODEL

Queens College, CUNY, Department of Computer Science Computational Finance CSCI 365 / 765 Fall 2017 Instructor: Dr. Sateesh Mane.

Lecture Note 8 of Bus 41202, Spring 2017: Stochastic Diffusion Equation & Option Pricing

A Poor Man s Guide. Quantitative Finance

Randomness and Fractals

Modelling the Term Structure of Hong Kong Inter-Bank Offered Rates (HIBOR)

King s College London

Simulation Analysis of Option Buying

The Black-Scholes Model

Actuarial Society of India

The Black-Scholes Model

An application of Ornstein-Uhlenbeck process to commodity pricing in Thailand

Computer Exercise 2 Simulation

Monte Carlo Methods for Uncertainty Quantification

Forecasting Life Expectancy in an International Context

- 1 - **** d(lns) = (µ (1/2)σ 2 )dt + σdw t

1 Implied Volatility from Local Volatility

We discussed last time how the Girsanov theorem allows us to reweight probability measures to change the drift in an SDE.

Practical Hedging: From Theory to Practice. OSU Financial Mathematics Seminar May 5, 2008

Computational Finance

The University of Chicago, Booth School of Business Business 41202, Spring Quarter 2011, Mr. Ruey S. Tsay. Solutions to Final Exam.

Modeling Uncertainty in Financial Markets

Numerical schemes for SDEs

Computer Exercise 2 Simulation

Counterparty Credit Risk Simulation

Continuous Time Finance. Tomas Björk

MONTE CARLO EXTENSIONS

ASC Topic 718 Accounting Valuation Report. Company ABC, Inc.

On Arbitrage Possibilities via Linear Feedback in an Idealized Market

Real-World Quantitative Finance

Reading: You should read Hull chapter 12 and perhaps the very first part of chapter 13.

Option Valuation with Sinusoidal Heteroskedasticity

Riccardo Rebonato Global Head of Quantitative Research, FM, RBS Global Head of Market Risk, CBFM, RBS

Spot/Futures coupled model for commodity pricing 1

Homework Assignments

Accelerated Option Pricing Multiple Scenarios

2.1 Mathematical Basis: Risk-Neutral Pricing

OPTIMAL TIMING FOR INVESTMENT DECISIONS

International Financial Markets Prices and Policies. Second Edition Richard M. Levich. Overview. ❿ Measuring Economic Exposure to FX Risk

Math Computational Finance Option pricing using Brownian bridge and Stratified samlping

Lecture 3. Sergei Fedotov Introduction to Financial Mathematics. Sergei Fedotov (University of Manchester) / 6

Computational Methods for Option Pricing. A Directed Research Project. Submitted to the Faculty of the WORCESTER POLYTECHNIC INSTITUTE

Math 416/516: Stochastic Simulation

Using Fractals to Improve Currency Risk Management Strategies

Queens College, CUNY, Department of Computer Science Computational Finance CSCI 365 / 765 Fall 2017 Instructor: Dr. Sateesh Mane.

1 The continuous time limit

Econophysics V: Credit Risk

About Black-Sholes formula, volatility, implied volatility and math. statistics.

Hedging Under Jump Diffusions with Transaction Costs. Peter Forsyth, Shannon Kennedy, Ken Vetzal University of Waterloo

EFFICIENT MONTE CARLO ALGORITHM FOR PRICING BARRIER OPTIONS

Math Option pricing using Quasi Monte Carlo simulation

NEWCASTLE UNIVERSITY SCHOOL OF MATHEMATICS, STATISTICS & PHYSICS SEMESTER 1 SPECIMEN 2 MAS3904. Stochastic Financial Modelling. Time allowed: 2 hours

A new Loan Stock Financial Instrument

BUSM 411: Derivatives and Fixed Income

Probability in Options Pricing

An Analysis of a Dynamic Application of Black-Scholes in Option Trading

Elementary Stochastic Calculus with Finance in View Thomas Mikosch

Monte Carlo Introduction

Lecture 17. The model is parametrized by the time period, δt, and three fixed constant parameters, v, σ and the riskless rate r.

MÄLARDALENS HÖGSKOLA

TEST OF BOUNDED LOG-NORMAL PROCESS FOR OPTIONS PRICING

Sensex Realized Volatility Index (REALVOL)

Volatility of Asset Returns

Optimal Search for Parameters in Monte Carlo Simulation for Derivative Pricing

A No-Arbitrage Theorem for Uncertain Stock Model

IEOR E4703: Monte-Carlo Simulation

Midterm Exam. b. What are the continuously compounded returns for the two stocks?

RISK MITIGATION IN FAST TRACKING PROJECTS

WITH SKETCH ANSWERS. Postgraduate Certificate in Finance Postgraduate Certificate in Economics and Finance

Valuing Early Stage Investments with Market Related Timing Risk

OULU BUSINESS SCHOOL. Ilkka Rahikainen DIRECT METHODOLOGY FOR ESTIMATING THE RISK NEUTRAL PROBABILITY DENSITY FUNCTION

A Comparative Study of Various Forecasting Techniques in Predicting. BSE S&P Sensex

An Introduction to Computational Finance

Practical example of an Economic Scenario Generator

American Option Pricing Formula for Uncertain Financial Market

Chapter 6 Forecasting Volatility using Stochastic Volatility Model

Stochastic Processes and Stochastic Calculus - 9 Complete and Incomplete Market Models

Transcription:

Applications of Stochastic Processes in Asset Price Modeling TJHSST Computer Systems Lab Senior Research Project 2008-2009 Preetam D Souza May 26, 2009 Abstract Stock market forecasting and asset price modeling have recently become important areas in the financial world today. The increasing complexity of the stock market and the lucrative field of investment management has fueled breakthrough developments in mathematical stock price modeling. New financial instruments that rely on an underlying asset s price in the future to determine their current price require accurate methods of stock modeling. One method of mathematical modeling uses random or pseudorandom methods known as stochastic processes to determine an asset s price in the future. This project aims to demonstrate the flexibility and accuracy of these stochastic models by implementing them in code and testing them against empirical data. The main model tested in this project will be the Geometric Brownian Motion diffusion process and it will be analyzed with a variety of stocks, both stable and volatile, to appreciate an understanding of its strengths and weaknesses during differing market conditions. Keywords: Stochastic processes, Brownian Motion, Financial Derivatives, Asset Price Modeling 1

Contents 1 Introduction 3 1.1 Scope of Study................................... 3 1.2 Expected results.................................. 3 1.3 Rationale...................................... 3 2 Theory 4 3 Procedures and Methodology 4 3.1 Structure...................................... 4 3.2 Model Inputs.................................... 5 3.3 Model Accuracy.................................. 5 4 Current Results 5 A Additional Simulation Runs 9 A.1 Google........................................ 9 A.2 Wal-Mart...................................... 10 A.3 Honda Motor Company.............................. 11 B Source code 12 B.1 Main model class.................................. 12 B.2 Geometric Brownian class............................. 13 B.3 Statistics class................................... 13 2

1 Introduction 1 Introduction 1.1 Scope of Study This project examines stochastic processes to predict stock price movements. Given the current price, volatility, and expected return of an arbitrary stock, several stochastic models exist to predict changes in price. The main model that will be implemented and tested is Geometric Brownian Motion (GBM), an adaptation of the standard Brownian Motion process. A standard Brownian Motion model assumes that stock prices themselves follow a random walk process. GBM, on the other hand, assumes that stock price returns, not specifically the price, follow a stochastic process. The goal of this project is to extensively test both of these models against empirical data for a single stock (IBM) to determine accuracy. Additionally, this project seeks to develop possible variance reduction techniques that improve the validity of both models. In order to test the models against empirical data, historical prices for a specific stock (such as IBM) in the past over an arbitrary time period are required. Yahoo! Finance has free stock price data in the past for many large companies and data from this website will be used for this experiment. 1.2 Expected results I expect that the stochastic modeling techniques will approximate a stock s change in price after running many simulated trials and fine-tuning the model. Over several runs, the model should converge to the actual stock price fluctuations. The results of the project can be shown visually through graphs. For example, historical IBM stock prices can be plotted along with the simulated run of the stock to show the accuracy of the model. If this project is successful, it could be of use to financial companies that use investment models to determine how to hedge their portfolios against risk. Improved methods of variance reduction to improve accuracy of these models also hold value for derivative pricing. Results from this project could also be used to further develop the implemented algorithms to more accurately model stock prices. In general, data garnered in this experiment will presumably reveal whether stochastic based models are accurate in predicting complex stock price movements. Calibration testing will also potentially reveal possible improvements to the current models. 1.3 Rationale Implementation of these stochastic models and extensive testing will lead to results that help to determine the accuracy and validity of these models when they are used to predict stock prices. Several financial firms tend to use these models to price their complex financial instruments and thus require a high degree of certainty that their models are correct to prevent risk and potential losses. Invalid models used to price these instruments can lead to potential mishaps for the entire economy; this can easily be seen in the housing market collapse and subsequent chaos on Wall Street where firms did not know the correct value of their mortgage-backed securities. Eliminating these models and developing improvements to them can lead to greater fundamental knowledge behind human behavior and more accurate asset pricing methods. 3

3 Procedures and Methodology 2 Theory Stochastic processes are can be represented with stochastic differential equations (SDEs) that describe changes in different quantities. Let S be the stock price, µ the drift rate (or mean), σ the volatility (or variance) of the stock, and let dz represent a Wiener Process. dz = φ dt where φ is drawn from a normal distribution N (0, 1). The SDE for Geometric Brownian Motion is given by: ds = µdt + σdz S Here ds represents the return on the stock. Multiplying by S to both sides of the equation S one obtains: ds = µsdt + σsdz This shows that the stock price cannot change once S = 0, which is a requirement for this model to accurately represent stock prices. 3 Procedures and Methodology 3.1 Structure After research of the theory behind these models, the actual models were implemented in code. Java was chosen as the prime programming language for all phases of this project. First, an RSS based class was created to retrieve real-time stock price data for an given stock from a free financial website. This will be used in later development to predict present movements of a stock price. A main statistics class was also created to act as a simple resource for calculating the mean, variance, and standard deviation for a list of a stock s historical prices over an arbitrary time period. The main model class is responsible for data parsing and simulation. This class reads in historical price data and utilizes the aforementioned statistical convenience class to calculate inputs to the model. Once these are determined, the simulation process begins. Currently, a Geometric Brownian Motion model is being used, but this class can easily be adopted to other models as long as they follow the same convention. These stochastic models were implemented using a discrete iterative algorithm to approximate the continuous time forms of the theoretical models. During the simulation, price changes over the given trading period (usually 1 day) are printed out to a file formatted to easily be plotted with Gnuplot. This model supports simultaneous simulations so that several different sample paths for a stock price can be plotted on the same graph. Stock prices over one year can be intuitively plotted on graphs to display the price fluctuations with a smooth curve drawn through the discrete points. Charts of key prices over a year can also be provided to demonstrate potential variations in the model from the empirical data. 4

4 Current Results 3.2 Model Inputs There are two main inputs to the Geometric Brownian Motion model that are obtained from empirical data in the past. The first is µ, the drift (mean) of the stock price s returns over the chosen period for analysis. This attribute is useful in determining the overall general drift rate of the stock and hence signals the direction towards which a stock tends to move over a long period of time. This is obtained by calculating the mean of the stock price s returns. Let S i represent the ith stock price, then: µ = 1 n n i=1 S i The other input is the volatility, or standard deviation, of the empirical data from the past. Let σ represent the volatility, then a reasonable algorithm for calculating the volatility is 1 : ( σ = 1 n n ) 2 Si 2 n 1 1 S i n 3.3 Model Accuracy i=1 The accuracy of the model with respect to empirical data can be estimated by calculating the Root Mean Squared Deviation (RMSD) of the data sets. This is a measure of the average of the squared errors between the model and the empirical data. Let S i represent the empirical price and Ŝi represent the simulated price. The RMSD is then defined as: RMSD = 1 n (Ŝi S i ) n 2 A large value indicates large deviations between the empirical data and the model, while a value close to zero represents a good fit. 4 Current Results The current model calculates simulated price changes for a stock and outputs them to a file that can be easily plotted along with the empirical price graph. Figures 1 and 2 on the next page demonstrate two different simulation runs of the Geometric Brownian model. The empirical data used for these runs are the IBM opening prices from January 1990 to January 1991. IBM was chosen to be an initial stock used for analysis due to its status as a bluechip stock and hence its general stability over several years. Each run is plotted with the empirical price curve and three simulation paths. In Figure 1, notice how one simulation path runs far off the drift line while the other two move with the empirical data. In Figure 2, all three simulations hug the drift line and closely approximate the historical price changes. Different sample runs of this model can produce dramatically different results, although they can all be considered valid paths for a stock price to take. Note that these figures are only 1 This algorithm is justified by the following relationship in probability theory: V ar(x) = E(X 2 ) E(X) 2, where V ar(x) is the variance of a random variable X and E(X) is the expected value of X. i=1 i=1 5

5 Conclusions demonstrating how accurately the Geometric Brownian process can fit empirical data in the past. Figures 3 and 4 on the next page demonstrate the accuracy of the Geometric Brownian model for the time period January 1991 to January 1992 for IBM stock. 1991-1992 was an overall bear session for IBM stock as its value steadily declined from $113 to $89. In Figure 3, it can easily be observed how the GBM model overestimates IBM growth for this period due to the fact that the drift rate is positive. Each simulation tends to be centered around the mean line, and thus the averaged simulation predicts a price that is a full $30 above the actual closing price. However, sometimes the GBM model can produce accurate results even in a down market, which can be seen in Figure 4. Seemingly against all odds, each run in this simulation runs below the drift line and yields an averaged ending price that is within $10 from the empirical closing price. The following graphs display just how variable each simulation can be; sometimes the model can produce accurate results but many other times it can either overestimate or underestimate a stock s potential for growth. A large part of the model is based on past data, so the importance of the choice of data for calculating the model inputs should not be neglected. See Appendix A for sample simulation runs on Google, Wal-mart, and Honda Motor Company shares. 5 Conclusions From the numerous trials of the Geometric Brownian Motion model under varying market conditions, it appears that it is capable of accurately representing stock price movements. The stochastic differential equations that govern the GBM model seem to be a fairly reasonable mathematical model for anticipating price changes based on historical price data. However, it is prudent to keep in mind that there is no certain consistency to the model s predictions. The inherent randomness associated with the general Weiner process that governs GBM gives rise to an unpredictable and occasionally highly volatile model. One way of dealing with volatility issues is to run several simulations and average them all together to obtain an averaged simulation run. Unfortunately, extensive averaging smooths out the stochastic nature of the model and destroys its defining characteristic of seemingly random motion. In this case, the model approaches the linear drift line of the given stock. In this project, three simulations were averaged together in order to mitigate volatility while preserving the model s stochastic nature. Given the strengths and weaknesses of the GBM model, it is insufficient to wholly concentrate on this individual model when determining investment decisions in the equity markets. Human judgmenet and other traditional forms of investment research should be used in conjunction with the GBM model in order to offset potential errors in the model s predictions. The GBM model may be especially useful in determining complex derivative prices that cannot be priced with the standard Black-Scholes formula. When used carefully, the GBM model can be a powerful tool in influencing investment decisions. 6

5 Conclusions Figure 1: Simulation 1 for IBM stock during January 1990-1991 Figure 2: Simulation 2 for IBM stock during January 1990-1991 7

5 Conclusions Figure 3: Simulation 3 for IBM stock during January 1991-1992 Figure 4: Simulation 4 for IBM stock during January 1991-1992 8

A Additional Simulation Runs A Additional Simulation Runs A.1 Google Figure 5: Simulation 1 for Google stock during April 2008-2009 Figure 6: Simulation 2 for Google stock during April 2008-2009 9

A Additional Simulation Runs A.2 Wal-Mart Figure 7: Simulation 1 for Wal-Mart stock during April 2008-2009 Figure 8: Simulation 2 for Wal-Mart stock during April 2008-2009 10

A Additional Simulation Runs A.3 Honda Motor Company Figure 9: Simulation 1 for Honda stock during April 2008-2009 Figure 10: Simulation 2 for Honda stock during April 2008-2009 11

B Source code B Source code B.1 Main model class // Preetam D Souza // 2. 1 7. 0 9 / I n p u t : H i s t o r i c a l s t o c k p r i c e s i n. c s v f o r m a t P r o c e s s : Parse h i s t o r i c a l p r i c e d a t a and o b t a i n u s e f u l s t a t i s t i c s s u c h a s mean and v a r i a n c e o f s t o c k p r i c e s. S i m l u l a t e t h e p r i c e s u s i n g t h e d i s r e t e t i m e form o f t h e Geometric Brownian p r o c e s s. Output : S i m u l a t e d s t o c k p r i c e s o v e r t h e s e t t i m e frame. Format : <Time Step> <empirical > <sim 1> <sim 2>... <sim n> <avg> <mean> / import j a v a. u t i l. ; import j a v a. i o. ; public c l a s s Model1 s t a t i c f i n a l int NUM = 3 ; // number o f s i m u l a t i o n s public s t a t i c void main ( String [ ] args ) throws Exception double d r i f t ; double v o l a t i l i t y ; double dt ; // t i m e s t e p double c u r p ; // i n i t i a l p r i c e // I n p u t P a r s i n g S t r i n g [ ] months = Jan, Feb, Mar, Apr, May, Jun, J u l, Aug, Sep, Oct, Nov, Dec ; ArrayList<Double> p r i c e s = new ArrayList<Double > ( ) ; System. out. p r i n t ( \ n P a r s i n g H i s t o r i c a l P r i c e s... ) ; PrintWriter pout = new PrintWriter (new BufferedWriter (new FileWriter ( HMC. txt ) ) ) ; PrintWriter sout = new PrintWriter (new BufferedWriter (new FileWriter ( simulation avg. txt ) ) ) ; Scanner s c = new Scanner (new F i l e ( HMC 07 08. c s v ) ) ; s c. n e x t L i n e ( ) ; pout. p r i n t f ( #Date\ t \topen \ thigh \tlow \ t C l o s e \n ) ; while ( s c. hasnext ( ) ) S t r i n g [ ] s = s c. n e x t L i n e ( ). s p l i t ( \\, ) ; pout. p r i n t f ( %s %s %s \ t%s \ t%s \ t%s \ t%s \n, s [ 0 ]. s u b s t r i n g ( 8, 1 0 ), months [ I n t e g e r. p a r s e I n t ( s [ 0 ]. s u b s t r i n g ( 5, 7 ) ) 1 ], s [ 0 ]. s u b s t r i n g ( 2, 4 ), s [ 1 ], s [ 2 ], s [ 3 ], s [ 4 ] ) ; p r i c e s. add ( Double. parsedouble ( s [ 1 ] ) ) ; System. out. p r i n t l n ( Done! \ n ) ; // S t a t i s t i c s c a l c u l a t i o n s o f d r i f t r a t e and v o l a t i l i t y System. out. p r i n t ( C a l c u l a t i n g i n p u t data s t a t i s t i c s... ) ; double [ ] p = new double [ p r i c e s. s i z e ( ) ] ; // p r i c e s ( r e c e n t t o l a t e s t o r d e r ) double [ ] r norm = new double [ p r i c e s. s i z e ( ) 1 ] ; // normal r e t u r n s double [ ] r l o g = new double [ p r i c e s. s i z e ( ) 1 ] ; // l o g r e t u r n s f o r ( int i =0; i <p. l e n g t h ; i ++) p [ i ] = p r i c e s. g e t ( i ) ; f o r ( int i =0; i <r l o g. l e n g t h ; i ++) r norm [ i ] = ( p [ i ] / p [ i +1]) 1.0; r l o g [ i ] = Math. l o g ( p [ i ] / p [ i + 1 ] ) ; dt = ( 1. 0 / p. l e n g t h ) ; // e a c h t i m e s t e p i s one day Stat s = new Stat ( ) ; d r i f t = s. mean ( r norm ) ; v o l a t i l i t y = s. sdev ( r l o g ) Math. s q r t ( p. l e n g t h ) ; // a n n u a l i z e d v o l a t i l i t y c u r p = p [ 0 ] ; // f o r n e x t y e a r s m o d e l i n g System. out. p r i n t f ( Done! \ n D r i f t : %f \ t A n n u a l i z e d V o l a t i l i t y : %f \n\n, d r i f t, v o l a t i l i t y ) ; // S i m u l a t i o n double ds ; double mean line = cur p ; double avg = 0 ; System. out. p r i n t ( Running S i m u l a t i o n... ) ; s o u t. p r i n t f ( 0 %.5 f, p [ p. l e n g t h 1 ] ) ; GeoBrownian [ ] g = new GeoBrownian [NUM] ; f o r ( int i =0; i <g. l e n g t h ; i ++) g [ i ] = new GeoBrownian ( cur p, d r i f t, v o l a t i l i t y ) ; avg += g [ i ]. g e t P r i c e ( ) ; s o u t. p r i n t f ( %.5 f, g [ i ]. g e t P r i c e ( ) ) ; s o u t. p r i n t f ( %.5 f %.5 f \n, avg / ( ( double )NUM), m e a n l i n e ) ; m e a n l i n e += ( m e a n l i n e d r i f t ) ; f o r ( int t =1; t<p. l e n g t h ; t++) avg = 0 ; s o u t. p r i n t f ( %d %.5 f, t, p [ p. l e n g t h t 1 ] ) ; 12

B Source code f o r ( int i =0; i <g. l e n g t h ; i ++) g [ i ]. p r o c e s s ( dt ) ; avg += g [ i ]. g e t P r i c e ( ) ; s o u t. p r i n t f ( %.5 f, g [ i ]. g e t P r i c e ( ) ) ; s o u t. p r i n t f ( %.5 f %.5 f \n, avg / ( ( double )NUM), m e a n l i n e ) ; m e a n l i n e += ( m e a n l i n e d r i f t ) ; System. out. p r i n t l n ( Done! \ n ) ; s o u t. p r i n t f ( #Mean : %f \n#v o l a t i l i t y : %f \n, d r i f t, v o l a t i l i t y ) ; s c. c l o s e ( ) ; pout. c l o s e ( ) ; s o u t. c l o s e ( ) ; B.2 Geometric Brownian class // Preetam D Souza / T h i s c l a s s s i m u l a t e d d i s c r e t e c h a n g e s i n s t o c k p r i c e u s i n g a g e o m e t r i c b r o w n i a n p r o c e s s. / import j a v a. u t i l. ; public c l a s s GeoBrownian private double c u r p r i c e ; private double mu; private double sigma ; public GeoBrownian ( double p r i c e, double d r i f t, double v o l a t i l i t y ) c u r p r i c e = p r i c e ; mu = d r i f t ; sigma = v o l a t i l i t y ; public double getprice ( ) return c u r p r i c e ; public void s e t P r i c e ( double p r i c e ) c u r p r i c e = p r i c e ; public double g e t D r i f t ( ) return mu; public void s e t D r i f t ( double d r i f t ) mu = d r i f t ; public double g e t V o l a t i l i t y ( ) return sigma ; public void s e t V o l a t i l i t y ( double v o l a t i l i t y ) sigma = v o l a t i l i t y ; // p r i c e c u r r e n t s t o c k p r i c e // mu d r i f t p a r a m e t e r // sigma s t o c k v o l a t i l i t y // d t t i m e s t e p ( u s u a l l y 1/ t r a d i n g p e r i o d s ) public double process ( double dt ) double phi ; double ds, dz ; B.3 Statistics class Random r = new Random ( ) ; phi = r. nextgaussian ( ) ; dz = phi Math. s q r t ( dt ) ; ds = c u r p r i c e (mu dt + sigma dz ) ; c u r p r i c e += ds ; return ds ; // Preetam D Souza // Based on P h i l i p Barker s DataDisperion package / C o n v e n i e n c e c l a s s t o i mplement s t a t i s t i c s a l g o r i t h m s f o r c a l c u l a t i n g t h e mean, v a r i a n c e and s t a n d a r d d e v i a t i o n f o r a d a t a s e t. 13

B Source code / // S t a t. j a v a import j a v a. u t i l. ; public c l a s s S t a t public S t a t ( ) public sta tic double mean ( double [ ] x ) double t o t a l = 0. 0 ; f o r ( int i =0; i <x. l e n g t h ; i ++) t o t a l += x [ i ] ; return t o t a l /x. l e n g t h ; public s t a t i c double v a r i a n c e ( double v1 [ ] ) double sumd = 0. 0 ; double t o t a l = 0. 0 ; f o r ( int i =0; i <v1. l e n g t h ; i ++) t o t a l += v1 [ i ] ; sumd += Math. pow ( v1 [ i ], 2 ) ; return ( sumd ( t o t a l ( t o t a l / v1. l e n g t h ) ) ) / ( ( v1. l e n g t h ) 1); public s t a t i c double sdev ( double v1 [ ] ) return Math. s q r t ( v a r i a n c e ( v1 ) ) ; 14

References References [1] Balaji, Raman. Introduction to Stochastic Finance, University of Connecticut. [2] Barker, Philip. Java Methods for Financial Engineering, Springer Publishing, May 2007. [3] Charnes, John. Using Simulation for Option Pricing School of Business, The University of Kansas. [4] Chance, Don. Essays in Derivatives, Wiley Publishing, August 1998. [5] Forsyth, Peter. An Introduction to Computational Finance without Agonizing Pain, School of Computer Science, University of Waterloo. [6] Straja, Sorin. Stochastic Modeling of Stock Prices, Montgomery Investment Technology, Inc. 15