390 likes | 533 Views
10. Visual Basic Functions. Open Excel. Click File -> Save As. Save As a Excel Macro-Enabled Workbook. Click File -> Options. Click Customize Ribbon. Tick Developer. Click OK. Select Developer menu. Functions. Excel uses functions to do most calculations =SUM(x) =COUNTIF( x,y )
E N D
Functions • Excel uses functions to do most calculations =SUM(x) =COUNTIF(x,y) =VLOOKUP(x,y,z) • They take an input value e.g. x, y, z then perform a calculation and return a result • We can write our own functions in Visual Basic
Area of a rectangle • We want to be able to type in a function such as =RectangleArea(Height, Width) • Excel should do the following calculation Area = Height * Width • Excel should then give us the result
This means Excel asks you for Height and WidthIt will then do calculations with these variables
You can also use this function by typing into the cell directly
Pricing a Futures Contract • Traders may want to calculate futures prices • We want Excel to calculate the Futures price by providing the Spot price, Risk-Free rate and Time =Future(Spot, Rf, Time) • Excel should calculate the following formula Future = (Spot)e(Rf)(Time)
Type Function Future(Spot, Rf, Time) Future = Spot * exp(Rf * Time)
Challenge • Create a function which will calculate the price of a share using the Dividend Growth model • You want a user to be able to use a function where they get the price by typing in a function such as: =DGMPrice (Dividend, InterestRate, GrowthRate) • Excel should then do the following calculation and return the result DGMPrice = Dividend / (InterestRate – GrowthRate) • What is the fair price of a share if it has a dividend of £2, interest rate of 0.06, and growth rate of 0.02?