Recent Posts
Archives

PostHeaderIcon Notions de finance: la VaR

La VaR (‘v’ et ‘r’ en majuscules, ‘a’ en minuscule) est une notion de finance. Originellement, “VaR” signifie “Value at Risk”, soit “valeur sous risque” en francais.

La VaR fournit une indication de la valeur maximale des pertes qui ne devrait pas etre depassee, sauf “evenement exceptionnel“.
Le calcul de VaR depend fortement de theories mathematiques (integration, probabilites, statitistiques…). L’estimation de la VaR depend principalement de trois parametres:

  • le niveau de confiance: en general on choisit 99% ou 95%. Les 1% ou 5% restants correspondent a l’evenement exceptionnel cite plus haut.
  • la distribution des actifs. En general on suppose qu’elle suit une loi normale de Gauss.
  • la fenetre de temps: les risques encourus sont d’autant plus eleves qu’ils s’etalent sur le temps.

Intuitivement, la VaR donne une indication du risque de se trouver ou non sur “le mauvais bout de la gaussienne”.

PostHeaderIcon GWT to GXT migration

These days, I am discovering GWT, and more accurately ExtGWT, aka GXT.

Case

I have to write a “Hello World” application based on GXT.

Steps

  • Firstly, follow Lars Vogel’s tutorial to have a “Hello World” in GWT.
  • In Eclipse, add a dependancy from your project to extjs-gxt-lib-2.1.1.jar (version compatible with your GWT version: 1.7 or 2.0), available at this link.
  • In your *.gwt.xml file, remove:
    [xml]<inherits name=’com.google.gwt.user.theme.standard.Standard’/>[/xml]

    and add:

    [xml]<inherits name=’com.extjs.gxt.ui.GXT’/>[/xml]

  • Get the gxt-all.css file, copy it into war/css/ folder
  • In your *.html file, add the lines:
    [xml]<link rel="stylesheet" type="text/css" href="css/gxt-all.css" />[/xml]
  • Now, adapt your Java entry point source class, replacing GWT widgets with GXT ones.
  • Restart your server and refresh the page in your browser. You have your “Hello World” in GXT!

PostHeaderIcon Notions de finance: le collateral

Definition du collateral sur Wikipedia: “Un collatéral est un actif transférable ou une garantie apportée, servant de gage au remboursement d’un prêt dans le cas où le bénéficiaire de ce dernier ne pourrait pas satisfaire ses obligations de paiement.”

Offrons un exemple: une banque (plus generalement: un Prime Broker) suppose qu’un produit financier donne, disons une action, ne peut pas perdre plus de 20% en une journee. Elle imposera alors un collateral de 20% (soit 0.2 en notation decimale), ce qui implique que le client aura un effet de levier de 5 (ie 1/0.2). D’autre part, la banque ne transfere pas concretement les titre a son client, elle le conserve en son nom propre, jusqu’au paiement complet et effectif du solde.

Supposons que cette action vaille 100€ un jour J donne. Le client l’achete en payant 20€, le reste est avance par la banque. Formellement, cette derniere conserve le titre a son nom. Le lendemain, catastrophe, l’action passe a 85€. Le client depose le bilan. La banque peut donc revendre l’action au prix du marche, soit 85€, et conserver les 20€ initialement verses par le client, et n’a donc pas perdu d’argent dans l’operation.

PostHeaderIcon This RJVM has already been shutdown

Error

Could not connect to remote service [ejb.services.myEjb]; nested exception is java.rmi.ConnectException: This RJVM has already been shutdown 4967659282374941940S:myServer:[7404,7404,-1,-1,-1,-1,-1]:myDomain:myEjbInstance

Explanation

Your EJB instance tries to lookup for a remote instance which seems to be shutdown. There may be many causes: IP / hostname resolution failed, remote servers are actually unreachables (such in the case of network issues), etc. Another potential issue may come from a bug in cluster management by WebLogic. Such a bug was identified and fixed by BEA with version 8 release ; yet, the bug may have kept on occuring on later version (9.2 in my case).
In my current case, the issue was that webservices, theorically deployed in the same WebLogic, were not started. Once the web services started, the issue vanished.

PostHeaderIcon Maven: resume build from a module

Case

