patchGNU Octave - Patches: patch #8205, Addition to financial package:...

 
 

patch #8205: Addition to financial package: blk*, bls*, and opprofit functions

Submitted by:  Parsiad Azimzadeh <parsiad>
Submitted on:  Tue 08 Oct 2013 02:04:23 AM UTC  
 
Category: NonePriority: 5 - Normal
Status: DonePrivacy: Public
Assigned to: NoneOpen/Closed: Closed

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Fri 18 Oct 2013 03:58:19 AM UTC, comment #4:

I have pushed your changeset (after some changes to the commit message to follow the guidelines and reference the new try catch block due to fsolve). Please see cset 3e631b4d89da from the repo.

I have added some input test to blsprice myself as well. As this functions seem to all have the same type of arguments (all numeric scalars or matrices, and if matrices all of the same size), it may be worth make it a private function and use it in all the other ones.

Carnë Draug <carandraug>
Project Member
Fri 11 Oct 2013 03:15:08 AM UTC, comment #3:

I have added a new patch that adds test cases to all of the functions. This patch also changes the input arguments in the code from the cryptic notation I was previously using (i.e. S_0, K, r, etc.) to something more human-friendly (i.e. Price, Strike, Rate, etc.).

Lastly, there seems to be some conflicting behavior in the octave fzero in which if a solution is not found in the given interval, an exception will be thrown. To circumvent this, I have simply surrounded the call to fzero with a try-catch statement that sets the value of the optimizer to NaN if none is found. Perhaps a comment should be put here to note that this try-catch should be removed if the fzero implementation is changed in the future.

Parsiad Azimzadeh <parsiad>
Wed 09 Oct 2013 03:15:44 PM UTC, comment #2:

I have confirmed that the version of blslambda shipped with MATLAB is indeed erroneous:

> I am writing in reference to your Service Request # 1-P03H5V
> regarding 'blslambda in financial package does not work as
> intended'.


> Thank you for notifying MathWorks of this issue. We have
> confirmed the bug, and we will work on fixing this issue for a
> future release.

Parsiad Azimzadeh <parsiad>
Tue 08 Oct 2013 08:36:58 PM UTC, comment #1:

I have pushed your changes after editing the commit message (following the commit message guidelines[1] but still keeping your signature) and adding the new functions to the INDEX and NEWS files [2].

I have then made a few more changes[3] to follow Octave code guidelines:

  1. use endif, endfunction, etc to end blocks rather than a general end;
  2. replaced tabs per spaces;
  3. moved the one sentence help text to the bottom (so that lookfor can be used to find this functions);
  4. used double quotes for strings;
  5. always leaving a spaces after a function call (so we can index between function call and variable indexing);
  6. added a minimum input check (just checking the number of arguments);
  7. set the variable defaults on the function definition line, rather than checking if the variable name exists
  8. if cheking if a condition is false, use "if (! condition)" and not "if (condition == 0)"

On the subject of input checking would be great if you could extend it.

On blsimpv you use two for loops. This is likely to be slow. In addition, it will only work up to 2 dimensions. And since Octave is column-major order, I have swapped the order of it so it will process down each column.

Finally, could you write some tests for these functions? See for example, the test blocks at the bottom of addtodate[4], datenum[5], or rgb2ntsc[5].

[1] http://wiki.octave.org/Commit_message_guidelines
[2] http://sourceforge.net/p/octave/financial/ci/bb3ab896bc3319907dabc7e05d25164c2b17e76a/
[3] http://sourceforge.net/p/octave/financial/ci/7350d2b4eaab53a26cfd933f19a5561a439c1f83/
[4] http://hg.savannah.gnu.org/hgweb/octave/file/b43da3876b64/scripts/time/addtodate.m
[5] http://hg.savannah.gnu.org/hgweb/octave/file/b43da3876b64/scripts/time/datenum.m
[6] http://hg.savannah.gnu.org/hgweb/octave/file/b43da3876b64/scripts/image/rgb2ntsc.m

Carnë Draug <carandraug>
Project Member
Tue 08 Oct 2013 02:04:23 AM UTC, original submission:

This patch adds the functions

  • blkimpv
  • blkprice
  • blsdelta
  • blsgamma
  • blsimpv
  • blslambda
  • blsprice
  • blsrho
  • blstheta
  • blsvega
  • opprofit

to the financial package.

It should be noted that the implementation of blslambda uses the (usual) definition of the lambda of an option which is dV/dS * S/V. The MATLAB implementation uses dV/dS evaluated at a dividend rate of zero, even when the lambda is evaluated at a nonzero dividend rate. It is currently unknown why this is done, but as a result of this, there is a small discrepancy between the output in the above and that of MATLAB.

Parsiad Azimzadeh <parsiad>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by parsiad (Submitted the item)
  • -unavailable- added by parsiad
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 26 Oct 2013 12:27:55 AM UTCcarandraugOpen/ClosedOpen=>Closed
    Fri 11 Oct 2013 03:09:26 AM UTCparsiadAttached File-=>Added 2013.10.10.parsiad-financial.patch, #29353
    Tue 08 Oct 2013 08:36:58 PM UTCcarandraugStatusNone=>Done
    Tue 08 Oct 2013 02:04:23 AM UTCparsiadAttached File-=>Added 2013.10.07.parsiad-financial.patch, #29316
      Carbon-Copy-=>Added -unavailable-

    Back to the top


    Powered by Savane 3.1-cleanup