mf703 Practice Midterm PDF
mf703 Practice Midterm PDF
November 3, 2022
Name:
BU ID:
Signature:
Problem 1 (10 points) SQL Programming
Consider the following table design structure:
instrument info
instrument id (int)
ticker (char(5))
sector id (int)
shares outstanding (numeric)
instrument prices
instrument id (int)
ticker (char(5))
quote date (datetime)
close (numeric)
open (numeric)
low (numeric)
daily return (numeric)
Table names are in bold, columns are listed in each line and data types are in paren-
theses.
1. (3 Points) Write a query using only the instrument prices table that selects a
time series of historical closing prices for a given ticker. Make sure the results
are sorted from oldest date to newest.
2. (3 points) Write a query that selects the closing price and shares outstanding
from the instrument info and instrument prices tables for a given ticker and
quote date. Only return the data if the instrument has a price in the instru-
ment prices table.
3. (3 points) Write a query that computes the average daily return for each sector
for a given date.
4. (1 point) You are asked to remove one redundant column from the instru-
ment prices table. Which column would you remove and why?
2
3
Problem 2 (10 points) Python Basic Concepts
What will be the result of the code? What will be printed to the console?
2. (2.5 points) Consider the following code that implements the Black-Scholes for-
mula for a European call:
1 def callPx ( s_0 , k , r , sigma , tau ):
2 sigmaRtT = ( sigma * math . sqrt ( tau ))
3 rSigTerm = ( r + sigma * sigma / 2.0) * tau
4 d1 = ( math . log ( s_0 / k ) + rSigTerm ) / sigmaRtT
5 d2 = d1 - sigmaRtT
6 term1 = s_0 * norm . cdf ( d1 )
7 term2 = k * math . exp ( - r * tau ) * norm . cdf ( d2 )
8 return term1 - term2
What happens when a negative value is passed for s 0? How about a negative
sigma? Add the proper exception handling to this function to handle these
parameter values.
3. (2.5 points) You are given two DataFrames which contain historical price data
for two different ETF’s. Unfortunately, the dates in the two data frames don’t
match exactly. Write the Python code necessary to merge these two data frames,
returning only dates where there are prices for both ETF’s.
4. (2.5 point) Suppose mat1 and mat2 are two Python numpy matrix objects, and
arr1 and arr2 are numpy array objects.
4
If we same data is stored in mat1 and arr1, and mat2 and arr2, respectively,
what will be the difference, if any, in behavior between multiplying mat1 *
mat2 and multiplying arr1 * arr2?
5
6
Problem 3 (20 points) Object Oriented Programming in Python
7
1 basePos3 = basePos1 + basePos2
What, if any changes would need to be made to the BasePosition class for this
to work?
8
9
Problem 4 (10 points) C++ Basic Concepts
Consider the following piece of C++ code:
1 class Foo {
2 Foo ( int bar_ ){
3 bar = bar_ ;
4 }
5
6 int bar ;
7 };
8
14 return 0;
15 }
1. (4 points) Will this code compile? If not, fix any errors so that it will compile.
If it will compile, what will the output be?
2. (4 points) Consider the following set of functions added to the Foo class:
1 int calcFooBar1 ( int val , int mult ){
2 bar = val * mult ;
3 val = bar ;
4 return bar ;
5 }
6
10
(1 point) Which calcFooBar function takes a pointer?
(3 points) What will be the output of the following code?
1 Foo f ;
2 int val = 1.0;
3 int mult = 5.0;
4
11 val = 1.0;
12 mult = 5.0;
13
20 val = 1.0;
21 mult = 5.0;
22
What will be the result of adding this function to the Foo class and calling it
from the main function?
11
12
Problem 5 (20 points) Object Oriented Programming in C++
Consider the following C++ code:
1 class Foo {
2 public :
3 Foo (){
4 std :: cout << " calling Foo constructor " << std :: endl ;
5 }
6
11 int bar ;
12 };
13
29 FooKid * fk ;
30 std :: cout << ( f == & f2 ) << std :: endl ;
31
32 delete f ;
33
38 return 0;
39 }
13
1. (10 points) What will be the output of the above code?
2. (2.5 points) Consider adding a function func() to the definition of Foo. What
would be the significance of making the function virtual? In what cases would
this be useful?
3. (2.5 points) When specifying that FooKid inherits from Foo, what is the signif-
icance of the public keyword? What would happen if instead this line read:
1 class FooKid : Foo
4. (2.5 points) Are there any dangling pointers created in the above code? If so,
what code would you change to fix this?
5. (2.5 points) Suppose the following function definition was added to the definition
of Foo:
1 virtual void printFunc () = 0;
What type of function is this? What impact would adding this have?
14
15
Problem 6 (20 points) Simulation Algorithm
Consider the Black-Scholes SDE:
You are asked to use this SDE to write a simulation algorithm to price an American
upside one touch option. Recall that the payoff of an American one touch is defined
as:
1. (2.5 points) List the set of parameters that you will have in your algorithm and
describe their meaning.
2. (7 Points) Write a piece of pseudo-code that you can use to simulate from the
given stochastic process.
3. (7 Points) Write a piece of pseudo-code that will define the payoff function for
your exotic option.
4. (3.5 points) Describe three unit tests that you would create to ensure that your
model prices are correct.
16
17
Problem 7 (10 points) Algorithms & Finance Applications
18
19
20
21
22
23