コード例 #1
0
double * getAllSTD(double * doubleSeries, const unsigned int arraySize, const unsigned int size, double dev)
{
	int outNbElement = 0;
	int outBeg = 0;
	double optInNbDev = dev;

	double * stddevDataOut = new double[arraySize];
	memset(stddevDataOut,0,arraySize * sizeof(double));

	TA_RetCode stddevRet =
		TA_STDDEV( 0,
			  arraySize - 1, 
			  doubleSeries,
			  size,
			  optInNbDev,
			  &outBeg,
		      &outNbElement,
		      stddevDataOut);

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

	delete [] stddevDataOut;

	return ret;
}
コード例 #2
0
double getSTD(const unsigned int size, CandleData * data, long numSticks)
{
	double stddev = 0.0;
	double * csData = CandleData::getData(data, CandleData::CLOSE, numSticks);
	int outNbElement = 0;
	int outBeg = 0;
	double optInNbDev = 1.0;

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

	TA_RetCode stddevRet =
		TA_STDDEV( 0,
			  numSticks - 1,
			  csData,
			  size,
		  	  optInNbDev,
			  &outBeg,
		      &outNbElement,
		      stddevDataOut);

	if(outNbElement == 0)
	{
		stddev = 0.0;
	}
	else
	{
		stddev = stddevDataOut[outNbElement - 1];
	}

	delete [] csData;
	delete [] stddevDataOut;
	
	return stddev;
}
コード例 #3
0
double getSTD(double * doubleSeries, const unsigned int size)
{
	double stddev = 0.0;
	int outNbElement = 0;
	int outBeg = 0;
	double optInNbDev = 1.0;

	double * stddevDataOut = new double[1];

	TA_RetCode stddevRet =
		TA_STDDEV( 0,
			  size - 1,
			  doubleSeries,
			  size,
		  	  optInNbDev,
			  &outBeg,
		      &outNbElement,
		      stddevDataOut);

	if(outNbElement == 0)
	{
		stddev = 0.0;
	}
	else
	{
		stddev = stddevDataOut[outNbElement - 1];
	}

	delete [] stddevDataOut;
	
	return stddev;
}
コード例 #4
0
double * getAllSTD(const unsigned int size, CandleData * data, long numSticks)
{
	double * closeData = CandleData::getData(data, CandleData::CLOSE, numSticks);

	int outNbElement = 0;
	int outBeg = 0;
	double optInNbDev = 1.0;

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

	TA_RetCode stddevRet =
		TA_STDDEV( 0,
			  numSticks - 1, 
			  closeData,
			  size,
			  optInNbDev,
			  &outBeg,
		      &outNbElement,
		      stddevDataOut);

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

	delete [] closeData;
	delete [] stddevDataOut;

	return ret;
}
コード例 #5
0
double getRegressionSTD(const unsigned int size, double optInNbDev, CandleData * data, long numSticks)
{
	double stddev = 0.0;
	double * slopeVal = getAllSlopeVal(size,data,numSticks);

	double * closeVals = CandleData::getData(data, CandleData::CLOSE, numSticks);
	int outNbElement = 0;
	int outBeg = 0;

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

	TA_RetCode subret = TA_SUB(0,
							numSticks -1,
							slopeVal,
							closeVals,
							&outBeg,
							&outNbElement,
							temp);


	double * deviation_ = new double[outNbElement + outBeg];
	memset(deviation_,0,(outNbElement + outBeg) * sizeof(double));
	memcpy(&deviation_[outBeg],temp,outNbElement*sizeof(double));

	delete [] closeVals;
	delete [] slopeVal;
	delete [] temp;

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

	TA_RetCode stddevRet =
		TA_STDDEV( 0,
			  numSticks - 1, 
			  deviation_,
			  size,
			  optInNbDev,
			  &outBeg,
		      &outNbElement,
		      temp);

	if(outNbElement == 0)
	{
		stddev = 0.0;
	}
	else
	{
		stddev = temp[outNbElement - 1];
	}

	delete [] temp;
	delete [] deviation_;
	
	return stddev;
}
コード例 #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;   

   retCode = TA_STDDEV(
                        startIdx,
                        endIdx,
                        testParam->close,
                        testParam->test->optInTimePeriod,
                        testParam->test->optInNbDeviation_1,                        
                        outBegIdx,
                        outNbElement,
                        outputBuffer );


   *lookback = TA_STDDEV_Lookback( testParam->test->optInTimePeriod,
                       testParam->test->optInNbDeviation_1 );

   return retCode;
}
コード例 #7
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;

   /* 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 );
   
   /* Make a simple first call. */
   retCode = TA_STDDEV(
                        test->startIdx,
                        test->endIdx,
                        gBuffer[0].in,
                        test->optInTimePeriod,
                        test->optInNbDeviation_1,                        
                        &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.
    */
   retCode = TA_STDDEV(
                        test->startIdx,
                        test->endIdx,
                        gBuffer[1].in,
                        test->optInTimePeriod,
                        test->optInNbDeviation_1,                        
                        &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(
                           rangeTestFunction, 
                           TA_FUNC_UNST_NONE,
                           (void *)&testParam, 1, 0 );
      if( errNb != TA_TEST_PASS )
         return errNb;
   }

   return TA_TEST_PASS;
}
コード例 #8
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;
  double	 optInDeviations;
/* 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 > 3) mexErrMsgTxt("#3 inputs possible #2 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 = 5;
  }
  if (nrhs >= 2+1) {
	if (!mxIsDouble(prhs[2]) || mxIsComplex(prhs[2]) ||
      mxGetN(prhs[2])*mxGetM(prhs[2]) != 1) 
    	mexErrMsgTxt("Input optInDeviations must be a scalar.");
   	/* Get the scalar input optInTimePeriod. */
   	optInDeviations =   mxGetScalar(prhs[2]);
  } else {
  	optInDeviations = 1.000000e+0;
  }

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

	retCode = TA_STDDEV(
                   startIdx, endIdx,
                   inReal,
                   optInTimePeriod,
                   optInDeviations,
                   &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 */