Financial Engineering Project Course. Lecture 3 Object Oriented Design Inheritance Abstract Base Classes Polymorphism Using XML to represent the swap.

Slides:



Advertisements
Similar presentations
Data Structures Lecture 2 Fang Yu Department of Management Information Systems National Chengchi University Fall 2011.
Advertisements

Java Exceptions. Types of exceptions  Checked exceptions: A checked exception is an exception that is typically a user error or a problem that cannot.
CS102--Object Oriented Programming Discussion 2: (programming strategy in java) – Two types of tasks – The use of arrays Copyright © 2008 Xiaoyan Li.
Week 5 Using snoop.jsp under Jigsaw Using JavaBeans with JSP Instance variables and local variables An application using JSP, JavaBeans, and FpML An application.
Lecture 4 Java Interfaces (review of inheritance and abstract classes) The XML DOM Java Examples Homework 3.
Internet Technologies 1 Lecture 1 Introduction.
Summer A-2000, Project Course-- Carnegie Mellon University 1 Financial Engineering Project Course.
March 2004Object Oriented Design1 Object-Oriented Design.
Object-Oriented Programming MISM/MSIT Carnegie Mellon University Professor Roehrig’s Notes.
Summer A-2000, Project Course-- Carnegie Mellon University 1 Financial Engineering Project Course.
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
Financial Engineering Project Course. Lecture 2 Swaps Homework 2 More Java Fundamentals.
OCT1 Java and XML (DOM and SAX) Some of the material for these slides came from the following sources: “XML a Manager’s Guide” by Kevin Dick “The XML Companion”
Internet Technologies Java and XML (DOM and SAX) Some of the material for these slides came from the following sources: “XML a Manager’s Guide” by Kevin.
Processing XML Processing XML using XSLT Processing XML documents with Java (DOM) Next week -- Processing XML documents with Java (SAX)
Internet Technologies1 Java and XML (DOM and SAX) Some of the material for these slides came from the following sources: “XML a Manager’s Guide” by Kevin.
Previous Exam 1.0. Question 1 - a Is the following statement true or false? Briefly explain your answer. A && B is the same as B && A for any Boolean.
Chapter 24 XML. CHAPTER GOALS Understanding XML elements and attributes Understanding the concept of an XML parser Being able to read and write XML documents.
Xpath Sources:
Swaps Copyright 2014 Diane Scott Docking 1. Learning Objectives Describe an interest rate swap Understand swap terminology Be able to set up a simple.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
CMSC 202 Interfaces. 11/20102 Classes and Methods When a class defines its methods as public, it describes how the class user interacts with the method.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Java WWW Week 10 Version 2.1 Mar 2008 Slide Java (JSP) and XML  Format of lecture: What is XML? A sample XML file… How to use.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 1: Course overview.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Viswanathan Inheritance and Polymorphism Course Lecture Slides 2 nd June 2010 “ We are.
1 Java and XML Modified from presentation by: Barry Burd Drew University Portions © 2002 Hungry Minds, Inc.
Object Oriented Programming: Java Edition By: Samuel Robinson.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
The Main Routine In these notes I call it DataImporter. It contains: A main routine the creates an instance of IndexerData, the root of our data model.
XML Processing in Java. Required tools Sun JDK 1.4, e.g.: JAXP (part of Java Web Services Developer Pack, already in Sun.
Java API for XML Processing (JAXP) Dr. Rebhi S. Baraka Advanced Topics in Information Technology (SICT 4310) Department of Computer.
ITI Introduction to Computing II Lab-6 Dewan Tanvir Ahmed University of Ottawa.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Introduction to Java Classes and Objects. What is a class A class is description of a structure that contains both data and methods – Describes a set.
Created by Terri Street Copyright, 2000  1,000,0001,000,000  500,000500,000  250,000250,000  125,000125,000  64,00064,000  32,00032,000  16,00016,000.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Example: O-O Payroll Program (§11.4) Object-Oriented Design Behavior. Our program should read a sequence of employees from an input file, ( managers, secretaries,
1 JAXP & XPATH. Objectives 2  XPath  JAXP Processing of XPath  Workshops.
Object Oriented Programming Java 1 Some Notes on Cloning, Packages and Visibility Notes from Bruce Eckel’s “Thinking in Java” and “Just Java” by.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
// Java2101.java This program tests the features of the class. public class Java2101 { public static void main (String args[]) { System.out.println("\nJAVA2101.JAVA\n");
Lecture 2: Object Oriented Programming Object Oriented Programming Java Lecture 2: Object Oriented Programming.
COME 339 WEEK 1. Example: The Course Class 2 TestCourceRunCourse.
LECTURE 8: EXCEPTIONS CSC 212 – Data Structures. Error Handling Goals  What should we do when an error occurs?  Should alert system to the error  May.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
INTEREST RATE SWAP S&L pays interest on $15 million at 11.5% 11.5% Fixed-Rate Obligation in Eurobond Market Commercial Bank Counterparty Southwest Savings.
Last Revision. Question1 Novice Java programmers often write code similar to, class C { public int x;... }... C[] a = new C[10]; for(int i = 0; i < a.length;
Advanced Programming Practice Questions Advanced Programming. All slides copyright: Chetan Arora.
Interfaces CMSC 202. Public Interfaces Objects define their interaction with the outside world through the their public interface. A class' public interface.
Object Oriented Programming Lecture 2: BallWorld.
Staples are our staple Building upon our solution.
Modern Programming Tools And Techniques-I
Inheritance ITI1121 Nour El Kadri.
Chapter 24 XML.
Java/XML.
Accessing Files in Java
Packages, Interfaces & Exception Handling
CS Week 14 Jim Williams, PhD.
Jagdish Gangolly State University of New York at Albany
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
WaysInJavaToParseXML
CS 180 Assignment 6 Arrays.
class PrintOnetoTen { public static void main(String args[]) {
XML document processing in Java using XPath and XSLT
Building Java Programs
Object Oriented Programming.
Presentation transcript:

Financial Engineering Project Course

Lecture 3 Object Oriented Design Inheritance Abstract Base Classes Polymorphism Using XML to represent the swap agreement Lab Exercise – processing XML with JAXP

Using the Swap to transform a liability Company A Company B LIBOR 5% 5.2% LIBOR + 0.8%

Role of Financial Intermediary Company A Company B 5.2% LIBOR + 0.8% LIBOR 5.015% LIBOR 4.985% Financial Institution Source : John Hull

Class Name Member data Methods

SwapAgreement double notional; double fixedRate; int numYears; int numPayments; fixedCashFlow() floatCashFlow()

SwapAgreement public class SwapAgreement { double notional; double fixedRate; int numYears; int numPayments;

public SwapAgreement(double notional, double fixed, int years, int numPayments) { this.notional = notional; fixedRate = fixed / 100; numYears = years; this.numPayments = numPayments; } public double floatCashFlow() { return (numYears / (double) numPayments) * Libor.getLIBOR()/100 * notional; } public double fixedCashFlow() { return (numYears / (double) numPayments) * fixedRate * notional; }

LIBOR Static array of values Static double getLibor() Static void nextLibor()

LIBOR public class Libor { //private static double values[] = { 4.2, 4.8, 5.3, 5.5, 5.6, 5.9, 6.4 }; private static int i = 0; private static double values[] = { 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 }; public static double getLIBOR() { return values[i]; }

public static void next() { i++; } public static void main(String a[]) { System.out.println(Libor.getLIBOR()); }

“is a” InterestPayment FloatInterestPayment FixedInterestPayment loanAmount years numPayments abstract computeAmount Abstract Base class computeAmount uses LIBOR basisPoints rate computeAmount Works with fixed rate Derived Classes Abstract classes are incomplete.

InterestPayment public abstract class InterestPayment { private double loanAmount; private int years; private int numPayments; public InterestPayment(double loanAmount, int years, int numPayments) { this.loanAmount = loanAmount; this.years = years; this.numPayments = numPayments; }

public abstract double computeAmount(); public double getLoanAmount() { return loanAmount; } public int getYears() { return years; } public int getNumPayments() { return numPayments; } }

FloatInterestPayment public class FloatInterestPayment extends InterestPayment { private double basisPoints; public FloatInterestPayment(double loanAmount, int years, int numPayments, double basisPoints) { super(loanAmount, years, numPayments); this.basisPoints = basisPoints; }

public double computeAmount() { double LIBOR = Libor.getLIBOR() / 100.0; return getLoanAmount() * ( LIBOR + basisPoints * 0.01 * 0.01 ) * (getYears() / (double)getNumPayments()); }

public static void main(String args[]) { FloatInterestPayment f = new FloatInterestPayment(100, 1, 2, 80); System.out.println(f.computeAmount()); }

FixedInterestPayment public class FixedInterestPayment extends InterestPayment { private double rate; public FixedInterestPayment(double loanAmount, int years, int numPayments, double rate) { super(loanAmount, years, numPayments); this.rate = rate / 100; }

public double computeAmount() { return getLoanAmount() * rate * (getYears() / (double)getNumPayments()); } public static void main(String args[]) { FixedInterestPayment f = new FixedInterestPayment(100, 1, 2,10.0); System.out.println(f.computeAmount()); }

“is a” Party FloatPayerParty FixedPayerParty InterestPayment outside; SwapAgreement agreement; double balance; abstract adjust() Abstract Base class Adjust() Fill in the details constructor

Party FloatPayerParty FixedPayerParty InterestPayment outside; SwapAgreement agreement; double balance; abstract adjust() Adjust() Calls outside.computeAmount()

Party FloatPayerParty FixedPayerParty InterestPayment outside; SwapAgreement agreement; double balance; abstract adjust() Adjust() Calls outside.computeAmount() and asks the agreement in order to adjust the balance

Party public abstract class Party { protected InterestPayment outside; protected SwapAgreement agreement; private double balance; public Party(InterestPayment i, SwapAgreement s) { outside = i; agreement = s; }

public abstract void adjust(); public String toString() { return "Balance = " + balance; } void decreaseBalance(double x) { balance = balance - x; } void increaseBalance(double x) { balance = balance + x; }

FixedPayerParty public class FixedPayerParty extends Party { public FixedPayerParty(InterestPayment i, SwapAgreement s) { super(i,s); }

public void adjust() { // pay outside lender double pay = outside.computeAmount(); decreaseBalance(pay); // Pay counterParty LIBOR by decreasing balance // by the correct amount pay = agreement.floatCashFlow(); decreaseBalance(pay); // Receive fixedRate amount agreed upon double get = agreement.fixedCashFlow(); }

FloatPayerParty public class FloatPayerParty extends Party { public FloatPayerParty(InterestPayment i, SwapAgreement s) { super(i,s); }

public void adjust() { // pay outside lender LIBOR + Points double pay = outside.computeAmount(); decreaseBalance(pay); // Receive counterParty LIBOR by adding to balance double get = agreement.floatCashFlow(); increaseBalance(get); // Pay fixedRate amount agreed upon pay = agreement.fixedCashFlow(); decreaseBalance(pay); }

Simulator public class Simulator { public static void main(String a[]) { SwapAgreement agree = new SwapAgreement(100, 5, 3, 6 ); FloatInterestPayment floatpmt = new FloatInterestPayment(100,3,6,0); FixedInterestPayment fixedpmt = new FixedInterestPayment(100,3,6,5); FixedPayerParty fixedParty = new FixedPayerParty(fixedpmt,agree); FloatPayerParty floatParty = new FloatPayerParty(floatpmt, agree);

for(int period = 1; period <= 6; period++) { fixedParty.adjust(); floatParty.adjust(); System.out.println(floatParty); Libor.next(); }

Output C:\McCarthy\Financial Engineering\FixedFloatSwap>java Simulator Balance = -2.5 Balance = -5.0 Balance = -7.5 Balance = Balance = Balance = -15.0

Role of Financial Intermediary Company A Company B 5.2% LIBOR + 0.8% LIBOR 5.015% LIBOR 4.985% Financial Institution Source : John Hull

Role of Financial Intermediary Company A Company B 5.2% LIBOR + 0.8% LIBOR 5.015% LIBOR 4.985% Financial Institution Source : John Hull The Bank has two agreements.

XML For the Agreement

A DTD For The Agreement <!ELEMENT FixedFloatSwap (Notional, Fixed_Rate, NumYears, NumPayments) >

Reading the SwapAgreement with JAXP import java.io.File; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.w3c.dom.Node; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException;

public class Simulator2 { public static void main(String argv[]) { Document doc; if(argv.length != 1 ) { System.err.println("usage: Simulator2 documentname"); System.exit(1); } try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); doc = docBuilder.parse(new File(argv[0])); Node top = doc.getDocumentElement();

if(top.hasChildNodes()) { NodeList list = top.getChildNodes(); for(int i = 0; i < list.getLength();i++) { Node n = list.item(i); if(n.getNodeType() == Node.ELEMENT_NODE){ Node content = n.getFirstChild(); String s = content.getNodeValue(); System.out.println(s); }

catch(SAXParseException err) { System.out.println("Parsing error" + ", line " + err.getLineNumber() + ", URI " + err.getSystemId()); System.out.println(" " + err.getMessage()); } catch(SAXException e) { Exception x = e.getException(); ((x == null) ? e : x).printStackTrace(); } catch (Throwable t) { t.printStackTrace(); } System.exit(0); }

Lab Problem: Execute the Simulator2 class on the SwapAgreement.xml file.