本文整理汇总了Java中org.threeten.bp.ZonedDateTime.now方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.now方法的具体用法?Java ZonedDateTime.now怎么用?Java ZonedDateTime.now使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.threeten.bp.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runOneScenarioDataProvided
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public void runOneScenarioDataProvided() {
ViewFactory viewFactory = createViewFactory();
MarketDataEnvironmentFactory environmentFactory =
new MarketDataEnvironmentFactory(new EmptyMarketDataFactory());
DefaultEngine engine = new DefaultEngine(viewFactory, environmentFactory, MoreExecutors.sameThreadExecutor());
ZonedDateTime valuationTime = ZonedDateTime.now();
ScenarioMarketDataEnvironment marketDataEnvironment =
new ScenarioDataBuilder()
.addMulticurve("base", BUNDLE1, createMulticurve(Currency.USD, 1))
.addMulticurve("base", BUNDLE2, createMulticurve(Currency.EUR, 2))
.valuationTime("base", valuationTime)
.build();
List<?> trades = ImmutableList.of(createTrade());
CalculationArguments calcArgs = CalculationArguments.builder().build();
ScenarioResults scenarioResults = engine.runScenarios(CONFIG, marketDataEnvironment, calcArgs, trades);
Map<String, Results> resultsMap = scenarioResults.getResults();
assertEquals(1, resultsMap.size());
Results results = resultsMap.get("base");
assertNotNull(results);
assertEquals(1, results.getRows().size());
assertEquals(1, results.get(0).getItems().size());
assertEquals("col1", results.getColumnNames().get(0));
assertEquals(Pairs.of(1.0, 2.0), results.get(0, 0).getResult().getValue());
}
示例2: execute
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
final Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
// 1. Build the analytic derivative to be priced
final ZonedDateTime now = ZonedDateTime.now(executionContext.getValuationClock());
final FinancialSecurity security = (FinancialSecurity) target.getSecurity();
final ExternalId underlyingId = FinancialSecurityUtils.getUnderlyingId(security);
final InstrumentDefinition<?> defn = security.accept(_converter);
final InstrumentDerivative derivative = defn.toDerivative(now);
if (derivative.accept(LastTimeCalculator.getInstance()) < 0.0) {
throw new OpenGammaRuntimeException("Equity option has already settled; " + security.toString());
}
// 2. Build up the market data bundle
final StaticReplicationDataBundle market = buildMarketBundle(underlyingId, executionContext, inputs, target, desiredValues);
// 3. Create result properties
final ValueRequirement desiredValue = desiredValues.iterator().next();
final ValueProperties resultProperties = desiredValue.getConstraints().copy()
.with(ValuePropertyNames.FUNCTION, getUniqueId())
.get();
// 4. The Calculation - what we came here to do
return computeValues(derivative, market, inputs, desiredValues, target.toSpecification(), resultProperties);
}
示例3: testPositionSecurityWithoutObligorIsIgnored
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void testPositionSecurityWithoutObligorIsIgnored() {
SecurityDocument document = new SecurityDocument();
CashSecurity security = new CashSecurity(Currency.of("USD"),
ExternalSchemes.financialRegionId("US"),
ZonedDateTime.now(),
ZonedDateTime.now().plusYears(5),
DayCounts.ACT_360,
0.05,
100000);
ExternalId secId = ExternalId.of("SEC_ID", "12345");
security.addExternalId(secId);
document.setSecurity(security);
_securityMaster.add(document);
Position posn = new SimplePosition(BigDecimal.ONE, secId);
assertEquals(_aggregator.classifyPosition(posn), "N/A");
}
示例4: whenHandleShot_thenShowShotTittlePreviewAndAuthorAvatarAndCreationDate
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void whenHandleShot_thenShowShotTittlePreviewAndAuthorAvatarAndCreationDate() {
ZonedDateTime now = ZonedDateTime.now();
when(shotMock.creationDate()).thenReturn(now);
removeFromBucketPresenter.handleShot(shotMock);
verify(viewMock).setShotTitle(name);
verify(viewMock).showShotPreview(url);
verify(viewMock).showAuthorAvatar(url);
verify(viewMock).showShotCreationDate(now);
}
示例5: execute
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
final Clock snapshotClock = executionContext.getValuationClock();
final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
final FinancialSecurity security = (FinancialSecurity) target.getSecurity();
final Currency payCurrency = security.accept(ForexVisitors.getPayCurrencyVisitor());
final Currency receiveCurrency = security.accept(ForexVisitors.getReceiveCurrencyVisitor());
if (now.isAfter(security.accept(ForexVisitors.getExpiryVisitor()))) {
throw new OpenGammaRuntimeException("FX forward " + payCurrency.getCode() + "/" + receiveCurrency + " has expired");
}
final ValueRequirement desiredValue = desiredValues.iterator().next();
final String payCurveName = desiredValue.getConstraint(ValuePropertyNames.PAY_CURVE);
final String receiveCurveName = desiredValue.getConstraint(ValuePropertyNames.RECEIVE_CURVE);
final String payCurveConfig = desiredValue.getConstraint(ValuePropertyNames.PAY_CURVE_CALCULATION_CONFIG);
final String receiveCurveConfig = desiredValue.getConstraint(ValuePropertyNames.RECEIVE_CURVE_CALCULATION_CONFIG);
final String fullPayCurveName = payCurveName + "_" + payCurrency.getCode();
final String fullReceiveCurveName = receiveCurveName + "_" + receiveCurrency.getCode();
final YieldAndDiscountCurve payCurve = getPayCurve(inputs, payCurrency, payCurveName, payCurveConfig);
final YieldAndDiscountCurve receiveCurve = getReceiveCurve(inputs, receiveCurrency, receiveCurveName, receiveCurveConfig);
final Map<String, Currency> curveCurrency = new HashMap<>();
curveCurrency.put(fullPayCurveName, payCurrency);
curveCurrency.put(fullReceiveCurveName, receiveCurrency);
final Object baseQuotePairsObject = inputs.getValue(ValueRequirementNames.CURRENCY_PAIRS);
if (baseQuotePairsObject == null) {
throw new OpenGammaRuntimeException("Could not get base/quote pair data");
}
final CurrencyPairs baseQuotePairs = (CurrencyPairs) baseQuotePairsObject;
final YieldAndDiscountCurve[] curves;
final String[] allCurveNames;
curves = new YieldAndDiscountCurve[] {payCurve, receiveCurve };
allCurveNames = new String[] {fullPayCurveName, fullReceiveCurveName };
// Implementation note: The ForexSecurityConverter create the Forex with currency order pay/receive. The curve are passed in the same order.
final ForexSecurityConverter converter = new ForexSecurityConverter(baseQuotePairs);
final InstrumentDefinition<?> definition = security.accept(converter);
final Forex forex = (Forex) definition.toDerivative(now);
final YieldCurveBundle yieldCurves = new YieldCurveBundle(allCurveNames, curves);
final ValueProperties.Builder properties = getResultProperties(target, desiredValue);
final ValueSpecification spec = new ValueSpecification(_valueRequirementName, target.toSpecification(), properties.get());
return getResult(forex, yieldCurves, target, desiredValues, inputs, spec, executionContext);
}
示例6: runMultipleScenariosDataProvided
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public void runMultipleScenariosDataProvided() {
ViewFactory viewFactory = createViewFactory();
MarketDataEnvironmentFactory environmentFactory =
new MarketDataEnvironmentFactory(new EmptyMarketDataFactory());
DefaultEngine engine = new DefaultEngine(viewFactory, environmentFactory, MoreExecutors.sameThreadExecutor());
ZonedDateTime valuationTime = ZonedDateTime.now();
ScenarioMarketDataEnvironment marketDataEnvironment =
new ScenarioDataBuilder()
.addMulticurve("base", BUNDLE1, createMulticurve(Currency.USD, 1))
.addMulticurve("base", BUNDLE2, createMulticurve(Currency.EUR, 2))
.valuationTime("base", valuationTime)
.addMulticurve("s1", BUNDLE1, createMulticurve(Currency.USD, 3))
.addMulticurve("s1", BUNDLE2, createMulticurve(Currency.EUR, 4))
.valuationTime("s1", valuationTime)
.addMulticurve("s2", BUNDLE1, createMulticurve(Currency.USD, 5))
.addMulticurve("s2", BUNDLE2, createMulticurve(Currency.EUR, 6))
.valuationTime("s2", valuationTime)
.build();
List<?> trades = ImmutableList.of(createTrade());
CalculationArguments calcArgs = CalculationArguments.builder().build();
ScenarioResults scenarioResults = engine.runScenarios(CONFIG, marketDataEnvironment, calcArgs, trades);
Map<String, Results> resultsMap = scenarioResults.getResults();
assertEquals(3, resultsMap.size());
Results baseResults = resultsMap.get("base");
Results s1Results = resultsMap.get("s1");
Results s2Results = resultsMap.get("s2");
assertNotNull(baseResults);
assertNotNull(s1Results);
assertNotNull(s2Results);
assertEquals(Pairs.of(1.0, 2.0), baseResults.get(0, 0).getResult().getValue());
assertEquals(Pairs.of(3.0, 4.0), s1Results.get(0, 0).getResult().getValue());
assertEquals(Pairs.of(5.0, 6.0), s2Results.get(0, 0).getResult().getValue());
}
示例7: execute
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
final Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
final ZonedDateTime now = ZonedDateTime.now(executionContext.getValuationClock());
final Double cleanPrice = (Double) inputs.getValue(MARKET_VALUE);
final InstrumentDerivative bond = BondAndBondFutureFunctionUtils.getBondOrBondFutureDerivative(executionContext, target, now, inputs);
final T result = bond.accept(_calculator, cleanPrice);
final ValueSpecification spec = new ValueSpecification(_valueRequirementName, target.toSpecification(), getResultProperties());
return Collections.singleton(new ComputedValue(spec, result));
}
示例8: getVolatilitySurface
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
protected BlackVolatilitySurface<?> getVolatilitySurface(final FunctionExecutionContext executionContext,
final FunctionInputs inputs, final ComputationTarget target) {
// From the Security, we get strike and expiry information to compute implied volatility
// TODO: INDUSTRIALISE: The types we're concerned about: EquityOptionSecurity, EquityIndexOptionSecurity, EquityIndexFutureOptionSecurity
final EquityOptionSecurity security = (EquityOptionSecurity) target.getSecurity();
final double strike = security.getStrike();
final Expiry expiry = security.getExpiry();
if (expiry.getAccuracy().equals(ExpiryAccuracy.MONTH_YEAR) || expiry.getAccuracy().equals(ExpiryAccuracy.YEAR)) {
throw new OpenGammaRuntimeException("There is ambiguity in the expiry date of the target security.");
}
final ZonedDateTime expiryDate = expiry.getExpiry();
final ZonedDateTime valuationDT = ZonedDateTime.now(executionContext.getValuationClock());
double timeToExpiry = TimeCalculator.getTimeBetween(valuationDT, expiryDate);
if (timeToExpiry == 0) { // TODO: See JIRA [PLAT-3222]
timeToExpiry = 0.0015;
}
// From the curve requirements, we get the forward and zero coupon prices
final ForwardCurve forwardCurve = getForwardCurve(inputs);
final double forward = forwardCurve.getForward(timeToExpiry);
final double discountFactor = getDiscountingCurve(inputs).getDiscountFactor(timeToExpiry);
// From the market value, we can then invert the Black formula
final Object optionPriceObject = inputs.getComputedValue(MarketDataRequirementNames.MARKET_VALUE);
if (optionPriceObject == null) {
throw new OpenGammaRuntimeException("Could not get market value of underlying option");
}
final double spotOptionPrice = (double) optionPriceObject;
final double forwardOptionPrice = spotOptionPrice / discountFactor;
final double impliedVol = BlackFormulaRepository.impliedVolatility(forwardOptionPrice, forward, strike, timeToExpiry, 0.3);
final Surface<Double, Double, Double> surface = ConstantDoublesSurface.from(impliedVol);
final BlackVolatilitySurfaceMoneyness impliedVolatilitySurface = new BlackVolatilitySurfaceMoneyness(surface, forwardCurve);
return impliedVolatilitySurface;
}
示例9: execute
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
final Set<ValueRequirement> desiredValues) throws AsynchronousExecution {
final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues);
final ValueProperties properties = desiredValue.getConstraints();
final ZonedDateTime now = ZonedDateTime.now(executionContext.getValuationClock());
final InstrumentDerivative derivative = BondAndBondFutureFunctionUtils.getBondOrBondFutureDerivative(executionContext, target, now, inputs);
final S issuerCurves = (S) inputs.getValue(CURVE_BUNDLE);
final ValueSpecification spec = new ValueSpecification(_valueRequirementName, target.toSpecification(), properties);
final T result = derivative.accept(_calculator, issuerCurves);
return Collections.singleton(new ComputedValue(spec, result));
}
示例10: execute
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
final ZonedDateTime now = ZonedDateTime.now(executionContext.getValuationClock());
final EquityOptionSecurity option = (EquityOptionSecurity) target.getSecurity();
final Object curveObject = inputs.getValue(ValueRequirementNames.YIELD_CURVE);
if (curveObject == null) {
throw new NullPointerException("Could not get yield curve for option");
}
final YieldAndDiscountCurve curve = (YieldAndDiscountCurve) curveObject;
final Expiry expiry = option.getExpiry();
final double t = DateUtils.getDifferenceInYears(now, expiry.getExpiry());
final double b = curve.getInterestRate(t);
final ValueRequirement desiredValue = desiredValues.iterator().next();
return Collections.singleton(new ComputedValue(new ValueSpecification(ValueRequirementNames.COST_OF_CARRY, target.toSpecification(), desiredValue.getConstraints()), b));
}
示例11: otherSecurityType
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void otherSecurityType() {
SecurityMaster securityMaster = mock(SecurityMaster.class);
ExternalIdVisitor visitor = new ExternalIdVisitor(securityMaster);
FXForwardSecurity security = new FXForwardSecurity(Currency.GBP, 123, Currency.AUD, 321, ZonedDateTime.now(),
ExternalId.of("reg", "123"));
security.accept(visitor);
assertTrue(security.getExternalIdBundle().isEmpty());
}
示例12: createNewBucket
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public static BucketDB createNewBucket(String name, String description) {
return new BucketDB(null, name, description, 0, ZonedDateTime.now());
}
示例13: getTimeLabel
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public static String getTimeLabel(Context context, ZonedDateTime dateTime) {
String label;
ZonedDateTime now = ZonedDateTime.now();
Duration duration = Duration.between(dateTime, now);
if (duration.getSeconds() <= DateTimeFormatUtil.SEC) {
label = context.getString(R.string.about_sec_ago);
} else if (duration.getSeconds() >= SEC
&& duration.getSeconds() < HALF_OF_MIN) {
label = context.getString(R.string.few_sec_ago);
} else if (duration.getSeconds() > HALF_OF_MIN &&
duration.getSeconds() <= MINUTE_IN_SEC + HALF_MINUTE_IN_SEC) {
label = context.getString(R.string.about_minute_ago);
} else if (duration.getSeconds() > MINUTE_IN_SEC + HALF_MINUTE_IN_SEC
&& duration.getSeconds() <= HALF_HOUR_IN_SEC) {
label = context.getString(R.string.few_minutes_ago);
} else if (duration.getSeconds() > HALF_HOUR_IN_SEC
&& duration.getSeconds() <= HOUR_IN_SEC + HALF_HOUR_IN_SEC) {
label = context.getString(R.string.about_hour_ago);
} else if (duration.getSeconds() > HOUR_IN_SEC + HALF_HOUR_IN_SEC
&& duration.getSeconds() <= DAY_IN_SEC) {
label = context.getString(R.string.few_hours_ago);
} else if (duration.getSeconds() >= DAY_IN_SEC &&
duration.getSeconds() < DAY_IN_SEC + HALF_DAY_IN_SEC) {
label = context.getString(R.string.yesterday);
} else {
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern(DATE_PATTERN + " " + TWELVE_HOUR_CLOCK_PATTERN)
.withZone(ZoneId.systemDefault());
label = dateTime.format(formatter);
}
return label;
}
示例14: execute
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
final Trade trade = target.getTrade();
final FinancialSecurity security = (FinancialSecurity) trade.getSecurity();
final Currency currency = FinancialSecurityUtils.getCurrency(security);
final Clock snapshotClock = executionContext.getValuationClock();
final ZonedDateTime now = ZonedDateTime.now(snapshotClock);
final LocalDate localNow = now.toLocalDate();
final ValueRequirement desiredValue = desiredValues.iterator().next();
final ValueProperties constraints = desiredValues.iterator().next().getConstraints();
final String curveName = constraints.getValues(ValuePropertyNames.CURVE).iterator().next();
final String fullCurveName = curveName + "_" + currency.getCode();
final HistoricalTimeSeriesBundle timeSeries = HistoricalTimeSeriesFunctionUtils.getHistoricalTimeSeriesInputs(executionContext, inputs);
final ValueRequirement curveSpecRequirement = getCurveSpecRequirement(currency, curveName);
final String curveCalculationConfigName = desiredValue.getConstraint(ValuePropertyNames.CURVE_CALCULATION_CONFIG);
final ConfigSource configSource = OpenGammaExecutionContext.getConfigSource(executionContext);
final MultiCurveCalculationConfig curveCalculationConfig = _curveCalculationConfigSource.getConfig(curveCalculationConfigName);
if (curveCalculationConfig == null) {
throw new OpenGammaRuntimeException("Could not find curve calculation configuration named " + curveCalculationConfigName);
}
final String[] curveNames = curveCalculationConfig.getYieldCurveNames();
final String[] fullCurveNames = new String[curveNames.length];
for (int i = 0; i < curveNames.length; i++) {
fullCurveNames[i] = curveNames[i] + "_" + currency;
}
final String curveCalculationMethod = curveCalculationConfig.getCalculationMethod();
final YieldCurveBundle curves = YieldCurveFunctionUtils.getYieldCurves(inputs, curveCalculationConfig);
final YieldCurveBundle fixedCurves = YieldCurveFunctionUtils.getFixedCurves(inputs, curveCalculationConfig, _curveCalculationConfigSource);
final InstrumentDefinition<?> definition = _converter.convert(trade);
if (definition == null) {
throw new OpenGammaRuntimeException("Definition for trade " + trade + " was null");
}
final Object curveSpecObject = inputs.getValue(curveSpecRequirement);
if (curveSpecObject == null) {
throw new OpenGammaRuntimeException("Could not get " + curveSpecRequirement);
}
final InterpolatedYieldCurveSpecificationWithSecurities curveSpec = (InterpolatedYieldCurveSpecificationWithSecurities) curveSpecObject;
final InstrumentDerivative derivative = _dataConverter.convert(security, definition, now, fullCurveNames, timeSeries);
final YieldCurveBundle bundle = YieldCurveFunctionUtils.getYieldCurves(inputs, curveCalculationConfig);
final Object jacobianObject = inputs.getValue(ValueRequirementNames.YIELD_CURVE_JACOBIAN);
if (jacobianObject == null) {
throw new OpenGammaRuntimeException("Could not get " + ValueRequirementNames.YIELD_CURVE_JACOBIAN);
}
final double[][] array = FunctionUtils.decodeJacobian(jacobianObject);
final DoubleMatrix2D jacobian = new DoubleMatrix2D(array);
DoubleMatrix1D sensitivities;
if (curveCalculationMethod.equals(MultiYieldCurvePropertiesAndDefaults.PRESENT_VALUE_STRING)) {
final Object couponSensitivitiesObject = inputs.getValue(getCouponSensitivitiesRequirement(currency, curveCalculationConfigName));
if (couponSensitivitiesObject == null) {
throw new OpenGammaRuntimeException("Could not get " + ValueRequirementNames.PRESENT_VALUE_COUPON_SENSITIVITY);
}
final DoubleMatrix1D couponSensitivity = new DoubleMatrix1D(FunctionUtils.decodeCouponSensitivities(couponSensitivitiesObject));
sensitivities = CALCULATOR.calculateFromPresentValue(derivative, fixedCurves, curves, couponSensitivity, jacobian, NSC);
} else {
sensitivities = CALCULATOR.calculateFromParRate(derivative, fixedCurves, curves, jacobian, NSC);
}
if (curveCalculationMethod.equals(FXImpliedYieldCurveFunction.FX_IMPLIED)) {
final Currency domesticCurrency = ComputationTargetType.CURRENCY.resolve(curveCalculationConfig.getTarget().getUniqueId());
final Currency foreignCurrency = ComputationTargetType.CURRENCY.resolve(_curveCalculationConfigSource
.getConfig(curveCalculationConfig.getExogenousConfigData().keySet().iterator().next()).getTarget().getUniqueId());
return YieldCurveNodeSensitivitiesHelper.getInstrumentLabelledSensitivitiesForCurve(sensitivities, domesticCurrency, foreignCurrency, fullCurveNames, curves,
_fxForwardCurveSpecificationSource, _fxForwardCurveDefinitionSource, localNow, getResultSpec(target, currency, fullCurveName, curveCalculationConfigName));
}
return YieldCurveNodeSensitivitiesHelper.getInstrumentLabelledSensitivitiesForCurve(fullCurveName, bundle, sensitivities, curveSpec,
getResultSpec(target, currency, curveName, curveCalculationConfigName));
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:67,代码来源:InterestRateFutureYieldCurveNodeSensitivitiesFunction.java
示例15: execute
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
/**
* {@inheritDoc} <p>
* INPUT: We are taking a VolatilitySurfaceData object, which contains all number of missing data, plus strikes and vols are in percentages <p>
* OUTPUT: and converting this into a StandardVolatilitySurfaceData object, which has no empty values, expiry is in years, and the strike and vol scale is without unit (35% -> 0.35)
*/
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target, final Set<ValueRequirement> desiredValues) {
final ZonedDateTime valTime = ZonedDateTime.now(executionContext.getValuationClock());
final LocalDate valDate = valTime.toLocalDate();
final ValueRequirement desiredValue = Iterables.getOnlyElement(desiredValues);
final Object specificationObject = inputs.getValue(ValueRequirementNames.VOLATILITY_SURFACE_SPEC);
if (specificationObject == null) {
throw new OpenGammaRuntimeException("Could not get volatility surface specification");
}
final VolatilitySurfaceSpecification specification = (VolatilitySurfaceSpecification) specificationObject;
final String surfaceQuoteUnits = specification.getQuoteUnits();
// Get the volatility surface data object
final Object rawSurfaceObject = inputs.getValue(ValueRequirementNames.VOLATILITY_SURFACE_DATA);
if (rawSurfaceObject == null) {
throw new OpenGammaRuntimeException("Could not get volatility surface");
}
@SuppressWarnings("unchecked")
final VolatilitySurfaceData<Pair<Integer, Tenor>, Double> rawSurface = (VolatilitySurfaceData<Pair<Integer, Tenor>, Double>) rawSurfaceObject;
final VolatilitySurfaceData<Double, Double> stdVolSurface;
if (surfaceQuoteUnits.equals(SurfaceAndCubePropertyNames.VOLATILITY_QUOTE)) {
stdVolSurface = getSurfaceFromVolatilityQuote(valDate, rawSurface);
} else if (surfaceQuoteUnits.equals(SurfaceAndCubePropertyNames.PRICE_QUOTE)) {
// Get the forward curve
final Object forwardCurveObject = inputs.getValue(ValueRequirementNames.FORWARD_CURVE);
if (forwardCurveObject == null) {
throw new OpenGammaRuntimeException("Could not get forward curve");
}
final ForwardCurve forwardCurve = (ForwardCurve) forwardCurveObject;
stdVolSurface = getSurfaceFromPriceQuote(valDate, rawSurface, forwardCurve, specification);
} else {
throw new OpenGammaRuntimeException("Cannot handle quote units " + surfaceQuoteUnits);
}
// Return
final ValueProperties constraints = desiredValue.getConstraints().copy().with(ValuePropertyNames.FUNCTION, getUniqueId()).get();
final ValueSpecification stdVolSpec = new ValueSpecification(ValueRequirementNames.STANDARD_VOLATILITY_SURFACE_DATA, target.toSpecification(), constraints);
return Collections.singleton(new ComputedValue(stdVolSpec, stdVolSurface));
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:47,代码来源:EquityFutureOptionVolatilitySurfaceDataFunction.java