hhashim1

Untitled

Jun 28th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.63 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. //ARRAY_ALLOC(tempBuffer1, 50);
  205. //ARRAY_ALLOC(tempBuffer2, 50);
  206.  
  207. ARRAY_ALLOC(tempBuffer1, optInTimePeriod);
  208. if (!tempBuffer1)
  209. return ENUM_VALUE(RetCode, TA_ALLOC_ERR, AllocErr);
  210.  
  211. ARRAY_ALLOC(tempBuffer2, optInTimePeriod);
  212. if (!tempBuffer2)
  213. {
  214. ARRAY_FREE(tempBuffer1);
  215. return ENUM_VALUE(RetCode, TA_ALLOC_ERR, AllocErr);
  216. }
  217.  
  218.  
  219. /* Calculate moving average. */
  220. retCode = FUNCTION_CALL(SMA)(startIdx, endIdx, inVolume,
  221. optInTimePeriod, &outBegIdx1, outNBElement, tempBuffer1);
  222.  
  223. if ((retCode != ENUM_VALUE(RetCode, TA_SUCCESS, Success)) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0))
  224. {
  225. ARRAY_FREE(tempBuffer1);
  226. ARRAY_FREE(tempBuffer2);
  227. VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  228. return retCode;
  229. }
  230.  
  231. /* Calculate the Standard Deviation */
  232. retCode = FUNCTION_CALL(STDDEV)(startIdx, endIdx, inVolume,
  233. optInTimePeriod, 1.0,
  234. &outBegIdx2, outNBElement, tempBuffer2);
  235.  
  236. if ((retCode != ENUM_VALUE(RetCode, TA_SUCCESS, Success)) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0))
  237. {
  238. ARRAY_FREE(tempBuffer1);
  239. ARRAY_FREE(tempBuffer2);
  240. VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  241. return retCode;
  242. }
  243.  
  244.  
  245. // startIdx is a MAX(startIdx, outBegIdx1, outBegIdx2)
  246. if (startIdx < outBegIdx1)
  247. startIdx = outBegIdx1;
  248. if (startIdx < outBegIdx2)
  249. startIdx = outBegIdx2;
  250.  
  251. VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
  252.  
  253. if (startIdx > endIdx)
  254. {
  255. ARRAY_FREE(tempBuffer1);
  256. ARRAY_FREE(tempBuffer2);
  257. VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  258. return retCode;
  259. }
  260.  
  261.  
  262. currentIdx = 0;
  263. currentIdx1 = startIdx - outBegIdx1;
  264. currentIdx2 = startIdx - outBegIdx2;
  265.  
  266. for (i = startIdx; i < endIdx; i++)
  267. {
  268. outReal[currentIdx++] = (inVolume[i] - tempBuffer1[currentIdx1++]) / tempBuffer2[currentIdx2++];
  269. }
  270.  
  271.  
  272. ARRAY_FREE(tempBuffer1);
  273. ARRAY_FREE(tempBuffer2);
  274. //(int)VALUE_HANDLE_DEREF(outNBElement) = currentIdx;
  275. VALUE_HANDLE_DEREF(outNBElement) = currentIdx;
  276.  
  277. return ENUM_VALUE(RetCode, TA_SUCCESS, Success);
  278. }
  279.  
  280. /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
  281. /* Generated */
  282. /* Generated */ #define USE_SINGLE_PRECISION_INPUT
  283. /* Generated */ #undef TA_LIB_PRO
  284. /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
  285. /* Generated */ #undef TA_PREFIX
  286. /* Generated */ #define TA_PREFIX(x) TA_S_##x
  287. /* Generated */ #endif
  288. /* Generated */ #undef INPUT_TYPE
  289. /* Generated */ #define INPUT_TYPE float
  290. /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
  291. /* Generated */ enum class Core::RetCode Core::RvStdev( int startIdx,
  292. /* Generated */ int endIdx,
  293. /* Generated */ SubArray<float>^ inVolume,
  294. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  295. /* Generated */ [Out]int% outBegIdx,
  296. /* Generated */ [Out]int% outNBElement,
  297. /* Generated */ SubArray<double>^ outReal )
  298. /* Generated */ #elif defined( _MANAGED )
  299. /* Generated */ enum class Core::RetCode Core::RvStdev( int startIdx,
  300. /* Generated */ int endIdx,
  301. /* Generated */ cli::array<float>^ inVolume,
  302. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  303. /* Generated */ [Out]int% outBegIdx,
  304. /* Generated */ [Out]int% outNBElement,
  305. /* Generated */ cli::array<double>^ outReal )
  306. /* Generated */ #elif defined( _JAVA )
  307. /* Generated */ public RetCode rvStdev( int startIdx,
  308. /* Generated */ int endIdx,
  309. /* Generated */ float inVolume[],
  310. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  311. /* Generated */ MInteger outBegIdx,
  312. /* Generated */ MInteger outNBElement,
  313. /* Generated */ double outReal[] )
  314. /* Generated */ #else
  315. /* Generated */ TA_RetCode TA_S_RVSTDEV( int startIdx,
  316. /* Generated */ int endIdx,
  317. /* Generated */ const float inVolume[],
  318. /* Generated */ int optInTimePeriod, /* From 2 to 100000 */
  319. /* Generated */ int *outBegIdx,
  320. /* Generated */ int *outNBElement,
  321. /* Generated */ double outReal[] )
  322. /* Generated */ #endif
  323. /* Generated */ {
  324. /* Generated */ //ENUM_DECLARATION(RetCode) retCode;
  325. /* Generated */ //double periodTotal;
  326. /* Generated */ //double tempReal, tempReal2;
  327. /* Generated */ int i;// , outIdx, trailingIdx, lookbackTotal;
  328. /* Generated */ ARRAY_REF(tempBuffer1);
  329. /* Generated */ ARRAY_REF(tempBuffer2);
  330. /* Generated */ //double rawRelVol;
  331. /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
  332. /* Generated */ if( startIdx < 0 )
  333. /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
  334. /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
  335. /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
  336. /* Generated */ #if !defined(_JAVA)
  337. /* Generated */ if(!inVolume)
  338. /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
  339. /* Generated */ #endif
  340. /* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT )
  341. /* Generated */ optInTimePeriod = 50;
  342. /* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) )
  343. /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
  344. /* Generated */ #if !defined(_JAVA)
  345. /* Generated */ if( !outReal )
  346. /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
  347. /* Generated */ #endif
  348. /* Generated */ #endif
  349. /* Generated */ ENUM_DECLARATION(RetCode) retCode;
  350. /* Generated */ int outBegIdx1, outBegIdx2;
  351. /* Generated */ int currentIdx, currentIdx1, currentIdx2;
  352. /* Generated */ //ARRAY_ALLOC(tempBuffer1, 50);
  353. /* Generated */ //ARRAY_ALLOC(tempBuffer2, 50);
  354. /* Generated */ ARRAY_ALLOC(tempBuffer1, optInTimePeriod);
  355. /* Generated */ if (!tempBuffer1)
  356. /* Generated */ return ENUM_VALUE(RetCode, TA_ALLOC_ERR, AllocErr);
  357. /* Generated */ ARRAY_ALLOC(tempBuffer2, optInTimePeriod);
  358. /* Generated */ if (!tempBuffer2)
  359. /* Generated */ {
  360. /* Generated */ ARRAY_FREE(tempBuffer1);
  361. /* Generated */ return ENUM_VALUE(RetCode, TA_ALLOC_ERR, AllocErr);
  362. /* Generated */ }
  363. /* Generated */ retCode = FUNCTION_CALL(SMA)(startIdx, endIdx, inVolume,
  364. /* Generated */ optInTimePeriod, &outBegIdx1, outNBElement, tempBuffer1);
  365. /* Generated */ if ((retCode != ENUM_VALUE(RetCode, TA_SUCCESS, Success)) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0))
  366. /* Generated */ {
  367. /* Generated */ ARRAY_FREE(tempBuffer1);
  368. /* Generated */ ARRAY_FREE(tempBuffer2);
  369. /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  370. /* Generated */ return retCode;
  371. /* Generated */ }
  372. /* Generated */ retCode = FUNCTION_CALL(STDDEV)(startIdx, endIdx, inVolume,
  373. /* Generated */ optInTimePeriod, 1.0,
  374. /* Generated */ &outBegIdx2, outNBElement, tempBuffer2);
  375. /* Generated */ if ((retCode != ENUM_VALUE(RetCode, TA_SUCCESS, Success)) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0))
  376. /* Generated */ {
  377. /* Generated */ ARRAY_FREE(tempBuffer1);
  378. /* Generated */ ARRAY_FREE(tempBuffer2);
  379. /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  380. /* Generated */ return retCode;
  381. /* Generated */ }
  382. /* Generated */ // startIdx is a MAX(startIdx, outBegIdx1, outBegIdx2)
  383. /* Generated */ if (startIdx < outBegIdx1)
  384. /* Generated */ startIdx = outBegIdx1;
  385. /* Generated */ if (startIdx < outBegIdx2)
  386. /* Generated */ startIdx = outBegIdx2;
  387. /* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
  388. /* Generated */ if (startIdx > endIdx)
  389. /* Generated */ {
  390. /* Generated */ ARRAY_FREE(tempBuffer1);
  391. /* Generated */ ARRAY_FREE(tempBuffer2);
  392. /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
  393. /* Generated */ return retCode;
  394. /* Generated */ }
  395. /* Generated */ currentIdx = 0;
  396. /* Generated */ currentIdx1 = startIdx - outBegIdx1;
  397. /* Generated */ currentIdx2 = startIdx - outBegIdx2;
  398. /* Generated */ for (i = startIdx; i < endIdx; i++)
  399. /* Generated */ {
  400. /* Generated */ outReal[currentIdx++] = (inVolume[i] - tempBuffer1[currentIdx1++]) / tempBuffer2[currentIdx2++];
  401. /* Generated */ }
  402. /* Generated */ ARRAY_FREE(tempBuffer1);
  403. /* Generated */ ARRAY_FREE(tempBuffer2);
  404. /* Generated */ //(int)VALUE_HANDLE_DEREF(outNBElement) = currentIdx;
  405. /* Generated */ VALUE_HANDLE_DEREF(outNBElement) = currentIdx;
  406. /* Generated */ return ENUM_VALUE(RetCode, TA_SUCCESS, Success);
  407. /* Generated */ }
  408. /* Generated */
  409. /* Generated */ #if defined( _MANAGED )
  410. /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
  411. /* Generated */ #endif
  412. /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
  413.  
  414.  
Advertisement
Add Comment
Please, Sign In to add comment