本文整理汇总了Java中org.threeten.bp.ZonedDateTime.of方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.of方法的具体用法?Java ZonedDateTime.of怎么用?Java ZonedDateTime.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.threeten.bp.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchHistoryOfChannel
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public List<SlackMessagePosted> fetchHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages) {
Map<String, String> params = new HashMap<>();
params.put("channel", channelId);
if (day != null) {
ZonedDateTime start = ZonedDateTime.of(day.atStartOfDay(), ZoneId.of("UTC"));
ZonedDateTime end = ZonedDateTime.of(day.atStartOfDay().plusDays(1).minus(1, ChronoUnit.MILLIS), ZoneId.of("UTC"));
params.put("oldest", convertDateToSlackTimestamp(start));
params.put("latest", convertDateToSlackTimestamp(end));
}
if (numberOfMessages > -1) {
params.put("count", String.valueOf(numberOfMessages));
} else {
params.put("count", String.valueOf(DEFAULT_HISTORY_FETCH_SIZE));
}
SlackChannel channel =session.findChannelById(channelId);
switch (channel.getType()) {
case INSTANT_MESSAGING:
return fetchHistoryOfChannel(params,FETCH_IM_HISTORY_COMMAND);
case PRIVATE_GROUP:
return fetchHistoryOfChannel(params,FETCH_GROUP_HISTORY_COMMAND);
default:
return fetchHistoryOfChannel(params,FETCH_CHANNEL_HISTORY_COMMAND);
}
}
示例2: fetchHistoryOfChannel
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public List<SlackMessagePosted> fetchHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages) {
Map<String, String> params = new HashMap<>();
params.put("channel", channelId);
if (day != null) {
ZonedDateTime start = ZonedDateTime.of(day.atStartOfDay(), ZoneId.of("UTC"));
ZonedDateTime end = ZonedDateTime.of(day.atStartOfDay().plusDays(1).minus(1, ChronoUnit.MILLIS), ZoneId.of("UTC"));
params.put("oldest", convertDateToSlackTimestamp(start));
params.put("latest", convertDateToSlackTimestamp(end));
}
if (numberOfMessages > -1) {
params.put("count", String.valueOf(numberOfMessages));
} else {
params.put("count", String.valueOf(1000));
}
return fetchHistoryOfChannel(params);
}
示例3: createIRFuture
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
private InterestRateFutureSecurity createIRFuture() {
Expiry expiry = new Expiry(ZonedDateTime.of(LocalDate.of(2014, 6, 18), LocalTime.of(0, 0), ZoneOffset.UTC));
String tradingExchange = "";
String settlementExchange = "";
Currency currency = Currency.USD;
double unitAmount = 1000;
ExternalId underlyingId = InterestRateMockSources.getLiborIndexId();
String category = "";
InterestRateFutureSecurity irFuture = new InterestRateFutureSecurity(expiry,
tradingExchange,
settlementExchange,
currency,
unitAmount,
underlyingId,
category);
// Need this for time series lookup
ExternalId irFutureId = ExternalSchemes.syntheticSecurityId("Test future");
irFuture.setExternalIdBundle(irFutureId.toBundle());
return irFuture;
}
示例4: toDerivativeNotFixed
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void toDerivativeNotFixed() {
final DayCount actAct = DayCounts.ACT_ACT_ISDA;
final ZonedDateTime zonedDate = ZonedDateTime.of(LocalDateTime.of(REFERENCE_DATE.toLocalDate(), LocalTime.MIDNIGHT), ZoneOffset.UTC);
final double paymentTime = actAct.getDayCountFraction(zonedDate, PAYMENT_DATE);
final double fixingTime = actAct.getDayCountFraction(zonedDate, FIXING_DATE);
final double fixingPeriodStartTime = actAct.getDayCountFraction(zonedDate, FRA_DEFINITION_1.getFixingPeriodStartDate());
final double fixingPeriodEndTime = actAct.getDayCountFraction(zonedDate, FRA_DEFINITION_1.getFixingPeriodEndDate());
final ForwardRateAgreement fra = new ForwardRateAgreement(CUR, paymentTime, ACCRUAL_FACTOR_PAYMENT, NOTIONAL, INDEX, fixingTime, fixingPeriodStartTime, fixingPeriodEndTime,
FRA_DEFINITION_1.getFixingPeriodAccrualFactor(), FRA_RATE);
final ForwardRateAgreement convertedFra = (ForwardRateAgreement) FRA_DEFINITION_1.toDerivative(REFERENCE_DATE);
assertEquals(convertedFra, fra);
assertEquals(fra, convertedFra);
final double shift = 0.01;
final DoubleTimeSeries<ZonedDateTime> fixingTS = ImmutableZonedDateTimeDoubleTimeSeries.of(FIXING_DATE, FRA_RATE + shift);
final ForwardRateAgreement convertedFra2 = (ForwardRateAgreement) FRA_DEFINITION_3.toDerivative(REFERENCE_DATE, fixingTS);
assertEquals(fra, convertedFra2);
}
示例5: testEqualsToAccuracy
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public void testEqualsToAccuracy() {
final ZonedDateTime zdtMinute = ZonedDateTime.of(LocalDateTime.of(2011, 7, 12, 12, 30, 0, 0), ZoneOffset.UTC);
final ZonedDateTime zdtHour = ZonedDateTime.of(LocalDateTime.of(2011, 7, 12, 12, 45, 0, 0), ZoneOffset.UTC);
final ZonedDateTime zdtDay = ZonedDateTime.of(LocalDateTime.of(2011, 7, 12, 11, 45, 0, 0), ZoneOffset.UTC);
final ZonedDateTime zdtMonth = ZonedDateTime.of(LocalDateTime.of(2011, 7, 11, 11, 45, 0, 0), ZoneOffset.UTC);
final ZonedDateTime zdtYear = ZonedDateTime.of(LocalDateTime.of(2011, 6, 11, 11, 45, 0, 0), ZoneOffset.UTC);
final ZonedDateTime zdtNone = ZonedDateTime.of(LocalDateTime.of(2010, 6, 11, 11, 45, 0, 0), ZoneOffset.UTC);
assertTrue(Expiry.equalsToAccuracy(ExpiryAccuracy.MIN_HOUR_DAY_MONTH_YEAR, zdtMinute, zdtMinute));
assertFalse(Expiry.equalsToAccuracy(ExpiryAccuracy.MIN_HOUR_DAY_MONTH_YEAR, zdtMinute, zdtHour));
assertTrue(Expiry.equalsToAccuracy(ExpiryAccuracy.HOUR_DAY_MONTH_YEAR, zdtHour, zdtMinute));
assertTrue(Expiry.equalsToAccuracy(ExpiryAccuracy.HOUR_DAY_MONTH_YEAR, zdtHour, zdtHour));
assertFalse(Expiry.equalsToAccuracy(ExpiryAccuracy.HOUR_DAY_MONTH_YEAR, zdtHour, zdtDay));
assertTrue(Expiry.equalsToAccuracy(ExpiryAccuracy.DAY_MONTH_YEAR, zdtDay, zdtHour));
assertTrue(Expiry.equalsToAccuracy(ExpiryAccuracy.DAY_MONTH_YEAR, zdtDay, zdtDay));
assertFalse(Expiry.equalsToAccuracy(ExpiryAccuracy.DAY_MONTH_YEAR, zdtDay, zdtMonth));
assertTrue(Expiry.equalsToAccuracy(ExpiryAccuracy.MONTH_YEAR, zdtMonth, zdtDay));
assertTrue(Expiry.equalsToAccuracy(ExpiryAccuracy.MONTH_YEAR, zdtMonth, zdtMonth));
assertFalse(Expiry.equalsToAccuracy(ExpiryAccuracy.MONTH_YEAR, zdtMonth, zdtYear));
assertTrue(Expiry.equalsToAccuracy(ExpiryAccuracy.YEAR, zdtYear, zdtMinute));
assertTrue(Expiry.equalsToAccuracy(ExpiryAccuracy.YEAR, zdtYear, zdtMonth));
assertTrue(Expiry.equalsToAccuracy(ExpiryAccuracy.YEAR, zdtYear, zdtYear));
assertFalse(Expiry.equalsToAccuracy(ExpiryAccuracy.YEAR, zdtYear, zdtNone));
}
示例6: testDeserialisation
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
* Tests that deserialising from JSON works.
*/
@Test
public void testDeserialisation() throws Exception
{
final Gson gson = Converters.registerAll(new GsonBuilder()).create();
final Container container = new Container();
container.ld = LocalDate.of(1969, 7, 21);
container.lt = LocalTime.of(12, 56, 0);
container.ldt = LocalDateTime.of(container.ld, container.lt);
container.odt = OffsetDateTime.of(container.ld, container.lt, ZoneOffset.ofHours(10));
container.ot = OffsetTime.of(container.lt, ZoneOffset.ofHours(10));
container.zdt = ZonedDateTime.of(container.ld, container.lt, ZoneId.of("Australia/Brisbane"));
container.i = container.odt.toInstant();
final JsonObject serialized = new JsonObject();
serialized.add("ld", new JsonPrimitive("1969-07-21"));
serialized.add("lt", new JsonPrimitive("12:56:00"));
serialized.add("ldt", new JsonPrimitive("1969-07-21T12:56:00"));
serialized.add("odt", new JsonPrimitive("1969-07-21T12:56:00+10:00"));
serialized.add("ot", new JsonPrimitive("12:56:00+10:00"));
serialized.add("zdt", new JsonPrimitive("1969-07-21T12:56:00+10:00[Australia/Brisbane]"));
serialized.add("i", new JsonPrimitive("1969-07-21T02:56:00Z"));
final String jsonString = gson.toJson(serialized);
final Container deserialised = gson.fromJson(jsonString, Container.class);
assertThat(deserialised.ld, is(container.ld));
assertThat(deserialised.ldt, is(container.ldt));
assertThat(deserialised.lt, is(container.lt));
assertThat(deserialised.odt, is(container.odt));
assertThat(deserialised.ot, is(container.ot));
assertThat(deserialised.zdt, is(container.zdt));
assertThat(deserialised.i, is(container.i));
}
示例7: createInterestRateFutureSecurity
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
private InterestRateFutureSecurity createInterestRateFutureSecurity(Currency currency) {
Expiry expiry = new Expiry(ZonedDateTime.of(LocalDate.of(2014, 6, 18), LocalTime.of(0, 0), ZoneOffset.UTC));
String tradingExchange = "";
String settlementExchange = "";
double unitAmount = 1000;
ExternalId underlyingId = InterestRateMockSources.getLiborIndexId();
String category = "";
return new InterestRateFutureSecurity(expiry,
tradingExchange,
settlementExchange,
currency,
unitAmount,
underlyingId,
category);
}
示例8: adjustedDateSchedule_rollEom_notAtEom_forwards
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void adjustedDateSchedule_rollEom_notAtEom_forwards() {
ZonedDateTime start = ZonedDateTime.of(2012, 4, 22, 0, 0, 0, 0, ZoneOffset.UTC);
ZonedDateTime end = ZonedDateTime.of(2013, 1, 18, 0, 0, 0, 0, ZoneOffset.UTC);
Period freq = Period.ofMonths(3);
RollDateAdjuster eom = EndOfMonthRollDateAdjuster.getAdjuster();
ZonedDateTime[] test = ScheduleCalculator.getAdjustedDateSchedule(
start, end, freq, StubType.SHORT_END, MOD_FOL, CALENDAR, eom);
assertEquals(3, test.length);
assertEquals(ZonedDateTime.of(2012, 7, 23, 0, 0, 0, 0, ZoneOffset.UTC), test[0]);
assertEquals(ZonedDateTime.of(2012, 10, 22, 0, 0, 0, 0, ZoneOffset.UTC), test[1]);
assertEquals(ZonedDateTime.of(2013, 1, 18, 0, 0, 0, 0, ZoneOffset.UTC), test[2]);
}
示例9: createFFTrade
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
private FedFundsFutureTrade createFFTrade(LocalDate expiryDate, double tradePrice) {
Expiry expiry = new Expiry(ZonedDateTime.of(expiryDate, LocalTime.of(0, 0), ZoneOffset.UTC));
FederalFundsFutureSecurity fedFundsFuture =
new FederalFundsFutureSecurity(expiry, TRADING_EX, SETTLE_EX, CCY, UNIT_AMOUNT, FED_FUND_INDEX_ID, CATEGORY);
fedFundsFuture.setExternalIdBundle(ExternalSchemes.syntheticSecurityId("Test future").toBundle());
SimpleTrade trade = new SimpleTrade(fedFundsFuture, TRADE_QUANTITY, COUNTERPARTY, TRADE_DATE, TRADE_TIME);
trade.setPremiumCurrency(Currency.USD);
trade.setPremium(tradePrice);
return new FedFundsFutureTrade(trade);
}
示例10: workingDaysTest
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void workingDaysTest() {
ZonedDateTime d1 = ZonedDateTime.of(2014, 7, 21, 12, 0, 0, 0, UTC); // Monday
ZonedDateTime d2 = ZonedDateTime.of(2014, 7, 26, 12, 0, 0, 0, UTC); // Saturday
ZonedDateTime d3 = ZonedDateTime.of(2014, 8, 1, 12, 0, 0, 0, UTC); // Friday
assertEquals(5, getWorkingDaysInclusive(d1, d2, WEEKEND_CALENDAR)); //Monday to Saturday
assertEquals(10, getWorkingDaysInclusive(d1, d3, WEEKEND_CALENDAR)); //Monday to Friday week
assertEquals(5, getWorkingDaysInclusive(d2, d3, WEEKEND_CALENDAR)); //Saturday to Friday
}
示例11: dayBetweenTest
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void dayBetweenTest() {
ZonedDateTime d0 = ZonedDateTime.of(2013, 8, 1, 12, 0, 0, 0, UTC); // Thursday
ZonedDateTime d1 = ZonedDateTime.of(2014, 7, 21, 12, 0, 0, 0, UTC); // Monday
ZonedDateTime d2 = ZonedDateTime.of(2014, 7, 26, 12, 0, 0, 0, UTC); // Saturday
ZonedDateTime d3 = ZonedDateTime.of(2014, 7, 28, 12, 0, 0, 0, UTC); // Monday
ZonedDateTime d4 = ZonedDateTime.of(2014, 8, 1, 12, 0, 0, 0, UTC); // Friday
ZonedDateTime d5 = ZonedDateTime.of(2014, 7, 22, 12, 0, 0, 0, UTC); // Tuesday
//same day
assertEquals(0, getDaysBetween(d0, d0, WEEKEND_CALENDAR));
assertEquals(1, getDaysBetween(d1, d5, WEEKEND_CALENDAR)); //Monday to Tuesday
assertEquals(5, getDaysBetween(d1, d2, WEEKEND_CALENDAR)); //Monday to Saturday
assertEquals(5, getDaysBetween(d1, d3, WEEKEND_CALENDAR)); //Monday to following Monday
assertEquals(0, getDaysBetween(d2, d3, WEEKEND_CALENDAR)); //Saturday to Monday
assertEquals(4, getDaysBetween(d2, d4, WEEKEND_CALENDAR)); //Saturday to Friday
assertEquals(3, getDaysBetween(d2, d4, HOLIDAY_CALENDAR)); //Saturday to Friday (with Wednesday a holiday)
//additive over a weekend
assertEquals(getDaysBetween(d1, d3, HOLIDAY_CALENDAR), getDaysBetween(d1, d2, HOLIDAY_CALENDAR) + getDaysBetween(d2, d3, HOLIDAY_CALENDAR));
//long periods
assertEquals(261, getDaysBetween(d0, d4, WEEKEND_CALENDAR));
assertEquals(259, getDaysBetween(d0, d4, HOLIDAY_CALENDAR));
}
示例12: testTimes2
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
protected ZonedDateTime[] testTimes2() {
ZonedDateTime one = ZonedDateTime.of(2010, 2, 11, 0, 0, 0, 0, ZoneOffset.UTC);
ZonedDateTime two = ZonedDateTime.of(2010, 2, 12, 0, 0, 0, 0, ZoneOffset.UTC);
ZonedDateTime three = ZonedDateTime.of(2010, 2, 13, 0, 0, 0, 0, ZoneOffset.UTC);
ZonedDateTime four = ZonedDateTime.of(2010, 2, 14, 0, 0, 0, 0, ZoneOffset.UTC);
ZonedDateTime five = ZonedDateTime.of(2010, 2, 15, 0, 0, 0, 0, ZoneOffset.UTC);
ZonedDateTime six = ZonedDateTime.of(2010, 2, 16, 0, 0, 0, 0, ZoneOffset.UTC);
return new ZonedDateTime[] {one, two, three, four, five, six };
}
示例13: noDividendTest
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
* No dividend payment.
*/
@Test
public void noDividendTest() {
// construct data bundle
ExerciseDecisionType exerciseType = ExerciseDecisionType.AMERICAN;
int nExpiries = EXPIRY_DATES.length;
boolean[][] isCalls = new boolean[nExpiries][];
for (int i = 0; i < nExpiries; ++i) {
int nOptions = PUT_PRICES[i].length;
isCalls[i] = new boolean[nOptions];
Arrays.fill(isCalls[i], false);
}
double[] timeToExpiries = toDateToDouble(TRADE_DATE, EXPIRY_DATES);
double[] tau = new double[] {};
double[] alpha = new double[] {};
double[] beta = new double[] {};
AffineDividends dividend = new AffineDividends(tau, alpha, beta);
ForwardCurveAffineDividends forwardCurve = new ForwardCurveAffineDividends(SPOT, SINGLE_CURVE, dividend);
// Equivalent construction of forward curve
// YieldAndDiscountCurve constantCurve = YieldCurve.from(ConstantDoublesCurve.from(0.0));
// ForwardCurveYieldImplied forwardCurve = new ForwardCurveYieldImplied(SPOT, SINGLE_CURVE, constantCurve);
BlackVolatilitySurfaceStrike volSurface = createSurface(SPOT, timeToExpiries, STRIKES, PUT_PRICES, isCalls,
forwardCurve, exerciseType);
StaticReplicationDataBundle data = new StaticReplicationDataBundle(volSurface, SINGLE_CURVE, forwardCurve);
// Option 1
ZonedDateTime expiryDate1 = EXPIRY_DATES[1];
LocalDate settlementDate1 = BusinessDayDateUtils.addWorkDays(expiryDate1.toLocalDate(), 3, NYC);
double targetStrike1 = 53.5; // OTM
EquityOptionDefinition targetOption1Dfn = new EquityOptionDefinition(false, targetStrike1, USD,
exerciseType, expiryDate1, settlementDate1, 100.0, SettlementType.PHYSICAL);
EquityOption targetOption1 = targetOption1Dfn.toDerivative(TRADE_DATE);
double[] expected1 = new double[] {40.85549009446838, 13278.034280702223, -0.211236426949203, 0.0872436729523134,
-0.02991197901689341, -0.005364512793468524, 0.03390731790197594, -6865.183875849098, 2835.4193709501856,
-972.1393180490358, -174.346665787727, 1101.987831814218 };
assertOptionResult(targetOption1, NOTIONAL, data, expected1);
// Option 2
ZonedDateTime expiryDate2 = ZonedDateTime.of(2014, 6, 6, 15, 0, 0, 0, ZID); // between expiryDates[1] and expiryDates[1]
LocalDate settlementDate2 = BusinessDayDateUtils.addWorkDays(expiryDate2.toLocalDate(), 3, NYC);
double targetStrike2 = 58.5; // ITM
EquityOptionDefinition targetOption2Dfn = new EquityOptionDefinition(false, targetStrike2, USD,
exerciseType, expiryDate2, settlementDate2, 100.0, SettlementType.PHYSICAL);
EquityOption targetOption2 = targetOption2Dfn.toDerivative(TRADE_DATE);
double[] expected2 = new double[] {388.8222088041128, 126367.21786133666, -0.6378366779223801, 0.0625115852644212,
-0.015518137566435322, -0.07812902673210956, 0.09324125158922084, -20729.692032477353, 2031.626521093689,
-504.33947090914796, -2539.1933687935607, 3030.340676649677 };
assertOptionResult(targetOption2, NOTIONAL, data, expected2);
}
示例14: visitBondNode
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
@Override
public InstrumentDefinition<?> visitBondNode(BondNode bondNode) {
Double yield = _marketData.getDataPoint(_dataId);
if (yield == null) {
throw new OpenGammaRuntimeException("Could not get market data for " + _dataId);
}
// TODO this is in here because we can't ask for data by ISIN directly.
BondSecurity bondSecurity = SecurityLink.resolvable(_dataId, BondSecurity.class).resolve();
ExternalId regionId = ExternalSchemes.financialRegionId(bondSecurity.getIssuerDomicile());
if (regionId == null) {
throw new OpenGammaRuntimeException("Could not find region for " + bondSecurity.getIssuerDomicile());
}
Calendar calendar = CalendarUtils.getCalendar(_regionSource, _holidaySource, regionId);
Currency currency = bondSecurity.getCurrency();
ZoneId zone = bondSecurity.getInterestAccrualDate().getZone();
ZonedDateTime firstAccrualDate =
ZonedDateTime.of(bondSecurity.getInterestAccrualDate().toLocalDate().atStartOfDay(), zone);
ZonedDateTime maturityDate =
ZonedDateTime.of(bondSecurity.getLastTradeDate().getExpiry().toLocalDate().atStartOfDay(), zone);
double rate = bondSecurity.getCouponRate() / 100;
DayCount dayCount = bondSecurity.getDayCount();
BusinessDayConvention businessDay = BusinessDayConventions.FOLLOWING;
String domicile = bondSecurity.getIssuerDomicile();
if (domicile == null) {
throw new OpenGammaRuntimeException("bond security domicile cannot be null");
}
String conventionName = domicile + "_TREASURY_BOND_CONVENTION";
ConventionBundle convention = _conventionSource.getConventionBundle(
ExternalId.of(InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME, conventionName));
if (convention == null) {
throw new OpenGammaRuntimeException("Convention called " + conventionName + " was null");
}
if (convention.isEOMConvention() == null) {
throw new OpenGammaRuntimeException("Could not get EOM convention information from " + conventionName);
}
boolean isEOM = convention.isEOMConvention();
YieldConvention yieldConvention = bondSecurity.getYieldConvention();
if (bondSecurity.getCouponType().equals("NONE") || bondSecurity.getCouponType().equals("ZERO COUPON")) { //TODO find where string is
return new PaymentFixedDefinition(currency, maturityDate, 1);
}
if (convention.getBondSettlementDays(firstAccrualDate, maturityDate) == null) {
throw new OpenGammaRuntimeException("Could not get bond settlement days from " + conventionName);
}
int settlementDays = convention.getBondSettlementDays(firstAccrualDate, maturityDate);
int exCouponDays = convention.getExDividendDays();
Period paymentPeriod = ConversionUtils.getTenor(bondSecurity.getCouponFrequency());
ZonedDateTime firstCouponDate =
ZonedDateTime.of(bondSecurity.getFirstCouponDate().toLocalDate().atStartOfDay(), zone);
ExternalIdBundle identifiers = bondSecurity.getExternalIdBundle();
String isin = identifiers.getValue(ExternalSchemes.ISIN);
String ticker = isin == null ? null : isin;
String shortName = bondSecurity.getIssuerName();
String sectorName = bondSecurity.getIssuerType();
FlexiBean classifications = new FlexiBean();
classifications.put(LegalEntityUtils.MARKET_STRING, bondSecurity.getMarket());
Sector sector = Sector.of(sectorName, classifications);
Region region = Region.of(
bondSecurity.getIssuerDomicile(), Country.of(bondSecurity.getIssuerDomicile()), bondSecurity.getCurrency());
Map<String, String> securityAttributes = bondSecurity.getAttributes();
Set<CreditRating> creditRatings = null;
for (String ratingString : LegalEntityUtils.RATING_STRINGS) {
if (securityAttributes.containsKey(ratingString)) {
if (creditRatings == null) {
creditRatings = new HashSet<>();
}
creditRatings.add(CreditRating.of(securityAttributes.get(ratingString), ratingString, true));
}
}
LegalEntity legalEntity = new LegalEntity(ticker, shortName, creditRatings, sector, region);
BondFixedSecurityDefinition securityDefinition = BondFixedSecurityDefinition.from(currency, firstAccrualDate,
firstCouponDate, maturityDate, paymentPeriod, rate, settlementDays, exCouponDays, calendar, dayCount,
businessDay, yieldConvention, isEOM, legalEntity);
// TODO: PLAT-5253 Standard days to settlement are missing in bond description.
ZonedDateTime settleDate = ScheduleCalculator.getAdjustedDate(_valuationTime, settlementDays, calendar);
return BondFixedTransactionDefinition.fromYield(securityDefinition, 1, settleDate, yield);
// TODO: User should choose between yield and price.
}
示例15: buildSwap
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
* Demonstrate building an equity variance swap and adding time series of observations. Check that the realized variance
* and present value of the swap are as expected when all the observations are known
*/
@Test(description = "Demo")
public void buildSwap() {
EquityVarianceSwapDefinition def = new EquityVarianceSwapDefinition(s_ObsStartTime, s_ObsEndTime, s_SettlementTime, s_Ccy, s_Calendar, s_AnnualizationFactor, s_VolStrike, s_VolNotional, false);
ZonedDateTime obsDate = ZonedDateTime.of(2014, 8, 11, 12, 0, 0, 0, UTC);
EquityVarianceSwap varSwap = def.toDerivative(obsDate);
System.out.println("time to observation start: " + varSwap.getTimeToObsStart());
System.out.println("time to observation end: " + varSwap.getTimeToObsEnd());
System.out.println("time to settlement: " + varSwap.getTimeToSettlement());
System.out.println("Var Notional: " + varSwap.getVarNotional());
System.out.println("Vol Notional: " + varSwap.getVolNotional());
System.out.println("Annualization Factor: " + varSwap.getAnnualizationFactor());
// we haven't added any observations, so all historical observations are treated as disrupted
System.out.println("Observations disrupted: " + varSwap.getObsDisrupted());
System.out.println("Observations expected: " + varSwap.getObsExpected());
double[] obs = varSwap.getObservations();
System.out.println("Observations: " + obs.length);
// now add some randomly generated observations, and compute some values on the settlement date (i.e. all observations
// are in the past)
int observationDays = getWorkingDaysInclusive(s_ObsStartTime, s_ObsEndTime, s_Calendar);
System.out.println("\nObsevations added: " + observationDays);
LocalDate[] dates = new LocalDate[observationDays];
double[] Prices = new double[observationDays];
double[] logPrices = new double[observationDays];
double dailyDrift = (s_Drift - 0.5 * s_Vol * s_Vol) / s_AnnualizationFactor;
double dailySD = s_Vol / Math.sqrt(s_AnnualizationFactor);
dates[0] = s_ObsStartTime.toLocalDate();
Prices[0] = 100.0;
logPrices[0] = Math.log(100.0);
double sum2 = 0;
for (int i = 1; i < observationDays; i++) {
dates[i] = BusinessDayDateUtils.addWorkDays(dates[i - 1], 1, s_Calendar);
logPrices[i] = logPrices[i - 1] + dailyDrift + dailySD * NORMAL.nextRandom();
Prices[i] = Math.exp(logPrices[i]);
double rtn = logPrices[i] - logPrices[i - 1];
sum2 += rtn * rtn;
}
LocalDateDoubleTimeSeries ts = ImmutableLocalDateDoubleTimeSeries.of(dates, Prices);
varSwap = def.toDerivative(s_SettlementTime, ts);
System.out.println("Observations disrupted: " + varSwap.getObsDisrupted());
System.out.println("Observations expected: " + varSwap.getObsExpected());
obs = varSwap.getObservations();
System.out.println("Observations: " + obs.length);
double relVar = REALIZED_VOL_CAL.evaluate(varSwap);
// even with B-S dynamics, the realized variance will differ from the expected variance
System.out.println("Expected variance: " + s_Vol * s_Vol + ", realized variance: " + relVar);
double calRelVar = s_AnnualizationFactor / (observationDays - 1) * sum2;
assertEquals(calRelVar, relVar, 1e-15); // check the calculation inside RealizedVariance is correct
// check the price computed by VarianceSwapStaticReplication is as expected when all the observations are known
double calPV = s_VolNotional / 2 / s_VolStrike * (calRelVar - s_VolStrike * s_VolStrike);
StaticReplicationDataBundle market = new StaticReplicationDataBundle(s_FlatVolSurf, s_DiscountCurve, s_FwdCurve);
double pv = PRICER.presentValue(varSwap, market);
System.out.println("Variance swap value at settlement: " + pv);
assertEquals(calPV, pv, 1e-9);
}