How to process a ViewDefenition using ViewProcessor


#1

I am trying to submit a ViewDefenition to the ViewProcessor.
But then am not getting there so far.

I added a new component and grabbed the the ViewProcessor and ViewDefenitionRepository instants.
Next i created a client to submit the ViewDefenition but then am stuck there.

ViewDefinition equityDefenition = _viewDefinitionRepository.getDefinition("Equity Portfolio View");
ViewClient vc = _viewProcessor.createViewClient(new UserPrincipal("Vineeth", "127.0.0.1"));
EnumSet<ViewExecutionFlags> flags = EnumSet.of(ViewExecutionFlags.RUN_AS_FAST_AS_POSSIBLE);
ViewExecutionOptions executionOptions = ExecutionOptions.singleCycle(Instant.now(), new MarketDataSpecification());
vc.attachToViewProcess(equityDefenition.getUniqueId(),executionOptions);

Here , i tired many combinations of the execution options but none seem to take me there.
From looking into the code i figured out that the ViewDefenition can be run as a single cycle , batch and infinite process.
I am looking for just a run specification.
The above code is erroring out telling “Error with market data provider”.
I am not able to grab the concepts in execution options.
I am not sure what to do here.

I am trying to run the functions over the historical data and it don’t involve live data.

Any pointers or suggestions would be greatly helpful.

Thanks
Vineeth


#2

Now i am facing a different issue.
I somehow made the ViewProcessor to start processing but now its not able to find the registered function.
CODE - https://gist.github.com/2776780
ERROR - https://gist.github.com/2776769
I learned that in OG-Example , the functions are registered using the component repositoryConfigurationSource.

But then i am not able to make out how to relate repositoryConfigurationSource to viewprocessor!!!

Kindly help me out here.

Thanks
Vineeth


#3

View processor construction, and configuration, is typically done from a Spring XML file. For example, example-viewprocessor-spring.xml, in the OG-Examples project:

A RepositoryConfigurationSource is used by RepositoryFactoryBean to create a FunctionRepository instance. This holds instances of FunctionDefinition which define the function repository.

This FunctionRepository instance can then be used to construct a CompiledFunctionService which also holds references to the FunctionCompilationContext and a FunctionRepositoryCompiler which will be needed to make use of the functions. This is used by both the view processor to construct graphs for execution and by the calculation nodes to execute the graphs.

A FunctionResolver instance must also be created, that corresponds to the same function repository, which will define how to select appropriate functions from that repository to construct the dependency graph.

The FunctionResolver and CompiledFunctionService instances are then passed to the ViewProcessor instance via the ViewProcessorFactoryBean.

Andrew.


#4

thanks @andrew

I understand the flow from your comment.
However am still pondering on few other questions.
I added a new component by adding a new entry in the example.ini file.
Then i grabbed the ViewProcessor instance and ViewDefinitionRepository instance.
Then i added this code to submit a ViewDefenition to Viewprocessor
CODE - https://gist.github.com/2776780

Here my assumption is that the function repository component is first read and it is some how linked to the ViewProcessor. And that the viewprocessor i got is linked to the function repository.

Anyway i also have the same ViewProcessor and ViewDefenition repostiory instances as the one WebAnalytics.
Now in the above code , am giving the same ViewDefenitioin as given by the WebAnalytics tab.

But then when i give a ViewDefenition for processing , ViewProcessor is not able to find the function but then when the same ViewDefeniton is given by WeAnalytics its working fine.

ERROR - https://gist.github.com/2776769

The issue might be that , i need to link the FunctionRepostiroy with viewprocessor myself.
Or it can be something else.

In anyway please let me know what i have missed.

Thanks
Vineeth


#5

Thank you for the clarification on what you are trying to do.

If the view is working from the web analytics tab, and you are using the same ViewProcessor instance, then it is correctly configured with your function repository.

It is possible that the historical data is not available. In line 2 of gist 2776780 the historical specification is declared with today’s date; there may not be points for this in the underlying timeseries database. Timeseries are often updated at the close of day so the most recent point is likely to be the previous working day.

With the view running in the web analytics view, can you drill down the dependency graph view to see which market data inputs are at the leaf nodes of the graph. Are there entries for these in the timeseries database? If so, do you get the same error if you set the HistoricalMarketDataSpecification for a date on which values are available?

Andrew.


#6

Hello @Andrew ,

Changing the date with an existing date in the DB is not helping.
I made sure that for that particular security a date existed in time series and changed the value at code to .
HistoricalMarketDataSpecification hd = MarketData.historical(LocalDate.of(2010, 6, 25) ,null, null);

But then am getting the same error - https://gist.github.com/2780935

Also without giving the execution option , am getting this strange error - https://gist.github.com/2780960
I feel its a bug.

Coming back to my requirement. I am planning to write a function when invoked will read data values from the historical time series master and produce the results. Here i am not planning to provide datasource to ViewClient while attaching.

How can i achieve this ?


#7

Following is the complete dump of what i have been doing.

What i want -

  • Write my own function and attach it to the function repo - This is kind of done
  • Run a portfolio against a function and harvest the result - This is what am trying to do.

