
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Evaluation of Risk in Investments in C++
In this problem, we are given two arrays each denoting an investment plan. Our task is to perform the evaluation of Risk in Investment and find which of the two investments is more promising.
Both the investments I1[][] and I2[][] has a set of outcomes and the probability of that investment outcome.
Using these values, we need to find the risk in each investment and then print the better investment out of the two investments.
For this, we will be using statistical mathematics and find some values that will help us conclude to the better investment.
We will find these values,
- Mean or average amount form the investment, the sum of product of investment outcome and probability.
- Deviation on the amount earned
We will find the value of,
standard Deviation / mean of investment about
The investment with a lesser value of S.D. / mean is the result.
Program to illustrate the working of our solution,
Example
#include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; typedef pair<float,float> Data; typedef vector Vector; float totalProdProbOutcome(const Vector & v) { float sum = 0; for ( auto i : v) { sum += i.first * i.second; } return sum; } float totalProb(const Vector & v) { float sum = 0.0; for ( auto i : v) { sum += i.second; } return sum; } float CalcMeanVal(const Vector & v) { return totalProdProbOutcome(v) / totalProb(v); } float calcStdDevi(const Vector & v) { float mean = CalcMeanVal(v); float sum = 0; for (auto i: v) sum += (i.first-mean)* (i.first-mean)*i.second; return sqrt(sum/totalProb(v)); } int main() { Vector A = { {450,0.3}, {250,0.4}, {100,0.2}, {300,0.1}}; Vector B = { {300,0.2}, {150,0.5}, {500,0.3}}; float meanA = CalcMeanVal(A); float meanB = CalcMeanVal(B); float SdA = calcStdDevi(A); float SdB = calcStdDevi(B); if( (SdA / meanA) > (SdB / meanB)) cout<<"Investment A is Better investment.\n"; else cout<<"Investment B is better investment.\n"; return 0; }
Output −
Investment B is better investment.
- Related Articles
- What are the three important steps in the evaluation of investments?
- What are the three components of cash in investments?
- Evaluation of Prefix Expressions in C++
- Evaluation of Expression Tree in C++
- Evaluation order of operands in C++
- Order of evaluation in C++ function parameters
- Types of Investments – Expansion, Diversification, Modernization, Replacement
- Evaluation of Boolean expression
- Short-circuit evaluation in JavaScript
- ICT in Assessment and Evaluation
- What are mutually exclusive investments?
- What is evaluation order of function parameters in C?
- Explain the evaluation of expressions of stacks in C language
- Residual Risk Vs. Secondary Risk
- What are the Stages of Evaluation in Credit Analysis Process?

Advertisements