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
 

Friday, June 3, 2011

Grouping tags based on Condition +XSLT

Here we are going to discus about how to group the tags under some condition in xslt. I will explain this by taking the Employer example.
        Before this we need to know some of the xslt functions and template calling .
  • generate-id()
  • key()
  • <xsl:key>
  • <xsl:template>
Suppose we have one xml which is having many number of branches in a company .Each branch has many number of employees. The xml looks like this.

<?xml version="1.0" ?>
<Employees>
<Employee>
<TeamID>1</TeamID>
<TeamName>Sales</TeamName>
<TaskID>1</TaskID>
<Hours>5</Hours>
<EmployeeID>1</EmployeeID>
<Name>Bob</Name>
<Surname>Shibob</Surname>
</Employee>
<Employee>
<TeamID>1</TeamID>
<TeamName>Sales</TeamName>
<TaskID>2</TaskID>
<Hours>4</Hours>
<EmployeeID>1</EmployeeID>
<Name>Bob</Name>
<Surname>Shibob</Surname>
</Employee>
<Employee>
<TeamID>1</TeamID>
<TeamName>Sales</TeamName>
<TaskID>4</TaskID>
<Hours>7</Hours>
<EmployeeID>2</EmployeeID>
<Name>Sara</Name>
<Surname>Lee</Surname>
</Employee>
<Employee>
<TeamID>2</TeamID>
<TeamName>Finance</TeamName>
<TaskID>5</TaskID>
<Hours>2</Hours>
<EmployeeID>3</EmployeeID>
<Name>John</Name>
<Surname>Smith</Surname>
</Employee>
<Employee>
<TeamID>2</TeamID>
<TeamName>Finance</TeamName>
<TaskID>3</TaskID>
<Hours>4</Hours>
<EmployeeID>4</EmployeeID>
<Name>Penny</Name>
<Surname>Wise</Surname>
</Employee>
<Employee>
<TeamID>2</TeamID>
<TeamName>Finance</TeamName>
<TaskID>5</TaskID>
<Hours>3</Hours>
<EmployeeID>4</EmployeeID>
<Name>Penny</Name>
<Surname>Wise</Surname>
</Employee>
</Employees>

To do this
·        First declare the one key variable
<xsl:key name=" keyEmployeeID" match="Employee" use=" EmployeeID"/>
·        Then write a for loop for iterating the Employee set
<xsl:for-each select="Employee”>
·        Then generate and id for each key value of employes
<xsl:for-each select="…………generate-id(key('keyEmployeeID', EmployeeID)[1])]">
·        Assign all this ids in to a array
<xsl:for-each select="tEmployee[generate-id(.) = generate-id(key('keyEmployeeID', EmployeeID)[1])]">


Valid XSD format values

xs:datetime
Valid xs:datetime value is 2005-05-27T14:11:00.943Z but the following values are not the valid one
  • 2005-05-27 14:11:00.943Z (missing date and time separator "T"),
  • 2005-05-27T14:11:00.943 (missing time zone)
  • 2005-05-27 14:11:00.943 (missing time separator and time zone).
xs:date
2005-05-27Z is a valid xs:date value but 2005-05-27 is not since no time zone is specified

xs:boolean
True is not a valid xs:boolean valied.It sholud be'true'.similarly 'False' is not valid value,it is 'false'

xs:decimal

value 0.12345678 but not 12E-4.to convert scientific number in to the decimal format you neet to use the following template convertSciToNumString (which is published in the previous post)

XStream - Features

XStream is a simple library to serialize objects to XML and back again.
Features
  • Ease of use. A high level facade is supplied that simplifies common use cases.
  • No mappings required. Most objects can be serialized without need for specifying mappings.
  • Performance. Speed and low memory footprint are a crucial part of the design, making it suitable for large object graphs or systems with high message throughput.
  • Clean XML. No information is duplicated that can be obtained via reflection. This results in XML that is easier to read for humans and more compact than native Java serialization.
  • Requires no modifications to objects. Serializes internal fields, including private and final. Supports non-public and inner classes. Classes are not required to have default constructor.
    Full object graph support. Duplicate references encountered in the object-model will be maintained. Supports circular references.
  • Integrates with other XML APIs. By implementing an interface, XStream can serialize directly to/from any tree structure (not just XML).
  • Customizable conversion strategies. Strategies can be registered allowing customization of how particular types are represented as XML.
  • Error messages. When an exception occurs due to malformed XML, detailed diagnostics are provided to help isolate and fix the problem.
  • Alternative output format. The modular design allows other output formats. XStream ships currently with JSON support and morphing

Tuesday, May 31, 2011

converting scientific number to Number - XSLT

To conver BigDecimal number in to the normal number in xslt ,we need to write  a new template .
then call this template in the following way
xsl:call-template name="convertSciToNumString"><xsl:with-param name="inputVal" select="percentAmmo" /></xsl:call-template>Template is
<xsl:template name="convertSciToNumString">
<xsl:param name="inputVal" select="0" />
<xsl:variable name="max-exp">
<xsl:value-of
select="'0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'" />
</xsl:variable>
<xsl:variable name="numInput">
<xsl:value-of select="translate(string($inputVal),'e','E')" />
</xsl:variable>
<!-- ==== Mantisa ==== -->
<xsl:variable name="numMantisa">
<xsl:value-of select="number(substring-before($numInput,'E'))" />
</xsl:variable>
<!-- ==== Exponent ==== -->
<xsl:variable name="numExponent">
<xsl:choose>
<xsl:when test="contains($numInput,'E+')">
<xsl:value-of select="substring-after($numInput,'E+')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-after($numInput,'E')" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- ==== Coefficient ==== -->
<xsl:variable name="numCoefficient">
<xsl:choose>
<xsl:when test="0 > $numExponent">
<xsl:text>0.</xsl:text>
<xsl:value-of select="substring($max-exp, 1, -number($numExponent)-1)" />
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:when test="$numExponent > 0">
<xsl:text>1</xsl:text>
<xsl:value-of select="substring($max-exp, 1, number($numExponent))" />
</xsl:when>
<xsl:otherwise>
1
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="result">
<xsl:value-of select="number($numCoefficient) * number($numMantisa)" />
</xsl:variable>
<xsl:choose>
<xsl:when test="$result = 'NaN'">
<xsl:value-of select="$numInput" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$result" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<