Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8411349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:24:14+00:00 2026-06-10T00:24:14+00:00

the following VBA code should be correct: Function BlackScholes(CallPutFlag As String, S As Double,

  • 0

the following VBA code should be correct:

Function BlackScholes(CallPutFlag As String, S As Double, X _
As Double, T As Double, r As Double, v As Double) As Double

Dim d1 As Double, d2 As Double

d1 = (Log(S / X) + (r - v ^ 2 / 2) * T) / (v * Sqr(T))
d2 = d1 - v * Sqr(T)
    If CallPutFlag = "c" Then
     BlackScholes = S * CND(d1) - X * Exp(-r * T) * CND(d2)
    ElseIf CallPutFlag = "p" Then
     BlackScholes = X * Exp(-r * T) * CND(-d2) - S * CND(-d1)
    End If

End Function

'// The cumulative normal distribution function
Public Function CND(X As Double) As Double

Dim L As Double, K As Double
Const a1 = 0.31938153: Const a2 = -0.356563782: Const a3 = 1.781477937:
Const a4 = -1.821255978: Const a5 = 1.330274429

L = Abs(X)
K = 1 / (1 + 0.2316419 * L)
CND = 1 - 1 / Sqr(2 * Application.Pi()) * Exp(-L ^ 2 / 2) * (a1 * K + a2 * K ^ 2 + a3 * K ^ 3 + a4 * K ^ 4 + a5 * K ^ 5)

If X < 0 Then
CND = 1 - CND
End If
End Function

Now I tried to do it in R:

blackscholes <- function(S, X, rf, T, sigma) {
values <- c(2)

d1 <- (log(S/X)+(rf-sigma^2/2)*T)/sigma*sqrt(T)
d2 <- d1 - sigma * sqrt(T)

values[1] <- S*pnorm(d1) - X*exp(-rf*T)*pnorm(d2)
values[2] <- X*exp(-rf*T) * pnorm(-d2) - S*pnorm(-d1)

values
}

With the following inputs I get slightly different results:

Spot    2,8
Strike  2,9
Risk free   0,01
T   0,083333333
Sigma   0,2

Using ‘fOptions’ R package the result is equal to the VBA one, then I do not understand where’s the R code mistake.

Any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:24:15+00:00Added an answer on June 10, 2026 at 12:24 am

    You have an error in

    d1 <- (log(S/X)+(rf-sigma^2/2)*T)/sigma*sqrt(T)
    

    which should read

    d1 <- (log(S/X)+(rf-sigma^2/2)*T)/(sigma*sqrt(T))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following VBA code generates <?xml version=1.0?> as output. Dim XML As New DomDocument
I have the following VBA code Private Sub CreateQuery_Click() Dim doc As Document Dim
I am trying to put the following code into VBA. What I ideally want
I need a VBA function that will perform the following: Find all unique values
Win-XP / Excel 2003 / VBA .... I have the following piece of code
I am using the following VBA code to export PPT slides to images. The
What does !escape do in the following line of VBA code? There isn't a
The following VBA code sits in a worksheet called SCU and the cell C4
I have the following vba-code in an MS-Access97-frontend which opens a word-document stored on
I have the following VBA code: mainFile = ActiveWorkbook.Name 'select all excel files in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.