Trading System API  3.0
Library for Simulating and Deploying Trading and Investment Strategies
TSACompInput.h
1 
2 /* ===================================================================
3 *
4 * T R A D I N G S Y S T E M A P I ™
5 * Copyright © 1999 - 2014 by Peter Ritter ( TradingSystemAPI.com )
6 * A L L R I G H T S R E S E R V E D
7 *
8 * Consult your license regarding permissions and restrictions.
9 * You may obtain a copy of the License at:
10 * http://www.TradingSystemAPI.com/licenses/LICENSE-TSAPI-3.0.html
11 *
12 * ====================================================================
13 */
14 
15 #ifndef TSA_COMP_INPUT__INCLUDED
16 #define TSA_COMP_INPUT__INCLUDED
17 
18 #include "TSARandGen.h"
19 #include "TSADatabase.h"
20 #include "TSAComponent.h"
21 #include "TSADatabaseReader.h"
22 
23 namespace tsa {
24 
25  class date_time;
26 
27  /*
28  ** ====================================================
29  ** > > > class table_reader_stream_adaptor < < <
30  ** ====================================================
31  */
32  class dll_export table_reader_stream_adaptor
33  : public in_stream_adaptor,
34  public fast::table_reader {
35  size_t m_nForwardShift;
36  public:
37  table_reader_stream_adaptor(void);
38  void Connect(fast::database& series_base, const std::string& tableName);
39  virtual ~table_reader_stream_adaptor(void);
40  public:
41  virtual void cmp__evaluate_bar(const date_time&) override;
42  public:
43  virtual void isa__set_forward_shift(size_t) override;
44  virtual void isa__set_position(const date_time&) override;
45  virtual bool isa__field_exists(const std::string&) override;
46  virtual size_t isa__field_index(const std::string&) override;
47  virtual size_t isa__field_count(void) override;
48  virtual const std::string& isa__field_name(size_t) override;
49  virtual type_t isa__field_type(size_t) override;
50  virtual variant isa__get_variant(size_t idx) override;
51  virtual double isa__get_double(size_t idx) override;
52  virtual void isa__update_value_at_position(size_t _idx) override;
53  virtual date_time isa__get_record_timestamp(void) override;
54  virtual date_time isa__begin(void) override;
55  virtual date_time isa__end(void) override;
56  virtual size_t isa__size(void) override;
57  virtual void isa__on_open(void) override {};
58  virtual std::string isa__stream_name(void) const override;
59  virtual void isa__get_price_bar(const date_time&, instrument_price_bar&) override;
60  virtual bool isa__get_time_of_next_bar(date_time& nextDateTime,
61  const date_time& currentDateTime) override;
62  virtual bool isa__implements_scheduling(void) const override {
63  return true;
64  }
65  };
66 
71  /*
72  ** ====================================================
73  ** > > > class random_walk_stream < < <
74  ** ====================================================
75  */
76 
78  class dll_export random_walk_stream :
79  public in_stream_adaptor, public tsa::object {
80  protected:
81  std::string m_stream_name;
82  double m_open, m_high, m_low, m_close, m_volume;
83  double m_bidsize, m_bid, m_ask, m_asksize;
84  std::string m_fields[10];
85  double m_prices[10];
86  bool m_self_scheduled;
87  rand_gen m_rng, m_rng_CC, m_rng_CO;
88  public:
89  double m_CO_muliplier = 0.4;
90  double m_CC_muliplier = 0.8;
91  double m_MH_muliplier = 1.0;
92  double m_LM_muliplier = 1.0;
93  double m_trend_factor = 0.15;
94  bool m_prev_CC_move_was_up;
95  bool m_prev_move_was_up = false;
96  double m_inflation_factor = 0.0;
97  date_time m_timestamp;
98  duration m_interval_duration;
99  double m_min_tick = 0.01;
100  public:
104  virtual ~random_walk_stream(void);
105  public:
107  void tick(double d) { m_min_tick = d; }
108 
110  void start_price(double d) { m_open = m_high = m_low = m_close = d; }
111 
113  void trend_factor(double d) { m_trend_factor = d; }
114 
116  void close_close_mult(double d) { m_CC_muliplier = d; }
117 
119  void close_open_mult(double d) { m_CO_muliplier = d; }
120 
122  void mean_high_mult(double d) { m_MH_muliplier = d; }
123 
125  void low_mean_mult(double d) { m_LM_muliplier = d; }
126 
130  void inflation_mult(double d) { m_inflation_factor = d; }
131 
132  public:
133  virtual void cmp__evaluate_bar(const date_time&) override;
134  virtual void next_bar(void);
135  public:
136  virtual void isa__get_price_bar(const date_time& date_time,
137  instrument_price_bar& priceBar) override;
138  virtual bool isa__get_time_of_next_bar(date_time& nextDateTime,
139  const date_time& currentDateTime) override;
140  virtual std::string isa__stream_name(void) const override;
141  virtual bool isa__implements_scheduling(void) const override;
142  public:
143  virtual void isa__set_position(const date_time&) override;
144  virtual bool isa__field_exists(const std::string&) override;
145  virtual size_t isa__field_index(const std::string&) override;
146  virtual type_t isa__field_type(size_t) override;
147  virtual size_t isa__field_count(void) override;
148  virtual const std::string& isa__field_name(size_t) override;
149  virtual date_time isa__get_record_timestamp(void) override;
150  virtual date_time isa__begin(void) override;
151  virtual date_time isa__end(void) override;
152  virtual size_t isa__size(void) override;
153  virtual void isa__on_open(void) override { ; }
154  public:
155  virtual variant isa__get_variant(size_t idx) override;
156  virtual double isa__get_double(size_t idx) override;
157  virtual void isa__update_value_at_position(size_t idx) override;
158  };
159 
161 
162  /*
163  ** ====================================================
164  ** >>> class manual_ohlcv <<<
165  ** ====================================================
166  */
167 
170  class dll_export manual_ohlcv
171  : public in_stream_adaptor, public tsa::object {
172  double prices[5];
173  std::string names[5];
174  bool m_bManualData;
175  public:
176  date_time m_ManualTimestamp;
177  //date_time m_CurrentTimestamp;
178  public:
180  manual_ohlcv(void);
181 
183  virtual ~manual_ohlcv(void);
184 
187  void set_next_bar(
188  const date_time& ts,
189  double o,
190  double h,
191  double l,
192  double c,
193  double v
194  );
195  public:
196  virtual void isa__get_price_bar(const date_time& date_time,
197  instrument_price_bar& priceBar) override;
198  virtual bool isa__get_time_of_next_bar(date_time& nextDateTime,
199  const date_time& currentDateTime) override;
200  virtual std::string isa__stream_name(void) const override;
201  virtual bool isa__implements_scheduling(void) const override;
202  public:
203  virtual void isa__set_position(const date_time&) override;
204  virtual bool isa__field_exists(const std::string&) override;
205  virtual size_t isa__field_index(const std::string&) override;
206  virtual type_t isa__field_type(size_t) override;
207  virtual size_t isa__field_count(void) override;
208  virtual const std::string& isa__field_name(size_t) override;
209  virtual date_time isa__get_record_timestamp(void) override;
210 
211  virtual date_time isa__begin(void) override;
212  virtual date_time isa__end(void) override;
213  virtual size_t isa__size(void) override;
214  virtual void isa__on_open(void) override { ; }
215  public:
216  virtual variant isa__get_variant(size_t idx) override;
217  virtual double isa__get_double(size_t idx) override;
218  virtual void isa__update_value_at_position(size_t idx) override;
219  };
220 
222 }//tsa
223 
224 #endif
Namespace for the &#39;Trading System API&#39; library.
Definition: original1.TSA3Core.cpp:20
void mean_high_mult(double d)
Standard deviation of (high-low)/2 to high price. Default is 1.0 percent.
Definition: TSACompInput.h:122
Definition: TSACompInput.h:78
Parent class for &#39;in-stream adaptors&#39;. in_stream object rely on adaptors for access to underlying dat...
Definition: TSAStreams.h:52
_value_types_type type_t
Defines type_t as an alias of enum _value_types_type.
Definition: TSATypeDef.h:189
variant objects can represent values of different types.
Definition: TSAVariant.h:140
Represents a duration - the difference between two date_time values.
Definition: TSATime.h:945
_value_types_type
Data type enumeration used throughout the library. Intended to be used via type_t.
Definition: TSATypeDef.h:166
Allows users to manually submit record data for the next bar. This is useful for testing new function...
Definition: TSACompInput.h:170
void close_close_mult(double d)
Standard deviation of close-close price changes. Default is 0.8 percent.
Definition: TSACompInput.h:116
void low_mean_mult(double d)
Standard deviation of low price to (high-low)/2. Default is 1.0 percent.
Definition: TSACompInput.h:125
Parent class for many library classes.
Definition: TSATypeDef.h:462
void start_price(double d)
Series start price.
Definition: TSACompInput.h:110
void close_open_mult(double d)
Standard deviation of close-open price changes. Default is 0.4 percent.
Definition: TSACompInput.h:119
static duration days(uint64_t)
Returns a duration equivalent to a given number of days.
Definition: TSATime.cpp:1402
Class representing a gregorian-date and time-of-day combination. The time component has microsecond r...
Definition: TSATime.h:428
void trend_factor(double d)
Probability of forcing price change in same direction as previous price change (trendiness).
Definition: TSACompInput.h:113
void inflation_mult(double d)
Sets inflation factor to inflate prices over time. 0.0 by default. This percentage is added to every ...
Definition: TSACompInput.h:130