WEB开发网
开发学院软件开发VC 用VC开发股票分析软件(一) 阅读

用VC开发股票分析软件(一)

 2008-09-25 19:27:11 来源:WEB开发网   
核心提示: 测试MACD//TestMACD.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#include"ta_libc.h"#include"iostre

测试MACD

//TestMACD.cpp:Definestheentrypointfortheconsoleapplication.
//
#include"stdafx.h"
#include"ta_libc.h"
#include"iostream.h"
TA_Real  closePrice[400];
TA_Real  out[400];
TA_IntegeroutBeg;
TA_IntegeroutNbElement;
/*...initializeyourclosingpricehere...*/
//TA_RetCoderetCode=TA_MA(0,399,&closePrice[0],30,TA_MAType_SMA,&outBeg,&outNbElement,&out[0]);
intmain(intargc,char*argv[])
{
  /*Theoutputisdisplayedhere*/
 for(intj=0;j<401;)
 {
   closePrice[j++]=1;
 }  
 TA_RetCoderetCode=TA_MA(0,399,&closePrice[0],30,TA_MAType_SMA,&outBeg,&outNbElement,&out[0]);
 for(inti=0;i<outNbElement;i++)
 printf("Day%d=%fn",outBeg+i,out[i]);
  printf("HelloWorld!n");
  return0;
}

这些分析函数都是公开源码的。国外有一家学院的研究机构发布了所有证券分析软件公式算法函数。

如果要用的话,要遵守GPL,采用的TA-LIB的名字,要署名。

地址:http://ta-lib.org/hdr_doc.htm。

个人非常羡慕这种研究文化....