What i did so far -

  • Extended WebsiteBasicsComponentFactory to grab the instances i want. Extended Class - https://gist.github.com/2781148
  • Published a new class for localhost:8080/jax/reports REST end point. - https://gist.github.com/2781160
  • Replaced WebsiteBasicsComponentFactory with the new class i extended in config/fullstack/example.ini
  • Edited the “Equity Portfolio” portfolio which comes with the OG-Example to include just one Position ( This is for my convenience) . The position is of that of YHOO .
  • Edited “Equity Portfolio View” ViewDefenition to include just “CAPM Beta” function
  • Triggered the ViewDefenition submission using the http call ‘http://localhost:8080/jax/reports
  • And this is what i see in the console - https://gist.github.com/2780935

Here i couldn’t find any documentation on how to run a portfolio against a viewDefenition. So i don’t have a full idea on the concepts of MarketDataSpecification or most of the options in execution options.

Any kind of direction or pointers would be of great help.

Thanks
Vineeth


#8

The meaning of the first parameter to the attachToViewProcess method on ViewClient without the execution options parameter is slightly different. When execution options are not specified, the first parameter must be an identifier of an existing view process not a view definition. This is the cause of the stack trace displayed in gist 2780960.

Normally we would write functions that declare data requirements (e.g. Market_Value) so that whether the data comes from a historical time series master for a given date, a specific market data snapshots, or live market data, can be specified through the data source parameter to a view client. This gives a lot of flexibility at the point at which the view client is being used without having to alter the function definition.

It is possible however to write a function that sources data directly from a historical time series and operate from that. The function would have to declare no input requirements (i.e. its getRequirements implementation return the empty set). In the execute method the FunctionExecutionContext will contain the historical time series source (see OpenGammaExecutionContext.getHistoricalTimeSeriesSource) that it can use to source its data values. Note that with no “market data” as direct or indirect inputs to the function it will only be executed on a full calculation cycle - any intermediate cycles will use the result it generated on the last full cycle.

If this is unclear I can post some code later this afternoon to demonstrate more fully.


#9

phew !!!
Finally got it working :slight_smile:
Thanks @Andrew , i owe it to you.

How i did - As you said , i emptied the list returned by getValueRequirements()
My New Function - https://gist.github.com/2781357

Still i would love to see the code examples on how to pass parameters while attaching the Viewdefention.


#10

Hello again @Andrew ,
Thanks for your support earlier , i was able to invoke functions on portfolio using viewprocessor.
My next target is to get an idea on how passing valueRequirement works.
I believe we are using MarketDataSpecification to specify the ValueRequirement for each Functions being called.
I am trying to use HistoricalMarketDataSpecification class here.

Kindly explain the how to sent ValueRequirements using this.

Thanks
Vineeth


#11

Hi @Andrew ,

After lot of poking around and with the help of this - http://docs.opengamma.com/display/DOC/Value+Requirements+and+Specifications
documentation i am able to understand how the whole graph , valuerequirement things fit in.
My next issue is that i am not able to make the code work.

It will help me a lot if you can give a working code example of calling ValueProcessor to invoke process function which have some input value requirement.

Thanks
Vineeth


#12

Thanks for the helpful thread. I am still confused in the complex design phase. I am not able to understand how to choose the model to be used for pricing. For example if I just add this for my barriers portfolio…

private ViewDefinition getBarriersViewDefinition(final String barrierPortfolioName)
{
final UniqueId portfolioId = getPortfolioId(barrierPortfolioName).toLatest();
final ViewDefinition viewDefinition = new ViewDefinition(barrierPortfolioName + " View", portfolioId, UserPrincipal.getTestUser());
viewDefinition.setDefaultCurrency(Currency.USD);

  final ViewCalculationConfiguration defaultCalc = new ViewCalculationConfiguration(viewDefinition, DEFAULT_CALC_CONFIG);

  addValueRequirements(defaultCalc, EquitySecurity.SECURITY_TYPE,
          new String[] {ValueRequirementNames.FAIR_VALUE});
  defaultCalc.addPortfolioRequirement(EquitySecurity.SECURITY_TYPE, ValueRequirementNames.PNL, ValueProperties.with(ValuePropertyNames.CURRENCY, Currency.USD.getCode()).get());
  viewDefinition.addViewCalculationConfiguration(defaultCalc);
  return viewDefinition;

}

There are too many things missing. I haven’t specified the model to be used to calculate the values. This is pretty basic stuff, but am quite poor in understanding complex java design. Any simple guidance on how to add a viewprocessor or some sort of model to this?

Thanks in advance


#13

So, in general, ValueRequirements have a range of Value Properties (which we also refer to as constraints), but there are often default values. If you look at

http://docs.opengamma.com/display/DOC120/Equity+Barrier+Option+Value+Requirements

You can see the available ValueRequirements on Equity barrier options and what the constraints are that are available. If you then look at a specific entry e.g. Present Value, then it will show you example values you might use for those properties. Some of these will require specific things like Volatility surfaces definitions and specifications to be created and added to the config system.

For example, the model is often selected using a property called ‘CalculationMethod’ which gets set to e.g. ‘BlackModel’.

Hope that helps.