If you repeat same calculation many times, it is useful to create your own function. As macro is repeating predefined steps, function returns a value.
Capital asset pricing model: expected return equals to risk free rate + (expected return of market portfolio – risk free rate) times beta-factor of the security.
This can be easily calculated in Excel.

Calculating CAPM manually is not an issue, but as said, repeating the same process often takes more time than creating a self made formula.
Function z_ser(fr, mr, b)
z_ser = fr + (mr – fr) * b
End Function
Save the functions in VBA editor under personal workbook, then the formula is available in all your Excel workbooks.
Function is calculating the value for z_ser based on input values rf, mr and b. I used to start my own functions with z_ to sort out my own functions. Another practice is to keep variable names short. It is faster to write and possibility for typing errors is lower than with long names.
Once you are done with VBA and you start to write formula in Excel application side, press fx button



Self made function can be used in the same way as Excel standard functions.







