About this question
Medium · Code Analysis · Quant Trader interview question · integer overflow, position sizing, C++, numerical stability
A trading firm uses a C++ program to calculate the number of shares to buy for a given stock. The program takes a portfolio size (in dollars) and calculates the number of shares by dividing the allocated capital for the stock by the current price of the stock. Critically, the number of shares is stored as a signed 32-bit integer (int). Specifically, the code does the following: Assume the portfolio size is 1 billion dollars (1,000,000,000). The allocation_percentage for a particular stock is 5%