Project

General

Profile

<xweld/>-finance

The xweld-finance project includes foundational classes that provide the basic building blocks useful to support the creation of financial applications.

Primary Features

The core functionality supported through <xweld/>’s finance module includes:

  • Business centers that specify company office or business unit localities and regions
  • Holiday calendars across multiple localities and time zones
  • Handling money, currency and configurable currency conversion
  • Discount factors, FX, and price quotations
  • Daycount calculators and DateRoll conventions
  • Countries, Regions and Business Centers
  • Lightweight Date and DateTime classes
  • Extensions to the core conversion mechanism to support conversion between strings and money and java Dates and xweld Dates

Packages and Classes

com.xweld.finance

A currency is represented as an enumeration of ISO 4217 Currency Codes.

com.xweld.finance class diagram

com.xweld.finance.currency

Money is an amount of money in a specific currency. An interface IMoney is defined such that multiple implementaitons of money can be supported. There are two built-in implementations, one based on BigDecimal amounts and one based on Double. Converters are also available to enable the ConversionManager to convert between implementations of the IMoney interface.

com.xweld.finance.currency class diagram

A factory pattern MoneyFactory may be used to define which implementation of IMoney you wish to use in your application. The system property MoneyFactory.COM_XWELD_MONEY_PROPERTY ("com.xweld.finance.currency.money") may be set to the value of an alternative implementation. The default is com.xweld.finance.currency.Money. Below is an example of setting the property to SmallMoney:

System.setProperty(MoneyFactory.COM_XWELD_MONEY_PROPERTY,
                   "com.xweld.finance.currency.SmallMoney");
IMoney<?> ten = MoneyFactory.create(10.0, CurrencyCode.USD);

The <xweld/> RoundingMethod class is used to round an amount of money to specific conventions and numbers of decimal places. For example, a US Dollar value typically uses two decimal places, while quoted interest rates use five. The default number of decimal places is configured and maintained in the currency defaults (com.xweld.finance.currency.CurrencyDefaults) class. This class associates a currency code with a rounding method and default number of decimal places. The RoundingMethod class is used to round a Money amount according to a rounding type, which is an enumerated list defined in com.xweld.finance.RoundingMethodType. All of these associations are maintained by the setup tool for your application.

The basic operations on Money - such as add, multiply, divide and subtract - are mutable. This means that a + b changes the internal value of a. The arithmetic operations check to ensure that the currencies of the operand are the same, and if they are not, an exception is thrown.

Converting Amounts Of Money Between Currency Denominations

Money values may be converted between currencies using implemenations of the ICurrencyConverter class. The default implementation is
the class com.xweld.finance.currency.DefaultCurrencyConverter, but all <xweld/> applications are free to override this implementation in two ways:

  • if your application uses the runtime module and the dependency injection framework, you can set the value of the property com.xweld.finance.currency.converter in your RuntimeContext to refer to your implementation of the interface and use the Inject attribute to intitialize instances of a converter
  • similarly, if you don't use the runtime injection framework then you can simply set the above property and use the CurrencyConverterFactory to create instances if ICurrencyConverters as ICurrencyConverter<BigDecimal> converter = CurrencyConverterFactory<BigDecimal>.create();

com.xweld.currency.conversion class diagram

For example:

 ICurrencyConverter<BigDecimal> converter = 
    CurrencyConverterFactory<BigDecimal>.create();
 Money original = 
    new Money(new BigDecimal("50000.123"), CurrencyCode.USD);
 Money converted = 
    converter.convert(("Reuters", QuoteSide.CLOSE, original, 
                        CurrencyCode.CAD, time, ResolutionType.LATEST);

Or by injection:

 RuntimeContext contex = ContextFactory.get();
 Injector injector = context.getInjector();

 /* get the converter directly from the Injector or use the @Inject attribute on a class field */
 ICurrencyConverter<?> converter = injector.get(ICurrencyConverter.class);
 Money original = 
    new Money(new BigDecimal("50000.123"), CurrencyCode.USD);
 Money converted = 
         converter.convert("Reuters", QuoteSide.CLOSE, original, 
                            CurrencyCode.CAD, time, ResolutionType.LATEST);

Note that the convert method returns a new copy of the original amount converted to the specified currency. The original value is unchanged.

com.xweld.finance.calendar

Dates And Times

The calendar package contains Date and DateTime classes which are used in <xweld/> applications to represent Date and points in time using an extremely lightweight implementation.

com.xweld.finance.calendar.date class diagram

Holidays and Holiday Calendars

Holiday Calendars are used to determine whether a specific day is a holiday for a given business center. Holiday Calendars are also used to answer questions such as "What is the last business day of the month?".

com.xweld.finance.calendar class diagram

com.xweld.finance.daycount

Daycount Calculators are used to calculate the number of days or fractions of years between any two dates, according to the standard convention used in the financial industry. The daycount class hierarchy supports an extensible number of daycount calculators using a pluggable factory pattern. There are many built-in calculators for the common set of conventions, but application developers are free to add their own by extending the factory pattern.

com.xweld.finance.daycount class diagram

com.xweld.finance.quote

The quote package defines the framework for returning quoted values. The values may be prices, discount factors, or FX rates.

com.xweld.finance.quote class diagram

Contact Us

For more information, please contact us at .

Copyright

Copyright © 1999-2012 Free North Alliance Inc. All Rights Reserved.

The contents of this web site, including all images, text, graphics and software, are the sole property of Free North Alliance Inc. and its agents. Unauthorized use or transmission is strictly forbidden by international copyright law.

com.xweld.finance.JPG View - com.xweld.finance class diagram (78.8 KB) John Free, 01 September 2011 10:34 AM

com.xweld.finance.currency.JPG View - com.xweld.finance.currency class diagram (162 KB) John Free, 01 September 2011 12:15 PM

com.xweld.finance.daycount.JPG View - com.xweld.finance.daycount class diagram (89.5 KB) John Free, 01 September 2011 12:32 PM

com.xweld.finance.calendar.date.JPG View - com.xweld.finance.calendar.date class diagram (70.5 KB) John Free, 01 September 2011 12:40 PM

com.xweld.finance.calendar.JPG View - com.xweld.finance.calendar class diagram (109 KB) John Free, 01 September 2011 12:50 PM

com.xweld.finance.quote.JPG View - com.xweld.finance.quote class diagram (121 KB) John Free, 01 September 2011 01:11 PM

com.xweld.finance.currency.conversion.JPG View - com.xweld.currency.conversion class diagram (37.7 KB) John Free, 12 January 2012 10:46 AM