hhashim1

Untitled

Jun 27th, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.99 KB | None | 0 0
  1. /* TA-LIB Copyright (c) 1999-2008, Mario Fortier
  2. * All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or
  5. * without modification, are permitted provided that the following
  6. * conditions are met:
  7. *
  8. * - Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * - Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in
  13. * the documentation and/or other materials provided with the
  14. * distribution.
  15. *
  16. * - Neither name of author nor the names of its contributors
  17. * may be used to endorse or promote products derived from this
  18. * software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  26. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  30. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  31. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33.  
  34. /* List of contributors:
  35. *
  36. * Initial Name/description
  37. * -------------------------------------------------------------------
  38. * MF Mario Fortier (Replace when you are the original author)
  39. *
  40. * Change history:
  41. *
  42. * MMDDYY BY Description
  43. * -------------------------------------------------------------------
  44. * XXXXXX MF Initial Version
  45. */
  46.  
  47. /**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
  48. /* All code within this section is automatically
  49. * generated by gen_code. Any modification will be lost
  50. * next time gen_code is run.
  51. */
  52. /* Generated */
  53. /* Generated */ #if defined( _MANAGED )
  54. /* Generated */ #include "TA-Lib-Core.h"
  55. /* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError)
  56. /* Generated */ namespace TicTacTec { namespace TA { namespace Library {
  57. /* Generated */ #elif defined( _JAVA )
  58. /* Generated */ #include "ta_defs.h"
  59. /* Generated */ #include "ta_java_defs.h"
  60. /* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError)
  61. /* Generated */ #else
  62. /* Generated */ #include <string.h>
  63. /* Generated */ #include <math.h>
  64. /* Generated */ #include "ta_func.h"
  65. /* Generated */ #endif
  66. /* Generated */
  67. /* Generated */ #ifndef TA_UTILITY_H
  68. /* Generated */ #include "ta_utility.h"
  69. /* Generated */ #endif
  70. /* Generated */
  71. /* Generated */ #ifndef TA_MEMORY_H
  72. /* Generated */ #include "ta_memory.h"
  73. /* Generated */ #endif
  74. /* Generated */
  75. /* Generated */ #define TA_PREFIX(x) TA_##x
  76. /* Generated */ #define INPUT_TYPE double
  77. /* Generated */
  78. /* Generated */ #if defined( _MANAGED )
  79. /* Generated */ int Core::RvStdevLookback( int optInTimePeriod ) /* From 2 to 100000 */
  80. /* Generated */
  81. /* Generated */ #elif defined( _JAVA )
  82. /* Generated */ public int rvStdevLookback( int optInTimePeriod ) /* From 2 to 100000 */
  83. /* Generated */
  84. /* Generated */ #else
  85. /* Generated */ TA_LIB_API int TA_RVSTDEV_Lookback( int optInTimePeriod ) /* From 2 to 100000 */
  86. /* Generated */
  87. /* Generated */ #endif
  88. /**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
  89. {
  90. /* insert local variable here */
  91.  
  92. /**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
  93. /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
  94. /* Generated */ /* min/max are checked for optInTimePeriod. */
  95. /* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT )
  96. /* Generated */ optInTimePeriod = 50;
  97. /* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) )
  98. /* Generated */ return -1;
  99. /* Generated */
  100. /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
  101. /**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
  102.  
  103. /* insert lookback code here. */
  104.  
  105. /* The lookback is driven by the middle band moving average. */
  106. return LOOKBACK_CALL(SMA)(optInTimePeriod);
  107. //return optInTimePeriod - 1;
  108. }
  109.  
  110. /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
  111. /*
  112. * TA_RVSTDEV - Relative Volume St Dev
  113. *
  114. * Input = Volume
  115. * Output = double
  116. *
  117. * Optional Parameters
  118. * -------------------
  119. * optInTimePeriod:(From 2 to 100000)
  120. * Number of period
  121. *
  122. *
  123. */
  124. /* Generated */
  125. /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
  126. /* Generated */ enum class Core::RetCode Core::RvStdev( int startIdx,
  127. /* Generated */ int endIdx,
  128. /* Generated */ SubArray<double>^ inVolume,
  129. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  130. /* Generated */ [Out]int% outBegIdx,
  131. /* Generated */ [Out]int% outNBElement,
  132. /* Generated */ SubArray<double>^ outReal )
  133. /* Generated */ #elif defined( _MANAGED )
  134. /* Generated */ enum class Core::RetCode Core::RvStdev( int startIdx,
  135. /* Generated */ int endIdx,
  136. /* Generated */ cli::array<double>^ inVolume,
  137. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  138. /* Generated */ [Out]int% outBegIdx,
  139. /* Generated */ [Out]int% outNBElement,
  140. /* Generated */ cli::array<double>^ outReal )
  141. /* Generated */ #elif defined( _JAVA )
  142. /* Generated */ public RetCode rvStdev( int startIdx,
  143. /* Generated */ int endIdx,
  144. /* Generated */ double inVolume[],
  145. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  146. /* Generated */ MInteger outBegIdx,
  147. /* Generated */ MInteger outNBElement,
  148. /* Generated */ double outReal[] )
  149. /* Generated */ #else
  150. /* Generated */ TA_LIB_API TA_RetCode TA_RVSTDEV( int startIdx,
  151. /* Generated */ int endIdx,
  152. /* Generated */ const double inVolume[],
  153. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  154. /* Generated */ int *outBegIdx,
  155. /* Generated */ int *outNBElement,
  156. /* Generated */ double outReal[] )
  157. /* Generated */ #endif
  158. /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
  159. {
  160. /* insert local variable here */
  161. //ENUM_DECLARATION(RetCode) retCode;
  162. //double periodTotal;
  163. //double tempReal, tempReal2;
  164. //int i;// , outIdx, trailingIdx, lookbackTotal;
  165. //ARRAY_REF(tempBuffer1);
  166. //ARRAY_REF(tempBuffer2);
  167. //double rawRelVol;
  168.  
  169. /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
  170. /* Generated */
  171. /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
  172. /* Generated */
  173. /* Generated */ /* Validate the requested output range. */
  174. /* Generated */ if( startIdx < 0 )
  175. /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
  176. /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
  177. /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
  178. /* Generated */
  179. /* Generated */ #if !defined(_JAVA)
  180. /* Generated */ /* Verify required price component. */
  181. /* Generated */ if(!inVolume)
  182. /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
  183. /* Generated */
  184. /* Generated */ #endif /* !defined(_JAVA)*/
  185. /* Generated */ /* min/max are checked for optInTimePeriod. */
  186. /* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT )
  187. /* Generated */ optInTimePeriod = 50;
  188. /* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) )
  189. /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
  190. /* Generated */
  191. /* Generated */ #if !defined(_JAVA)
  192. /* Generated */ if( !outReal )
  193. /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
  194. /* Generated */
  195. /* Generated */ #endif /* !defined(_JAVA) */
  196. /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
  197. /* Generated */
  198. /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
  199.  
  200. /* insert local variable here */
  201. ENUM_DECLARATION(RetCode) retCode;
  202. int outBegIdx1, outBegIdx2;
  203. int currentIdx, currentIdx1, currentIdx2;
  204. int i;
  205. ARRAY_REF(tempBuffer1);
  206. ARRAY_REF(tempBuffer2);
  207. ARRAY_ALLOC(tempBuffer1, optInTimePeriod);
  208. ARRAY_ALLOC(tempBuffer2, optInTimePeriod);
  209.  
  210.  
  211. /* Calculate moving average. */
  212. retCode = FUNCTION_CALL(SMA)(startIdx, endIdx, inVolume,
  213. optInTimePeriod, &outBegIdx1, outNBElement, tempBuffer1);
  214.  
  215. if ((retCode != ENUM_VALUE(RetCode, TA_SUCCESS, Success)) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0))
  216. {
  217. ARRAY_FREE(tempBuffer1);
  218. ARRAY_FREE(tempBuffer2);
  219. VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  220. return retCode;
  221. }
  222.  
  223. /* Calculate the Standard Deviation */
  224. retCode = FUNCTION_CALL(STDDEV)(startIdx, endIdx, inVolume,
  225. optInTimePeriod, 1.0,
  226. &outBegIdx2, outNBElement, tempBuffer2);
  227.  
  228. if ((retCode != ENUM_VALUE(RetCode, TA_SUCCESS, Success)) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0))
  229. {
  230. ARRAY_FREE(tempBuffer1);
  231. ARRAY_FREE(tempBuffer2);
  232. VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  233. return retCode;
  234. }
  235.  
  236.  
  237. // startIdx is a MAX(startIdx, outBegIdx1, outBegIdx2)
  238. if (startIdx < outBegIdx1)
  239. startIdx = outBegIdx1;
  240. if (startIdx < outBegIdx2)
  241. startIdx = outBegIdx2;
  242.  
  243. VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
  244.  
  245. if (startIdx > endIdx)
  246. {
  247. ARRAY_FREE(tempBuffer1);
  248. ARRAY_FREE(tempBuffer2);
  249. VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  250. return retCode;
  251. }
  252.  
  253.  
  254. currentIdx = 0;
  255. currentIdx1 = startIdx - outBegIdx1;
  256. currentIdx2 = startIdx - outBegIdx2;
  257.  
  258. for (i = startIdx; i < endIdx; i++)
  259. {
  260. outReal[currentIdx++] = (inVolume[i] - tempBuffer1[currentIdx1++]) / tempBuffer2[currentIdx2++];
  261. }
  262.  
  263.  
  264. ARRAY_FREE(tempBuffer1);
  265. ARRAY_FREE(tempBuffer2);
  266. (int)VALUE_HANDLE_DEREF(outNBElement) = currentIdx;
  267.  
  268. return ENUM_VALUE(RetCode, TA_SUCCESS, Success);
  269. }
  270.  
  271. /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
  272. /* Generated */
  273. /* Generated */ #define USE_SINGLE_PRECISION_INPUT
  274. /* Generated */ #undef TA_LIB_PRO
  275. /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
  276. /* Generated */ #undef TA_PREFIX
  277. /* Generated */ #define TA_PREFIX(x) TA_S_##x
  278. /* Generated */ #endif
  279. /* Generated */ #undef INPUT_TYPE
  280. /* Generated */ #define INPUT_TYPE float
  281. /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
  282. /* Generated */ enum class Core::RetCode Core::RvStdev( int startIdx,
  283. /* Generated */ int endIdx,
  284. /* Generated */ SubArray<float>^ inVolume,
  285. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  286. /* Generated */ [Out]int% outBegIdx,
  287. /* Generated */ [Out]int% outNBElement,
  288. /* Generated */ SubArray<double>^ outReal )
  289. /* Generated */ #elif defined( _MANAGED )
  290. /* Generated */ enum class Core::RetCode Core::RvStdev( int startIdx,
  291. /* Generated */ int endIdx,
  292. /* Generated */ cli::array<float>^ inVolume,
  293. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  294. /* Generated */ [Out]int% outBegIdx,
  295. /* Generated */ [Out]int% outNBElement,
  296. /* Generated */ cli::array<double>^ outReal )
  297. /* Generated */ #elif defined( _JAVA )
  298. /* Generated */ public RetCode rvStdev( int startIdx,
  299. /* Generated */ int endIdx,
  300. /* Generated */ float inVolume[],
  301. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  302. /* Generated */ MInteger outBegIdx,
  303. /* Generated */ MInteger outNBElement,
  304. /* Generated */ double outReal[] )
  305. /* Generated */ #else
  306. /* Generated */ TA_RetCode TA_S_RVSTDEV( int startIdx,
  307. /* Generated */ int endIdx,
  308. /* Generated */ const float inVolume[],
  309. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  310. /* Generated */ int *outBegIdx,
  311. /* Generated */ int *outNBElement,
  312. /* Generated */ double outReal[] )
  313. /* Generated */ #endif
  314. /* Generated */ {
  315. /* Generated */ //ENUM_DECLARATION(RetCode) retCode;
  316. /* Generated */ //double periodTotal;
  317. /* Generated */ //double tempReal, tempReal2;
  318. /* Generated */ //int i;// , outIdx, trailingIdx, lookbackTotal;
  319. /* Generated */ //ARRAY_REF(tempBuffer1);
  320. /* Generated */ //ARRAY_REF(tempBuffer2);
  321. /* Generated */ //double rawRelVol;
  322. /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
  323. /* Generated */ if( startIdx < 0 )
  324. /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
  325. /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
  326. /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
  327. /* Generated */ #if !defined(_JAVA)
  328. /* Generated */ if(!inVolume)
  329. /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
  330. /* Generated */ #endif
  331. /* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT )
  332. /* Generated */ optInTimePeriod = 50;
  333. /* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) )
  334. /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
  335. /* Generated */ #if !defined(_JAVA)
  336. /* Generated */ if( !outReal )
  337. /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
  338. /* Generated */ #endif
  339. /* Generated */ #endif
  340. /* Generated */ ENUM_DECLARATION(RetCode) retCode;
  341. /* Generated */ int outBegIdx1, outBegIdx2;
  342. /* Generated */ int currentIdx, currentIdx1, currentIdx2;
  343. /* Generated */ int i;
  344. /* Generated */ ARRAY_REF(tempBuffer1);
  345. /* Generated */ ARRAY_REF(tempBuffer2);
  346. /* Generated */ ARRAY_ALLOC(tempBuffer1, optInTimePeriod);
  347. /* Generated */ ARRAY_ALLOC(tempBuffer2, optInTimePeriod);
  348. /* Generated */ retCode = FUNCTION_CALL(SMA)(startIdx, endIdx, inVolume,
  349. /* Generated */ optInTimePeriod, &outBegIdx1, outNBElement, tempBuffer1);
  350. /* Generated */ if ((retCode != ENUM_VALUE(RetCode, TA_SUCCESS, Success)) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0))
  351. /* Generated */ {
  352. /* Generated */ ARRAY_FREE(tempBuffer1);
  353. /* Generated */ ARRAY_FREE(tempBuffer2);
  354. /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  355. /* Generated */ return retCode;
  356. /* Generated */ }
  357. /* Generated */ retCode = FUNCTION_CALL(STDDEV)(startIdx, endIdx, inVolume,
  358. /* Generated */ optInTimePeriod, 1.0,
  359. /* Generated */ &outBegIdx2, outNBElement, tempBuffer2);
  360. /* Generated */ if ((retCode != ENUM_VALUE(RetCode, TA_SUCCESS, Success)) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0))
  361. /* Generated */ {
  362. /* Generated */ ARRAY_FREE(tempBuffer1);
  363. /* Generated */ ARRAY_FREE(tempBuffer2);
  364. /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  365. /* Generated */ return retCode;
  366. /* Generated */ }
  367. /* Generated */ // startIdx is a MAX(startIdx, outBegIdx1, outBegIdx2)
  368. /* Generated */ if (startIdx < outBegIdx1)
  369. /* Generated */ startIdx = outBegIdx1;
  370. /* Generated */ if (startIdx < outBegIdx2)
  371. /* Generated */ startIdx = outBegIdx2;
  372. /* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
  373. /* Generated */ if (startIdx > endIdx)
  374. /* Generated */ {
  375. /* Generated */ ARRAY_FREE(tempBuffer1);
  376. /* Generated */ ARRAY_FREE(tempBuffer2);
  377. /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  378. /* Generated */ return retCode;
  379. /* Generated */ }
  380. /* Generated */ currentIdx = 0;
  381. /* Generated */ currentIdx1 = startIdx - outBegIdx1;
  382. /* Generated */ currentIdx2 = startIdx - outBegIdx2;
  383. /* Generated */ for (i = startIdx; i < endIdx; i++)
  384. /* Generated */ {
  385. /* Generated */ outReal[currentIdx++] = (inVolume[i] - tempBuffer1[currentIdx1++]) / tempBuffer2[currentIdx2++];
  386. /* Generated */ }
  387. /* Generated */ ARRAY_FREE(tempBuffer1);
  388. /* Generated */ ARRAY_FREE(tempBuffer2);
  389. /* Generated */ (int)VALUE_HANDLE_DEREF(outNBElement) = currentIdx;
  390. /* Generated */ return ENUM_VALUE(RetCode, TA_SUCCESS, Success);
  391. /* Generated */ }
  392. /* Generated */
  393. /* Generated */ #if defined( _MANAGED )
  394. /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
  395. /* Generated */ #endif
  396. /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
  397.  
  398.  
Advertisement
Add Comment
Please, Sign In to add comment