⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ta_beta.c

📁 股票主要技术指标源码
💻 C
📖 第 1 页 / 共 2 页
字号:
   /* Process remaining of lookback until ready to output the first value. */   i = ++trailingIdx;   while( i < startIdx )   {       tmp_real = inReal0[i];       if( !TA_IS_ZERO(last_price_x) )          x = (tmp_real-last_price_x)/last_price_x;       else          x = 0.0;       last_price_x = tmp_real;       tmp_real = inReal1[i++];       if( !TA_IS_ZERO(last_price_y) )          y = (tmp_real-last_price_y)/last_price_y;       else          y = 0.0;       last_price_y = tmp_real;       S_xx += x*x;       S_xy += x*y;       S_x += x;       S_y += y;         }      outIdx = 0; /* First output always start at index zero */   n = (double)optInTimePeriod;   do   {       tmp_real = inReal0[i];       if( !TA_IS_ZERO(last_price_x) )          x = (tmp_real-last_price_x)/last_price_x;       else          x = 0.0;       last_price_x = tmp_real;       tmp_real = inReal1[i++];       if( !TA_IS_ZERO(last_price_y) )          y = (tmp_real-last_price_y)/last_price_y;       else          y = 0.0;       last_price_y = tmp_real;       S_xx += x*x;       S_xy += x*y;       S_x += x;       S_y += y;       /* Always read the trailing before writing the output because the input and output        * buffer can be the same.        */       tmp_real = inReal0[trailingIdx];       if( !TA_IS_ZERO(trailing_last_price_x) )          x = (tmp_real-trailing_last_price_x)/trailing_last_price_x;       else          x = 0.0;       trailing_last_price_x = tmp_real;       tmp_real = inReal1[trailingIdx++];       if( !TA_IS_ZERO(trailing_last_price_y) )          y = (tmp_real-trailing_last_price_y)/trailing_last_price_y;       else          y = 0.0;       trailing_last_price_y = tmp_real;       /* Write the output */       tmp_real = (n * S_xx) - (S_x * S_x);       if( !TA_IS_ZERO(tmp_real) )          outReal[outIdx++] = ((n * S_xy) - (S_x * S_y)) / tmp_real;       else          outReal[outIdx++] = 0.0;       /* Remove the calculation starting with the trailingIdx. */       S_xx -= x*x;       S_xy -= x*y;       S_x -= x;       S_y -= y;          } while( i <= endIdx );   /* All done. Indicate the output limits and return. */   VALUE_HANDLE_DEREF(outNBElement) = outIdx;   VALUE_HANDLE_DEREF(outBegIdx) = startIdx;   return ENUM_VALUE(RetCode,TA_SUCCESS,Success);}/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****//* Generated */ /* Generated */ #define  USE_SINGLE_PRECISION_INPUT/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )/* Generated */    #undef   TA_PREFIX/* Generated */    #define  TA_PREFIX(x) TA_S_##x/* Generated */ #endif/* Generated */ #undef   INPUT_TYPE/* Generated */ #define  INPUT_TYPE float/* Generated */ #if defined( _MANAGED )/* Generated */ enum class Core::RetCode Core::Beta( int    startIdx,/* Generated */                                      int    endIdx,/* Generated */                                      cli::array<float>^ inReal0,/* Generated */                                      cli::array<float>^ inReal1,/* Generated */                                      int           optInTimePeriod, /* From 1 to 100000 *//* Generated */                                      [Out]int%    outBegIdx,/* Generated */                                      [Out]int%    outNBElement,/* Generated */                                      cli::array<double>^  outReal )/* Generated */ #elif defined( _JAVA )/* Generated */ public RetCode beta( int    startIdx,/* Generated */                      int    endIdx,/* Generated */                      float        inReal0[],/* Generated */                      float        inReal1[],/* Generated */                      int           optInTimePeriod, /* From 1 to 100000 *//* Generated */                      MInteger     outBegIdx,/* Generated */                      MInteger     outNBElement,/* Generated */                      double        outReal[] )/* Generated */ #else/* Generated */ TA_RetCode TA_S_BETA( int    startIdx,/* Generated */                       int    endIdx,/* Generated */                       const float  inReal0[],/* Generated */                       const float  inReal1[],/* Generated */                       int           optInTimePeriod, /* From 1 to 100000 *//* Generated */                       int          *outBegIdx,/* Generated */                       int          *outNBElement,/* Generated */                       double        outReal[] )/* Generated */ #endif/* Generated */ {/* Generated */     double S_xx = 0.0f; /* Generated */     double S_xy = 0.0f; /* Generated */     double S_x = 0.0f; /* Generated */     double S_y = 0.0f; /* Generated */     double last_price_x = 0.0f; /* Generated */     double last_price_y = 0.0f; /* Generated */     double trailing_last_price_x = 0.0f; /* Generated */     double trailing_last_price_y = 0.0f; /* Generated */     double tmp_real = 0.0f; /* Generated */     double x; /* Generated */     double y; /* Generated */     double n = 0.0f;/* Generated */     int i, outIdx;/* Generated */     int trailingIdx, nbInitialElementNeeded;/* Generated */  #ifndef TA_FUNC_NO_RANGE_CHECK/* Generated */     if( startIdx < 0 )/* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);/* Generated */     if( (endIdx < 0) || (endIdx < startIdx))/* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);/* Generated */     #if !defined(_JAVA)/* Generated */     if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */     if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */     #endif /* Generated */     if( (int)optInTimePeriod == TA_INTEGER_DEFAULT )/* Generated */        optInTimePeriod = 5;/* Generated */     else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) )/* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */     #if !defined(_JAVA)/* Generated */     if( !outReal )/* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */     #endif /* Generated */  #endif /* Generated */    nbInitialElementNeeded = optInTimePeriod;/* Generated */    if( startIdx < nbInitialElementNeeded )/* Generated */       startIdx = nbInitialElementNeeded;/* Generated */    if( startIdx > endIdx )/* Generated */    {/* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);/* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);/* Generated */       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);/* Generated */    }   /* Generated */    trailingIdx = startIdx-nbInitialElementNeeded;/* Generated */    last_price_x = trailing_last_price_x = inReal0[trailingIdx];/* Generated */    last_price_y = trailing_last_price_y = inReal1[trailingIdx];/* Generated */    i = ++trailingIdx;/* Generated */    while( i < startIdx )/* Generated */    {/* Generated */        tmp_real = inReal0[i];/* Generated */        if( !TA_IS_ZERO(last_price_x) )/* Generated */           x = (tmp_real-last_price_x)/last_price_x;/* Generated */        else/* Generated */           x = 0.0;/* Generated */        last_price_x = tmp_real;/* Generated */        tmp_real = inReal1[i++];/* Generated */        if( !TA_IS_ZERO(last_price_y) )/* Generated */           y = (tmp_real-last_price_y)/last_price_y;/* Generated */        else/* Generated */           y = 0.0;/* Generated */        last_price_y = tmp_real;/* Generated */        S_xx += x*x;/* Generated */        S_xy += x*y;/* Generated */        S_x += x;/* Generated */        S_y += y;      /* Generated */    }/* Generated */    outIdx = 0; /* Generated */    n = (double)optInTimePeriod;/* Generated */    do/* Generated */    {/* Generated */        tmp_real = inReal0[i];/* Generated */        if( !TA_IS_ZERO(last_price_x) )/* Generated */           x = (tmp_real-last_price_x)/last_price_x;/* Generated */        else/* Generated */           x = 0.0;/* Generated */        last_price_x = tmp_real;/* Generated */        tmp_real = inReal1[i++];/* Generated */        if( !TA_IS_ZERO(last_price_y) )/* Generated */           y = (tmp_real-last_price_y)/last_price_y;/* Generated */        else/* Generated */           y = 0.0;/* Generated */        last_price_y = tmp_real;/* Generated */        S_xx += x*x;/* Generated */        S_xy += x*y;/* Generated */        S_x += x;/* Generated */        S_y += y;/* Generated */        tmp_real = inReal0[trailingIdx];/* Generated */        if( !TA_IS_ZERO(trailing_last_price_x) )/* Generated */           x = (tmp_real-trailing_last_price_x)/trailing_last_price_x;/* Generated */        else/* Generated */           x = 0.0;/* Generated */        trailing_last_price_x = tmp_real;/* Generated */        tmp_real = inReal1[trailingIdx++];/* Generated */        if( !TA_IS_ZERO(trailing_last_price_y) )/* Generated */           y = (tmp_real-trailing_last_price_y)/trailing_last_price_y;/* Generated */        else/* Generated */           y = 0.0;/* Generated */        trailing_last_price_y = tmp_real;/* Generated */        tmp_real = (n * S_xx) - (S_x * S_x);/* Generated */        if( !TA_IS_ZERO(tmp_real) )/* Generated */           outReal[outIdx++] = ((n * S_xy) - (S_x * S_y)) / tmp_real;/* Generated */        else/* Generated */           outReal[outIdx++] = 0.0;/* Generated */        S_xx -= x*x;/* Generated */        S_xy -= x*y;/* Generated */        S_x -= x;/* Generated */        S_y -= y;       /* Generated */    } while( i <= endIdx );/* Generated */    VALUE_HANDLE_DEREF(outNBElement) = outIdx;/* Generated */    VALUE_HANDLE_DEREF(outBegIdx) = startIdx;/* Generated */    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);/* Generated */ }/* Generated */ /* Generated */ #if defined( _MANAGED )/* Generated */ }}} // Close namespace TicTacTec.TA.Lib/* Generated */ #endif/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -