double getROC(const unsigned int size, CandleData * data, long numSticks)
{
	double roc = 0.0;
	double * csData = CandleData::getData(data, CandleData::CLOSE, numSticks);
	int outNbElement = 0;
	int outBeg = 0;

	double * rocDataOut = new double[numSticks + size];

	TA_RetCode rocRet =
		TA_ROC( 0,
			  numSticks - 1,
			  csData,
			  size,
			  &outBeg,
		      &outNbElement,
		      rocDataOut);

	if(outNbElement == 0)
	{
		roc = 0.0;
	}
	else
	{
		roc = rocDataOut[outNbElement - 1];
	}

	delete [] csData;
	delete [] rocDataOut;
	
	return roc;
}
double * getAllROC(const unsigned int size, CandleData * data, long numSticks)
{
	double * closeData = CandleData::getData(data, CandleData::CLOSE, numSticks);

	int outNbElement = 0;
	int outBeg = 0;

	int arraySize = numSticks + size;
	double * rocDataOut = new double[arraySize];
	memset(rocDataOut,0,arraySize * sizeof(double));

	TA_RetCode emaRet =
		TA_ROC( 0,
			  numSticks - 1, 
			  closeData,
			  size,
			  &outBeg,
		      &outNbElement,
		      rocDataOut);

	double * ret = new double[arraySize + outBeg];
	memset(ret,0,(arraySize + outBeg) * sizeof(double));
	memcpy(&ret[outBeg],rocDataOut,arraySize*sizeof(double));

	delete [] closeData;
	delete [] rocDataOut;

	return ret;
}
Example #3
0
/**** Local functions definitions.     ****/
static TA_RetCode rangeTestFunction( TA_Libc *libHandle, 
                              TA_Integer startIdx,
                              TA_Integer endIdx,
                              TA_Real *outputBuffer,
                              TA_Integer *outBegIdx,
                              TA_Integer *outNbElement,
                              TA_Integer *lookback,
                              void *opaqueData,
                              unsigned int outputNb )
{
   TA_RetCode retCode;
   TA_RangeTestParam *testParam;

   (void)outputNb;
  
   testParam = (TA_RangeTestParam *)opaqueData;   

   if( testParam->test->theFunction == TA_MOM_TEST )
   {
      retCode = TA_MOM( libHandle,
                        startIdx,
                        endIdx,
                        testParam->close,
                        testParam->test->optInTimePeriod_0,                        
                        outBegIdx,
                        outNbElement,
                        outputBuffer );

      *lookback = TA_MOM_Lookback(testParam->test->optInTimePeriod_0 );
   }
   else if( testParam->test->theFunction == TA_ROC_TEST )
   {
      retCode = TA_ROC( libHandle,
                        startIdx,
                        endIdx,
                        testParam->close,
                        testParam->test->optInTimePeriod_0,                        
                        outBegIdx,
                        outNbElement,
                        outputBuffer );
      *lookback = TA_ROC_Lookback(testParam->test->optInTimePeriod_0 );
   }
   else if( testParam->test->theFunction == TA_ROCR_TEST )
   {
      retCode = TA_ROCR( libHandle,
                         startIdx,
                         endIdx,
                         testParam->close,
                         testParam->test->optInTimePeriod_0,                         
                         outBegIdx,
                         outNbElement,
                         outputBuffer );
      *lookback = TA_ROCR_Lookback(testParam->test->optInTimePeriod_0 );
   }
   else
      retCode = TA_UNKNOWN_ERR;

   return retCode;
}
Example #4
0
/* The gateway routine */
void mexFunction(int nlhs, mxArray *plhs[],
                 int nrhs, const mxArray *prhs[])
{
/* ----------------- Variables ----------------- */
/* input variables */
/* mandatory input */
  int startIdx;
  int endIdx;
  double * inReal;
/* optional input */
  int	 optInTimePeriod;
/* output variables */ 
  int outBegIdx;
  int outNbElement;
  double*	 outReal;
/* input dimentions */ 
  int inSeriesRows;
  int inSeriesCols;
/* error handling */
  TA_RetCode retCode;

/* ----------------- input/output count ----------------- */  
  /*  Check for proper number of arguments. */
  if (nrhs < 1 || nrhs > 2) mexErrMsgTxt("#2 inputs possible #1 optional.");
  if (nlhs != 1) mexErrMsgTxt("#1 output required.");
/* ----------------- INPUT ----------------- */ 
  /* Create a pointer to the input matrix inReal. */
  inReal = mxGetPr(prhs[0]);
  /* Get the dimensions of the matrix input inReal. */
  inSeriesCols = mxGetN(prhs[0]);
  if (inSeriesCols != 1) mexErrMsgTxt("inReal only vector alowed.");
  inSeriesRows = mxGetM(prhs[0]);  
  endIdx = inSeriesRows - 1;  
  startIdx = 0;

 /* Process optional arguments */ 
  if (nrhs >= 1+1) {
	if (!mxIsDouble(prhs[1]) || mxIsComplex(prhs[1]) ||
      mxGetN(prhs[1])*mxGetM(prhs[1]) != 1) 
    	mexErrMsgTxt("Input optInTimePeriod must be a scalar.");
   	/* Get the scalar input optInTimePeriod. */
   	optInTimePeriod = (int)  mxGetScalar(prhs[1]);
  } else {
  	optInTimePeriod = 10;
  }

/* ----------------- OUTPUT ----------------- */
  outReal = mxCalloc(inSeriesRows, sizeof(double));
/* -------------- Invocation ---------------- */

	retCode = TA_ROC(
                   startIdx, endIdx,
                   inReal,
                   optInTimePeriod,
                   &outBegIdx, &outNbElement,
                   outReal);
/* -------------- Errors ---------------- */
   if (retCode) {
   	   mxFree(outReal);
       mexPrintf("%s%i","Return code=",retCode);
       mexErrMsgTxt(" Error!");
   }
  
   // Populate Output
  plhs[0] = mxCreateDoubleMatrix(outBegIdx+outNbElement,1, mxREAL);
  memcpy(((double *) mxGetData(plhs[0]))+outBegIdx, outReal, outNbElement*mxGetElementSize(plhs[0]));
  mxFree(outReal);  
} /* END mexFunction */
Example #5
0
static ErrorNumber do_test( TA_Libc *libHandle,
                            const TA_History *history,
                            const TA_Test *test )
{
   TA_RetCode retCode;
   ErrorNumber errNb;
   TA_Integer outBegIdx;
   TA_Integer outNbElement;
   TA_RangeTestParam testParam;

   /* Set to NAN all the elements of the gBuffers.  */
   clearAllBuffers();

   /* Build the input. */
   setInputBuffer( 0, history->close, history->nbBars );
   setInputBuffer( 1, history->close, history->nbBars );

   CLEAR_EXPECTED_VALUE(0);

   /* Make a simple first call. */
   if( test->theFunction == TA_MOM_TEST )
   {
      retCode = TA_MOM( libHandle,
                        test->startIdx,
                        test->endIdx,
                        gBuffer[0].in,
                        test->optInTimePeriod_0,                        
                        &outBegIdx,
                        &outNbElement,
                        gBuffer[0].out0 );
   }
   else if( test->theFunction == TA_ROC_TEST )
   {
      retCode = TA_ROC( libHandle,
                        test->startIdx,
                        test->endIdx,
                        gBuffer[0].in,
                        test->optInTimePeriod_0,                        
                        &outBegIdx,
                        &outNbElement,
                        gBuffer[0].out0 );
   }
   else if( test->theFunction == TA_ROCR_TEST )
   {
      retCode = TA_ROCR( libHandle,
                         test->startIdx,
                         test->endIdx,
                         gBuffer[0].in,
                         test->optInTimePeriod_0,                         
                         &outBegIdx,
                         &outNbElement,
                         gBuffer[0].out0 );
   }

   errNb = checkDataSame( gBuffer[0].in, history->close,history->nbBars );
   if( errNb != TA_TEST_PASS )
      return errNb;

   CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 );

   outBegIdx = outNbElement = 0;

   /* Make another call where the input and the output are the
    * same buffer.
    */
   CLEAR_EXPECTED_VALUE(0);
   if( test->theFunction == TA_MOM_TEST )
   {
      retCode = TA_MOM( libHandle,
                        test->startIdx,
                        test->endIdx,
                        gBuffer[1].in,
                        test->optInTimePeriod_0,                        
                        &outBegIdx,
                        &outNbElement,
                        gBuffer[1].in );
   }
   else if( test->theFunction == TA_ROC_TEST )
   {
      retCode = TA_ROC( libHandle,
                        test->startIdx,
                        test->endIdx,
                        gBuffer[1].in,
                        test->optInTimePeriod_0,                        
                        &outBegIdx,
                        &outNbElement,
                        gBuffer[1].in );
   }
   else if( test->theFunction == TA_ROCR_TEST )
   {
      retCode = TA_ROCR( libHandle,
                         test->startIdx,
                         test->endIdx,
                         gBuffer[1].in,
                         test->optInTimePeriod_0,                         
                         &outBegIdx,
                         &outNbElement,
                         gBuffer[1].in );
   }

   /* The previous call should have the same output as this call.
    *
    * checkSameContent verify that all value different than NAN in
    * the first parameter is identical in the second parameter.
    */
   errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in );
   if( errNb != TA_TEST_PASS )
      return errNb;

   CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 );

   if( errNb != TA_TEST_PASS )
      return errNb;

   /* Do a systematic test of most of the
    * possible startIdx/endIdx range.
    */
   testParam.test  = test;
   testParam.close = history->close;

   if( test->doRangeTestFlag )
   {
      errNb = doRangeTest( libHandle,
                           rangeTestFunction, 
                           TA_FUNC_UNST_NONE,
                           (void *)&testParam, 1 );
      if( errNb != TA_TEST_PASS )
         return errNb;
   }

   return TA_TEST_PASS;
}
Example #6
0
/**** Local functions definitions.     ****/
static TA_RetCode rangeTestFunction( TA_Integer    startIdx,
                                     TA_Integer    endIdx,
                                     TA_Real      *outputBuffer,
                                     TA_Integer   *outputBufferInt,
                                     TA_Integer   *outBegIdx,
                                     TA_Integer   *outNbElement,
                                     TA_Integer   *lookback,
                                     void         *opaqueData,
                                     unsigned int  outputNb,
                                     unsigned int *isOutputInteger )
{
   TA_RetCode retCode;
   TA_RangeTestParam *testParam;

   (void)outputNb;
   (void)outputBufferInt;
  
   *isOutputInteger = 0;

   testParam = (TA_RangeTestParam *)opaqueData;   
   switch( testParam->test->theFunction )
   {
   case TA_MOM_TEST:
      retCode = TA_MOM(
                        startIdx,
                        endIdx,
                        testParam->close,
                        testParam->test->optInTimePeriod,                        
                        outBegIdx,
                        outNbElement,
                        outputBuffer );

      *lookback = TA_MOM_Lookback(testParam->test->optInTimePeriod );
      break;
   case TA_ROC_TEST:
      retCode = TA_ROC(
                        startIdx,
                        endIdx,
                        testParam->close,
                        testParam->test->optInTimePeriod,                        
                        outBegIdx,
                        outNbElement,
                        outputBuffer );
      *lookback = TA_ROC_Lookback(testParam->test->optInTimePeriod );
      break;
   case TA_ROCR_TEST:
      retCode = TA_ROCR(
                         startIdx,
                         endIdx,
                         testParam->close,
                         testParam->test->optInTimePeriod,                         
                         outBegIdx,
                         outNbElement,
                         outputBuffer );
      *lookback = TA_ROCR_Lookback(testParam->test->optInTimePeriod );
      break;
   case TA_ROCR100_TEST:
      retCode = TA_ROCR100(
                            startIdx,
                            endIdx,
                            testParam->close,
                            testParam->test->optInTimePeriod,                         
                            outBegIdx,
                            outNbElement,
                            outputBuffer );
      *lookback = TA_ROCR100_Lookback(testParam->test->optInTimePeriod );
      break;
   case TA_ROCP_TEST:
      retCode = TA_ROCP(
                         startIdx,
                         endIdx,
                         testParam->close,
                         testParam->test->optInTimePeriod,                         
                         outBegIdx,
                         outNbElement,
                         outputBuffer );
      *lookback = TA_ROCP_Lookback(testParam->test->optInTimePeriod );
      break;
   default:
      retCode = TA_INTERNAL_ERROR(130);
   }

   return retCode;
}