NatanZB

Untitled

Jun 26th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. static bool InvesmentBrokerExample() {
  2. cout << "STARTING" << endl;
  3. InvestmentBroker broker;
  4. broker.addShare("THIS", 54, 95);
  5. broker.addShare("TEST", 888, 95);
  6. broker.addShare("NAT", 553, 84);
  7. broker.addShare("VAL", 336, 58);
  8. broker.addBond("THIS", 448, 54);
  9. broker.addBond("TEST", 550, 31);
  10. broker.addBond("OKOK", 662, 66);
  11. broker.addShare("I", 448, 54);
  12. const string customer1 = "111111111";
  13. const string customer2 = "111111112";
  14. const string customer4 = "111111114";
  15. const string customer9 = "123123219";
  16. ASSERT_THROW(CustomerNotExistException, broker.changePreference(customer1, LOW_RISK, 14839));
  17. broker.addCustomer(customer1, 25000, HIGH_RISK);
  18. broker.addCustomer(customer2, 44125, LOW_RISK);
  19. broker.addCustomer(customer4, 30000, HIGH_RISK);
  20. broker.addCustomer(customer9, 15222, LOW_RISK);
  21. broker.nextTradeDay(); //new customers!
  22. const string customer5 = "111111115";
  23. const string customer6 = "111111116";
  24. const string customer7 = "111111117";
  25. const string customer8 = "432211238";
  26. broker.addCustomer(customer5, 25000, HIGH_RISK);
  27. broker.addCustomer(customer6, 44125, LOW_RISK);
  28. broker.addCustomer(customer7, 30000, HIGH_RISK);
  29. broker.addCustomer(customer8, 15222, LOW_RISK);
  30. broker.nextTradeDay(); //new customers!
  31. broker.nextTradeDay(); //new customers!
  32. broker.nextTradeDay(); //new customers!
  33. broker.addBond("HAVE", 550, 85);
  34. broker.addBond("LACK", 662, 66);
  35. broker.addShare("OF", 5.9, 34);
  36. broker.addBond("SEX", 662, 97);
  37. broker.addShare("BCUZ", 1, 21);
  38. broker.addBond("MTM", 662, 13);
  39. broker.nextTradeDay(); //new customers!
  40. broker.addBond("IS", 785, 45);
  41. broker.addBond("VERY", 1124, 11);
  42. broker.addShare("LONG", 123.45, 95);
  43. broker.addShare("RAF", 45.45, 88);
  44. const string customer3 = "111111113";
  45. broker.addCustomer(customer3, 30000, LOW_RISK);
  46. broker.nextTradeDay(); //new customers!
  47. broker.nextTradeDay(); //new customers!
  48. broker.nextTradeDay(); //new customers!
  49. broker.printFullReport();
  50. broker.printCustomerReport(customer1);
  51. broker.printCustomerReport(customer2);
  52. broker.printCustomerReport(customer3);
  53. broker.printCustomerReport(customer4);
  54. broker.printCustomerReport(customer5);
  55. broker.printCustomerReport(customer6);
  56. broker.printCustomerReport(customer7);
  57. broker.printCustomerReport(customer8);
  58. broker.printCustomerReport(customer9);
  59. ASSERT_THROW(IllegalSecurityNameException,broker.addShare("THISNAMEISTOOLONG!", 45.45, 88));
  60. ASSERT_THROW(IllegalSecurityNameException,broker.addShare("ZzZz", 45.45, 88));
  61. ASSERT_THROW(InvalidSecurityAmountException,broker.addShare("JSUS", -3, 0));
  62. ASSERT_THROW(NegetiveSecurityValueException,broker.addShare("JSUS", -3, 5));
  63. ASSERT_THROW(CustomerAlreadyExistException, broker.addCustomer(customer8, 15222, LOW_RISK));
  64. ASSERT_THROW(SecurityAlreadyExistException, broker.addBond("VERY", 1124, 11));
  65. ASSERT_THROW(SecurityAlreadyExistException, broker.addShare("LONG", 123.45, 95));
  66. //create risks
  67. int i = 1;
  68. for (i = 1; i < 14; ++i) {
  69. if (! i % 10) {
  70. if (i % 3) {
  71. broker.sellPortfolio("111111113");
  72. } else {
  73. broker.sellPortfolio("111111112");
  74. }
  75. }
  76. if (! i % 9) {
  77. if (i % 2) {
  78. broker.changePreference(customer1, HIGH_RISK, i + 3);
  79. } else {
  80. broker.changePreference(customer9, LOW_RISK, i - 1);
  81. }
  82. }
  83. if (! i % 8) {
  84. if (i % 3) {
  85. broker.changePreference(customer2, HIGH_RISK, i + 3);
  86. } else {
  87. broker.changePreference(customer8, LOW_RISK, i - 1);
  88. }
  89. }
  90. if (! i % 7) {
  91. if (i % 2) {
  92. broker.changePreference(customer3, HIGH_RISK, i);
  93. } else {
  94. broker.changePreference(customer7, LOW_RISK, i - 1);
  95. }
  96. }
  97. if (! i % 6) {
  98. if (i % 5) {
  99. broker.changePreference(customer4, HIGH_RISK, i + 3);
  100. } else {
  101. broker.changePreference(customer6, LOW_RISK, i - 1);
  102. }
  103. }
  104. if (! i % 5) {
  105. if (i % 3) {
  106. broker.changePreference(customer5, HIGH_RISK, i + 3);
  107. } else {
  108. broker.changePreference(customer5, LOW_RISK, i);
  109. }
  110. }
  111. if (! i % 4) {
  112. if (i % 3) {
  113. broker.changePreference(customer6, HIGH_RISK, i + 3);
  114. } else {
  115. broker.changePreference(customer4, LOW_RISK, i - 1);
  116. }
  117. }
  118. if (! i % 3) {
  119. if (i % 3) {
  120. broker.changePreference(customer7, HIGH_RISK, i + 3);
  121. } else {
  122. broker.changePreference(customer3, LOW_RISK, i - 1);
  123. }
  124. }
  125. if (! i % 2) {
  126. if (i % 3) {
  127. broker.changePreference(customer8, HIGH_RISK, i + 10);
  128. } else {
  129. broker.changePreference(customer2, LOW_RISK, i - 1);
  130. }
  131. }
  132. if (! i % 11) {
  133. if (i % 3) {
  134. broker.changePreference(customer9, HIGH_RISK, i + 3);
  135. } else {
  136. broker.changePreference(customer1, LOW_RISK, i - 1);
  137. }
  138. }
  139. if (! i % 12) {
  140. if (i % 5) {
  141. ASSERT_THROW(CustomerNotExistException, broker.changePreference("987654321", LOW_RISK, i - 1));
  142. ASSERT_THROW(CustomerNotExistException, broker.sellPortfolio("988654321"));
  143. } else {
  144. broker.changePreference(customer1, LOW_RISK, i - 1);
  145. }
  146. }
  147. if (! i % 13) {
  148. if (i % 5) {
  149. broker.sellPortfolio(customer1);
  150. broker.sellPortfolio(customer3);
  151. broker.sellPortfolio(customer5);
  152. broker.sellPortfolio(customer6);
  153. } else {
  154. broker.sellPortfolio(customer2);
  155. broker.sellPortfolio(customer4);
  156. broker.sellPortfolio(customer6);
  157. broker.sellPortfolio(customer7);
  158. broker.sellPortfolio(customer8);
  159. }
  160. }
  161. broker.nextTradeDay();
  162. cout << "Day " << i+3 << " | i = "<< i << endl;
  163. broker.printFullReport();
  164. broker.printCustomerReport(customer1);
  165. broker.printCustomerReport(customer1, PAPER_BOND);
  166. broker.printCustomerReport(customer1, PAPER_SHARE);
  167. broker.printCustomerReport(customer2);
  168. broker.printCustomerReport(customer2, PAPER_BOND);
  169. broker.printCustomerReport(customer2, PAPER_SHARE);
  170. broker.printCustomerReport(customer3);
  171. broker.printCustomerReport(customer3, PAPER_BOND);
  172. broker.printCustomerReport(customer3, PAPER_SHARE);
  173. broker.printCustomerReport(customer4);
  174. broker.printCustomerReport(customer4, PAPER_BOND);
  175. broker.printCustomerReport(customer4, PAPER_SHARE);
  176. broker.printCustomerReport(customer5);
  177. broker.printCustomerReport(customer5, PAPER_BOND);
  178. broker.printCustomerReport(customer5, PAPER_SHARE);
  179. broker.printCustomerReport(customer6);
  180. broker.printCustomerReport(customer6, PAPER_BOND);
  181. broker.printCustomerReport(customer6, PAPER_SHARE);
  182. broker.printCustomerReport(customer7);
  183. broker.printCustomerReport(customer7, PAPER_BOND);
  184. broker.printCustomerReport(customer7, PAPER_SHARE);
  185. broker.printCustomerReport(customer8);
  186. broker.printCustomerReport(customer8, PAPER_BOND);
  187. broker.printCustomerReport(customer8, PAPER_SHARE);
  188. broker.printCustomerReport(customer9);
  189. broker.printCustomerReport(customer9, PAPER_BOND);
  190. broker.printCustomerReport(customer9, PAPER_SHARE);
  191. }
  192. for(int j = i; j < 10*i ; j++){
  193. broker.nextTradeDay();
  194. cout << "Day " << j+3 << " | j = "<< j << endl;
  195. broker.printFullReport();
  196. }
  197. broker.printFullReport();
  198. cout << "FINISHED!" << endl;
  199. return true;
  200. }
Advertisement
Add Comment
Please, Sign In to add comment