The xweld-finance project includes foundational classes that provide the basic building blocks useful to support the creation of financial applications.
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¶
A currency is represented as an enumeration of ISO 4217 Currency Codes.
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.
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
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.converterin your RuntimeContext to refer to your implementation of the interface and use the
Injectattribute 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();
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.
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.
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?".
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.
The quote package defines the framework for returning quoted values. The values may be prices, discount factors, or FX rates.
For more information, please contact us at firstname.lastname@example.org.
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.