ITQuants blog

How to add clauses on a future (and other instruments) in Sophis Risque

Mar 6

Written by:
3/6/2013 4:02 PM  RssIcon

Even if the AddClauseOfThisType and SetNthclauseOfThisType exist on the CSRInstrument class, these methods work fine an a CSROption but do nothing on a CSRFuture, at least on versions < Risque 7.1. Thus, the only way to save them is to insert them directly into the database using the CSRSqlQuery class. To prevent some problems, the right way to implement it is the following one:

1 - load the data using the CSqlQuery::QueryWithNResults and the following description for the structure

 

01.struct SSLoadClause
02.{
03.    long m_beginDate;
04.    long m_endDate;
05.    long m_paymentDate;
06.    long m_type;
07.    char m_comment[201];
08.    double m_min;
09.    double m_max;
10.    double m_value;
11.};
12. 
13.CSRStructureDescriptor _desc(8,sizeof(SSLoadClause));
14. 
15.ADD(&_desc, SSLoadClause, m_beginDate,rdfInteger)
16.ADD(&_desc, SSLoadClause, m_endDate,rdfInteger)
17.ADD(&_desc, SSLoadClause, m_paymentDate,rdfInteger)
18.ADD(&_desc, SSLoadClause, m_type,rdfInteger)
19.ADD(&_desc, SSLoadClause, m_comment, rdfString)
20.ADD(&_desc, SSLoadClause, m_min, rdfFloat)
21.ADD(&_desc, SSLoadClause, m_max, rdfFloat)
22.ADD(&_desc, SSLoadClause, m_value, rdfFloat)
23. 
24.std::stringstream _query;
25._query <<  "SELECT DATE_TO_NUM(DATEDEB),DATE_TO_NUM(DATEFIN),DATE_TO_NUM(DATEPAYE),TYPE,COM1,LEMIN,LEMAX,VALEUR FROM CLAUSE WHERE SICOVAM=" << sicovam << " ORDER BY CODE";
26. 
27.int _count = 0;
28.SSLoadClause* _results = NULL;
29.errorCode _ret = CSRSqlQuery::QueryWithNResults(_query.str().c_str(), &_desc, (void**)(&_results), &_count);

2 - implement the save using the notification provided by CSRInstrumentAction, on NotifyCreated or NotifyModified

3 - on modification, delete the records and add the audit. The current sicovam of the instrument being saved in audit can be retrieved using the current session and the SEQTITRES.CURRVAL value:

 

01.bool DeleteClauses(long sicovam)
02.{
03.    std::stringstream _query;
04.    errorCode _err = 0;
05. 
06.    long _newCode = 0;
07.    _err = CSRSqlQuery::QueryReturning1Long("select SEQTITRES.CURRVAL from dual",&_newCode);
08.    if(_err!=0)
09.        return false;
10. 
11.    _query.str("");
12.    _query << "insert into clause (sicovam,code,datedeb,datefin,type,lemin,lemax,com1,com2,valeur,datepaye,lemin_pct,lemax_pct,valeur_pct,datecross, DELTA_ADJ_VALUE_DATE, DELTA_ADJ_AMOUNT_CCY_OPTION, DELTA_ADJ_AMOUNT_CCY_DELTA) select /* HSBC 4104 */ " << _newCode << ",code,datedeb,datefin,type,lemin,lemax,com1,com2,valeur,datepaye,lemin_pct,lemax_pct,valeur_pct,datecross, DELTA_ADJ_VALUE_DATE, DELTA_ADJ_AMOUNT_CCY_OPTION, DELTA_ADJ_AMOUNT_CCY_DELTA  from clause where sicovam = " << sicovam;
13.    _err = CSRSqlQuery::QueryWithoutResult(_query.str().c_str());
14.    if(_err!=0)
15.        return false;
16. 
17.    _query.str("");
18.    _query << "insert into infos_histo (sicovam, date_validite, userident, modif, type_table,nom_table, new_sicovam) values( " << sicovam << ",sysdate-TO_DATE('01/01/1904','DD/MM/YYYY'),1,2,7,'clause'," << _newCode << ")";
19.    _err = CSRSqlQuery::QueryWithoutResult(_query.str().c_str());
20.    if(_err!=0)
21.        return false;
22.    _query.str("");
23.    _query << "DELETE FROM CLAUSE WHERE SICOVAM=" << sicovam;
24.    _err = CSRSqlQuery::QueryWithoutResult(_query.str().c_str());
25.    return _err == 0;
26.}

4 - save the information using an insert:

01.bool InsertClause(long sicovam, long code, const SSClause& sc)
02.{
03.    std::stringstream _query;
04. 
05.    _query.precision(6);
06.    _query.setf(std::ios_base::fixed, std::ios_base::floatfield);
07. 
08.    _query << "INSERT INTO CLAUSE(SICOVAM,CODE,TYPE,COM1,LEMIN,LEMAX,VALEUR,DATEDEB,DATEFIN,DATEPAYE) VALUES("
09.        << sicovam << ","
10.        << code << ","
11.        << sc.type << ",'"
12.        << sc.comment << "',"
13.        << sc.minimum.value << ","
14.        << sc.maximum.value << ","
15.        << sc.value.value << ",NUM_TO_DATE("
16.        << sc.start_date << "),NUM_TO_DATE("
17.        << sc.end_date << "),NUM_TO_DATE("
18.        << sc.payment_date << "))";
19. 
20.    errorCode _err = CSRSqlQuery::QueryWithoutResult(_query.str().c_str());
21.    return _err == 0;
22.}

 

Remark: concerning the type of the clause, if user clauses are used, it has to correspond to the id stored in the field CLAUSEUSER.NUMERO.

Tags:
Categories:

Search blog