本文整理汇总了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();
}
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}