Issues getting a vba function to call another vba function

GeorgeA

New Member
Joined
Mar 27, 2016
Messages
7
I'm currently a college student in a financial modeling course and we've recently jumped into vba coding. I don't have much experience, so everything is a bit new. We have a question that assigned to us that follows:

A hybrid linked note is an instrument that provides investors fixed income and equity market. It is structured by combining a return that is 75% equity and 25% fixed income. The investment pays the greater of the par value, $1,000, or the price times the 75% percentage increase in the S&P 500 plus 25% the return on the Barclays US Aggregate Index.
Write 2 functions (hlnPayoff, hlnReturn). The first, hlnPayoff, calculates the security payoff at maturity. The second, hlnReturn, calculates the annualized return assuming continuous compounding. The function hlnReturn should call the payoff function.
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Price | Years | SP5000 | SP5001 | Barclay US Agg0 | Barclay US Agg1

953 | 1 | 1783 | 1995 | 1810 | 1887
914 | 2 | 1298 | 1498 | 1909 | 1942
811 | 5 | 1288 | 1568 | 1710 | 1887
733 | 8 | 1335 | 1270 | 1612 | 1923

</code>My code so far is as follow:

Code:
Function hlnPayoff(price As Currency, sp0 As Currency, sp1 As Currency, bar0 As Currency, bar1 As Currency)
Const par As Currency = 1000


hlnPayoff = price * (1 + (((sp1 - sp0) / sp0) * 0.75) + (((bar1 - bar0) / bar0) * 0.25))


If hlnPayoff < par Then
    hlnPayoff = par
Else
    hlnPayoff = hlnPayoff
End If
    
End Function


Function hlnReturn(price As Currency, years As Integer, sp0 As Currency, sp1 As Currency, bar0 As Currency, bar1 As Currency)


hlnReturn = Application.WorksheetFunction.Ln(hlnPayoff / price) / years


End Function

The hlnPayoff seems to be working fine, and I'm getting a result that I am satisfied with. But I'm having issues getting the hlnReturn function to work at all. I think my biggest issue is that the hlnReturn needs to call the hlnPayoff funtion, and I'm not entirely sure how to make that work. My issue seems to be that I'm getting an "argument not optional" error, and I'm not sure how to correct it.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You need to pass arguments when you call hlnPayoff.

The arguments of hlnReturn are scoped only to that procedure, if you want them to be used for the hlnPayoff calculation, you have to pass them when calling the function

Also the VBA function Log is the same as the worksheet function LN (different than the worksheet function LOG)

Code:
hlnReturn = Log(hlnPayoff(price, sp0, sp1,bar0, bar1) / price) / years
 
Upvote 0
Ah, thank you. That worked perfectly. As a follow up, do you think there is a better way for me to define my variables? I tried to Dim them, but then I kept getting a duplication error, so I went with the current method just to get it to work. Any suggestions? Or should I just leave it as is?
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top