Financial Programming and Data Analysis I - Vba - : MSC in Finance
Financial Programming and Data Analysis I - Vba - : MSC in Finance
- VBA -
MSc in Finance
Exercise sheet
Exercise 1:
Using InputBox, write a macro that asks a seller the sale the pre-tax price of a product, the
number of units sold and the VAT rate and returns the bill. Then, write a function that
returns the bill amount.
Exercise 2:
Using InputBox, write a program that takes a name as argument and returns the string
“Hello” name “!”. Then the program asks “How old are you?”. If the user enters a number
less than 18, the program returns “Parental advisory requested”. If the number is equal to or
above 18, the program returns “Parental advisory not requested”. If the syntax is invalid, the
program returns “Invalid answer” and the box “How old are you?” appears again (and so on).
Exercise 3:
A store has the following pricing rule:
0.10$ for the first ten copies
0.09$ for the next twenty copies
0.08$ for the next copies.
1. Write a macro that asks, through InputBox, the user to enter the number of copies
printed and returns the bills accordingly.
2. Redo the same exercise but instead of using InputBox, create a function (ex.:
Mybill(…)) that returns the bills. Call the function under excel and test it for a large
range of copy number.
Exercise 4:
With InputBox, write a macro that asks the user to enter a number. Then the algorithm
displays the five numbers that precedes the number and the ten next numbers too.
Dim nb as Integer
Dim vect(1 to 5) as string
Dim vect(1 to 10) as string
Nb = inputbox (“enter a number”)
For i = 1 to 5
Vect(i) = nb - 1
Nb = nb – 1
MsgBx (number -1)
Exercise 6:
If you have used the while (for) loop in the previous exercise, do it again using the for (while)
loop instead.
Exercise 7:
Write a function that computes the NPV of a project, given a discounted rate, an initial
investment and a stream of future cash flows.
Example:
Disc_r = 0.0005
I_0 = 100000
CF_stream = [10000,15000,20000,40000]
You create: My_NPV_Function(Disc_r, I_0, CF_stream)
Test it under Excel
Dim N as Integer
N = WorksheetFunction.Count(CF_steam)
Dim Sum_Disc_CF As Single
Sum_Disc_CF = 0
For i = 1 to N
Sum_Disc_CF = Sum_Disc_CF + CF_steam (i) / (1+Disc_r)^i
Next i
Remark: The cash flows could be numbers aligned in one single excel column/line.
Exercice 8:
Exercise 7 with all arguments exhibited on a excel spreadsheet. A control button generates
the NPV.
More advanced:
Exercise 9:
Price an option with the Black and Scholes formula on a non-dividend paying stock. To do so,
create a VBA function.
Optional: Use the approximation provided by Hull (2002) for the normal CDF.
Exercice 10:
Exercise 9 with the parameters shown on a excel spreadsheet. The Black and Scholes value is
generated with a control button.