Пример #1
0
void getPhasor(double outInPhase, double outQuadrature, CandleData * data, long numSticks)
{
    outInPhase = 0.0;
    outQuadrature = 0.0;

    double * csData = CandleData::getData(data, CandleData::CLOSE, numSticks);

    int outNbElement = 0;
    int outBeg = 0;

    double * dataOut1 = new double[numSticks];
    memset(dataOut1,0,numSticks * sizeof(double));
    double * dataOut2 = new double[numSticks];
    memset(dataOut2,0,numSticks * sizeof(double));

    TA_RetCode ret =
        TA_HT_PHASOR( 0,
                      numSticks-1,
                      csData,
                      &outBeg,
                      &outNbElement,
                      dataOut1,
                      dataOut2);


    if(outNbElement != 0)
    {
        outInPhase = dataOut1[outNbElement - 1];
        outQuadrature = dataOut2[outNbElement - 1];
    }

    delete [] csData;
    delete [] dataOut1;
    delete [] dataOut2;
}
Пример #2
0
void getPhasorAll(double *& outInPhase, double *& outQuadrature, CandleData * data, long numSticks)
{
    double * csData = CandleData::getData(data, CandleData::CLOSE, numSticks);

    int outNbElement = 0;
    int outBeg = 0;

    double * dataOut1 = new double[numSticks];
    memset(dataOut1,0,numSticks * sizeof(double));
    double * dataOut2 = new double[numSticks];
    memset(dataOut2,0,numSticks * sizeof(double));

    TA_RetCode ret =
        TA_HT_PHASOR( 0,
                      numSticks-1,
                      csData,
                      &outBeg,
                      &outNbElement,
                      dataOut1,
                      dataOut2);


    outInPhase = new double[numSticks + outBeg];
    memset(outInPhase,0,(numSticks + outBeg) * sizeof(double));
    memcpy(&outInPhase[outBeg],dataOut1,numSticks*sizeof(double));

    outQuadrature = new double[numSticks + outBeg];
    memset(outQuadrature,0,(numSticks + outBeg) * sizeof(double));
    memcpy(&outQuadrature[outBeg],dataOut2,numSticks*sizeof(double));

    delete [] csData;
    delete [] dataOut1;
    delete [] dataOut2;
}
Пример #3
0
/**** Local functions definitions.     ****/
static TA_RetCode rangeTestFunction( 
                              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;
   TA_Real *out1;
   TA_Real *out2;
   TA_Real *dummyOutput;
   (void)outputNb;
  
   testParam = (TA_RangeTestParam *)opaqueData;   

   dummyOutput = TA_Malloc( (endIdx-startIdx+1) * sizeof(TA_Real) );
                     
   if( outputNb == 0 )
   {
      out1 = outputBuffer;
      out2 = dummyOutput;
   }
   else
   {
      out1 = dummyOutput;
      out2 = outputBuffer;
   }

   switch( testParam->test->theFunction )
   {
   case TA_HT_PHASOR_TEST:
      retCode = TA_HT_PHASOR( startIdx,
                              endIdx,
                              testParam->price,
                              outBegIdx,
                              outNbElement,                          
                              out1, out2 );
      *lookback = TA_HT_PHASOR_Lookback();
      break;
   case TA_HT_SINE_TEST:
      retCode = TA_HT_SINE( startIdx,
                            endIdx,
                            testParam->price,
                            outBegIdx,
                            outNbElement,                          
                            out1, out2 );
      *lookback = TA_HT_SINE_Lookback();
      break;
   default:
      retCode = TA_INTERNAL_ERROR(132);
   }

   TA_Free(dummyOutput);
   return retCode;
}
Пример #4
0
static ErrorNumber do_test( const TA_History *history,
                            const TA_Test *test )
{
   TA_RetCode retCode;
   ErrorNumber errNb;
   TA_Integer outBegIdx;
   TA_Integer outNbElement;
   TA_RangeTestParam testParam;
   const TA_Real *referenceInput;

   /* 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 );
   setInputBuffer( 2, history->close,  history->nbBars );

   /* Change the input to MEDPRICE for some tests. */
   switch( test->theFunction )
   {
   case TA_HT_PHASOR_TEST:
   case TA_HT_SINE_TEST:
      TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low,
                   &outBegIdx, &outNbElement, gBuffer[0].in );

      TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low,
                   &outBegIdx, &outNbElement, gBuffer[1].in );

      /* Will be use as reference */
      TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low,
                   &outBegIdx, &outNbElement, gBuffer[2].in );

      referenceInput = gBuffer[2].in;
      break;
   default:
      referenceInput = history->close;
   }

   /* Make a simple first call. */
   switch( test->theFunction )
   {
   case TA_HT_PHASOR_TEST:
      retCode = TA_HT_PHASOR( test->startIdx,
                              test->endIdx,
                              gBuffer[0].in,
                              &outBegIdx,
                              &outNbElement,
                              gBuffer[0].out0,
                              gBuffer[0].out1 );
      break;
   case TA_HT_SINE_TEST:
      retCode = TA_HT_SINE( test->startIdx,
                            test->endIdx,
                            gBuffer[0].in,
                            &outBegIdx,
                            &outNbElement,
                            gBuffer[0].out0,
                            gBuffer[0].out1 );
      break;
   default:
      retCode = TA_INTERNAL_ERROR(133);
   }

   /* Check that the inputs were preserved. */
   errNb = checkDataSame( gBuffer[0].in, referenceInput, history->nbBars );
   if( errNb != TA_TEST_PASS )
      return errNb;

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

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

   outBegIdx = outNbElement = 0;

   /* Make another call where the input and the output 
    * are the same buffer.
    */
   switch( test->theFunction )
   {
   case TA_HT_PHASOR_TEST:
      retCode = TA_HT_PHASOR( test->startIdx,
                              test->endIdx,
                              gBuffer[0].in,
                              &outBegIdx,
                              &outNbElement,
                              gBuffer[0].in,
                              gBuffer[1].out1
                            );
      break;
   case TA_HT_SINE_TEST:
      retCode = TA_HT_SINE( test->startIdx,
                            test->endIdx,
                            gBuffer[0].in,
                            &outBegIdx,
                            &outNbElement,
                            gBuffer[0].in,
                            gBuffer[1].out1
                          );
      break;
   default:
      retCode = TA_INTERNAL_ERROR(134);
   }

   /* 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[0].in );
   if( errNb != TA_TEST_PASS )
      return errNb;

   errNb = checkSameContent( gBuffer[0].out1, gBuffer[1].out1 );
   if( errNb != TA_TEST_PASS )
      return errNb;

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

   /* Make another call where the input and the output 
    * are the same buffer.
    */
   switch( test->theFunction )
   {
   case TA_HT_PHASOR_TEST:
      retCode = TA_HT_PHASOR( test->startIdx,
                              test->endIdx,
                              gBuffer[1].in,
                              &outBegIdx,
                              &outNbElement,
                              gBuffer[1].out0,
                              gBuffer[1].in
                            );
      break;
   case TA_HT_SINE_TEST:
      retCode = TA_HT_SINE( test->startIdx,
                              test->endIdx,
                              gBuffer[1].in,
                              &outBegIdx,
                              &outNbElement,
                              gBuffer[1].out0,
                              gBuffer[1].in
                            );
      break;
   default:
      retCode = TA_INTERNAL_ERROR(134);
   }

   /* 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].out1, gBuffer[1].in );
   if( errNb != TA_TEST_PASS )
      return errNb;

   errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].out0 );
   if( errNb != TA_TEST_PASS )
      return errNb;

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

   /* Do a systematic test of most of the
    * possible startIdx/endIdx range.
    */
   testParam.test  = test;
   testParam.price = referenceInput;

   if( test->doRangeTestFlag )
   {
      switch( test->theFunction )
      {
      case TA_HT_PHASOR_TEST:
         errNb = doRangeTest( rangeTestFunction, 
                              TA_FUNC_UNST_HT_PHASOR,
                              (void *)&testParam, 1, 0 );
         break;
      case TA_HT_SINE_TEST:
         errNb = doRangeTest( rangeTestFunction, 
                              TA_FUNC_UNST_HT_SINE,
                              (void *)&testParam, 1, 10 );
         break;

      default:
         errNb = doRangeTest( rangeTestFunction, 
                              TA_FUNC_UNST_NONE,
                              (void *)&testParam, 1, 0 );
      }
      if( errNb != TA_TEST_PASS )
         return errNb;
   }

   return TA_TEST_PASS;
}
Пример #5
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 */
/* output variables */ 
  int outBegIdx;
  int outNbElement;
  double*	 outInPhase;
  double*	 outQuadrature;
