Ask Experts Questions for FREE Help !
Ask
    beginner123's Avatar
    beginner123 Posts: 9, Reputation: 1
    New Member
     
    #1

    Mar 31, 2009, 09:26 AM
    Black Scholes Calculator
    Hi,

    My professor gave an assignment whereby we have to create a Black Scholes option pricing calculator to give the call and put premium. He never gave us the formula, but stated we should search online. He also stated that we can use any source as long as we document it. I found a website which gives the code, but I'm having some difficulty deciphering it because it will not work as is. I am new to programming and would like some assistance please.

    Here is a link to the website which has the formula and the code:
    Espen Haug

    There are more websites out there but I can't seem to find out what I'm doing wrong. This is what I have so far:


    //Code to calculate date difference

    System::TimeSpan daysdiff;
    double yearsdiff;
    daysdiff = this->dtpExpirationDate->Value -
    this->dtpCurrentDate->Value;
    yearsdiff = ((double) daysdiff.Days / 365.0);
    tbYearsDifference->Text = yearsdiff.ToString(".00");

    if (this->dtpExpirationDate->Value < this->dtpCurrentDate->Value) {
    MessageBox::Show("Expiration Date needs to be later than
    Current Date!");
    }


    // Code to calculate Call Premium

    double stock, strike, risk, volatility, call, sqrt;
    double d1, d2;
    double log;
    stock = Convert::ToDouble(tbStockPrice->Text);
    strike = Convert::ToDouble(tbStrikePrice->Text);
    yearsdiff = Convert::ToDouble(tbYearsDifference->Text);
    risk = Convert::ToDouble(tbRiskFreeRate->Text);
    volatility = Convert::ToDouble(tbVolatility->Text);
    d1 = (log(stock / strike) + (risk + (volatility *volatility) / 2) * yearsdiff)
    / (volatility * sqrt(yearsdiff));
    d2 = d1 - volatility * sqrt(yearsdiff);
    call = stock * CND(d1) - strike * exp(-risk * yearsdiff) * CND(d2);
    tbCallPremium->Text = Convert::ToString(call);
    tbCallPremium->Text = call.ToString(".00");

    //Code for cumulative normal distribution

    double CND (double strike), L, K, w, pow;
    double sqrt;
    double const a1 = 0.31938153, a2 = -0.356563782, a3 = 1.781477937,
    a4 = -1.821255978, a5 = 1.330274429;
    L = fabs(strike);
    K = 1.0 / (1.0 + 0.2316419 * L);
    w = 1.0 - 1.0 / sqrt(2 * Pi) * exp(-L *L / 2) * (a1 * K + a2 * K *K + a3 *
    pow(K,3) + a4 * pow(K,4) + a5 * pow(K,5));

    We have to use a date time picker to calculate the date, that's why it's included.

    I've made a couple changes, but I'm sure you can find tons of mistakes.

    PLEASE HELP :)

    Thank You.
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #2

    Apr 2, 2009, 05:20 AM

    I think the first thing to do, before generating code, is to figure out how to do the calculation manually. Until you understand it at that level, there's no way that you can generate code to do it.

    You're probably not going to find someone who is willing to figure that out for you. If there's a specific problem that you're having, and you know how to do it manually, post and I'll help you out.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Vb 6.0 calculator [ 2 Answers ]

Please help me! On my prject , I need a source code of a vb 6.0 calculator please help. Tnx

Probability using TI-83 Plus Calculator [ 1 Answers ]

One medical textbook states that only 6% of th human population has blood type O-Negative. Assume that a simple random sample of 45 people are selected. A. Find the probability that 5 of the selected people have blood type O-Negative. Would this be considered unusual. Why or why not? B. Find...

TI-84 Plus Calculator [ 1 Answers ]

This is sort of a math question and it isn't. I just bought this calculator yesterday, and the book that came with it does not tell me how to program the Quadratic formula as well as other equations into this calculator. And someone I know in my class has the same one and told me that this can be...

How to do e-0.05 on a calculator [ 5 Answers ]

Hi there, What are the exact steps I press on a calculator to do the following: - 40e-0.05 I keep getting the wrong answer? Any help is appreciated


View more questions Search