PL/SQL to calculate XIRR in Oracle

Hi All
can i get a code to calculate XIRR in Oracle using plsql, (i know its there in OLAP but its costly.), Can i get any code where i can do it with plsql
Thanks in Advance
s.z.a

I've tested what you have posted here. And, it gives me huge number of error - because of your typo mistake.
I've rectify it and now it is running. Here is the script --
satyaki>
satyaki>create or replace type p_date_array is varray(200000) of date;
  2  /
Type created.
satyaki>
satyaki>
satyaki>create or replace type t_amount_array is varray(200000) of number;
  2  /
Type created.
satyaki>
satyaki>
satyaki>create or replace FUNCTION XIRR(p_date_array in t_date_array,
  2  p_amount_array in t_amount_array,
  3  p_guess in number default 0
  4 
  5  ) RETURN NUMBER AS
  6 
  7  BEGIN
  8  declare
  9  z number := 0;
10  step_limit number := 0;
11  temp number;
12  step number := 0.1;
13  d number := 0.5;
14  l_MaxDate date;
15  l_MinDate date;
16  srok number;
17  begin
18  l_MaxDate := p_date_array(1);
19  l_MinDate := p_date_array(1);
20 
21  -- 5@2K9 ?@>E>4: ?>8A: <0:A. 40BK 8 =0;8G8O E>BO 1K >4=>3> <8=CA0 8 ?;NA0 2 ?>B>:0E
22  for i in 1 .. p_date_array.count loop
23  if p_date_array(i) > l_MaxDate then
24  l_MaxDate := p_date_array(i);
25  end if;
26  if p_date_array(i) < l_MinDate then
27  l_MinDate := p_date_array(i);
28  end if;
29  end loop;
30  /
Warning: Function created with compilation errors.
satyaki>
satyaki>
satyaki>sho errors;
Errors for FUNCTION XIRR:
LINE/COL ERROR
29/9     PLS-00103: Encountered the symbol "end-of-file" when expecting
         one of the following:
         begin case declare end exception exit for goto if loop mod
         null pragma raise return select update while with
         <an identifier> <a double-quoted delimited-identifier>
         <a bind variable> << close current delete fetch lock insert
         open rollback savepoint set sql execute commit forall merge
         <a single-quoted SQL string> pipe
satyaki>
satyaki>ed
Wrote file afiedt.buf
  1  create or replace FUNCTION XIRR(p_date_array in p_date_array,
  2                                  p_amount_array in t_amount_array,
  3                                  p_guess in number default 0
  4                                 )
  5  RETURN NUMBER
  6  IS
  7  BEGIN
  8    declare
  9      z number := 0;
10      step_limit number := 0;
11      temp number;
12      step number := 0.1;
13      d number := 0.5;
14      l_MaxDate date;
15      l_MinDate date;
16      srok number;
17    begin
18      l_MaxDate := p_date_array(1);
19      l_MinDate := p_date_array(1);
20      -- 5@2K9 ?@>E>4: ?>8A: <0:A. 40BK 8 =0;8G8O E>BO 1K >4=>3> <8=CA0 8 ?;NA0 2 ?>B>:0E
21      for i in 1 .. p_date_array.count
22      loop
23        if p_date_array(i) > l_MaxDate then
24           l_MaxDate := p_date_array(i);
25        end if;
26        if p_date_array(i) < l_MinDate then
27           l_MinDate := p_date_array(i);
28        end if;
29      end loop;
30      select months_between(l_MaxDate, l_MinDate)
31      into srok
32      from dual;
33      loop
34        temp := p_amount_array(1);
35        for i in 2 .. p_amount_array.count
36        loop
37          temp := temp + p_amount_array(i)/power((1 + d),(p_date_array(i) - p_date_array(1))/365);
38        end loop;
39        if (temp > 0) and (z = 0) then
40           step := step / 2;
41           z := 1;
42        end if;
43        if (temp < 0) and (z = 1) then
44            step := step / 2;
45            z := 0;
46        end if;
47        if (z = 0) then
48            d := d - step;
49        else
50            d := d + step;
51        end if;
52        step_limit := step_limit + 1;
53        exit when((round(temp * 100000) = 0) or (step_limit = 10000));
54      end loop;
55        return d;
56    end;
57* END XIRR;
satyaki>/
Function created.
satyaki>
satyaki>
satyaki>
satyaki>
satyaki>set serveroutput on
satyaki>
satyaki>
satyaki>DECLARE
  2    P_DATE_ARRAY PMA.T_DATE_ARRAY;
  3    P_AMOUNT_ARRAY PMA.T_AMOUNT_ARRAY;
  4    P_GUESS NUMBER;
  5    v_Return NUMBER;
  6  BEGIN
  7    -- Modify the code to initialize the variable
  8    P_DATE_ARRAY := T_DATE_ARRAY(to_date('01.01.2007','dd.mm.yyyy'),to_date('01.07.2007','dd.mm.yyyy'),to_
  9    -- Modify the code to initialize the variable
10    P_AMOUNT_ARRAY := T_AMOUNT_ARRAY(-100,58,60);
11    P_GUESS := NULL;
12   
13    v_Return := XIRR(
14    P_DATE_ARRAY => P_DATE_ARRAY,
15    P_AMOUNT_ARRAY => P_AMOUNT_ARRAY,
16    P_GUESS => P_GUESS
17    );
18    DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
19  END;
20  /
  P_DATE_ARRAY PMA.T_DATE_ARRAY;
ERROR at line 2:
ORA-06550: line 2, column 16:
PLS-00201: identifier 'PMA.T_DATE_ARRAY' must be declared
ORA-06550: line 2, column 16:
PL/SQL: Item ignored
ORA-06550: line 3, column 18:
PLS-00201: identifier 'PMA.T_AMOUNT_ARRAY' must be declared
ORA-06550: line 3, column 18:
PL/SQL: Item ignored
ORA-06550: line 8, column 3:
PLS-00320: the declaration of the type of this expression is incomplete or
malformed
ORA-06550: line 8, column 3:
PL/SQL: Statement ignored
ORA-06550: line 10, column 3:
PLS-00320: the declaration of the type of this expression is incomplete or
malformed
ORA-06550: line 10, column 3:
PL/SQL: Statement ignored
ORA-06550: line 14, column 19:
PLS-00320: the declaration of the type of this expression is incomplete or
malformed
ORA-06550: line 13, column 3:
PL/SQL: Statement ignored
satyaki>
satyaki>
satyaki>DECLARE
  2    PDA P_DATE_ARRAY;
  3    PAA T_AMOUNT_ARRAY;
  4    P_GUESS NUMBER;
  5    v_Return NUMBER;
  6  BEGIN
  7    -- Modify the code to initialize the variable
  8    PDA := P_DATE_ARRAY(to_date('01.01.2007','dd.mm.yyyy'),to_date('01.07.2007','dd.mm.yyyy'),to_date('01.01.2008','dd.mm.yyyy'));
  9    -- Modify the code to initialize the variable
10    PAA := T_AMOUNT_ARRAY(-100,58,60);
11    P_GUESS := NULL;
12   
13    v_Return := XIRR(P_DATE_ARRAY => PDA,P_AMOUNT_ARRAY => PAA,P_GUESS => P_GUESS);
14    DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
15  END;
16  /
v_Return = .248719024658203125
PL/SQL procedure successfully completed.
satyaki>
satyaki>
satyaki>Please post your code with proper indentation, so that everyone can get your code easily.
Regards.
Satyaki De.

Similar Messages

  • How to 100% Protect PL/SQL Code By Wrapped in Oracle Database 10g R2

    Hello,
    Is Possible to 100% Protect PL/SQL Code By Wrapped in Oracle 10g R2 ?
    If it is not possible by wrap in oracle 10g R2,
    Please, let me suggest, how i will be able to 100% protect PL/SQL code in Oracle Database 10g R2.
    Because, I have lot of functions, procedures & package's in my project.
    Which is running in field filed.
    So, i have needed to protect 100%.
    Also, will i convert to al functions, procedures & package's to .pll file ?
    And .pll file to .plx file?
    Is it possible to convert .plx file to .pll file ?
    Please, let know any better solutions in this case....
    Regards
    Mehedi

    Hello,
    No, wrapping is not a 100% secure method. It could prevent your code from amateurs, but not from professional hackers. Look at the article http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/wrap.htm#BEHGBJAA
    It says: "•Wrapping is not a secure method for hiding passwords or table names.
    Wrapping a PL/SQL unit prevents most users from examining the source code, but might not stop all of them."
    Edited by: apiminov on 03.12.2012 3:23
    Edited by: apiminov on 03.12.2012 3:24

  • Migrating from MS SQL Server 2005 database to Oracle 10g

    Hello,
    I wanted the full procedure or steps to Migrate the MS SQL Server 2005 database to Oracle 10g. Is there a known procedure to do this or is there a tool which is used?
    I have not done migration of database from MS SQL Server to Oracle. Any help is appreciated. Thanks a lot for the time.
    Regards,
    RPS

    Wrong forum, go to the database forum!
    cu
    Andreas

  • What will you do if any SQL is not working.in oracle 10g...apps 11.5.10.2

    What will you do if any SQL is not working. in oracle 10g....apps 11.5.10.2

    928714 wrote:
    yes sir.If you help me in answering my questions i wll be very thankful to you sir.
    tnx,I haven't a clue.
    As you have been advised in many of your posts, go study the documentation for whichever specific topic you are interested in.
    For me to answer your questions, I would need to go get that documentation.
    Then I would need to read that documentation.
    Then I would need to write a forum post that interprets what I think I learned from that documentation.
    It is so very much faster if YOU go do that instead of posting to a forum and expecting others to do it. You will remember what you study for a lot longer time if you teach yourself.

  • Sql Server Reporting  services with ORACLE

    We are thinking of using Sql Server Reporting servicesvwith an ORACLE DB.
    I will like to know the pros and cons.
    Any advice would be appreciated..
    Thanks alot.

    Hello,
    You'll find many doc, examples, demos ... on OTN :
    http://www.oracle.com/technology/products/reports/index.html
    http://www.oracle.com/technology/documentation/reports.html
    http://www.oracle.com/technology/products/reports/htdocs/search.html?cat=ALP&col=ALC&submit=Search
    For the Ref Cursors :
    Oracle® Reports Building Reports
    10g Release 2 (10.1.2)
    B13895-01
    40 Building a Paper Report with REF CURSORs
    Regards

  • Extract the data from SQL Server and Import into Oracle

    Hi,
    I would like to run a daily job that will export the table data from SQL server table (it will be only one or two table) and Import back into Oracle table (it might one or two table tables).
    Could you please guide me that how can i do this using either sql server or oracle?
    We have oracle 9.2 and sql server 2005.
    Normally i do from flat file which is generated by source destination nand i dump into oracle using sql*loader but this time I have to directly extract/export the data from MS Sql server and load into Oracle table, mostly it will reload so i might doing any massaging data during the load.
    If you show me the detail approach, it will be really appreciated.
    I have access to Sql server but i don't how to use sql server to do this or using oracle as a daily job even becuase have to schedule the job for this as it will be a daily job.
    Thanks,
    poratips

    Unless you can find an open source ODBC driver for SQL Server that runs on Solaris (and I wouldn't be overly hopeful there) Heterogeneous Services would require that you license something-- a third party ODBC driver, a new Oracle instance, or an Oracle Transparent Gateway.
    As I stated below, you could certainly use SQL Server's ETL tool, DTS. Oracle's ETL tools would require additional licensing since you're just on 9.2. You could also write a small application (Java or otherwise) that connected to both databases and transferred the data. If you're particularly enterprising, you could load the SQL Server Type 4 JDBC driver into Oracle's JVM and write a Java stored procedure that connected to the SQL Server database via JDBC, but that's a pretty convoluted approach.
    Justin

  • Which sql developer version will support oracle 8.1.7

    hi
    which sql developer version will support oracle 8.1.7 or is it necessary to use plsql developer to connect to database (oracle 8.1.7)

    Hi,
    SQL Developer version 1.2.1 is able to connect to 8.1.7 with limited functionality (prepared reports and browser for objects could not work)..
    Next version (tested with 3.2 64-bit) of SQL developer could be "hacked" to connect to 8.1.7 by simply copy file C:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.zip from Oracle client prior 11
    into appropriate jdk\jre\lib\ext folder.

  • How to find GUI SQL*Plus command tool in Oracle 8i (version 8.1.7)

    I had installed Oracel 8i Enterprise Edition (version 8.1.7) on my server machine (Windows NT 4.0), I'd like to use Oracle Navigator (GUI SQL*PLUS command tool), but I can not find it from the menu. I know Oracle Navigator is available in Oracle 7. Can anyone tell me where and how to use GUI SQL*PLUS command tool in Oracle 8i Enterprise Edition (version 8.1.7) ?
    thanks a lot.
    David Zhu

    Hi
    Oracle Navigator is part of Personal Oracle7 and Oracle Lite. I don't know is it available in 8i Personal Edition but I am sure that it is not part of Standard and Enterprise Edition.
    Regards
    null

  • SQL Developer does not support Oracle 8i

    Hi,
    I was waiting a tool from Oracle like SQL Developer for a long time, finally it came, but I am a little disapointed, so Why SQL Developer does not support Oracle 8i? Other free tools like SQUIRREL can do it. I also have worked in previous projects using PL/SQL Developer and it works fine...Why a native Oracle tool can not do it?
    I am in a project where we have to upgrade the Oracle database to a newer version, but I cannot have access to the old one...
    I know there are some threads in this forum, and some people can work with 8i with no issues. Can anyone who works with SQL Developer and Oracle 8i please tell me how to do it?
    Thanks,
    --Javier
    Edited by: javierlarota on Dec 9, 2009 5:40 AM
    Edited by: javierlarota on Dec 9, 2009 5:41 AM

    That's what I thought, the issue is more commercial ($$$) than technical. Anyway...I downloaded the version 1.1 but now I am getting an ORA-02248: invalid option for ALTER SESSION error. 00604. 00000 "error occurred at recursive SQL level %s".
    Thanks,
    --Javier                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Convert sql form 3.0 to oracle form

    hi all
    if someone know how to convert oracle sql form 3.0 to oracle form
    best regards

    Hi Samer:
    The f45gen executable tha come with forms 4.5 can move your forms to 4.5 and then you can upgrade to forms 6i (or possibly 9i). Unfortunately I am writing this from home and I do not have Forms 4.5 her but I do have it at work. I'll sees if I can get you the correct syntax by tomorrow (if I have time). In the mean time if you have forms 4.5 you can try looking at the help for maybe f45gen or conversion, etc and you may get the syntax. Hope this helps.
    Thomas Morgan

  • Migration from sql server 2005 tables to oracle tables.

    Hi,
    Kindly give the steps to migrate from sql server 2005 tables to oracle tables.
    Kindly advise
    Oracle database version:
    Oracle Database 10g Release 10.2.0.1.0 - Production
    PL/SQL Release 10.2.0.1.0 - Production
    "CORE 10.2.0.1.0 Production"
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Edited by: 873127 on Jul 18, 2011 9:46 PM

    Are you migrating or taking continual updates?
    If migrating it might be worth considering The SQLDeveloper Migration Workbench (which moves more than just data)..
    http://www.oracle.com/technetwork/database/migration/sqldevmigrationworkbench-132899.pdf
    Cheers
    David

  • Replication SQL Server 7 Database to Oracle 9i

    Hi -
    I'm new to Database Replication, what are the steps for database replication from a MS SQL Server 7 database to Oracle 9i? Eventually this SQL Server Database will be going to SQL Server 2000 are the steps different, if so what are they?
    Thanks
    Much

    I do not what you mean with Replicate between SQL Server and Oracle. Perhaps you mean migrate from SQL Server to Oracle or to stablish a transparent gateway.
    I am going to give you this reference:
    Migration Workbench Reference Guide for Microsoft SQL Server and Sybase Adaptive Server Migrations Contents / Search / Index / PDF
    Heterogeneous Connectivity Administrator's Guide Contents / Search / Index / PDF
    http://otn.oracle.com/pls/db92/db92.docindex?remark=homepage
    Joel P�rez

  • Migrating MS SQL Server 7.0 TO Oracle 8.1.5

    Hello,
    We are currently using Win NT 4.0, MS SQL Server with a PVCS Tracker 6.0 from Merant and will be upgrading to PVCS Dimension 6.0 from Merant.
    The Dimension 6.0 product runs on Win NT 4.0, uses Oracle Server 8.1.5 with Oracle 8 ODBC Driver 2.5.3.1.0
    I need to migrate MS SQL Server 7.0 To Oracle 8.1.5. Do you have a migration procedure available?
    Thanks!
    TP

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Oracle Migration Workbench Team:
    The Oracle Migration Workbench will assist you in the Migration of the SQL*Server 7 DB. It is available as a free download from this site.
    <HR></BLOCKQUOTE>
    null

  • Migrating SQL Server 7.0 to Oracle 8i in Different Operating Systems

    I am migrating SQL Server 7.0 Databases on NT to Oracle 8i on Sun 2.6. Is there is any other way other then Migration Workbench.
    If Mig Workbench is OK. What are the steps to do Migration.
    null

    Hi,
    You can perform this action with the Oracle Migration Workbench. Just install the Workbench on the same machine as your SQL Server database.
    You can then configure the workbench to point to the oracle database on your Sun machine.
    You can use the Oracle database on your Sun machine for both your destination database (the database to which you migrate your SQL Server schema and data) and workbench repository.
    In order to do this you will need to configure a tnsnames.ora entry. The tool that will do this configuration for you should be started up at the end of the workbench installation. It is a fairly straightfoward process.
    You then need to create a user in your oracle database that will store the workbench repository.
    Once you have comleted these steps you will be able to migrate SQL Server on NT to Oracle on Sun.
    It is exactly the same process as migrating to Oracle on NT except you are pointing the Workbench to Oracle on a Sun box.
    Regards
    John

  • Migration from MS SQL Server 7.0 to ORACLE 7.3

    I am unable to download WorkBench. Does it support the migration from MS SQL Server 7.0 to ORACLE 7.3 anyway.

    Actually, I have to do the conversion from MS SQL Server 7.0 to ORACLE 7.3. I am thinking to do migration firt then do the conversion by writing the packages. Is there any other way to do it......
    I am unable to download WorkBench. Does it support the migration from MS SQL Server 7.0 to ORACLE 7.3 anyway.

Maybe you are looking for

  • Hot Synch Note pad

    Can anyone tell me why I am unable to  synchronise note pad from my Tungsten T2 to my PC. Everything else synchronises OK? Thanks Post relates to: Tungsten T2

  • 'AND' process in a process chain failure - need help

    For the first time and out of no where, two separate 'AND' processes in two separate process chains failed on two separate days. It displayed error the same messages in both isntances as below. It seems that when the first load completed and the seco

  • Help please - unable to open missing photos 'browse' dialogue box

    Hi All, new to the forum, but long time LR user. I have a problem with LR v.3.4.1 I have a few missing photos (quite a few actually) in my catalogue from when I moved hard drives in v1.  I jumped from v.1 to v3.  But used to be able to find them stil

  • Prob with chinese font bold, italic... in PDF report

    Hello everyone ! :D My symptoms (overview) : to create my RDF report, I'm using a font, simsun.ttf, wich allow me to view chineses and french characters. Everything is ok, except in PDF format, all the items remains in "normal" style. My configuratio

  • Pixelated web gallery images

    I am experiencing several pixelated images in web galleries that I create.  It seems that the pixelation occurs only with the color black such as a black suit.  The pixels show up as whit or white-gray.  Here is one example.  There are about 12 image