1 | /* |
2 | * Legal Notice |
3 | * |
4 | * This document and associated source code (the "Work") is a part of a |
5 | * benchmark specification maintained by the TPC. |
6 | * |
7 | * The TPC reserves all right, title, and interest to the Work as provided |
8 | * under U.S. and international laws, including without limitation all patent |
9 | * and trademark rights therein. |
10 | * |
11 | * No Warranty |
12 | * |
13 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
14 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
15 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
16 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
17 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
18 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
19 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
20 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
21 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
22 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
23 | * WITH REGARD TO THE WORK. |
24 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
25 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
26 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
27 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
28 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
29 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
30 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
31 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
32 | * |
33 | * Contributors |
34 | * - Sergey Vasilevskiy, Doug Johnson |
35 | */ |
36 | |
37 | /****************************************************************************** |
38 | * Description: This class represents an extension of the |
39 | * MEEApproximation class orginally written by Sergey for |
40 | * EGenLoader. |
41 | * This new class now provides additional functionality |
42 | * for use at runtime by the MEE as well. All of the |
43 | * price/time functionality needed to emulate a securities |
44 | * behavior in the market is captured here. |
45 | * |
46 | ******************************************************************************/ |
47 | |
48 | #ifndef MEE_SECURITY_H |
49 | #define MEE_SECURITY_H |
50 | |
51 | #include "utilities/EGenUtilities_stdafx.h" |
52 | #include "TradeTypeIDs.h" |
53 | #include "SecurityPriceRange.h" |
54 | |
55 | namespace TPCE { |
56 | |
57 | class CMEESecurity { |
58 | private: |
59 | CRandom m_rnd; |
60 | CMoney m_fRangeLow; // price range start |
61 | CMoney m_fRangeHigh; // price range end |
62 | CMoney m_fRange; // price range length (high - low) |
63 | int m_iPeriod; // time to get to the same price (in seconds) |
64 | INT32 m_TradingTimeSoFar; // for picking up where we last left off on the |
65 | // price curve |
66 | |
67 | CDateTime *m_pBaseTime; // Wall clock time corresponding to m_fInitialTime |
68 | CDateTime *m_pCurrentTime; |
69 | |
70 | // Mean delay between Pending and Submission times |
71 | // for an immediatelly triggered (in-the-money) limit |
72 | // order. Calculated outside based on scale factor |
73 | // and the number of customers (e.g. MF rate). |
74 | // |
75 | // The actual delay is randomly calculated in the range |
76 | // [0.5 * Mean .. 1.5 * Mean] |
77 | // |
78 | double m_fMeanInTheMoneySubmissionDelay; |
79 | |
80 | /* |
81 | * Calculate the "unique" starting offset |
82 | * in the price curve based on the security ID (0-based) |
83 | * 0 corresponds to m_fRangeLow price, |
84 | * m_fPeriod/2 corresponds to m_fRangeHigh price, |
85 | * m_fPeriod corresponds again to m_fRangeLow price |
86 | * |
87 | * PARAMETERS: |
88 | * IN SecurityIndex - unique security index to generate a unique |
89 | * starting price |
90 | * |
91 | * RETURNS: |
92 | * time from which to calculate initial price |
93 | */ |
94 | inline double InitialTime(TIdent SecurityIndex); |
95 | |
96 | /* |
97 | * Negative exponential distribution. |
98 | * |
99 | * PARAMETERS: |
100 | * IN fMean - mean value of the distribution |
101 | * |
102 | * RETURNS: |
103 | * random value according to the negative |
104 | * exponential distribution with the given mean. |
105 | */ |
106 | inline double NegExp(double fMean); |
107 | |
108 | /* |
109 | * Calculate time required to move between certain prices |
110 | * with certain initial direction of price change. |
111 | * |
112 | * PARAMETERS: |
113 | * IN fStartPrice - price at the start of the time interval |
114 | * IN fEndPrice - price at the end of the time interval |
115 | * IN iStartDirection - direction (up or down) on the price curve |
116 | * at the start of the time interval |
117 | * |
118 | * RETURNS: |
119 | * seconds required to move from the start price to the end price |
120 | */ |
121 | double CalculateTime(CMoney fStartPrice, CMoney fEndPrice, int iStartDirection); |
122 | |
123 | public: |
124 | /* |
125 | * Default constructor (no parameters) to be able |
126 | * to allocate an array of security objects. |
127 | * |
128 | * PARAMETERS: |
129 | * none. |
130 | * |
131 | * RETURNS: |
132 | * not applicable. |
133 | */ |
134 | CMEESecurity(); |
135 | |
136 | /* |
137 | * Initialize before the first use. |
138 | * Separated from constructor in order to have default (no-parameters) |
139 | * constructor. |
140 | * |
141 | * PARAMETERS: |
142 | * IN TradeTimeSoFar - point where we last left |
143 | * off on the price curve IN pBaseTime - wall clock |
144 | * time corresponding to the initial time for all securities IN pCurrentTime |
145 | * - current time for the security (determines current price) IN |
146 | * fMeanInTheMoneySubmissionDelay - Mean delay between Pending and |
147 | * Submission times for an immediatelly triggered (in-the-money) limit |
148 | * order. |
149 | * |
150 | * RETURNS: |
151 | * none |
152 | */ |
153 | void Init(INT32 TradingTimeSoFar, CDateTime *pBaseTime, CDateTime *pCurrentTime, |
154 | double fMeanInTheMoneySubmissionDelay); |
155 | |
156 | /* |
157 | * Calculate price at a certain point in time. |
158 | * |
159 | * PARAMETERS: |
160 | * IN SecurityIndex - unique security index to generate a |
161 | * unique starting price IN fTime - seconds from initial time |
162 | * |
163 | * RETURNS: |
164 | * price according to the triangular function |
165 | * that will be achived at the given time |
166 | */ |
167 | CMoney CalculatePrice(TIdent SecurityIndex, double fTime); |
168 | |
169 | /* |
170 | * Calculate current price for the security identified by its index |
171 | * (0-based). |
172 | * |
173 | * PARAMETERS: |
174 | * IN SecurityIndex - unique identifier for the security. |
175 | * |
176 | * RETURNS: |
177 | * price at this point in time given with integer number of cents. |
178 | */ |
179 | CMoney GetCurrentPrice(TIdent SecurityIndex); |
180 | |
181 | /* |
182 | * Return minimum price on the price curve for any security. |
183 | * |
184 | * PARAMETERS: |
185 | * none. |
186 | * |
187 | * RETURNS: |
188 | * minimum price given with integer number of cents. |
189 | */ |
190 | CMoney GetMinPrice(void); |
191 | |
192 | /* |
193 | * Return maximum price on the price curve for any security. |
194 | * |
195 | * PARAMETERS: |
196 | * none. |
197 | * |
198 | * RETURNS: |
199 | * maximum price given with integer number of cents. |
200 | */ |
201 | CMoney GetMaxPrice(void); |
202 | |
203 | /* |
204 | * Calculate triggering time for limit orders. |
205 | * |
206 | * PARAMETERS: |
207 | * IN SecurityIndex - unique security index to generate a |
208 | * unique starting price IN fPendingTime - pending time of the order, in |
209 | * seconds from time 0 IN fLimitPrice - limit price of the order IN |
210 | * TradeType - order trade type |
211 | * |
212 | * RETURNS: |
213 | * the expected submission time |
214 | */ |
215 | double GetSubmissionTime(TIdent SecurityIndex, double fPendingTime, CMoney fLimitPrice, eTradeTypeID TradeType); |
216 | |
217 | /* |
218 | * Return the expected completion time and the completion price. |
219 | * Completion time is between 0 and 5 seconds |
220 | * with 1 sec mean. |
221 | * |
222 | * Used to calculate completion time for |
223 | * both limit (first must get submission time) |
224 | * and market orders. |
225 | * |
226 | * Equivalent of MEE function sequence |
227 | * 'receive trade' then 'complete the trade request'. |
228 | * |
229 | * PARAMETERS: |
230 | * IN SecurityIndex - unique security index to generate a |
231 | * unique starting price IN fSubmissionTime - time when the order was |
232 | * submitted, in seconds from time 0 OUT pCompletionPrice - completion |
233 | * price of the order |
234 | * |
235 | * RETURNS: |
236 | * the approximated completion time for the trade |
237 | * |
238 | */ |
239 | double GetCompletionTime(TIdent SecurityIndex, double fSubmissionTime, |
240 | CMoney *pCompletionPrice // output parameter |
241 | ); |
242 | }; |
243 | |
244 | } // namespace TPCE |
245 | |
246 | #endif // MEE_SECURITY_H |
247 | |