/* input dimentions */ 
  int inSeriesRows;
  int inSeriesCols;
/* error handling */
  TA_RetCode retCode;

/* ----------------- input/output count ----------------- */  
  /*  Check for proper number of arguments. */
  if (nrhs < 1 || nrhs > 1) mexErrMsgTxt("#1 inputs possible #0 optional.");
  if (nlhs != 2) mexErrMsgTxt("#2 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 */ 

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

	retCode = TA_HT_PHASOR(
                   startIdx, endIdx,
                   inReal,
                   &outBegIdx, &outNbElement,
                   outInPhase,                   outQuadrature);
/* -------------- Errors ---------------- */
   if (retCode) {
   	   mxFree(outInPhase);
   	   mxFree(outQuadrature);
       mexPrintf("%s%i","Return code=",retCode);
       mexErrMsgTxt(" Error!");
   }
  
   // Populate Output
  plhs[0] = mxCreateDoubleMatrix(outBegIdx+outNbElement,1, mxREAL);
  memcpy(((double *) mxGetData(plhs[0]))+outBegIdx, outInPhase, outNbElement*mxGetElementSize(plhs[0]));
  mxFree(outInPhase);  
  plhs[1] = mxCreateDoubleMatrix(outBegIdx+outNbElement,1, mxREAL);
  memcpy(((double *) mxGetData(plhs[1]))+outBegIdx, outQuadrature, outNbElement*mxGetElementSize(plhs[1]));
  mxFree(outQuadrature);  
} /* END mexFunction */