ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TAlibAPI.h
Go to the documentation of this file.
1 
8 //
9 // to see, namespace, better, maybe for Indicator also ? but cannot create object. Indicator is an object
10 // http://stackoverflow.com/questions/9321/how-do-you-create-a-static-class-in-c
11 // avoid
12 // TAlibAPI::status=false
13 // Warning: Automatic variable TAlibAPI::status is allocated (tmpfile):1
14 // replaced by lazy initialization
15 //
16 // Idea from book, register function with a pointer to function, to the correct indicator
17 // To check, use of Mechanism in TA_Lib to get all functions
18 // First approach, define some function
19 // Maybe after, use abstract class, but more complex, need more tests
20 
21 
22 //
23 // Make computation
24 // Divided in group in TA_lib, for instance:
25 // TA_(S_)_MA use TA_MAType as option, there exists an enum for choosing sma,ema...
26 //
27 // First approach, define some function
28 // Maybe after, use abstract class, but more complex
29 //
30 // Idea one class TaLibAPI, singleton creates only one for init TaLib
31 // TaLib.Init(), with flag
32 // Replaced by lazy initialization
33 //
34 // One class computeTA:
35 //
36 // Maybe derive class for effective calculation: No sure makes sense
37 // Specific for MA (SMA,EMA,...) use maximum of TAlib types and enum
38 // Specific for Momentum, Oscillator see differences
39 // Specific for Candle figures: gap, harami,
40 //
41 // Can imagine computeOther: correlation (2 stocks), Stock Return
42 //
43 // Should be called by who ?
44 // Called by class Stock, by LoadListDataStock for TA
45 // Could be a simple namespace ? Correlation 2 Stocks, Others
46 
47 #ifndef TALIBAPI_H_
48 #define TALIBAPI_H_
49 
50 #include <map>
51 #include <vector>
52 #include <memory>
53 
54 #include "TALibException.h"
55 #include "ta_libc.h"
56 // Manage to avoid before, only because of GetCArray2 and overload float/double
57 #include "../utils/TimeScale.h"
58 
59 // forward declaration
60 class Indicator;
61 class ListDataStockBase;
62 class TAlibAPI;
63 class TAResource;
64 
74 class TAlibAPI
75 {
76 
77  protected :
78 
91  int ComputeMA(float **arraydata_c_in, unsigned int size_input, std::string str_label,
92  int param, double ** arraydata_c_out,int & offset_begin,int & out_nb_data) const;
93 
106  int ComputeMACD(float **arraydata_c_in, unsigned int size_input, std::string str_label,
107  std::vector<int> params, double **arraydata_c_out, unsigned int nb_array_out,
108  int & offset_begin, int & out_nb_data) const;
109  public :
110  // TAResource public for small unit-tests, can make protected after
119  {
120  private :
123  static bool Init();
124  static bool Shutdown();
126 
128  TAResource();
129 
130  public :
134  static std::shared_ptr<TAResource> CreateResource();
136  virtual ~TAResource();
137  }; // end class TAResource
138 
142  TAlibAPI();
144  virtual ~TAlibAPI();
146 
152  long UseCount() {return res_ptr.use_count();}
156  TAResource* ShrpGet() {return res_ptr.get();}
158 
169  bool Compute( const ETime tmscl, const Indicator new_indic, const std::vector<int>& vec_param,
170  const std::vector< ListDataStockBase *>& vec_ldata_in, ListDataStockBase *ldata_out) const
171  throw (TALibException);
173 
174  // Add test for interaction with talib_abstract
175  // can get lots of info about the indicator
176  // focus first on CandleStick CDL*
177  static void GetListFunctions();
178 
179  private :
181  std::shared_ptr<TAResource> res_ptr;
182 };
183 
184 #endif /* TALIBAPI_H_ */
long UseCount()
Wrapper to shared_ptr::use_count() return number of shared_ptr associated to private data member res_...
Definition: TAlibAPI.h:152
TAlibAPI()
Default constructor.
Definition: TAlibAPI.cpp:18
"Clever" enumeration of the ListDataStock type : StockCSV, Volume, EMA, BOLL,...
Definition: Indicator.h:29
virtual ~TAlibAPI()
Destructor.
Definition: TAlibAPI.cpp:31
int ComputeMA(float **arraydata_c_in, unsigned int size_input, std::string str_label, int param, double **arraydata_c_out, int &offset_begin, int &out_nb_data) const
Compute Moving Averges : SMA, EMA, WMA.
Definition: TAlibAPI.cpp:373
static void GetListFunctions()
Definition: TAlibAPI.cpp:521
bool Compute(const ETime tmscl, const Indicator new_indic, const std::vector< int > &vec_param, const std::vector< ListDataStockBase * > &vec_ldata_in, ListDataStockBase *ldata_out) const
Compute an indicator.
Definition: TAlibAPI.cpp:138
static std::shared_ptr< TAResource > CreateResource()
Return a shared pointer on the current resource.
Definition: TAlibAPI.cpp:96
TAResource * ShrpGet()
return the pointer to TAResource.
Definition: TAlibAPI.h:156
std::shared_ptr< TAResource > res_ptr
Shared pointer to the unique TAResource.
Definition: TAlibAPI.h:181
Wrapper/Adapter to the library ta-lib.
Definition: TAlibAPI.h:74
int ComputeMACD(float **arraydata_c_in, unsigned int size_input, std::string str_label, std::vector< int > params, double **arraydata_c_out, unsigned int nb_array_out, int &offset_begin, int &out_nb_data) const
Compute others indicators : MACD, AD, RSI, STOCHF.
Definition: TAlibAPI.cpp:426
ETime
Enumeration for the different time representation, from instantaneous (INST) to year(YEAR) ...
Definition: TimeScale.h:48
static bool Init()
Definition: TAlibAPI.cpp:41
TAResource()
Constructor made private, to force use of CreateResource()
Definition: TAlibAPI.cpp:79
Centralize all exception coming form the TALib library interface.
Abstract base class for the ListDataStock, for storing base pointers in vectors.
Definition: ListDataStock.h:50
Base class for exception coming from talibapi interface.
static bool Shutdown()
Definition: TAlibAPI.cpp:60
virtual ~TAResource()
Destructor.
Definition: TAlibAPI.cpp:87