lecture 4 finance pro ject somesh jha 1 lo w lev el
play

Lecture 4 Finance Pro ject Somesh Jha 1 Lo w-Lev el Design - PDF document

Lecture 4 Finance Pro ject Somesh Jha 1 Lo w-Lev el Design do cumen t W e will call the Lo w-Lev el Design do cumen t LLD from no w on. Be v ery detailed. Programming should b e a v ery small


  1. Lecture 4 Finance Pro ject Somesh Jha 1

  2. Lo w-Lev el Design do cumen t W e will call the Lo w-Lev el Design do cumen t � LLD from no w on. Be v ery detailed. Programming should b e a � v ery small step after this do cumen t is o v er. State the language upfron t. W e will b e � using and hence Ob ject-Orien ted JAVA Programming. Men tion eac h ob ject with its purp ose and � description of the constructors and the metho ds whic h can b e called from outside (these will b e the metho ds in public JA V A). 2

  3. LLD (Con td) Order y our ob jects b y uses relation. F or � example, if is used b y ob ject describ e O O 1 2 �rst. In case of recursion, pic k an order O 1 arbitrarily . Indicate if a class extends some other class � or if a class is going to b e abstract. Also, giv e a short rationale wh y did y ou c ho ose to mak e a certain class abstract. Revisit the LLD while/after doing th � implemen tation. Y ou will b e stra ying from the design a little bit. W e will use LLD and additional information to understand and test y our co de. 3

  4. Logistics Due Date: 12,1999 . Feb � Remem b er more detail the b etter. � This will mak e y our job while implemen tation v ery easy . Also try to distribute w ork so that di�eren t � p eople w ork on descriptions of di�eren t ob jects. Men tion clearly who is resp onsible for whic h � ob ject. The p erson describing the design of an ob ject will also implemen t it. In the implemen tation the author of eac h ob ject should b e men tioned v ery clearly in the header �les. 4

  5. Logistics (Con td) There should b e one system in tegrator who � will tak e descriptions/implemen tation of the ob jects and see whether they all �t together. The of the program will b e put main loop together b y the system in tegrator. Men tion the roles of the team mem b ers in � the do cumen t. After a team mem b er implemen ts an ob ject, � another team mem b er should r eview the co de. Y ou will b e surprised ho w man y silly errors y ou will catc h during review. Men tion the review er in the header �le with the ob ject (along with the author of-course). 5

  6. Implemen tation Due date: 1999 . March 1, � Mak e sure y ou ha v e clear instructions � describing ho w to use the system. State limiting assumptions y ou made while � implemen ting. Please giv e a phone n um b er of a p erson w e � can call in case w e ha v e di�cult y running y our system. This p erson should preferably b e the system in tergrator b ecause he/she has the o v erall idea ab out y our system. 6

  7. ob ject MortgagePool Obje ctName: ob ject. MortgagePool � Extends: Object . � Implements: None. � Uses: None. � Constructor � A single constructor whic h tak es v arious parameters of the mortgage p o ol. Please see Lecture 2. Assumption: I am going to assume a homogeneous mortgage p o ol. 7

  8. ob ject (Con td) MortgagePool Metho d: � double[] cashFlows(double SMMS[]) T ak es as parameter arra y of SMMs for v arious times and returns arra y of cash-�o ws for eac h time up=�-to the lifetime of the mortgage. Assume that arra y of SMMs has same size as the lifetime of the mortgage p o ol. Metho d: � double next-cash-flow(double SMM) This allo ws the ob ject to b e used in an iter ative mo de . Whenev er, this metho d is called the cash-�o w in the curren t time p erio d is returned and the curren t time p erio d in the mortgage p o ol is incremen ted. 8

  9. The parameter SMM determines the prepa ymen t for this time p erio d. 9

  10. ob ject BondObject Name: BondObject . � Extends: Object . � Implements: None. � Uses: None. � Constructor � Name of the �le/database (with the b ond data) is passed to the constructor. W e will assume that the b ond data is in a �le with all the required quan tities. 10

  11. ob ject (Con td) BondObject Metho ds: � double yield(t,T) Yield at time of a zero-coup on b ond t maturing at time . T double price(t,T) Price at time of a zero-coup on b ond t maturing at time . T double volatility(t,T) V olatilit y at time of a zero-coup on b ond t maturing at time . T This ob ject will b e used in pricing Note: � MBS with deterministic cash-�o ws. Please see Lecture 3 for a closed form expression. 11

  12. ob ject NormalRandom Name: NormalRandom . � Extends: None. � Uses: java.util.Random . � Constructor: � T ak e the mean and v ariance as parameters and record it in ternally . W e will generate t w o n um b ers with Normal distribution with mean and v ariance v . m 12

  13. ob ject (Con td) NormalRandom Metho d: � double[] nextRandom() Generate two random n um b ers with standard normal distribution. Metho d w e will follo w is due to Bo x-Muller-Marsagli a. Please see next slide for a description of the metho d. Before returning the random n um b ers apply the appropriate transform to matc h the mean and the v ariance giv en in the constructor. Using the follo wi ng transformation p ( x + m ) v 13

  14. Bo x-Muller-Marsaglia metho d . This algorithm is also called the p olar � metho d . Step 1 � Generate t w o random v ariables and U U 1 2 (use the metho d nextDouble ) in the class java.util.Random . T ransform these v ariables according to the equations giv en b elo w: = 2 U 1 V � 1 1 = 2 U 1 V � 2 2 14

  15. Bo x-Muller-Marsagalia (Con td) Step 2 � Compute according to the equation giv en S b elo w: 2 2 + V V 1 2 Step 3 � If 1, go to step 1. S � Step 4 � Return and giv en b y the equations: X X 1 2 v � 2 ln S u = X V u 1 1 t S v � 2 ln S u = X V u 2 2 t S Steps 1 through 3 are executed 1.27 Note: � times on the a v erage with standard deviation of 0.587. So w e are not returning to Step 1 to o man y times. 15

  16. InterestRate Name: InterestRate . � Extends: None. � Implements: None. � Uses: NormalRandom . � Constructor � W e will use the Co x-Ingersoll-Ro ss mo del. Constructor will tak e all the parameters as argumen ts. Please see the SDE giv en b elo w: p = � ( � ) dt + dr r � r dW � The parameters � , � , , and the initial � short rate are passed to the constructor. r 0 Assumption: The mo del has already b een calibrated. 16

  17. ob ject (Con td) InterestRate Metho d � void instantiate(double N,double T) P arameter is the time horizon. is the T N n um b er of discrete time steps w e will divide the time in terv al in to. [0,T] Assumption: W e assume that is in T mon ths and has gran ularit y of at-least a N mon th. Metho d: � double[] nextPath() Generates a random path where the t -th elemen t in the arra y is the short rate at the t -th time. Let b e the step size giv en b y h 17

  18. the follo wi ng expression: T N Generate random path according to the follo wi ng recurrence equation: s ( i + 1) = � ( � ( i )) h + ( i ) (0 ; h ) r r � r N � where r ( i ) is the short rate at the discrete time step and (0 ; h ) is a random n um b er i N with normal distribution (mean 0 and v ariance h ). Use metho d in ob ject is used to generate this NormalRandom n um b er. 18

  19. ob ject PrePayment Name: PrePayment . � Extends: None. � Implements: None. � Uses: None. � Constructor � P ass a �ag indication whic h option of prepa ymen t function is going to b e used (see Lecture 3 for explanation of the options). F or option A pass a v ector of PSAs and for option B pass the v arious parameters . � ; � ; � 1 2 3 19

  20. (Con td) PrePayment Metho d: double[] smmVector(int T) � Use only with option A. Returns the v ector of SMMs upto time horizon . T Metho d: double smmRandom(double � pi,double rf7, double burnout,double season) Giv es the random SMM giv en the required parameters. Please see Lecture 3 for the explanation. Need a random n um b er with P oisson Distribution ( Haven't described here ). it 20

  21. PassThrough Name: PassThrough . � Extends: None. � Implements: None. � Uses: MortgagePool , InterestRate , � BondObject , and PrePayment . Constructor � P ass an ob ject of t yp e MortgagePool , InterestRate , Prepayment , BondObject , and time horizon to the constructor. is the underlying mortgage MortgagePool p o ol for the pass-through securit y . 21

Recommend


More recommend