@Override public Instrument extract(FieldMap inMessage) { // if the symbol already contains the expiry information, go ahead and create it // if it doesn't, piece the expiry onto the symbol and use that String symbol = getSymbol(inMessage); if(symbol == null) { return null; } try { return Future.fromString(symbol); } catch (IllegalArgumentException ignored) {} // assume the symbol is the underlying, not the full symbol (this is the common case, it seems) // therefore, use the multi-argument constructor instead String expiry = OptionFromMessage.getExpiry(inMessage); if(expiry == null) { return null; } Future future = new Future(symbol, expiry); return future; } /* (non-Javadoc)
@Override public int compare(Future inO1, Future inO2) { return new CompareToBuilder().append(inO1.getSymbol(), inO2.getSymbol()) .append(inO1.getExpirationMonth(), inO2.getExpirationMonth()) .append(inO1.getExpirationYear(), inO2.getExpirationYear()).toComparison(); } }
/** * Gets the symbol in the form SYMBOL-YYYYMM or SYMBOL-YYYYMMDD as appropriate. * * @return a <code>String</code> value */ @Override public String getFullSymbol() { String symbol = getSymbol(); if(FUTURE_STRING.matcher(symbol).matches()) { return symbol; } return String.format("%s-%s", //$NON-NLS-1$ symbol, getExpiryAsString()); } /**
/** * Gets the instrument expiry as a <code>String</code> in the format <code>YYYYMM</code> or <code>YYYYMMDD</code> as appropriate. * * @return a <code>String</code> value */ public String getExpiryAsString() { if(getExpirationDay() != -1) { return String.format("%1$4d%2$s%3$2d", //$NON-NLS-1$ getExpirationYear(), getExpirationMonth().getMonthOfYear(), getExpirationDay()); } else { return String.format("%1$4d%2$s", //$NON-NLS-1$ getExpirationYear(), getExpirationMonth().getMonthOfYear()); } } /* (non-Javadoc)
/** * Gets the future maturity as a <code>MaturityMonthYear</code> value. * * @return a <code>MaturityMonthYear</code> value */ public final MaturityMonthYear getExpiryAsMaturityMonthYear() { return new MaturityMonthYear(String.format("%1$4d%2$s", //$NON-NLS-1$ getExpirationYear(), getExpirationMonth().getMonthOfYear())); } /**
/** * Creates a future position key. Note that account and traderId are converted to <code>null</code> if they only contain whitespace. * * @param inSymbol a <code>String</code> value * @param inExpiry a <code>String</code> value * @param inAccount a <code>String</code> value * @param inTraderId a <code>String</code> value * @throws IllegalArgumentException if one of the given parameters are invalid */ public static PositionKey<Future> createFutureKey(String inSymbol, @Nullable String inExpiry, @Nullable String inAccount, @Nullable String inTraderId) { return createKey(new Future(inSymbol, inExpiry), inAccount, inTraderId); } /**
@Override public void validate(Instrument inInstrument) throws OrderValidationException { Future option = (Future)inInstrument; validateExpirationYear(option.getExpirationYear()); } }
int maturityDay = future.getExpirationDay(); switch(FIXVersion.getFIXVersion(inBeginString)){ case FIX_SYSTEM: //fall through inBeginString, inMessage); inMessage.setField(future.getExpiryAsMaturityMonthYear()); if(maturityDay != -1) { inMessage.setField(new MaturityDay(String.valueOf(maturityDay)));
@Override public Instrument resolveSymbol(String inSymbol) { if(FIX_SYMBOL_PATTERN.matcher(inSymbol).matches()) { return Future.fromString(inSymbol); } return null; } /* (non-Javadoc)
/** * Sets the CFI Code on the given <code>Message</code> for the given <code>Future</code>. * * @param inMessage a <code>FieldMap</code> value * @param inFuture a <code>Future</code> value */ private static void setCFICode(FieldMap inMessage, Future inFuture) { String cfiCode = CFICodeUtils.getCFICode(inFuture); if(cfiCode != null) { inMessage.setField(new CFICode(cfiCode)); } inMessage.setField(inFuture.getExpiryAsMaturityMonthYear()); } }
Validate.notNull(inExpiry, Messages.NULL_EXPIRY.getText()); Validate.isTrue(isValidDate(inExpiry), Messages.INVALID_EXPIRY.getText(inExpiry)); int year = Integer.parseInt(inExpiry.substring(0,
@Override public String generateSymbol(Instrument inInstrument) { if(inInstrument instanceof Future) { Future future = (Future)inInstrument; return future.getFullSymbol(); } else if(inInstrument instanceof Option) { Option option = (Option)inInstrument; return OptionUtils.getOsiSymbolFromOption(option); } else if(inInstrument instanceof Currency) { Currency currency = (Currency)inInstrument; return currency.getLeftCCY() + "/" + currency.getRightCCY(); } else { return inInstrument.getSymbol(); } } }
/** * Parses the given <code>String</code> to create a <code>Future</code> instrument. * * @param inFullSymbol a <code>String</code> value in the form <code>SYMBOL-YYYYMM</code> or <code>SYMBOL-YYYYMDD</code> * @return a <code>Future</code> value * @throws IllegalArgumentException if the given <code>String</code> cannot be parsed */ public static Future fromString(String inFullSymbol) { inFullSymbol = StringUtils.trimToNull(inFullSymbol); Validate.notNull(inFullSymbol, Messages.NULL_SYMBOL.getText()); if(!inFullSymbol.contains("-")) { throw new IllegalArgumentException(Messages.INVALID_SYMBOL.getText(inFullSymbol)); } int dashIndex = inFullSymbol.lastIndexOf('-'); assert(dashIndex != -1); String symbol = inFullSymbol.substring(0, dashIndex); String expiry = inFullSymbol.substring(dashIndex+1); return new Future(symbol, expiry); } /**
return Future.fromString(inSymbol); } catch (IllegalArgumentException ignored) {} try {
@Override public void set(Instrument inInstrument, DataDictionary inDictionary, String inMsgType, FieldMap inMessage) { setSecurityType(inInstrument, inDictionary, inMsgType, inMessage); setSymbol(inInstrument, inDictionary, inMsgType, inMessage); Future future = (Future)inInstrument; //set as many fields as are available in the dictionary. if(inDictionary.isMsgField(inMsgType, CFICode.FIELD)) { setCFICode(inMessage, future); } if(inDictionary.isMsgField(inMsgType, MaturityMonthYear.FIELD)) { inMessage.setField(future.getExpiryAsMaturityMonthYear()); } } /**
} else if(instrument instanceof Future) { Future future = (Future)instrument; positionKey = PositionKeyFactory.createFutureKey(future.getSymbol(), future.getExpiryAsString(), rpcAccount, rpcTraderId);
new Future(inUnderlyingSymbol, inExpirationMonth, inExpirationYear));