C#, Newtonsoft.Json, .NET Application.
The Investment Calculator is a risk assessment tool designed to calculate and assess soley or porfolio investment. This application fetch real data from internet and leverages object-oriented principles to manage user choice of investment (stock/ bond), investment portfolios risk assessments.
ROI is calculated as:
P&L is determined by:
Risk assessment specifically through the standard deviation of returns
Where:
-
$R_i$ is the return of the investment in the ith period, -
$\bar{R}$ is the average return of the investment, -
$N$ is the total number of observations.
- Inheritance: BondInvestment and StockInvestment inherit from the abstract class Investment, which defines shared properties and methods like amountInvested, roi, and AssessRisk.
- Encapsulation: Properties and methods are encapsulated within classes, such as Investment and User, ensuring that data is hidden from external access and is accessible only through methods in the class.
- Polymorphism: Methods like AssessRisk are overridden in derived classes (BondInvestment and StockInvestment), allowing them to implement specific risk assessment logic.
Class structure
- UIManagement: Manages user interactions and controls the flow of the application, facilitating operations like creating users, adding investments, and displaying analyses. The public userSelection() method make program responds to user inputs, which guide the program flow.
- User + Portfolio: Handles user data and their investment portfolios. Each User has a Portfolio, which aggregates multiple Investments.
- Risk Assessment: Contains logic to assess the risk of different types of investments. The method AssessBondRisk suggests specialized risk assessment for bonds.
- Investment: use Newtonsoft.Json to retrieving data from online databases (such as Yahoo Finance). Newtonsoft.Json can convert C# objects into JSON and JSON into C# objects (serialization and deserialization, respectively), it is helpful to fetch real-time financial data, which is essential for evaluating the ROI and performance of investments.
- Portfolio: has methods to calculate total ROI and to assess the risk of the entire portfolio, crucial for giving users a holistic view of their investments' performance. Program Flow
- The Main() function in the Program class likely initializes the application, setting up necessary components and possibly loading initial data.
-
Here, all stock data are presented in a structured JSON format.
-
Risk assessment base on amount Invested and analized ROI & PnL.
- Clone the repository to your local machine.
- Ensure you have .NET framework installed.
- Navigate to the project directory and build the project.
- Execute the program to start calculating investments.
My code aren't perfect, I want to adjust the logic of risk assessment to be more robust. Feel free to fork the repository and submit pull requests. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE.md file for details.
If you have any questions or feedback, please contact me at discussion.