ITQuants blog

Fusion Capital Sophis v7: how to compute user data on calculation servers?

Jun 3

Written by:
6/3/2016 2:13 PM  RssIcon

Before the v7, in order to serialize specific indicators calculated by the internal quant libraries, virtual methods like CSRInstrument::GetCalculationData and CSRInstrument::SetCalculationData were used. These methods are not deprecated and a specific implementation of the class CSRComputationResults should be used. The goal of this post is to explain how to declare such a class and to give a complete sample ready to use.

First, in order to serialize specific indicators, a new class that inherits from CSRComputationResults should be declared. For example, the following code can be used, in the header file :

#pragma once
 
class ITQComputationResults : public CSRGenericContainer
{
public:
    ITQComputationResults();
    ITQComputationResults(const CLComputationResults& other);
    virtual ~ITQComputationResults();
 
    inline double Theta2() const { return m_theta2 ; }
    inline double& Theta2() { return m_theta2; }
    inline void SetTheta2(double newVal) { m_theta2 = newVal; }
 
    virtual CSRGenericContainer* Clone() const;
    virtual const char* GetName() const;
 
    virtual void WriteToArchive(sophis::tools::CSRArchive& a) const;
    virtual void ReadFromArchive(const sophis::tools::CSRArchive& a);
protected:
    double m_theta2;
};

 

The methods WriteToArchive and ReadFromArchive will permit to serialize extra data (in our case a new greek Theta2). The name is important too, because it will be used as a key during the serializing: on the calculation server, the computation will declare a new type of computations using this name, will serialize it and give it back to the GUI. On the GUI side, it will use the name in order to create an instance of this class (class factory).

The .cpp file can be declared as follow :

 

#include "ComputationResults.h"
 
ITQComputationResults::ITQComputationResults() : m_theta2(0.0)
{
}
 
ITQComputationResults::ITQComputationResults(const CLComputationResults& other) : m_theta2(other.m_theta2)
{
}
 
ITQComputationResults::~ITQComputationResults()
{
}
 
CSRGenericContainer* ITQComputationResults::Clone() const
{
    return new ITQComputationResults(*this);
}
 
const char* ITQComputationResults::GetName() const
{
    return "ITQComputationResults";
}
 
void ITQComputationResults::WriteToArchive(sophis::tools::CSRArchive& a) const
{
    a << this->Theta2();
}
 
void ITQComputationResults::ReadFromArchive(const sophis::tools::CSRArchive& a)
{
    a >> this->Theta2();
}

 

At this step, we need to declare the class factory in the UNVERSAL_MAIN entrypoint as follow:

INITIALIZE_GENERICCONTAINER(ITQComputationResults);

 

That will permit to create the right object when retrieving in the GUI the data from the CS.

In the pricer, it means in the class that inherits from CSRMetaModel, we need to populate the results as follow, the CSRMetaModel::ComputeAllCore virtual method for example :

ITQMetaModelOption::ComputeAllCore(CSRInstrument& insturment, const CSRMarketData& context, CSRComputationResults& results)
{
...
 
    ITQComputationResults* specificResults = new ITQComputationResults();
    specificResults->SetTheta2(pOption->m_theoreticalResult.Theta2);
    results.AddSpecificResults(*specificResults);
...
}

 

And that's all, folks!

 

Search blog