程序代写 Programming for Quantitative & Computational Finance

Programming for Quantitative & Computational Finance
Instructor: Ng
Introduction to OOP

Copyright By PowCoder代写 加微信 powcoder

Object-Oriented Programming
• Learntsofar:proceduralprogramming(ie. based on functions and procedures)
• OOP:centeredaroundobjects
• Abstractionofconceptsfromvariousconcrete use cases
• Usecaseexample:tradeclasses

Object-Oriented Programming
• Benefits:
– More re-usability of code
– More organized (at least it allows you to do so)
– Hide complexity from users who call the objects and methods
– Good object design upfront
– Changing object design later may require changing common code being used by other use cases

• Classdefinition
– Data variables and methods (Class attributes)
• Objectconstructor
– An instance of a class
• Objectdestructor
• BasicconceptsinOOP – Encapsulation
– Inheritance
– Polymorphism
• Usecase:tradeclasses

Encapsulation
• Privatevspublic
• Privatemembers:__xxx
• Privatedataormethodsshouldnotbecalled

Inheritance
• Hierarchyofclasses
• Baseclass
• Derivedclasses(orsub-classes)
x, y, __w my_method() __my_method()
MySubClass
x, y, __w, z my_method() __my_method() sub_method()

Polymorphism
• Differentimplementationofabaseclassmethod in different sub-classes
x, y, __w my_method() __my_method()
changed inherited
MySubClass2
x, y, __w, z my_method() __my_method() sub_method()

Multiple inheritance • Derivedfrommultiplebaseclasses
x, y, __w my_method() __my_method()
YourClass m
your_method()
x, y, __w, m my_method() __my_method() your_method()

Example: Trade class
• Defineabaseclassforequitytrades
• DerivedclassforEuropeancalloptionson equity
• Definemethodsforvaluations

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com