Nested Loop is giving me same or wrong answers when i need to calculate the equity return

Nested Loop is giving me same or wrong answers when i need to calculate the equity return



Background: Greetings! I had to randomly sample a value from normal distribution (done) and use that value (mean is "that value") to see how much an initial equity value of 100 increases in 3582weeks and provide the final profited value. As in:



equity=100



equity = equity + 100*mean



I need to run 1000 trials to see how different values of "mean" give different profited values.



I'm able to get the answer for the 3582 weeks for the first trial, but when i'm adding another loop for "1000 trials," it's either giving me the same values or wrong values.



Problem: The loop is either giving me the same values or completely in-correct values. method: computeStats()..



Note: I've shown the constructor in the blog just for reference to show what i'm really doing.


class Sample extends SimulateMarket{ //SimulateMarket is the Application class

ArrayList<Double> data = new ArrayList<Double>();
private double mean, stdDev;
private Random random;
SimulateMarket mySim = new SimulateMarket(); //mySim is an instance of SimulateMarket class used to access variables of Simulate Class

public Sample(int size, double theMean, double theStdDev) //Comstructor used for the Distributional Technique
random = new Random();
for(int i=0; i<3582 ; i++)
data.add(theMean+random.nextGaussian()*theStdDev); //Random sampling from Normal Distribution
mean = getMean(); //getMean() method is used to get Mean
stdDev = getStdDev(mean);
Collections.sort(data);//getStdDev is used for getting Standard Deviation
System.out.println(this); //for printing the results


public void computeStats()
ArrayList<Double> myData = new ArrayList<Double>();

for(int j=0; j<1000; j++)
equity = 100;
for(int i=0; i<3582; i++)
equity = equity + 100*mean;


myData.add(equity);


for(Double num: myData)
System.out.println(num);









It looks like you're computing the same stats 1000 times. Do you want to compute 1000 different samples? You don't need your 1000 loop in computeStats for that. You need it wherever you're creating your new Sample().

– Paul Hicks
Sep 6 '18 at 3:28


computeStats


new Sample()






that worked! Apparently i was stuck in this thing since 5 hours!

– Shahbaz Malik
Sep 6 '18 at 3:40




1 Answer
1



Apparently, i was adding the 1000 loop in the wrong place. That's where it needs to be- in the main method


public static void main(String args) throws java.io.IOException
for(int j=0; j<1000; j++)
Sample equity = new Sample(3582, 0.0016, 0.0205);
equity.computeStats();




Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)