本文整理汇总了Java中yahoofinance.histquotes.HistoricalQuote类的典型用法代码示例。如果您正苦于以下问题:Java HistoricalQuote类的具体用法?Java HistoricalQuote怎么用?Java HistoricalQuote使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HistoricalQuote类属于yahoofinance.histquotes包,在下文中一共展示了HistoricalQuote类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: streamResult
import yahoofinance.histquotes.HistoricalQuote; //导入依赖的package包/类
private void streamResult(ObservableEmitter<List<AbstractQuote>> emitter, Map<String, Stock> batchResult) {
logger.info("streamResult");
if (emitter != null) {
for (Stock ss : batchResult.values()) {
List<HistoricalQuote> historicalQuotes;
try {
historicalQuotes = ss.getHistory();
List<List<HistoricalQuote>> quotes = Lists.partition(historicalQuotes, 2000);
for (List<HistoricalQuote>hq : quotes) {
List<AbstractQuote> histQs = hq.stream().filter(s -> s != null)
.map(
s -> createQuote(s,ss.getSymbol())
).collect(Collectors.toList());
logger.info("emitter(" + histQs.size() + ")");
emitter.onNext(histQs);
}
} catch (IOException e) {
logger.error("cannot get stock quote history.. [" + ss.getName() + ", " + ss.getSymbol() + "]", e);
ErrorQuote q = ErrorQuote.newQuoteInError(ss.getName(),e,e.getMessage(),QuoteErrorType.HISTORY);
emitter.onNext(Lists.newArrayList(q));
}
}
//emitter.onComplete();
}
}
开发者ID:charcode,项目名称:StockScreener,代码行数:26,代码来源:YahooFinanceWrapper.java
示例2: getMA
import yahoofinance.histquotes.HistoricalQuote; //导入依赖的package包/类
/**
* Returns a moving average from a stock's history
* @author Michael Bick
* @param daysAgo amount of days ago the moving average is from
* @param days amount of days to use in the moving average
* @return moving average
* @throws IOException
*/
public BigDecimal getMA(int daysAgo, int days) throws IOException {
// Gets historical quotes
List<HistoricalQuote> quotes = getHistory(daysAgo, days);
// Calculate the moving average
BigDecimal ma = new BigDecimal(0);
for (HistoricalQuote quote : quotes) {
ma = ma.add(quote.getAdjClose());
// System.out.println(quote.getAdjClose());
// System.out.println(ma);
}
ma = ma.divide(new BigDecimal(quotes.size()), 2, RoundingMode.HALF_UP); // Rounds the "regular" way to 2 decimal places
return ma;
}
开发者ID:lnmangione,项目名称:Stock-Bot,代码行数:24,代码来源:Symbol.java
示例3: createQuote
import yahoofinance.histquotes.HistoricalQuote; //导入依赖的package包/类
private Quote createQuote(HistoricalQuote s, String symbol) {
Quote quote = new Quote((Long) null, symbol,
safeGetDouble(s.getOpen()),
safeGetDouble(s.getClose()), safeGetDouble(s.getHigh()), safeGetDouble(s.getLow()),safeDivide(s.getAdjClose(), s.getClose()),
s.getVolume(), safeGetDate(s.getDate()));
return quote;
}
开发者ID:charcode,项目名称:StockScreener,代码行数:9,代码来源:YahooFinanceWrapper.java
示例4: getHistory
import yahoofinance.histquotes.HistoricalQuote; //导入依赖的package包/类
/**
* Returns list of historical quotes using days from most to least recent
* @author Michael Bick
* @param daysAgo days ago the first quote is from
* @param days amount of days of historical quotes
* @return list of historical quotes from time period
* @throws IOException
*/
public List<HistoricalQuote> getHistory(int daysAgo, int days) throws IOException {
// Create an integer to hold the farthest back day requested
int fromDay = daysAgo + days;
// Filter the list down to what we need
// Only subtract 1 from first parameter because it is inclusive
return history.subList(daysAgo, fromDay);
}
开发者ID:lnmangione,项目名称:Stock-Bot,代码行数:17,代码来源:Symbol.java
示例5: testFeed
import yahoofinance.histquotes.HistoricalQuote; //导入依赖的package包/类
@Ignore
@Test
public void testFeed()
{
Stock stock = YahooFinance.get("WES.AX");
StockDividend dividend = stock.getDividend();
Calendar twoYearsBack = GregorianCalendar.getInstance();
twoYearsBack.add(Calendar.YEAR, -2);
List<HistoricalQuote> history = stock.getHistory(twoYearsBack, Interval.WEEKLY);
Assert.assertEquals("AUD", stock.getCurrency());
}
开发者ID:joshpassenger,项目名称:jfreestock,代码行数:13,代码来源:FeedTest.java
示例6: doInBackground
import yahoofinance.histquotes.HistoricalQuote; //导入依赖的package包/类
@Override
protected StockQuoteItem doInBackground(String... params) {
if (params.length == 0) {
return null;
}
try {
String symbol = params[0];
Stock stock = YahooFinance.get(symbol);
StockQuote quote = stock.getQuote();
String name = stock.getName();
float price = quote.getPrice().floatValue();
float change = quote.getChange().floatValue();
float percentChange = quote.getChangeInPercent().floatValue();
StockQuoteItem stockQuoteItem = new StockQuoteItem();
stockQuoteItem.setName(name);
stockQuoteItem.setPrice(price);
stockQuoteItem.setChange(change);
stockQuoteItem.setPercentChange(percentChange);
Calendar from = Calendar.getInstance();
Calendar to = Calendar.getInstance();
from.add(Calendar.YEAR, -2);
// WARNING! Don't request historical data for a stock that doesn't exist!
// The request will hang forever X_x
List<HistoricalQuote> history = stock.getHistory(from, to, Interval.WEEKLY);
StringBuilder historyBuilder = new StringBuilder();
for (HistoricalQuote it : history) {
historyBuilder.append(it.getDate().getTimeInMillis());
historyBuilder.append(", ");
historyBuilder.append(it.getClose());
historyBuilder.append("\n");
}
stockQuoteItem.setHistoryBuilder(historyBuilder);
ContentValues quoteCV = new ContentValues();
quoteCV.put(Contract.Quote.COLUMN_SYMBOL, symbol);
quoteCV.put(Contract.Quote.COLUMN_NAME, name);
quoteCV.put(Contract.Quote.COLUMN_PRICE, price);
quoteCV.put(Contract.Quote.COLUMN_PERCENTAGE_CHANGE, percentChange);
quoteCV.put(Contract.Quote.COLUMN_ABSOLUTE_CHANGE, change);
quoteCV.put(Contract.Quote.COLUMN_HISTORY, historyBuilder.toString());
return stockQuoteItem;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
开发者ID:jkozh,项目名称:stockhawk,代码行数:56,代码来源:FetchStockTask.java
示例7: createEconomicPerDate
import yahoofinance.histquotes.HistoricalQuote; //导入依赖的package包/类
private Map<Date, Economic> createEconomicPerDate(
yahoofinance.Stock yahooStock) {
Map<Date, Economic> ret = null;
if (yahooStock != null) {
List<HistoricalQuote> history;
try {
Map<Date, Economic> economyMap = new TreeMap<Date, Economic>(
new Comparator<Date>() {
// reverse comparer to put the latest first
@Override
public int compare(Date first, Date second) {
return first.after(second) ? -1 : 1;
}
});
Economic economicForToday = extractTodayEconomic(yahooStock);
if (economicForToday != null
&& economicForToday.getDate() != null) {
economyMap
.put(economicForToday.getDate(), economicForToday);
}
// Calendar now = Calendar.getInstance();
// Long calendarMs = now.getTimeInMillis();
// Long days_7 = 7*24*60*60*1000L;
//
//
// Calendar lastWeek = Calendar.getInstance();
// lastWeek.setTimeInMillis(calendarMs - days_7);
// history = yahooStock.getHistory(lastWeek,now,Interval.DAILY);
// if (history != null) {
//
// for (HistoricalQuote h : history) {
// Calendar date = h.getDate();
// h.
// }
// }
ret = new ConcurrentHashMap<Date, Economic>(economyMap);
} catch (Exception e) {
log.error("cannot get history", e);
}
}
return ret;
}
开发者ID:charcode,项目名称:StockScreener,代码行数:45,代码来源:YahooDataConverterImpl.java
示例8: getDay
import yahoofinance.histquotes.HistoricalQuote; //导入依赖的package包/类
/**
* Returns one day of historical information
* @author Michael Bick
* @param daysAgo amount of days ago to get information from
* @return historical quote from a given amount of days ago
* @throws IOException
*/
public HistoricalQuote getDay(int daysAgo) throws IOException {
return getHistory(daysAgo, 1).get(0);
}
开发者ID:lnmangione,项目名称:Stock-Bot,代码行数:11,代码来源:Symbol.java
注:本文中的yahoofinance.histquotes.HistoricalQuote类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论