Your have a multi-module project. For any reason, the build fails on your 32nd project (out of 70).
You indentify the issue, fix it, and need rebuild your project. Yet, you don’t want to rebuild the 31 first projects. Rather, you prefer to start on the 32nd one.
On older version of Maven, you had to edit your pom.xml, comment the 31 projects, launch the build and uncomment the projects.

Fix

From Maven 2.1, a new option is available: -rf or —resume-from. Thanks to this option, you can hint to Maven to restart the build at any point you like.

PostHeaderIcon ServletAuthentication.AUTHENTICATED

Case

You have this code
[java]ServletAuthentication servletAuthentication = new ServletAuthentication(LOGIN_USERNAME_LABEL, LOGIN_PASSWORD_LABEL);
Integer answer = servletAuthentication.weak(request, response);[/java]

But you always get FAILED_AUTHENTICATION as answer, while you expect to receive AUTHENTICATED.

Fix

In WebLogic configuration, set the control flag for Custom Authentication Provider and Default Weblogic Authentication Provider at SUFFICIENT.

PostHeaderIcon Mule: File transport reads many times the same file

Case
With Mule ESB 2.2.1, I use a classic <file:inbound-endpoint>:

[xml]<file:inbound-endpoint path="${fromPath}"
pollingFrequency="3000" fileAge="5000"
moveToDirectory="${moveToDirectory}"
synchronous="true"
>
<transformers>
<transformer ref="mySimpleCSVParser">
</transformers>
</file:inbound-endpoint>
[/xml]

When I launch the Mule with no component (entreprise layer), everything is OK: the file is loaded, parsed and moved. But when I introduce a minimal component, which does nothing, then the file is read many times. Mule ESB seems to loop indefinitely, reading the file many times, without deleting it from the directory.

[java]INFO  2010-03-04 15:47:18,291 [connector.file.0.receiver.6] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: C:\temp\myFile.txt[/java]

Fix

Firstly I tried to increase the pollingFrequency attribute, assuming that the file had not yet been completely parsed when another cycle of “load-parse-move”. But it did not fix the issue.

Indeed, the problem was not related to the component layer, but to the parser itself. To fix the issue, you have to ensure the InputStream is properly closed in your Transformer layer:

[java]try
{
inputStream.close();
return  answer;
} catch (IOException e)
{
throw new TransformerException((Message)null, e);
}[/java]

PostHeaderIcon Get a field of a bean in Spring

Case

I have to instanciate an object of type FooDao. The only constructor available is FooDao(Connection connection).

On another hand, I have a bean of type BasicDataSource. From this BasicDataSource, I can get a Connection, through the call of BasicDataSource.getConnection().

Question: how to instanciate a bean of type FooDao in Spring?

Solution

The idea, to retrieve a field member of a bean, is to use the attributes factory-bean and factory-method, from which we will get a new bean.

Use the following Spring context file:

[xml]

<bean id="myBasicDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<!– complete … –>
</bean>

<bean id="connection" factory-bean="myBasicDataSource" factory-method="getConnection"
scope="singleton"/>

<bean id="myFooDao" class="com.my.company.FooDao">
<constructor-arg ref="connection"/>
</bean>
[/xml]

Many thanks to David Chau from SFEIR for his help in this issue!

PostHeaderIcon EhCache integration within Spring

Case

You have to use a EhCache in a couple of beans, instancied via Spring.

Fix

In your main Spring configuration file, declare the following block:

[xml]
<bean id="customCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="shared" value="false" />
<property name="cacheManager">
<bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath*:ehcache.xml" />
</bean>
</property>
<property name="cacheName" value="SampleConfigOne" />
</bean>
[/xml]

Then, in any of your beans, declare the following property:

[xml]<property name="cache" value="customCache"/>[/xml]

PostHeaderIcon Unit Test output redirection onto the console, with Maven 2

Case

You have to build your project. All tests are OK when you run them in your IDE, but one or more unit tests fail when you launch the build with Maven 2. When this happens, you have to open the SureFire tests reports to read the failures details.

But you’d rather read the failure in the standard output. In other terms, you would like the output to be redirected onto the console, and not in log files.

Fix

When you launch the build, specify the following option:

-Dsurefire.useFile=false