/**
 * Copyright (C) 2011 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.financial.analytics.conversion;

import com.opengamma.OpenGammaRuntimeException;
import com.opengamma.analytics.financial.equity.variance.EquityVarianceSwapDefinition;
import com.opengamma.core.holiday.HolidaySource;
import com.opengamma.financial.convention.HolidaySourceCalendarAdapter;
import com.opengamma.financial.convention.calendar.Calendar;
import com.opengamma.financial.convention.frequency.Frequency;
import com.opengamma.financial.convention.frequency.PeriodFrequency;
import com.opengamma.financial.convention.frequency.SimpleFrequency;
import com.opengamma.financial.security.FinancialSecurityVisitorAdapter;
import com.opengamma.financial.security.equity.EquityVarianceSwapSecurity;
import com.opengamma.util.ArgumentChecker;
import com.opengamma.util.money.Currency;

/**
 * Converts {@link EquityVarianceSwapSecurity} to {@link EquityVarianceSwapDefinition}, which is required
 * for use in the analytics library.
 */
public class EquityVarianceSwapConverter extends FinancialSecurityVisitorAdapter<EquityVarianceSwapDefinition> {
  /** The holiday source */
  private final HolidaySource _holidaySource;

  /**
   * @param holidaySource Source for good business day information, not null
   */
  public EquityVarianceSwapConverter(final HolidaySource holidaySource) {
    ArgumentChecker.notNull(holidaySource, "holiday source");
    _holidaySource = holidaySource;
  }

  @Override
  public EquityVarianceSwapDefinition visitEquityVarianceSwapSecurity(final EquityVarianceSwapSecurity security) {
    final Currency currency = security.getCurrency();
    final Calendar calendar = new HolidaySourceCalendarAdapter(_holidaySource, currency);
    final Frequency frequency = security.getObservationFrequency();
    final PeriodFrequency periodFrequency;
    if (frequency instanceof PeriodFrequency) {
      periodFrequency = (PeriodFrequency) frequency;
    } else if (frequency instanceof SimpleFrequency) {
      periodFrequency = ((SimpleFrequency) frequency).toPeriodFrequency();
    } else {
      throw new OpenGammaRuntimeException("Can only handle PeriodFrequency and SimpleFrequency");
    }
    if (security.isParameterizedAsVariance()) {
      return EquityVarianceSwapDefinition.fromVarianceParams(security.getFirstObservationDate(), security.getLastObservationDate(),
          security.getSettlementDate(), periodFrequency,
          security.getCurrency(), calendar, security.getAnnualizationFactor(),
          security.getStrike(), security.getNotional(), true);
    }
    return EquityVarianceSwapDefinition.fromVegaParams(security.getFirstObservationDate(), security.getLastObservationDate(),
        security.getSettlementDate(), periodFrequency,
        security.getCurrency(), calendar, security.getAnnualizationFactor(),
        security.getStrike(), security.getNotional(), true);
  }

}

@@ -86,16 +86,17 @@
 anies%0A *
+ 
 %0A * Plea
@@ -191,56 +191,8 @@
 n;%0A%0A
-import com.opengamma.OpenGammaRuntimeException;%0A
 impo
@@ -460,209 +460,8 @@
 ar;%0A
-import com.opengamma.financial.convention.frequency.Frequency;%0Aimport com.opengamma.financial.convention.frequency.PeriodFrequency;%0Aimport com.opengamma.financial.convention.frequency.SimpleFrequency;%0A
 impo
@@ -1569,467 +1569,11 @@
 cy);
-%0A
    
- final Frequency frequency = security.getObservationFrequency();%0A    final PeriodFrequency periodFrequency;%0A    if (frequency instanceof PeriodFrequency) %7B%0A      periodFrequency = (PeriodFrequency) frequency;%0A    %7D else if (frequency instanceof SimpleFrequency) %7B%0A      periodFrequency = ((SimpleFrequency) frequency).toPeriodFrequency();%0A    %7D else %7B%0A      throw new OpenGammaRuntimeException(%22Can only handle PeriodFrequency and SimpleFrequency%22);%0A    %7D
 %0A   
@@ -1748,26 +1748,16 @@
 nDate(),
-%0A         
  securit
@@ -1782,35 +1782,8 @@
 e(),
- periodFrequency,%0A         
  sec
@@ -1804,32 +1804,42 @@
 ncy(), calendar,
+%0A         
  security.getAnn
@@ -1857,26 +1857,16 @@
 actor(),
-%0A         
  securit
@@ -2042,24 +2042,16 @@
 nDate(),
-%0A       
  securit
@@ -2076,33 +2076,8 @@
 e(),
- periodFrequency,%0A       
  sec
@@ -2106,16 +2106,24 @@
 alendar,
+%0A       
  securit
@@ -2149,24 +2149,16 @@
 actor(),
-%0A       
  securit

Remove observation frequency from VarianceSwapDefinition and EquityVarianceSwapDefinition