About this question
Medium · Code Analysis · Quant Trader interview question · integer overflow, position sizing, C++, numerical stability
A trading firm uses the following C++ function to calculate the number of shares to buy. The return type is a signed 32-bit int, whose representable range is $-2{,}147{,}483{,}648$ through $2{,}147{,}483{,}647$. Call the function with: - portfolio_size = 1'000'000'000'000.0 (one trillion dollars) - allocation_percentage = 0.05 (5%) - stock_price = 10.0 dollars per share The calculation before the cast is $$ \frac{1{,}000{,}000{,}000{,}000\times0.05}{10}=5{,}000{,}000{,}000 $$ What does the C++ s