| 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 |
| 35 | * - Doug Johnson |
| 36 | */ |
| 37 | |
| 38 | /* |
| 39 | * Class representing the LAST_TRADE table. |
| 40 | */ |
| 41 | #ifndef LAST_TRADE_TABLE_H |
| 42 | #define LAST_TRADE_TABLE_H |
| 43 | |
| 44 | #include "EGenTables_common.h" |
| 45 | #include "MEESecurity.h" |
| 46 | |
| 47 | #include "input/DataFileManager.h" |
| 48 | |
| 49 | namespace TPCE { |
| 50 | |
| 51 | class CLastTradeTable : public TableTemplate<LAST_TRADE_ROW> { |
| 52 | TIdent m_iSecurityCount; |
| 53 | TIdent m_iStartFromSecurity; |
| 54 | const CSecurityFile &m_SecurityFile; |
| 55 | CDateTime m_date; |
| 56 | CMEESecurity m_MEESecurity; |
| 57 | int m_iHoursOfInitialTrades; |
| 58 | TIdent m_iSecurityCountForOneLoadUnit; |
| 59 | |
| 60 | /* |
| 61 | * LAST_TRADE table row generation |
| 62 | */ |
| 63 | void GenerateLastTradeRow() { |
| 64 | m_SecurityFile.CreateSymbol(m_iLastRowNumber, m_row.LT_S_SYMB, static_cast<int>(sizeof(m_row.LT_S_SYMB))); |
| 65 | |
| 66 | m_row.LT_DTS = m_date; |
| 67 | |
| 68 | m_MEESecurity.Init(m_iHoursOfInitialTrades * SecondsPerHour, NULL, NULL, 0); |
| 69 | |
| 70 | m_row.LT_PRICE = m_MEESecurity.CalculatePrice(m_iLastRowNumber, 0).DollarAmount(); |
| 71 | |
| 72 | m_row.LT_OPEN_PRICE = m_MEESecurity.CalculatePrice(m_iLastRowNumber, 0).DollarAmount(); |
| 73 | |
| 74 | // LT_VOL tracks the trading volume for the current day. Initial |
| 75 | // population ends on a day boundary, so set LT_VOL to 0 for the start |
| 76 | // of the next day. |
| 77 | m_row.LT_VOL = 0; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * Reset the state for the next load unit. |
| 82 | * |
| 83 | * PARAMETERS: |
| 84 | * none. |
| 85 | * |
| 86 | * RETURNS: |
| 87 | * none. |
| 88 | */ |
| 89 | void InitNextLoadUnit() { |
| 90 | // No RNG calls in this class, so don't need to reset the RNG. |
| 91 | |
| 92 | ClearRecord(); // this is needed for EGenTest to work |
| 93 | } |
| 94 | |
| 95 | public: |
| 96 | /* |
| 97 | * Constructor. |
| 98 | */ |
| 99 | CLastTradeTable(const DataFileManager &dfm, TIdent iCustomerCount, TIdent iStartFromCustomer, |
| 100 | INT32 iHoursOfInitialTrades) |
| 101 | : TableTemplate<LAST_TRADE_ROW>(), m_SecurityFile(dfm.SecurityFile()), |
| 102 | m_iHoursOfInitialTrades(iHoursOfInitialTrades) { |
| 103 | m_iSecurityCount = m_SecurityFile.CalculateSecurityCount(iCustomerCount); |
| 104 | m_iStartFromSecurity = m_SecurityFile.CalculateStartFromSecurity(iStartFromCustomer); |
| 105 | |
| 106 | m_iLastRowNumber = m_iStartFromSecurity; |
| 107 | |
| 108 | // Go to the last day of initial trades. |
| 109 | // |
| 110 | m_date.Set(InitialTradePopulationBaseYear, InitialTradePopulationBaseMonth, InitialTradePopulationBaseDay, |
| 111 | InitialTradePopulationBaseHour, InitialTradePopulationBaseMinute, InitialTradePopulationBaseSecond, |
| 112 | InitialTradePopulationBaseFraction); |
| 113 | m_date.Add(m_iHoursOfInitialTrades / HoursPerWorkDay, 0, true); |
| 114 | |
| 115 | m_iSecurityCountForOneLoadUnit = m_SecurityFile.CalculateSecurityCount(iDefaultLoadUnitSize); |
| 116 | }; |
| 117 | |
| 118 | bool GenerateNextRecord() { |
| 119 | if (m_iLastRowNumber % m_iSecurityCountForOneLoadUnit == 0) { |
| 120 | InitNextLoadUnit(); |
| 121 | } |
| 122 | |
| 123 | GenerateLastTradeRow(); |
| 124 | |
| 125 | ++m_iLastRowNumber; |
| 126 | |
| 127 | // Update state info |
| 128 | m_bMoreRecords = m_iLastRowNumber < (m_iStartFromSecurity + m_iSecurityCount); |
| 129 | |
| 130 | return (MoreRecords()); |
| 131 | } |
| 132 | }; |
| 133 | |
| 134 | } // namespace TPCE |
| 135 | |
| 136 | #endif // LAST_TRADE_TABLE_H |
| 137 | |