1. Homepage
  2. Programming
  3. [2022] SMU - QF633 C++ for Financial Engineering - Assignment 3 - Order Manager

[2022] SMU - QF633 C++ for Financial Engineering - Assignment 3 - Order Manager

Engage in a Conversation
Financial EngineeringC++QF633C++ for Financial EngineeringSMU

QF633 Assignment 3

May 29, 2022 CourseNana.COM


CourseNana.COM

CourseNana.COM

In this assignment, we will explore building a simple but very efficient order manager using the <algorithm> library. CourseNana.COM

An order is minimally represented by the following data structure: CourseNana.COM


CourseNana.COM

CourseNana.COM

struct Order { CourseNana.COM

int price ; // the order ’s price , and int type used instead of double type for simplicity CourseNana.COM

int open_qty ; // the open qty of the order CourseNana.COM

std :: string order_id ; // unique order identifier to identify the order CourseNana.COM

bool is_sell ; // order side , true - buy order , false - sell order CourseNana.COM

}; CourseNana.COM


CourseNana.COM

An order manager is a class which manages all the open orders, i.e. order with open_qty > 0. The order manager should keep the records in a std::vector in CourseNana.COM

a sorted manner: CourseNana.COM

      •       orders with lower prices should be placed before orders with higher prices
      •       orders with the same price should be sorted according to the order of

insertion, i.e. FIFO order CourseNana.COM

class OrderManager { CourseNana.COM

public : CourseNana.COM

// add a new record to the order manager CourseNana.COM

void Add ( int price , int qty , const std :: string & order_id , bool is_sell ); CourseNana.COM

// update the open_qty for an existing order record and delete the record if updated_open_qty == 0 CourseNana.COM

void Update ( const std :: string & order_id , int updated_open_qty ); CourseNana.COM

// print all orders following the order specified , i.e. CourseNana.COM

// - from lower prices to high prices CourseNana.COM

// - following FIFO if same price CourseNana.COM

void PrintAllOrders () const ; CourseNana.COM

private : CourseNana.COM

std :: vector <Order > orders_ ; CourseNana.COM

}; CourseNana.COM


CourseNana.COM

With following code snippets, the expected output is inline commented. CourseNana.COM

CourseNana.COM

OrderManager order_manager ; CourseNana.COM

order_manager . Add (100 , 2, "o1", true ); CourseNana.COM

order_manager . Add (99 , 1, "o2", true ); CourseNana.COM

order_manager . Add (100 , 3, "o3", true ); CourseNana.COM

order_manager . Add (101 , 4, "o4", true ); CourseNana.COM

order_manager . PrintAllOrders (); CourseNana.COM

// price =99 open_qty =1 order_id =o2 is_sell =1 CourseNana.COM

// price =100 open_qty =2 order_id =o1 is_sell =1 CourseNana.COM

// price =100 open_qty =3 order_id =o3 is_sell =1 CourseNana.COM

// price =101 open_qty =4 order_id =o4 is_sell =1 CourseNana.COM

order_manager . Update ("o3", 1); CourseNana.COM

order_manager . Update ("o2", 0); CourseNana.COM

order_manager . Add (98 , 5, "o5", false ); CourseNana.COM

order_manager . Add (101 , 1, "o6", true ); CourseNana.COM

  CourseNana.COM

order_manager . Add (100 , 2, "o7", true ); CourseNana.COM

order_manager . PrintAllOrders (); CourseNana.COM

// price =98 open_qty =5 order_id =o5 is_sell =0 CourseNana.COM

// price =100 open_qty =2 order_id =o1 is_sell =1 CourseNana.COM

// price =100 open_qty =1 order_id =o3 is_sell =1 CourseNana.COM

// price =100 open_qty =2 order_id =o7 is_sell =1 CourseNana.COM

// price =101 open_qty =4 order_id =o4 is_sell =1 CourseNana.COM

// price =101 open_qty =1 order_id =o6 is_sell =1 CourseNana.COM


CourseNana.COM


CourseNana.COM

Approach 1: Add and then sort CourseNana.COM

One obvious approach is to simply append the new record to the std::vector,and then sort the std::vector to the desired order. Can you please given an implementation following this approach? CourseNana.COM

Hint: please take note the following description from std::sort documentation: Sorts the elements in the range [first, last) in non-descending order. The order of equal elements is not guaranteed to be preserved.. CourseNana.COM


CourseNana.COM

Approach 2: Add while preserving the ordering CourseNana.COM

The other alternative approach is to insert the new report to the correct position of the std::vector, i.e. firstly find the position to insert the new record while preserving the ordering and secondly to insert the new record to the found location. With this approach, it’s not necessary to call sort separately. CourseNana.COM


CourseNana.COM

We could linearly scan the std::vector to find the correct position to insert, but a better way is to use binary search. During the lecture, we have introduced std::binary_search which can tell if an element exists in an given range. There are another two important functions in the binary search operations category, namely std::lower_bound and std::upper_bound. Can you use either function to find the correct position to insert the new record for this approach? CourseNana.COM

The following files have been provided in the zip file: CourseNana.COM

- order .h: declaration for struct Order CourseNana.COM

- order . cpp : definition for struct Order CourseNana.COM

- order_manager .h: declaration for class Order Manager CourseNana.COM

- order_manager_v1 . cpp : implementation to be provided using approach 1 CourseNana.COM

- order_manager_v2 . cpp : implementation to be provided using approach 2 CourseNana.COM

- main . cpp : main function which gives two simple test cases CourseNana.COM

- CMakeLists . txt: cmake project file to be provided CourseNana.COM

You are expected to: CourseNana.COM

  provide an implementation using approach 1 inside order_manager_v1.cpp. CourseNana.COM

  provide an implementation using approach 2 inside order_manager_v2.cpp. CourseNana.COM

  complete the CMakeLists.txt to compile an executable order_manager_v1 for approach 1 and an executable order_manager_v2 for approach 2. CourseNana.COM

  provide a PDF document assignment3.pdf, which describes CourseNana.COM

– the time complexity for OrderManager::Add, and OrderManager::Update for both approaches. CourseNana.COM

– rationale of how to make sure the desired ordering is maintained for both approaches CourseNana.COM

  create a zip file as Assignment3_YourName.zip, which contains 1) the pdf  report, 2) the completed source codes as well as the CMakeLists.txt, and submit to eLearn. CourseNana.COM

[Bonus point]: You are encouraged to use functions from <algorithm> rather than writing plain for loop. CourseNana.COM

CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Financial Engineering代写,C++代写,QF633代写,C++ for Financial Engineering代写,SMU代写,Financial Engineering代编,C++代编,QF633代编,C++ for Financial Engineering代编,SMU代编,Financial Engineering代考,C++代考,QF633代考,C++ for Financial Engineering代考,SMU代考,Financial Engineeringhelp,C++help,QF633help,C++ for Financial Engineeringhelp,SMUhelp,Financial Engineering作业代写,C++作业代写,QF633作业代写,C++ for Financial Engineering作业代写,SMU作业代写,Financial Engineering编程代写,C++编程代写,QF633编程代写,C++ for Financial Engineering编程代写,SMU编程代写,Financial Engineeringprogramming help,C++programming help,QF633programming help,C++ for Financial Engineeringprogramming help,SMUprogramming help,Financial Engineeringassignment help,C++assignment help,QF633assignment help,C++ for Financial Engineeringassignment help,SMUassignment help,Financial Engineeringsolution,C++solution,QF633solution,C++ for Financial Engineeringsolution,SMUsolution,