/*Listofcontributors:
*
* Initial Name/description
* -------------------------------------------------------------------
* MF   MarioFortier
* JPP   JPPienaar(j.pienaar@mci.co.za)
*
*Changehistory:
*
* MMDDYYBY Description
* -------------------------------------------------------------------
* 112400MF Templatecreation.
* 052603MF Adaptcodetocompilewith.NETManagedC++
* 080403JPP Fix#767653forlogicwhenswappingperiods.
*
*/
/****STARTGENCODESECTION1-DONOTDELETETHISLINE****/
/*Allcodewithinthissectionisautomatically
*generatedbygen_code.Anymodificationwillbelost
*nexttimegen_codeisrun.
*/
/*Generated*/ 
/*Generated*/#ifdefined(_MANAGED)
/*Generated*/  #include"TA-Lib-Core.h"
/*Generated*/  #defineTA_INTERNAL_ERROR(Id)(RetCode::InternalError)
/*Generated*/  namespaceTicTacTec{namespaceTA{namespaceLibrary{
/*Generated*/#elifdefined(_JAVA)
/*Generated*/  #include"ta_defs.h"
/*Generated*/  #include"ta_java_defs.h"
/*Generated*/  #defineTA_INTERNAL_ERROR(Id)(RetCode.InternalError)
/*Generated*/#else
/*Generated*/  #include<string.h>
/*Generated*/  #include<math.h>
/*Generated*/  #include"ta_func.h"
/*Generated*/#endif
/*Generated*/ 
/*Generated*/#ifndefTA_UTILITY_H
/*Generated*/  #include"ta_utility.h"
/*Generated*/#endif
/*Generated*/ 
/*Generated*/#ifndefTA_MEMORY_H
/*Generated*/  #include"ta_memory.h"
/*Generated*/#endif
/*Generated*/ 
/*Generated*/#defineTA_PREFIX(x)TA_##x
/*Generated*/#defineINPUT_TYPE double
/*Generated*/ 
/*Generated*/#ifdefined(_MANAGED)
/*Generated*/intCore::MacdLookback(int     optInFastPeriod,/*From2to100000*/
/*Generated*/           int     optInSlowPeriod,/*From2to100000*/
/*Generated*/           int     optInSignalPeriod) /*From1to100000*/
/*Generated*/ 
/*Generated*/#elifdefined(_JAVA)
/*Generated*/publicintmacdLookback(int     optInFastPeriod,/*From2to100000*/
/*Generated*/            int     optInSlowPeriod,/*From2to100000*/
/*Generated*/            int     optInSignalPeriod) /*From1to100000*/
/*Generated*/ 
/*Generated*/#else
/*Generated*/intTA_MACD_Lookback(int     optInFastPeriod,/*From2to100000*/
/*Generated*/          int     optInSlowPeriod,/*From2to100000*/
/*Generated*/          int     optInSignalPeriod) /*From1to100000*/
/*Generated*/ 
/*Generated*/#endif
/****ENDGENCODESECTION1-DONOTDELETETHISLINE****/
{
 /*insertlocalvariablehere*/
 inttempInteger;
/****STARTGENCODESECTION2-DONOTDELETETHISLINE****/
/*Generated*/#ifndefTA_FUNC_NO_RANGE_CHECK
/*Generated*/  /*min/maxarecheckedforoptInFastPeriod.*/
/*Generated*/  if((int)optInFastPeriod==TA_INTEGER_DEFAULT)
/*Generated*/   optInFastPeriod=12;
/*Generated*/  elseif(((int)optInFastPeriod<2)||((int)optInFastPeriod>100000))
/*Generated*/   return-1;
/*Generated*/ 
/*Generated*/  /*min/maxarecheckedforoptInSlowPeriod.*/
/*Generated*/  if((int)optInSlowPeriod==TA_INTEGER_DEFAULT)
/*Generated*/   optInSlowPeriod=26;
/*Generated*/  elseif(((int)optInSlowPeriod<2)||((int)optInSlowPeriod>100000))
/*Generated*/   return-1;
/*Generated*/ 
/*Generated*/  /*min/maxarecheckedforoptInSignalPeriod.*/
/*Generated*/  if((int)optInSignalPeriod==TA_INTEGER_DEFAULT)
/*Generated*/   optInSignalPeriod=9;
/*Generated*/  elseif(((int)optInSignalPeriod<1)||((int)optInSignalPeriod>100000))
/*Generated*/   return-1;
/*Generated*/ 
/*Generated*/#endif/*TA_FUNC_NO_RANGE_CHECK*/
/****ENDGENCODESECTION2-DONOTDELETETHISLINE****/
 /*insertlookbackcodehere.*/
 /*Thelookbackisdrivenbythesignallineoutput.
  *
  *(mustalsoaccountfortheinitialdataconsume 
  * bytheslowperiod).
  */
 /*Makesureslowisreallyslowerthan
  *thefastperiod!ifnot,swap...
  */
 if(optInSlowPeriod<optInFastPeriod)
 {
   /*swap*/
   tempInteger   =optInSlowPeriod;
   optInSlowPeriod=optInFastPeriod;
   optInFastPeriod=tempInteger;
 }
 return LOOKBACK_CALL(EMA)(optInSlowPeriod )
     +LOOKBACK_CALL(EMA)(optInSignalPeriod);
}
/****STARTGENCODESECTION3-DONOTDELETETHISLINE****/
/*
*TA_MACD-MovingAverageConvergence/Divergence
* 
*Input =double
*Output=double,double,double
* 
*OptionalParameters
*-------------------
*optInFastPeriod:(From2to100000)
*  NumberofperiodforthefastMA
* 
*optInSlowPeriod:(From2to100000)
*  NumberofperiodfortheslowMA
* 
*optInSignalPeriod:(From1to100000)
*  Smoothingforthesignalline(nbofperiod)
* 
* 
*/
/*Generated*/ 
/*Generated*/#ifdefined(_MANAGED)&&defined(USE_SUBARRAY)
/*Generated*/enumclassCore::RetCodeCore::Macd(int  startIdx,
/*Generated*/                   int  endIdx,
/*Generated*/                   SubArray^  inReal,
/*Generated*/                   int     optInFastPeriod,/*From2to100000*/
/*Generated*/                   int     optInSlowPeriod,/*From2to100000*/
/*Generated*/                   int     optInSignalPeriod,/*From1to100000*/
/*Generated*/                   [Out]int%  outBegIdx,
/*Generated*/                   [Out]int%  outNBElement,
/*Generated*/                   cli::array<double>^ outMACD,
/*Generated*/                   cli::array<double>^ outMACDSignal,
/*Generated*/                   cli::array<double>^ outMACDHist)
/*Generated*/#elifdefined(_MANAGED)
/*Generated*/enumclassCore::RetCodeCore::Macd(int  startIdx,
/*Generated*/                   int  endIdx,
/*Generated*/                   cli::array<double>^inReal,
/*Generated*/                   int     optInFastPeriod,/*From2to100000*/
/*Generated*/                   int     optInSlowPeriod,/*From2to100000*/
/*Generated*/                   int     optInSignalPeriod,/*From1to100000*/
/*Generated*/                   [Out]int%  outBegIdx,
/*Generated*/                   [Out]int%  outNBElement,
/*Generated*/                   cli::array<double>^ outMACD,
/*Generated*/                   cli::array<double>^ outMACDSignal,
/*Generated*/                   cli::array<double>^ outMACDHist)
/*Generated*/#elifdefined(_JAVA)
/*Generated*/publicRetCodemacd(int  startIdx,
/*Generated*/           int  endIdx,
/*Generated*/           double   inReal[],
/*Generated*/           int     optInFastPeriod,/*From2to100000*/
/*Generated*/           int     optInSlowPeriod,/*From2to100000*/
/*Generated*/           int     optInSignalPeriod,/*From1to100000*/
/*Generated*/           MInteger  outBegIdx,
/*Generated*/           MInteger  outNBElement,
/*Generated*/           double    outMACD[],
/*Generated*/           double    outMACDSignal[],
/*Generated*/           double    outMACDHist[])
/*Generated*/#else
/*Generated*/TA_RetCodeTA_MACD(int  startIdx,
/*Generated*/          int  endIdx,
/*Generated*/          constdoubleinReal[],
/*Generated*/          int     optInFastPeriod,/*From2to100000*/
/*Generated*/          int     optInSlowPeriod,/*From2to100000*/
/*Generated*/          int     optInSignalPeriod,/*From1to100000*/
/*Generated*/          int     *outBegIdx,
/*Generated*/          int     *outNBElement,
/*Generated*/          double    outMACD[],
/*Generated*/          double    outMACDSignal[],
/*Generated*/          double    outMACDHist[])
/*Generated*/#endif
/****ENDGENCODESECTION3-DONOTDELETETHISLINE****/
{
 /*Insertlocalvariableshere.*/
/****STARTGENCODESECTION4-DONOTDELETETHISLINE****/
/*Generated*/ 
/*Generated*/#ifndefTA_FUNC_NO_RANGE_CHECK
/*Generated*/ 
/*Generated*/  /*Validatetherequestedoutputrange.*/
/*Generated*/  if(startIdx<0)
/*Generated*/   returnENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
/*Generated*/  if((endIdx<0)||(endIdx<startIdx))
/*Generated*/   returnENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
/*Generated*/ 
/*Generated*/  #if!defined(_JAVA)
/*Generated*/  if(!inReal)returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/  #endif/*!defined(_JAVA)*/
/*Generated*/  /*min/maxarecheckedforoptInFastPeriod.*/
/*Generated*/  if((int)optInFastPeriod==TA_INTEGER_DEFAULT)
/*Generated*/   optInFastPeriod=12;
/*Generated*/  elseif(((int)optInFastPeriod<2)||((int)optInFastPeriod>100000))
/*Generated*/   returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/ 
/*Generated*/  /*min/maxarecheckedforoptInSlowPeriod.*/
/*Generated*/  if((int)optInSlowPeriod==TA_INTEGER_DEFAULT)
/*Generated*/   optInSlowPeriod=26;
/*Generated*/  elseif(((int)optInSlowPeriod<2)||((int)optInSlowPeriod>100000))
/*Generated*/   returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/ 
/*Generated*/  /*min/maxarecheckedforoptInSignalPeriod.*/
/*Generated*/  if((int)optInSignalPeriod==TA_INTEGER_DEFAULT)
/*Generated*/   optInSignalPeriod=9;
/*Generated*/  elseif(((int)optInSignalPeriod<1)||((int)optInSignalPeriod>100000))
/*Generated*/   returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/ 
/*Generated*/  #if!defined(_JAVA)
/*Generated*/  if(!outMACD)
/*Generated*/   returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/ 
/*Generated*/  if(!outMACDSignal)
/*Generated*/   returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/ 
/*Generated*/  if(!outMACDHist)
/*Generated*/   returnENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
/*Generated*/ 
/*Generated*/  #endif/*!defined(_JAVA)*/
/*Generated*/#endif/*TA_FUNC_NO_RANGE_CHECK*/
/*Generated*/ 
/****ENDGENCODESECTION4-DONOTDELETETHISLINE****/
 /*InsertTAfunctioncodehere.*/ 
 returnFUNCTION_CALL(INT_MACD)(startIdx,endIdx,inReal,
                 optInFastPeriod,
                 optInSlowPeriod,
                 optInSignalPeriod,
                 outBegIdx,
                 outNBElement,
                 outMACD,
                 outMACDSignal,
                 outMACDHist);
}
#ifdefined(_MANAGED)&&defined(USE_SUBARRAY)&&!defined(USE_SINGLE_PRECISION_INPUT)
enumclassCore::RetCodeCore::TA_INT_MACD(int  startIdx,
                      int  endIdx,
                      SubArray^inReal,
                      int  optInFastPeriod,/*0isfix12*/
                      int  optInSlowPeriod,/*0isfix26*/
                      int  optInSignalPeriod_2,
                      [Out]int%outBegIdx,
                      [Out]int%outNBElement,
                      cli::array<double>^outMACD,
                      cli::array<double>^outMACDSignal,
                      cli::array<double>^outMACDHist)
#elifdefined(_MANAGED)
enumclassCore::RetCodeCore::TA_INT_MACD(int  startIdx,
                      int  endIdx,
                      cli::array<INPUT_TYPE>^inReal,
                      int  optInFastPeriod,/*0isfix12*/
                      int  optInSlowPeriod,/*0isfix26*/
                      int  optInSignalPeriod_2,
                      [Out]int%outBegIdx,
                      [Out]int%outNBElement,
                      cli::array<double>^outMACD,
                      cli::array<double>^outMACDSignal,
                      cli::array<double>^outMACDHist)
#elifdefined(_JAVA)
RetCodeTA_INT_MACD(int    startIdx,
          int    endIdx,
          INPUT_TYPEinReal[],
          int    optInFastPeriod,/*0isfix12*/
          int    optInSlowPeriod,/*0isfix26*/
          int    optInSignalPeriod_2,
          MInteger outBegIdx,
          MInteger outNBElement,
          double  outMACD[],
          double  outMACDSignal[],
          double  outMACDHist[])
#else
TA_RetCodeTA_PREFIX(INT_MACD)(int  startIdx,
                int  endIdx,
                constINPUT_TYPEinReal[],
                int  optInFastPeriod,/*0isfix12*/
                int  optInSlowPeriod,/*0isfix26*/
                int  optInSignalPeriod_2,
                int *outBegIdx,
                int *outNBElement,
                double   outMACD[],
                double   outMACDSignal[],
                double   outMACDHist[])
#endif
{
 ARRAY_REF(slowEMABuffer);
 ARRAY_REF(fastEMABuffer);
 doublek1,k2;
 ENUM_DECLARATION(RetCode)retCode;
 inttempInteger;
 VALUE_HANDLE_INT(outBegIdx1);
 VALUE_HANDLE_INT(outNbElement1);
 VALUE_HANDLE_INT(outBegIdx2);
 VALUE_HANDLE_INT(outNbElement2);
 intlookbackTotal,lookbackSignal;
 inti;
 /*!!!Alotofspeedoptimizationcouldbedone
  *!!!withthisfunction. 
  *!!!
  *!!!AbetterapproachwouldbetouseTA_INT_EMA
  *!!!justtogettheseedingvaluesforthe
  *!!!fastandslowEMA.Thenprocessthedifference
  *!!!inanallocatedbufferuntilenoughdatais
  *!!!availableforthefirstsignalvalue.
  *!!!Fromthatpointalltheprocessingcan
  *!!!bedoneinatightloop.
  *!!!
  *!!!Thatapproachwillhavethefollowing
  *!!!advantage:
  *!!! 1)Onememallocationneededinsteadoftwo.
  *!!! 2)Thememallocationsizewillbeonlythe
  *!!!   signallookbackperiodinsteadofthe 
  *!!!   wholerangeofdata.
  *!!! 3)Processingwillbedoneinatightloop.
  *!!!   allowingtoavoidalotofmemorystore-load
  *!!!   operation.
  *!!! 4)Thememcpyattheendwillbeeliminated!
  *!!!
  *!!!IfonlyIhadtime....
  */

上一页  1 2 

Tags:VC 开发 股票

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接