390 likes | 560 Views
This guide provides step-by-step instructions on how to create custom functions in Excel using Visual Basic for Applications (VBA). It covers saving workbooks as macro-enabled files, accessing the Developer menu, and defining functions such as `RectangleArea`, which calculates the area based on height and width. Additionally, it demonstrates how to calculate futures prices using the formula `Future(Spot, Rf, Time)` and how to implement the Dividend Growth Model. Perfect for traders and analysts looking to enhance their Excel skills with custom calculations.
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?