Group Abstract Group Abstract

Message Boards Message Boards

0
|
13.3K Views
|
7 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Debugging the code for pricing European option

Posted 11 years ago
Attachments:
POSTED BY: Kausik Datta
7 Replies
POSTED BY: David Gathercole
Posted 11 years ago

Hi Sean. I uploaded the new version of code (replaced original code). Now it is calculating finite difference table fd but still some problem in Do Loop where I have two different criteria to update matrix "fd". I am expecting logic in IF which is supposed to work for all element in row (nas1+1) as I start updating matrix from right. However logic is failing after second iteration. Hence matrix is getting incorrectly updated from (10,4)th element. (10,4)th element is computed using previous value of (11,5)th matrix fd (which is 1).Can you opine why Do loop is not updating in correct sequence?

Attachments:
POSTED BY: Kausik Datta
Posted 11 years ago
POSTED BY: Kausik Datta

It looks like you need to debug your code.

Debugging code is easier when the code has been broking up into smaller parts. Each smaller part can be tested and checked to make sure it works correctly.

  1. What kinds of error messages do you see? Maybe pick one at a time.
  2. What part of your code does the error message refer to?

If looks like you've set the variable nas to be a string, but later on you use it as a number.

POSTED BY: Sean Clarke
Posted 11 years ago

I am not getting any error message. That's why I am assuming code is correct but obviously some problem in the code that's why it is not returning the euro.

It seems I have written the code in one cell. So not sure how to debug in parts. Can you please explain little more on how to debug in parts. Also I have only one function boptval which is supposed to return price of the option. but yes I can always see if table d1, d2 or d3 is correct. Can you please help in providing one example on how to debug in parts?

Also I am providing nas as input in boptval like boptval[100, 1, 0.2, 0.05, 2, "c", 100, 80]. So nas is 80. So don't see how function can recognize it as string.

POSTED BY: Kausik Datta

The Wolfram Language uses square brackets for calling a function. So you should write:

boptval["100", "1", "20", "5", "c", "100", "80"]

Also, boptval is defined to take 8 arguments. Here you have given it 7 arguments.

POSTED BY: Sean Clarke
Posted 11 years ago

Hi Sean. Thanks for comments. I made changes it still does return option value. I made some changes in the code too and uploaded the revised version. Pl use the most updated version of code

POSTED BY: Kausik Datta
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard