简体   繁体   English

在 Java 中生成随机股票代码的最有效方法?

[英]Most efficient way to generate a random stock ticker in Java?

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.我对 Java 相当陌生,所以如果这是一个微不足道的问题,我很抱歉。

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.基本上,我目前的设置方式是我有一个方法可以创建一个大小为 1-5 的随机字母字符串,然后在诸如市场观察之类的网站上搜索随机字符串以查看是否显示任何结果。

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.但是,我想知道一个更有效的实现是否只是上传一个数组/xml 文件,其中包含来自大多数主要证券交易所的上市公司的股票代码,这会让我像 8,000 多个标准一样。 I could also downsize and only work with stock in the NYSE, but that would still be working with like 1,900 values.我也可以缩小规模,只使用纽约证券交易所的股票,但这仍然适用于大约 1,900 个值。 I'll be looking up these tickers on Marketwatch as well.我也会在 Marketwatch 上查找这些代码。 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.我还只需要为我的项目生成大约 100 个随机股票代码。

Thank you so much!!太感谢了!!

There is java library called faker.有一个名为 faker 的 java 库。 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: Maven:

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

GIT: GIT:

https://github.com/DiUS/java-faker 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 https://github.com/DiUS/java-faker/blob/master/src/main/resources/en/stock.yml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM