Friday, March 13, 2015

JMS Listener:



This makes Message handling is loosely coupled with either subscriber /Receiver

MessageListener is an interface which is available in the JMS package. which facilitates the Listner
for a message and send an event to either a Subscriber / Receiver.

This interface contain on method .

public void onMessage(Message msg);

Provide an implimentation to this in your own class

import javax.jms.*;

public class JMSListener implements MessageListener
{

    public void onMessage(Message msg)
    {
        try{
           
            TextMessage tm  = (TextMessage) msg;
            System.out.println(tm.getText());

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}


configure this JMSListener in the subscriber,

    tSubscriber.setMessageListener(new JMSListener());

Transaction Management in JMS



          By Default JMS auto Transactyions are auto committed.  Session is actually taken care the Transaction Mgmt in JMS.

To enable Transaction mgmt ,Set "true" to the first parameter While creating a session from connection.

Set  "false" to the first parameter While creating a session from connection and try following statement.

    QueueSession qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    qsession.rollback();

It will cause the following exception,

com.ibm.msg.client.jms.DetailedIllegalStateException: JMSCC0014: It is not valid to call the 'rollback' method on a nontransacted session. The application called a method that must not be called on a nontransacted session. Change the application program to remove this behavior.

Set "true" to the first parameter While creating a session from connection and try following statement.

    QueueSession qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   
    <send a message 1>
    <send a message 2>
    <send a message 3>

    qsession.rollback();

Browse the above message in the MQ Explorer and find out the result.

Following Program explain the Transaction mgmt in JMS

import javax.jms.*;
import java.util.Hashtable;
import javax.naming.*;
import java.io.*;
public class JMSTransactionDemo
{
    public static void main(String args[])
    {
      
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Enter 10 Messages ......");

            Hashtable ht = new Hashtable();
            ht.put(Context.PROVIDER_URL,"file:/C:/JNDI-Directory");
            ht.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
            Context ctx = new InitialContext(ht);
          
            QueueConnectionFactory qcf = (QueueConnectionFactory)ctx.lookup("MY_QCF");
          
            Queue qu = (Queue) ctx.lookup("MY_Q");

            QueueConnection qcon = qcf.createQueueConnection();

            //QueueSession qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            QueueSession qsession = qcon.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);

            QueueSender qSender =  qsession.createSender(qu);
          
            for(int i=0;i<=10;i++){    

                TextMessage msg =  qsession.createTextMessage();
              
                String line = br.readLine();

                msg.setText(line );
              
          
                qSender.send(msg);

                if(i==5)
                    qsession.rollback();

                if(i==10)
                    qsession.commit();
            }

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

Thursday, March 12, 2015

About JMS

A specification that describes a common way for Java programs to create,send, receive and read distributed enterprise messages.
                              JMS is a part of the Java Platform, Enterprise Edition, and is defined by a specification developed under the Java Community Process as JSR 914.  It is a messaging standard that allows application components based on the Java Enterprise Edition (Java EE) to create, send, receive, and read messages.  It allows the communication between different components of a distributed application to be loosely coupled, reliable, and asynchronous.

Messages are

    Asynchronous:
    -------------
        a client does not have to request them in order to receive them.
    Reliable:
    ----------
        can ensure message is delivered safely once and only once.

Messaging Domains
-----------------
   Point-to-Point



    Publish/Subscribe





JMS Administration With IBM WebSphere MQ
-----------------------------------------------
0. Create a Queue Manager in Websphere MQ as QM1
   Create a Local queue under a QM1 as LQ1

1.check the PROVIDER_URL in the C:\Program Files\IBM\WebSphere MQ\java\bin

2. Create a folder for PROVIDER_URL like (C:/JNDI-Directory)

3. execute the JMSAdmin.bat in C:\Program Files\IBM\WebSphere MQ\java\bin

4. define the queue connection Factory
     define qcf(MY_QCF) qmgr(QM1)
  which will create a file in the C:/JNDI-Directory as  .bindings

5.create destination object
    define q(MY_Q) queue(LQ1) qmgr(QM1)

  which will update this details in the .bindings file in C:/JNDI-Directory

6. configure JNDI in Websphere MQ   
    . click on JMS Administrated Object
    . right click and choose add initial context
    . select File System Option
    . and browse the JNDI-Directory by clicking the Browse button
    . Click Next -> Finish

JMS Client
-----------




1.  Initialize the InitialContext with the following values
    .provide the value PROVIDER_URL
    .provide the value INITIAL_CONTEXT_FACTORY

    Hashtable ht = new Hashtable();
    ht.put(Context.PROVIDER_URL,"file:/C:/JNDI-Directory");
    ht.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
    Context ctx = new InitialContext(ht);

2. Retrieve the configured QueueConnectionFactory from InitialContext by passing "MY_QCF"
    QueueConnectionFactory qcf = (QueueConnectionFactory)ctx.lookup("MY_QCF");

3. Retrieve the configured Queue from InitialContext by passing "MY_Q"
    Queue qu = (Queue) ctx.lookup("MY_Q");

4. Create the QueueConnection from QueueConnectionFactory
    QueueConnection qcon = qcf.createQueueConnection();

5. Create the QueueSession from QueueConnection
    QueueSession qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

7. Create the QueueSender  from QueueSession
    QueueSender qSender =  qsession.createSender(qu);

8. Create the Text Message from QueueSession
    TextMessage msg =  qsession.createTextMessage();

9. send a text throw Text Message
   
    msg.setText(args[0]);

    qSender.send(msg);



Example Sender Program

import javax.jms.*;
import java.util.Hashtable;
import javax.naming.*;
public class JMSSender
{
    public static void main(String args[])
    {
       
        try
        {
            Hashtable ht = new Hashtable();
            ht.put(Context.PROVIDER_URL,"file:/C:/JNDI-Directory");
            ht.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
            Context ctx = new InitialContext(ht);
           
            QueueConnectionFactory qcf = (QueueConnectionFactory)ctx.lookup("MY_QCF");
           
            Queue qu = (Queue) ctx.lookup("MY_Q");

            QueueConnection qcon = qcf.createQueueConnection();

            QueueSession qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
           
            QueueSender qSender =  qsession.createSender(qu);

            TextMessage msg =  qsession.createTextMessage();

            msg.setText(args[0]);
           
            qSender.send(msg);

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}


Example Receiver Program


import javax.jms.*;
import java.util.Hashtable;
import javax.naming.*;
public class JMSReceiver
{
    public static void main(String args[])
    {
       
        try
        {
            Hashtable ht = new Hashtable();
            ht.put(Context.PROVIDER_URL,"file:/C:/JNDI-Directory");
            ht.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");

            Context ctx = new InitialContext(ht);
           
            QueueConnectionFactory qcf = (QueueConnectionFactory)ctx.lookup("MY_QCF");
           
            Queue qu = (Queue) ctx.lookup("MY_Q");

            QueueConnection qcon = qcf.createQueueConnection();
           
            qcon.start();

            QueueSession qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
           
            QueueReceiver qReceiver = qsession.createReceiver(qu);
           
            TextMessage tmsg= (TextMessage) qReceiver.receive(30000);
           
            System.out.println(tmsg.getText());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}


Example Publisher Program

import javax.jms.*;
import java.util.Hashtable;
import javax.naming.*;
public class JMSPublisher
{
    public static void main(String args[])
    {
       
        try
        {
            Hashtable ht = new Hashtable();
            ht.put(Context.PROVIDER_URL,"file:/C:/JNDI-Directory");
            ht.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
           
            Context ctx = new InitialContext(ht);
           
            TopicConnectionFactory tcf = (TopicConnectionFactory)ctx.lookup("MY_TCF");

            Topic topic= (Topic ) ctx.lookup("MY_T");

            TopicConnection tcon = tcf.createTopicConnection();
           
            TopicSession tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
           
            TopicPublisher tp = tsession.createPublisher(topic);

            TextMessage msg =  tsession.createTextMessage();

            msg.setText(args[0]);
           
            tp.publish(msg);
           
            tsession.close();

            tcon.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

Example Subscriber Program

import javax.jms.*;
import java.util.Hashtable;
import javax.naming.*;
public class JMSSubscriber
{
    public static void main(String args[])
    {
       
        try
        {
            Hashtable ht = new Hashtable();
            ht.put(Context.PROVIDER_URL,"file:/C:/JNDI-Directory");
            ht.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
            Context ctx = new InitialContext(ht);
           
            TopicConnectionFactory tcf = (TopicConnectionFactory)ctx.lookup("MY_TCF");
           
            Topic topic = (Topic) ctx.lookup("MY_T");

            TopicConnection tcon = tcf.createTopicConnection();
           
            tcon.start();

            TopicSession tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
           
            TopicSubscriber tSubscriber= tsession.createSubscriber(topic);
           
            TextMessage tmsg= (TextMessage) tSubscriber.receive(3000000);
           
            System.out.println(tmsg);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

Wednesday, October 17, 2012

Enable/Disable Constraints In an Oracle Database

Triggers
alter trigger <TGR_NAME> disable;
alter trigger <TGR_NAME> enable;

Primary Key
alter table <TABLE_NAME> disable  PRIMARY KEY;
alter table <TABLE_NAME> disable  CONSTRAINT <PK_NAME>;

alter table <TABLE_NAME> enable PRIMARY KEY;
alter table <TABLE_NAME> enable CONSTRAINT <PK_NAME>;


Foreign Key
alter table <TABLE_NAME> disable CONSTRAINT <FK_NAME>;
alter table <TABLE_NAME> enable CONSTRAINT <FK_NAME>;

Finding foreign key constraints in an Oracle database

SELECT   uc.constraint_name||CHR(10)
||      '('||ucc1.TABLE_NAME||'.'||ucc1.column_name||')' constraint_source
,       'REFERENCES'||CHR(10)
||      '('||ucc2.TABLE_NAME||'.'||ucc2.column_name||')' references_column
FROM     user_constraints uc
,        user_cons_columns ucc1
,        user_cons_columns ucc2
WHERE    uc.constraint_name = ucc1.constraint_name
AND      uc.r_constraint_name = ucc2.constraint_name
AND      ucc1.POSITION = ucc2.POSITION -- Correction for multiple column primary keys.
AND      uc.constraint_type = 'R'
ORDER BY ucc1.TABLE_NAME
,        uc.constraint_name;

Thursday, September 27, 2012

java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()

Cause:
weblogic and websphere are not able to load the hibernate3.x jar file from the provided WAR file. To resolve this issue , use the following solution
solution is:
Added the hibernate-jpa-2.0-api-1.0.0.Final.jar in the Following path
JAVA_HOME \jre\lib\ext
and also place same jar in  weblogic specific JRE\lib\ext folde

 

Monday, January 2, 2012

setting debug port in the Tomcat and weblogic

Tomcat
adding this stuff to your startup script so that you are always running tomcat in debug mode.
  1. Open the startup script in (your_tomcat_home)/bin (WIN: startup.bat, UNIX: startup.sh)
  2. Add the following lines at the first blank line in the file (around line 8)
    WIN:
    set JPDA_ADDRESS=8000
    set JPDA_TRANSPORT=dt_socket
    
    UNIX:
    export JPDA_ADDRESS=8000
    export JPDA_TRANSPORT=dt_socket
    
  3. Change the execute line at the end to include jpda start
    WIN:
    call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
    
    UNIX:
    exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"
    
  4. Run the startup script when starting tomcat to run tomcat in debug mode
Weblogic
    use the following points to enable the debug port
  1. go to the domain in the weblogic
  2. open the bin
  3. edit the setDomainEnv.sh
  4. past the JAVA_DEBUG="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8087,server=y,suspend=n -Djava.compiler=NONE"
  5. then execute the startWeblogic.sh

Friday, December 30, 2011

installing the SVN

Use the following site to install svn plug-in
Proxy setting in the windows
1.       Go to C:\Documents and Settings\user\Application data\subversion\
2.       Find server file
3.       Add the proxy setting
[global]
http-proxy-host = web-proxy.mycompany.com
http-proxy-port = 8080
http-proxy-username = <userID>
http-proxy-password = <password>


Installing and using the Maven

Follow the following steps to create the Maven
1.        Download the latest version of Maven from the following site

2.        Extract the downloaded zip file
3.        Create .bat file using the following line
a.        @SET MAVEN_ARGS=%*
b.       @SET JAVA_HOME=C:\HOMEWARE\sunjdk160_10
c.        @SET JAVA_CMD="%JAVA_HOME%\bin\java.exe"
d.       @SET M2_HOME=C:\HOMEWARE\mywork\apache-maven-3.0.3
e.        @SET CPATH=%M2_HOME%\boot\plexus-classworlds-2.4.jar
f.         %JAVA_CMD% -classpath %CPATH% -Dclassworlds.conf=%M2_HOME%\bin\m2.conf -Dmaven.home=%M2_HOME% org.codehaus.classworlds.Launcher %MAVEN_ARGS% -e
4.        Name this batch file as “mvn.bat”
5.        Then run the mvn –version for checking the installation
6.      Change the JAVA_HOME and M2_HOME path as per the installation of java and maven

Setting the repository
1.       Go to the path which is specified in the M2_HOME
2.       Then open the conf folder
3.       Find the setting.xml file
4.       Find the <localRepository /> tag
a.       Specify the repository  path as per the convince
                                                              i.      <localRepository>C:\HOMEWARE\maven-local-repo</localRepository>
5.       If you’re in the office
a.       find the available and accessible mirrors and fill in the  <mirror />
b.      configure all public repositories and plug-in repository in the <profile />
Using Maven
1.       Download a project from the one of the famous site
a.       svn checkout http://micrite.googlecode.com/svn/trunk/ micrite-read-only
2.       Extract the zip file in the c:\
3.       Copy our mvn.bat file in to the  project file and run the following commands
a.       mvn clean          
b.      mvn install
c.       mvn eclips:eclipse


Monday, November 21, 2011

Calculate Bond Price in Java

Calculate Bond Price in Java

We tried all the tools to calculate the BondPrice .finaly nothing achived with third party tools .
Luckly we found the following class to calculate the yeild price of the Bond. This class is more accurate
than any other tool.
  java.text.DateFormat;
import
java.text.SimpleDateFormat;
import
java.util.Calendar;
import
 
java.util.Date;
public
Calendar maturity = Calendar.getInstance();
maturity.setTime(formatDate(
Calendar settlement = Calendar.getInstance();
settlement.setTime(formatDate(
Price price =
class Price {public static void main(String[] args) {"08/28/2012"));"02/29/2012"));new Price();try {double priceVa2 = price.tbondPrice( new Date(settlement.getTimeInMillis()), // settlementDate
new Date(maturity.getTimeInMillis()), // maturityDate
0.0865,
// rate
0.0895205173068493,
// yield
100.,
// redemption
2,
// frequency
0
// basis
);
System.
}
e.printStackTrace();
}
}
{
Calendar cal=
Date date1 =
out.println(priceVa2);catch (Exception e) {public static Date formatDate(String date)null;null; try
{
DateFormat formatter ;
formatter =
date1 = (Date)formatter.parse(date);
cal=Calendar.getInstance();
cal.setTime(date1);
}
e.printStackTrace();
}
}
{
{
{
paramCalendar1.add(5, -1);
}
{
paramCalendar2.add(5, 1);
}
{
paramCalendar2.add(5, -1);
}
}
new SimpleDateFormat("MM/dd/yyyy");catch(Exception e){return date1; private long days360(Calendar paramCalendar1, Calendar paramCalendar2, boolean paramBoolean)int i = paramCalendar1.get(5);int j = paramCalendar2.get(5);int k = paramCalendar1.get(2);int l = paramCalendar2.get(2);int i1 = paramCalendar1.get(1);int i2 = paramCalendar2.get(1);if (!(paramBoolean))if (i > 30)if ((j == 31) && (i > 30))else if (j == 31)else
{
{
paramCalendar1.add(5, -1);
}
{
paramCalendar2.add(5, -1);
}
}
i = paramCalendar1.get(5);
j = paramCalendar2.get(5);
}
{
{
{
d1 += paramDouble2 * Math.pow(d3, d2 * -1.0D);
d2 += 1.0D;
}
}
d1 -= paramDouble4;
}
{
d1 = 0.0D;
d1 = 100.0D * paramDouble1 / frequency;
}
Calendar SettlementDt = Calendar.getInstance();
SettlementDt.setTimeInMillis(paramDate1.getTime());
Calendar maturityDt = Calendar.getInstance();
maturityDt.setTimeInMillis(paramDate2.getTime());
Calendar prevCpnDt = Calendar.getInstance();
{
prevCpnDt.set(SettlementDt.get(1) + 1, maturityDt.get(2), maturityDt.get(5) - 1);
}
if (i > 30)if (j > 30)int i3 = (i2 - i1) * 12 + l - k;return (i3 * 30 + j - i);private double calculatedPrice(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4, double paramDouble5, int paramInt1, int paramInt2)int j = paramInt1;double d3 = 1.0D + paramDouble1 / paramInt2;double d2 = paramDouble5;double d1 = paramDouble3 * Math.pow(d3, (j - 1 + d2) * -1.0D);if (paramDouble2 > 0.0D)for (int i = 1; i <= j; ++i)return d1;public double tbondPrice(Date paramDate1, Date paramDate2, double paramDouble1, double paramDouble2, double paramDouble3, int frequency, int paramInt2)throws Exceptiondouble d1;if (paramDouble1 == 0.0D)else {int j = 12 / frequency;if (((SettlementDt.get(1) + 1) % 4 != 0) && (maturityDt.get(2) == 2) && (maturityDt.get(5) == 29))else
{
prevCpnDt.set(SettlementDt.get(1) + 1, maturityDt.get(2), maturityDt.get(5));
}
}
}
{
prevCpnDt.set(maturityDt.get(1), maturityDt.get(2), maturityDt.get(5));
}
{
prevCpnDt.add(2, j * -1);
}
Calendar nextCpnDt = Calendar.getInstance();
nextCpnDt.set(prevCpnDt.get(1), prevCpnDt.get(2), prevCpnDt.get(5));
nextCpnDt.add(2, j);
{
l2 = days360(prevCpnDt, nextCpnDt,
l1 = days360(SettlementDt, nextCpnDt,
}
if (maturityDt.getTimeInMillis() < SettlementDt.getTimeInMillis()) {throw new Exception("The maturity date mast be greater then settlement date.");if (paramDouble3 < 0.0D)throw new Exception("The redemption price must be grater than zero.");if ((frequency != 1) && (frequency != 2) && (frequency != 3) && (frequency != 4) && (frequency != 6) && (frequency != 12))throw new Exception("The frequency must be 1, 2, 3, 4, 6, or 12.");if ((paramInt2 != 1) && (paramInt2 != 0)) {throw new Exception("The basis must be 1 or 0.");if (prevCpnDt.getTimeInMillis() > maturityDt.getTimeInMillis())while (prevCpnDt.getTimeInMillis() > SettlementDt.getTimeInMillis())int maxPeriod = (maturityDt.get(1) - prevCpnDt.get(1)) * 12 + maturityDt.get(2) - prevCpnDt.get(2);int i = maxPeriod / j;long l2;long l1;if (paramInt2 == 0)true);true);else
{
l2 = nextCpnDt.getTimeInMillis() - prevCpnDt.getTimeInMillis();
l1 = nextCpnDt.getTimeInMillis() - SettlementDt.getTimeInMillis();
}
{
d4 = (paramDouble3 + d1) / (paramDouble2 * d5 + 1.0D) - d3;
}
d4 = calculatedPrice(paramDouble2, d1, paramDouble3, d3, d2, i, frequency);
}
}
{
d += paramArrayOfDouble1[j] * Math.exp(-paramArrayOfDouble3[j] * paramArrayOfDouble2[j]);
}
}
{
d5 = 0.0D;
d5 = 100.0D * paramDouble1 / paramInt1;
}
Calendar localCalendar1 = Calendar.getInstance();
localCalendar1.setTimeInMillis(paramDate1.getTime());
Calendar localCalendar2 = Calendar.getInstance();
localCalendar2.setTimeInMillis(paramDate2.getTime());
}
Calendar localCalendar3 = Calendar.getInstance();
{
localCalendar3.set(localCalendar1.get(1) + 1, localCalendar2.get(2), localCalendar2.get(5) - 1);
}
double d2 = Double.parseDouble(""+l1) / Double.parseDouble(""+l2);double d3 = d1 * (1.0D - d2);double d4;if ((i == 1) || (i == 0))double d5 = d2 / frequency;else {return d4;public double priceOfBond(double paramDouble1, double paramDouble2, double paramDouble3, double[] paramArrayOfDouble1, double[] paramArrayOfDouble2, double[] paramArrayOfDouble3)double d = 0.0D;int i = paramArrayOfDouble1.length;for (int j = 0; j < i; ++j) {return (paramDouble1 * Math.exp(-paramDouble3 * paramDouble2) + d);public double yieldToMaturityFromPrice(Date paramDate1, Date paramDate2, double paramDouble1, double paramDouble2, double paramDouble3, int paramInt1, int paramInt2)throws Exceptiondouble d5;if (paramDouble1 == 0.0D)else {int k = 12 / paramInt1;if (localCalendar2.getTimeInMillis() < localCalendar1.getTimeInMillis())throw new Exception("The maturity date mast be greater then settlement date");if (paramDouble2 < 0.0D)throw new Exception("The price must be strictly positive.");if (paramDouble3 < 0.0D)throw new Exception("The redemption price must be grater than zero.");if ((paramInt1 != 1) && (paramInt1 != 2) && (paramInt1 != 3) && (paramInt1 != 4) && (paramInt1 != 6) && (paramInt1 != 12))throw new Exception("The frequency must be 1, 2, 3, 4, 6, or 12.");if ((paramInt2 != 1) && (paramInt2 != 0)) {throw new Exception("The basis must be 1 or 0.");if (((localCalendar1.get(1) + 1) % 4 != 0) && (localCalendar2.get(2) == 2) && (localCalendar2.get(5) == 29))else
{
localCalendar3.set(localCalendar1.get(1) + 1, localCalendar2.get(2), localCalendar2.get(5));
}
{
localCalendar3.set(localCalendar2.get(1), localCalendar2.get(2), localCalendar2.get(5));
}
{
localCalendar3.add(2, k * -1);
}
Calendar localCalendar4 = Calendar.getInstance();
localCalendar4.set(localCalendar3.get(1), localCalendar3.get(2), localCalendar3.get(5));
localCalendar4.add(2, k);
{
l2 = days360(localCalendar3, localCalendar4,
l1 = days360(localCalendar1, localCalendar4,
}
if (localCalendar3.getTimeInMillis() > localCalendar2.getTimeInMillis())while (localCalendar3.getTimeInMillis() > localCalendar1.getTimeInMillis())int l = (localCalendar2.get(1) - localCalendar3.get(1)) * 12 + localCalendar2.get(2) - localCalendar3.get(2);int j = l / k;long l2;long l1;if (paramInt2 == 0)false);false);else
{
l2 = localCalendar4.getTimeInMillis() - localCalendar3.getTimeInMillis();
l1 = localCalendar4.getTimeInMillis() - localCalendar1.getTimeInMillis();
}
{
d4 = yieldWith1Coupon(d5, paramDouble3, paramDouble2, d7, d6, paramInt1);
}
double d6 = l1 / l2;double d7 = d5 * (1.0D - d6);double d4;if ((j == 1) || (j == 0))else
{
{
d2 = 0.1D;
}
{
d2 *= 2.0D;
}
d4 = 0.5D * (d3 + d2);
{
}
{
d3 = d4;
}
double d3 = -1.0D;double d2 = paramDouble1;if (d2 == 0.0D)while (calculatedPrice(d2, d5, paramDouble3, d7, d6, j, paramInt1) > paramDouble2)for (int i = 1; i <= 200; ++i)double d1 = calculatedPrice(d4, d5, paramDouble3, d7, d6, j, paramInt1) - paramDouble2;if (Math.abs(d1) < 0.0001D) {break;if (d1 > 0.0D)else
{
d2 = d4;
}
d4 = 0.5D * (d3 + d2);
}
}
}
{
}
}
return d4;private double yieldWith1Coupon(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4, double paramDouble5, int paramInt)double d3 = paramDouble2 + paramDouble1;double d1 = paramDouble3 + paramDouble4;double d2 = d3 / d1 - 1.0D;double d4 = paramDouble5 / paramInt;return (d2 / d4);


import

Friday, October 14, 2011

A small note on Nostro and Vostro

A bank counts a nostro account with a credit balance as a cash asset in its balance sheet. Conversely, a vostro account with a credit balance (i.e. a deposit) is a liability, and a vostro with a debit balance (a loan) is an asset. Thus in many banks a credit entry on an account ("CR") is regarded as negative movement, and a debit ("DR") is positive - the reverse of usual commercial accounting conventions.
With the advent of computerised accounting, nostros and vostros just need to have opposite signs within any one bank's accounting system; that is, if a nostro in credit has a positive sign, then a vostro in credit must have a negative sign. This allows for a reconciliation by summing all accounts to zero (a trial balance) - the basic premise of double-entry bookkeeping.
Typical usage:Nostro accounts are mostly commonly used for currency settlement, where a bank or other financial institution needs to hold balances in a currency other than its home accounting unit.
For example: First National Bank of A does some transactions (loans, foreign exchange, etc.) in USD, but banks in A will only handle payments in AUD. So FNB of A opens a USD account at foreign bank Credit Mutuel de B, and instructs all counter-parties to settle transactions in USD at "account no. 123456 in name of FNBA, at CMB, X Branch". FNBA maintains its own records of that account, for reconciliation; this is its nostro account. CMB's record of the same account is the vostro account.
Now, FNBA sells AUD1,000,000 to C (a counterparty who has an AUD account with FNBA, and a USD account with CMB) for a net consideration of USD2,000,000.

FNBA will make the following entries in its own accounting system:

(Internal) FX AUD trading account1,000,000 DRAUD Account in name of C1,000,000 CR
USD Nostro at CMB (FNBA's nostro)2,000,000 DR(Internal) FX USD trading account2,000,000 CR




Over at CMB, they record the following transaction:
USD Account in name of C2,000,000 DRUSD Account in name of FNBA (CMB's vostro)2,000,000 CR