public static MovingAverages calcMovingAverages(List<HistoryRecord> records, boolean isEMA, int period) {
		if( records == null || records.isEmpty() )
			return null;
		
		MovingAverages mas = new MovingAverages();
		mas.setSymbol(records.get(0).getSymbol());
		mas.setEMA(isEMA);
		mas.setPeriod(period);
		List<MovingAverage> maList = new ArrayList<MovingAverage>();
		mas.setMovingAverages(maList);
		
		BigDecimal prevEMA = null;
		BigDecimal EMAMultiplier = new BigDecimal(2).divide(new BigDecimal(period + 1), 4, BigDecimal.ROUND_HALF_UP);
		for( int i=0; i<records.size(); i++ ) {
			Record r = records.get(i);
			MovingAverage ma = new MovingAverage();
			ma.setDate(r.getDate());
			ma.setSymbol(r.getSymbol());
			BigDecimal sma = calcSMA(records, i, period);
			if( !isEMA ) {
				ma.setValue(sma);
			} else {
				if( prevEMA == null ) {
					ma.setValue(sma);
				} else {
					ma.setValue(r.getValue().subtract(prevEMA).multiply(EMAMultiplier).add(prevEMA));
				}
				prevEMA = ma.getValue();
			}
			maList.add(ma);
		}
		
		return mas;
	}