software development csu 670 fall 2007 karl lieberherr

Post on 20-Dec-2015

216 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Software DevelopmentCSU 670 Fall 2007

Karl Lieberherr

Textbook

• Booch: OOAD(3)– Concepts

• partially a review from OOD but much new material, e.g. – Law of Demeter (pages 116, 117)

– Method• partially a review from OOD but much new material, e.g.,

– software development lifecycle

– project management

– Applications• useful examples

Project: Algorithmic Trading of Derivatives

• Derivatives are financial instruments whose value derives from the value of assets underlying them"

• Examples of the financial instruments used in derivatives transactions, which reference these underlying assets include: options …

• Options are financial instruments that convey the right, but not the obligation, to engage in a future transaction on some underlying security.

Website

• for selling and buying derivatives• derivatives can be created on the fly• Derivative:

– Kind: G– creator name (has to provide raw material of kind G,

has to pay for finished product)• price offered

– buyer name (has to work to produce finished product)• price paid

– outcome• raw material provided• price to be paid by creator

• possibility for re-selling a derivative that was bought

• is this different than offering the derivative with a higher price

• are prices public?

Special kinds of derivatives

• Derivatives are often used to control risks: weather, foreign currency fluctuations, interest rates.

• Evergreen derivatives don’t control risks that depend on unknown time-dependent factors.

• They depend on G = set of relations. This is a time-independent known object.

Abstract problem: Pricing of derivative

• Pricing of following derivative D(G): option to get for free one batch of raw material of type G (details of batch unknown) and the option to sell the finished product made of the raw material within one day of receipt of the raw material at a price proportional to the quality of the finished product.

• all prices are in [0,1] (million dollars).

Concrete Problem

• batch of raw material of type G– G-formula F

• finished product– assignment J for G-formula F plus F

• quality of finished product– satisfaction ratio of assignment J for F

Questions

• How much is D(G) worth for a given G?

CNF: a simple language

Program = Expression.Expression : LetExp | CNF.LetExp = <assign> Literal <body> Expression. CNF = <clauses> List(Clause).Clause = <weight> Weight <body> Body.Body : Literals | Sat | Unsat.Sat = “sat”.Unsat = “unsat”.Literals = <literals> List(Literal).Literal : Pos | Neg common Variable.Variable = <v> Ident.Pos = .Neg = .List(S) ~{S}.

Values

• expressed values– possible values of expressions

• CNF (results of reductions)

• denoted values– values bound to variables

• Literal (assignment)

Environments

• store values associated with each variable

Let expression

(value-of (LetExp lit body) s) =

(value-of body [lit] s)

CNF

(value-of (CNF clauses sat unsat) [l] s) =

(CNF clauses1 sat1 unsat1)

(value-of (Clause weight literals)[l] s) =

(Clause weight1 body)

Exercise 1.17

• (down lst) wraps parentheses around each top-level element of lst.

• solution: – from list:List to r:topLevel(list)

• replace r by (list r)

Exercise 1.27

• (flatten slist)

• solution:

• from Root to p:Primitive collect p into list

• notice generalization: flatten other structures than lists

Help with project 2

• Understanding code: find the data abstractions

• Data abstraction: separate interface from implementation

Interface for a class dictionary

• Constructors: LetExp(Literal,Expression)– Clause_PList(Nonempty_Clause_PList)

• Accessors: LetExp: – Literal get_assignment(), – Expression get_body()

• Parser: static LetExp.parse()• Printer (needs a bit of code because

PrintVisitor is provided) • similar for other visitors

For phases 3 and 4: List Structure

• List(X)

X_List NonEmpty_X_Listfirst

next

X

it

Iterating through a DemeterJ list

• Have an X_List xlist;

java.util.Enumeration en = xlist.elements();

while (en.hasMoreElements()) {

if (e.equals((X) en.nextElement()))

{ found = true; }

found = false;

}

Enumeration Interfaceboolean hasMoreElements();Object nextElement();

Iterating through a DemeterJ list:

in class X_Listpublic java.util.Enumeration elements() {

return new X_List(first);

}

public Object nextElement() {

X car = first.get_it();

first = first.get_next(); return (Object) car;

}

Iterating through a DemeterJ list:

in class X_Listpublic boolean hasMoreElements()

{ return (first != null); }

Enumeration interface is old fashioned

• Use Iterator interface instead– boolean hasNext();– Object next();– void remove(); (optional operation)

• Compare to

Enumeration Interfaceboolean hasMoreElements();Object nextElement();

Enumeration interface is old fashioned

• ListIterator is a subinterface of Iterator– boolean hasNext();– Object next();– void remove(); (optional operation)– add, hasPrevious, previousIndex, nextIndex,

previous, set

Java documentation

• The functionality of the Enumeration interface is duplicated by the Iterator interface. … shorter method names ... New implementations should consider using Iterator in preference to Enumeration.

Traversal with a ListIterator

void traverse_maxSize(IntegerRef m){

for (ListIterator i=this.listIterator(); i.hasNext();)

{

DirectoryEntry de =

(DirectoryEntry) i.next();

de.traverse_maxSize(m);

}

How can you get an Iterator?

• Interface Collection:– Iterator iterator();

• Example: – class Vector implements interface List– interface List extends interface Collection– Therefore: Use the Iterator interface to go

through a vector

Context switch: Keep it simple with XML

XML

• Elements have Content• Elements can have different content types.• An XML element is everything from (including)

the element's start tag to (including) the element's end tag.

• An element can have element content, mixed content, simple content, or empty content. An element can also have attributes.

• We use only: element content and simple content.

Others, including the official XML authors

• Are for simplification.

From w3schools

• An expanded date element is used in the third: (THIS IS MY FAVORITE):

<note> <date> <day>12</day> <month>11</month> <year>2002</year> </date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend! </body> </note>

From the w3schools website• Avoid using attributes? • Should you avoid using attributes? • Some of the problems with using attributes are: • attributes cannot contain multiple values (child elements can) • attributes are not easily expandable (for future changes) • attributes cannot describe structures (child elements can) • attributes are more difficult to manipulate by program code • attribute values are not easy to test against a Document Type

Definition (DTD) - which is used to define the legal elements of an XML document

• If you use attributes as containers for data, you end up with documents that are difficult to read and maintain. Try to use elements to describe data.

Don't end up like this (this is not how XML should be used):

<note day="12" month="11" year="2002" to="Tove" from="Jani" heading="Reminder" body="Don't forget me this weekend!"> </note>

From the official XML tutorialhttp://www.w3schools.com/xml/xml

_attributes.asp

• There are no rules about when to use attributes, and when to use child elements. My experience is that attributes are handy in HTML, but in XML you should try to avoid them. Use child elements if the information feels like data.

Based on the w3schools recommendation

• We decide to use only a subset of XML• We use elements and no attributes.• The elements either have element content

or simple content.• The simple content is either an Ident, a

String or a Text or any of the primitive types of Java (int, float, etc.) and their corresponding wrapper classes (Integer, Float, etc.)

top related