Suppose you are a disciplined investor. In the beginning of each month, you inve
ID: 3682360 • Letter: S
Question
Suppose you are a disciplined investor. In the beginning of each month, you invest the same amount of your saved money in selected funds. After 10 ten years, how much will be your investment? This depends on two factors: the amount of your monthly investment, the monthly return of your investment portfolio.
For the monthly investment amount, you may consider scenarios of different amounts, e.g., $50, $100, $500, and $1,000. For monthly return, well, nobody would know because the market fluctuates all the time. But we can use simulated values for the returns. According to the article at https://www.ifa.com/articles/with_stock_returns_ normally_distributed/, historic monthly returns roughly have a normal distribution.
For the simulation, we assume that monthly return is drawn probabilistically from two normal distributions:
• 95% probability from N(1%, 2.5%)
• 5% probability from N(?4.5%, 2.5%)
You will be provided with a partially finished program. After adding your code to complete the program, it will output the monthly rate of return and account balance for each saving scenario. Below is a sample output.
Below is my Partially Completed Program:
The program includes two helper methods to generate simulated monthly returns. You only need
to add code to the main method as instructed by the embedded comments.
import java.util.Random;
public class InvestSimulation {
private static Random random = new Random();
private static double nMean=-.045, nStd=.025, pMean=.01, pStd=.025;
public static void main(String... args ) {
int N=120; // for ten years (120 months)
double[] r = new double[N];
generateReturns(r);
// add your code here:
// use a 1-D array to hold monthly investment amounts (four scenarios)
// create a 2-D array for storing monthly balance (120 months, 4 scenarios)
// define a variable to store running total of monthly return
// use a nested loop to populate the 2-D array and output data.
}
public static double getGaussian(double mean, double stddev) {
return mean + stddev*random.nextGaussian();
}
public static void generateReturns(double[] r) {
for (int i=0; i if (Math.random()<.05) { // negative return
r[i] = getGaussian(nMean, nStd);
} else {
r[i] = getGaussian(pMean, pStd);
}
}
}
}
Explanation / Answer
//use a 1-D array to hold monthly investment amounts (four scenarios)
int investment_amounts[] = { 50, 100, 500, 1000};
System.out.println(" investment_amounts is" + "$"+investment_amounts[3]);
//create a 2-D array for storing monthly balance (120 months, 4 scenarios)
int i, ,j;
int[][] a1 = new int[months][scenarios];
"[" motnhs "]"+ "[" senarios "]");
//define a variable to store running total of monthly return
int k;
int rt = 0; //accumulator
for (int k= 1; k <= 120; k++) {
Scanner scan = new Scanner(System.in);
System.out.println("enter an integer");
k = scan.nextInt();
System.out.println("the current total is");
int count =k + rt;
System.out.println(count);
}
//use a nested loop to populate the 2-D array and output data.
for (int i=0; i<months; i++)//for entering data in the row