Custom sequrity questions

Hello,

We are trying to create our custom financial security, following http://docs.opengamma.com/display/DOC210/Adding+support+for+a+new+custom+Security

  • We have create ExampleSecurity class
  • We have created ExampleSecurityVisitor class
  • We have created/populated db part for our security

Now OpenGamma can see our security, but each time we try to open view with our security OpenGamma fails with NPEs complaining about accept() method in ExampleSecurity.

From documentation it is not clear what should we do in this method?
Also in documentation is mentioned that we should extend FinancialSecurityVisitorAdapter, what should we add there?

There are some visitors that the web ui uses in order to work out how to display securities. These aren’t really extensible (without code changes to the platform) unfortunately so you have to write your accept() method in such a way that it gives the ui what it needs.

If the following doesn’t work can you post the exception that gets raised.

Can you try modifying your accept() method to look like:

@Override
public T accept(final FinancialSecurityVisitor visitor) {
ArgumentChecker.notNull(visitor, “visitor”);

//TODO remove visitor logic out of security when different solution is implemented
if (visitor instanceof ExampleSecurityVisitor) {
  return ((ExampleSecurityVisitor<T>) visitor).visitExampleSecurity(this);
} else if (visitor instanceof OtcSecurityVisitor) {
  return (T) Boolean.FALSE;
} else if (visitor instanceof UnderlyingSecurityVisitor) {
  return null;
} else if (visitor instanceof SecurityTemplateModelObjectBuilder) {
  //TODO SecurityTemplateModelObjectBuilder will need to be changed back to package private
  return null;
} else if (visitor instanceof SecurityTemplateNameProvider) {
  //TODO SecurityTemplateNameProvider will need to be changed back to package private
  return (T) "default-security.ftl";
}

throw new IllegalArgumentException("ExampleSecurity needs to handle an instance of the "  + visitor.getClass() + " + visitor.");

}

If the following doesn’t work can you post the exception that gets raised.
it not works, here is exception

java.lang.IllegalArgumentException: ExampleSecurity needs to handle an instance of the class com.opengamma.financial.security.FinancialSecurityUtils$7 + visitor.
at com.epam.opengamma.basket.BasketSecurity.accept(BasketSecurity.java:62) ~[classes/:na]
at com.opengamma.financial.security.FinancialSecurityUtils.getCurrency(FinancialSecurityUtils.java:343) ~[classes/:na]
at com.opengamma.financial.analytics.model.sensitivities.ExternallyProvidedSensitivitiesYieldCurvePV01Function.createCurrencyValueProperties(ExternallyProvidedSensitivitiesYieldCurvePV01Function.java:73) ~[classes/:na]
at com.opengamma.financial.analytics.model.sensitivities.ExternallyProvidedSensitivitiesYieldCurvePV01Function.getResults(ExternallyProvidedSensitivitiesYieldCurvePV01Function.java:112) ~[classes/:na]
at com.opengamma.engine.function.resolver.ResolutionRule.getResults(ResolutionRule.java:139) ~[classes/:na]
at com.opengamma.engine.function.resolver.DefaultCompiledFunctionResolver.resolveFunction(DefaultCompiledFunctionResolver.java:510) ~[classes/:na]
at com.opengamma.engine.depgraph.GetFunctionsStep.getFunctions(GetFunctionsStep.java:249) ~[classes/:na]
at com.opengamma.engine.depgraph.GetFunctionsStep.run(GetFunctionsStep.java:235) ~[classes/:na]

I see, ideally you’d want to be able to detect that this visitor is trying to determine the currency (if any) of your security and thus return that (or null if currency isn’t a valid attribute). Unfortunately this visitor is anonymous and so you can’t do an instance of check. I’ll submit a ticket on our side to fix this for the next release.

Until then the options to bypass this are:

  1. Just return null from the accept method for any unknown visitors. This should be ok as none of our built in functions will be capable of handling this security anyway.
  2. Download and modify the code locally.

Thanks for your answers

  1. Just return null from the accept method for any unknown visitors. This should be ok as none of our built in functions will be capable of handling this security anyway.

My next issues is… I can not make my function work with this new security, do you have suggestions how we can make it happen?

Can you post some example code? You can put break points or printout statements on getResults() & getRequirements() functions to see if they get called and what values you are returning. Does your View definition request that value for your security?

Thank, we could sort it out… we just made our in function getResults() method return proper value