0

Im currently working on a personal project that basically creates a bunch of random stock portfolios and goes through them to pick the best one. I am fairly new to Java, so I'm sorry in advance if this is a trivial question.

Basically, the way I am currently set up is that I have a method that creates a random string of letters size 1-5, and then searches for the random string on a site like market watch to see if any results show up.

However, I was wondering if a more efficient implementation would to just upload an array/xml file with the tickers from publicly traded companies from most major stock exchanges, which would put me in like the 8,000+ criteria. I could also downsize and only work with stock in the NYSE, but that would still be working with like 1,900 values. I'll be looking up these tickers on Marketwatch as well. I am also open to any better suggestions, since I doubt either of these are very efficient implementations.

I also only need to generate, say around 100 random stock tickers for my project.

Thank you so much!!

  • 1
    It would probably be quicker for you to just go and get a list of popular stocks and hard code these values than it would be to generate them? Otherwise do some web scraping. – Adam Nov 06 '19 at 22:24
  • I was considering that, but I kind of want to include less popular/under looked stocks to add more variation in my data. It's mainly because I want to try implementing a simpler version of a genetic algorithm to create my final portfolios, and them comparing them to my own. If all else fails tho I'll probably go that route – Komm Süsser Tod Nov 06 '19 at 22:33

1 Answers1

1

There is java library called faker. It has list of quotes and you can pick random using:

    Faker faker = new Faker();
    System.out.println(faker.stock().nsdqSymbol());
    System.out.println(faker.stock().nyseSymbol());

Maven:

<dependency>
    <groupId>com.github.javafaker</groupId>
    <artifactId>javafaker</artifactId>
    <version>1.0.1</version>
</dependency>

GIT:

https://github.com/DiUS/java-faker

File with all possible stocks:

https://github.com/DiUS/java-faker/blob/master/src/main/resources/en/stock.yml

Ivan Lymar
  • 2,180
  • 11
  • 26