public static ValueRequirement getValueRequirement( SecuritySource secMaster, final UnderlyingType underlying, final Security security) { if (security instanceof EquityOptionSecurity) { final EquityOptionSecurity option = (EquityOptionSecurity) security; switch (underlying) { case SPOT_PRICE: Security optionUnderlying = secMaster.getSecurity(ExternalIdBundle.of(option.getUnderlyingId())); return new ValueRequirement( MarketDataRequirementNames.MARKET_VALUE, ComputationTargetType.SECURITY, optionUnderlying.getUniqueId()); case SPOT_VOLATILITY: throw new NotImplementedException( "Don't know how to get spot volatility for " + option.getUniqueId()); case IMPLIED_VOLATILITY: throw new NotImplementedException( "Don't know how to get implied volatility for " + option.getUniqueId()); case INTEREST_RATE: return new ValueRequirement( ValueRequirementNames.YIELD_CURVE, ComputationTargetType.PRIMITIVE, option.getUniqueId()); case COST_OF_CARRY: throw new NotImplementedException( "Don't know how to get cost of carry for " + option.getUniqueId()); default: throw new NotImplementedException( "Don't know how to get ValueRequirement for " + underlying); } } throw new NotImplementedException( "Can only get ValueRequirements for options (was " + security + ")"); }
static void assertEquityOptionSecurity(EquityOptionSecurity expectedOption, Security sec) { assertNotNull(expectedOption); assertNotNull(sec); EquityOptionSecurity actualOption = (EquityOptionSecurity) sec; assertEquals(expectedOption.getExternalIdBundle(), actualOption.getExternalIdBundle()); assertEquals(expectedOption.getUniqueId(), actualOption.getUniqueId()); assertEquals(expectedOption.getSecurityType(), actualOption.getSecurityType()); assertEquals(expectedOption.getCurrency(), actualOption.getCurrency()); assertEquals(expectedOption.getOptionType(), actualOption.getOptionType()); assertTrue(expectedOption.getStrike() == actualOption.getStrike()); assertEquals(expectedOption.getExpiry(), actualOption.getExpiry()); assertEquals(expectedOption.getUnderlyingId(), actualOption.getUnderlyingId()); assertEquals(expectedOption.getName(), actualOption.getName()); // check the lot assertSecurity(expectedOption, sec); }