The Global Beverage Corporation Exchange is a new stock market trading in drinks companies.
Your company is building an object-oriented system to run that trading.
You have been assigned to build part of the core object model for a limited phase 1
Provide the complete source code that will:
For a given stock,
Given any price as input, calculate the dividend yield
Given any price as input, calculate the P/E Ratio
Record a trade, with timestamp, quantity, buy or sell indicator and price
Calculate Volume Weighted Stock Price based on trades in past 5 minutes
Calculate the GBCE All Share Index using the geometric mean of the Volume Weighted Stock Price for all stocks
Constraints & Notes
Written in one of these languages - Java, C#, C++, Python
The source code should be suitable for forming part of the object model of a production application, and can be proven to meet the requirements. A shell script is not an appropriate submission for this assignment.
No database, GUI or I/O is required, all data need only be held in memory
No prior knowledge of stock markets or trading is required – all formulas are provided below.
The code should provide only the functionality requested, however it must be production quality.
Table 1. Sample data from the Global Beverage Corporation Exchange
Stock Symbols
Type
Last Dividend
Fixed Dividend
Par Value
TEA
Common
0
100
POP
Common
8
100
ALE
Common
23
60
GIN
Preferred
8
2%
100
JOE
Common
12
250
Table 2. Formulas
Common
Preferred
Dividend Yield
LastDividend / Price
(Fixed Dividend * Par Value) / Price
P/E Ratio
Price / Dividend
Geometric Mean
n√ p1 * p2 * p3* ... pn
Volume Weighted Stock Price
(∑i TradedPricei * Quantityi) / ∑i Quantityi
Implementation
Summary
Solution implemented using C# 9.0, .NET Core 7.0
Unit test framework: xUnit 2.4.2, Moq 4.18.4, FluentAssertions 6.10.0
IDE: Visual Studio Code v1.77.1
Code documented with XML for C# documentation comments
Solution Structure
SuperSimpleStockMarket - a library containing the implementation of all requirements listed above. This library is designed to be used as part of a core object model or registered in a DI container as a component of a RESTful Web API. All data models are implemented as plain data classes, ready for JSON serialization, and are decoupled from services that encapsulate model behavior and data processing. This ensures flexibility and maintainability.
SuperSimpleStockMarket.Api - sample Web API demostrating SuperSimpleStockMarket usage.
SuperSimpleStockMarket.Tests - unit tests demonstrating that the SuperSimpleStockMarket library meets the requirements.
How To Run SuperSimpleStockMarket.Api
Open Visual Studio Code and choose one of the following options to run the API in debug mode:
Press F5
From the top menu: Run -> Start Debugging
From the side menu: press Run and Debug button -> select .NET Core Launch (Web API) from a drop-down list on top -> press Play button