I have created a function which returns parameters from a database. The database (Access) have 2 columns, where in the first there are dates, and in 2nd Rate. I use ADO method. In the following code, InterpoleDate is a simple linear interpolation method , i have tested and which runs correctly. My problem is that the method ReturnParamSimple returns stupid values. So, i would like to know if anybody could help me to find my error?
double EuropeanSwaption ::ReturnParamSimple(COleDateTime EndDate,_variant_t IndexColumn,_variant_t ParameterTable)
{
double Parameter1,Parameter2,Parameter;
COleDateTime Date1,Date2;
CString strTemp;
strTemp.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Swaption\\taux.mdb;"
_bstr_t strcnn(strTemp);
_RecordsetPtr pTp("ADODB.Recordset"
try
{
pTp->Open(ParameterTable,strcnn,adOpenStatic,adLockOptimistic,adCmdTableDirect);
pTp->MoveFirst();
if(EndDate<pTp->Fields->GetItem("date"->Value)
{
Date1=pTp->Fields->GetItem("date"->Value;
Parameter1=pTp->Fields->GetItem(IndexColumn)->Value;
pTp->MoveNext();
Date2=pTp->Fields->GetItem("date"->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
Parameter=InterpolDate(Date1,Date2,EndDate,Parameter1,Parameter2);
}
else
{
while(EndDate>pTp->Fields->GetItem("date"->Value)
{
pTp->MoveNext();
if(pTp->EndOfFile)
{
pTp->MovePrevious();
Date2=pTp->Fields->GetItem("date"->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
pTp->MovePrevious();
Date1=pTp->Fields->GetItem("date"->Value;
Parameter1=pTp->Fields->GetItem(IndexColumn)->Value;
Parameter=InterpolDate(Date1,Date2,EndDate,Parameter1,Parameter2);
}
}
if(EndDate==pTp->Fields->GetItem("date"->Value)
{
Parameter=pTp->Fields->GetItem("IndexColumn"->Value;
}
else
{
Date2=pTp->Fields->GetItem("date"->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
pTp->MovePrevious();
Date1=pTp->Fields->GetItem("date"->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
Parameter=InterpolDate(Date1,Date2,EndDate,Parameter1,Parameter2);
}
}
pTp->Close();
}
catch(_com_error &e)
{
AfxMessageBox("Ne peut pas accéder à la table"
pTp->Close();
}
return Parameter;
}
thanks in advance
jayjay
double EuropeanSwaption ::ReturnParamSimple(COleDateTime EndDate,_variant_t IndexColumn,_variant_t ParameterTable)
{
double Parameter1,Parameter2,Parameter;
COleDateTime Date1,Date2;
CString strTemp;
strTemp.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Swaption\\taux.mdb;"
_bstr_t strcnn(strTemp);
_RecordsetPtr pTp("ADODB.Recordset"
try
{
pTp->Open(ParameterTable,strcnn,adOpenStatic,adLockOptimistic,adCmdTableDirect);
pTp->MoveFirst();
if(EndDate<pTp->Fields->GetItem("date"->Value)
{
Date1=pTp->Fields->GetItem("date"->Value;
Parameter1=pTp->Fields->GetItem(IndexColumn)->Value;
pTp->MoveNext();
Date2=pTp->Fields->GetItem("date"->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
Parameter=InterpolDate(Date1,Date2,EndDate,Parameter1,Parameter2);
}
else
{
while(EndDate>pTp->Fields->GetItem("date"->Value)
{
pTp->MoveNext();
if(pTp->EndOfFile)
{
pTp->MovePrevious();
Date2=pTp->Fields->GetItem("date"->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
pTp->MovePrevious();
Date1=pTp->Fields->GetItem("date"->Value;
Parameter1=pTp->Fields->GetItem(IndexColumn)->Value;
Parameter=InterpolDate(Date1,Date2,EndDate,Parameter1,Parameter2);
}
}
if(EndDate==pTp->Fields->GetItem("date"->Value)
{
Parameter=pTp->Fields->GetItem("IndexColumn"->Value;
}
else
{
Date2=pTp->Fields->GetItem("date"->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
pTp->MovePrevious();
Date1=pTp->Fields->GetItem("date"->Value;
Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;
Parameter=InterpolDate(Date1,Date2,EndDate,Parameter1,Parameter2);
}
}
pTp->Close();
}
catch(_com_error &e)
{
AfxMessageBox("Ne peut pas accéder à la table"
pTp->Close();
}
return Parameter;
}
thanks in advance
jayjay