<commit_before>/**
 * Copyright (C) 2009 - 2009 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.financial.var.covariance;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import cern.colt.matrix.DoubleMatrix2D;

import com.opengamma.engine.security.SecurityKey;
import com.opengamma.financial.covariance.CovarianceMatrixCalculator;
import com.opengamma.financial.var.StandardVaRDataBundle;
import com.opengamma.timeseries.DoubleTimeSeries;

/**
 * 
 * 
 * @author emcleod
 */
public class StandardVaRCovarianceMatrix {
  private final StandardVaRDataBundle _data;
  private final CovarianceMatrixCalculator _calculator;
  private DoubleMatrix2D _matrix;
  private List<SecurityKey> _keys;

  public StandardVaRCovarianceMatrix(final StandardVaRDataBundle data, final CovarianceMatrixCalculator calculator) {
    if (data == null)
      throw new IllegalArgumentException("VaR data bundle was null");
    if (calculator == null)
      throw new IllegalArgumentException("Covariance calculator was null");
    init(data, calculator);
    _data = data;
    _calculator = calculator;
  }

  private void init(final StandardVaRDataBundle data, final CovarianceMatrixCalculator calculator) {
    final Map<SecurityKey, DoubleTimeSeries> map = data.getAllReturnData();
    _keys = new ArrayList<SecurityKey>();
    final DoubleTimeSeries[] ts = new DoubleTimeSeries[map.size()];
    int count = 0;
    for (final Map.Entry<SecurityKey, DoubleTimeSeries> entry : map.entrySet()) {
      _keys.add(entry.getKey());
      ts[count++] = entry.getValue();
      count++;
    }
    _matrix = calculator.evaluate(ts);
  }

  public StandardVaRDataBundle getData() {
    return _data;
  }

  public CovarianceMatrixCalculator getCalculator() {
    return _calculator;
  }

  public DoubleMatrix2D getCovarianceMatrix() {
    return _matrix;
  }

  public List<SecurityKey> getSecurityKeys() {
    return _keys;
  }

  public StandardVaRCovarianceMatrix getSubSetMatrix(final Set<SecurityKey> keys) {
    return new StandardVaRCovarianceMatrix(getData().getSubSetBundle(keys), getCalculator());
  }

  public Double getCovariance(final SecurityKey key1, final SecurityKey key2) {
    final int index1 = _keys.indexOf(key1);
    if (index1 == -1)
      throw new IllegalArgumentException("Security " + key1 + " was not in the data set");
    final int index2 = _keys.indexOf(key2);
    if (index2 == -1)
      throw new IllegalArgumentException("Security " + key2 + " was not in the data set");
    return _matrix.getQuick(index1, index2);
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + (getCalculator() == null ? 0 : getCalculator().hashCode());
    result = prime * result + (getData() == null ? 0 : getData().hashCode());
    result = prime * result + (getSecurityKeys() == null ? 0 : getSecurityKeys().hashCode());
    result = prime * result + (getCovarianceMatrix() == null ? 0 : getCovarianceMatrix().hashCode());
    return result;
  }

  @Override
  public boolean equals(final Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    final StandardVaRCovarianceMatrix other = (StandardVaRCovarianceMatrix) obj;
    if (getCalculator() == null) {
      if (other.getCalculator() != null)
        return false;
    } else if (!getCalculator().equals(other.getCalculator()))
      return false;
    if (getData() == null) {
      if (other.getData() != null)
        return false;
    } else if (!getData().equals(other.getData()))
      return false;
    if (getSecurityKeys() == null) {
      if (other.getSecurityKeys() != null)
        return false;
    } else if (!getSecurityKeys().equals(other.getSecurityKeys()))
      return false;
    if (getCovarianceMatrix() == null) {
      if (other.getCovarianceMatrix() != null)
        return false;
    } else if (!getCovarianceMatrix().equals(other.getCovarianceMatrix()))
      return false;
    return true;
  }
}<commit_msg>Commented out the code in this class.<commit_after>/**
 * Copyright (C) 2009 - 2009 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.financial.var.covariance;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import cern.colt.matrix.DoubleMatrix2D;

import com.opengamma.engine.security.SecurityKey;
import com.opengamma.financial.covariance.CovarianceMatrixCalculator;
import com.opengamma.financial.var.StandardVaRDataBundle;
import com.opengamma.timeseries.DoubleTimeSeries;

/**
 * 
 * 
 * @author emcleod
 */
public class StandardVaRCovarianceMatrix {
/*
 *   private final StandardVaRDataBundle _data;
  private final CovarianceMatrixCalculator _calculator;
  private DoubleMatrix2D _matrix;
  private List<SecurityKey> _keys;


 *   public StandardVaRCovarianceMatrix(final StandardVaRDataBundle data, final CovarianceMatrixCalculator calculator) {
 
    if (data == null)
      throw new IllegalArgumentException("VaR data bundle was null");
    if (calculator == null)
      throw new IllegalArgumentException("Covariance calculator was null");
    init(data, calculator);
    _data = data;
    _calculator = calculator;
  }

  private void init(final StandardVaRDataBundle data, final CovarianceMatrixCalculator calculator) {
    final Map<SecurityKey, DoubleTimeSeries> map = data.getAllReturnData();
    _keys = new ArrayList<SecurityKey>();
    final DoubleTimeSeries[] ts = new DoubleTimeSeries[map.size()];
    int count = 0;
    for (final Map.Entry<SecurityKey, DoubleTimeSeries> entry : map.entrySet()) {
      _keys.add(entry.getKey());
      ts[count++] = entry.getValue();
      count++;
    }
    _matrix = calculator.evaluate(ts);
  }

  public StandardVaRDataBundle getData() {
    return _data;
  }

  public CovarianceMatrixCalculator getCalculator() {
    return _calculator;
  }

  public DoubleMatrix2D getCovarianceMatrix() {
    return _matrix;
  }

  public List<SecurityKey> getSecurityKeys() {
    return _keys;
  }

  public StandardVaRCovarianceMatrix getSubSetMatrix(final Set<SecurityKey> keys) {
    return new StandardVaRCovarianceMatrix(getData().getSubSetBundle(keys), getCalculator());
  }

  public Double getCovariance(final SecurityKey key1, final SecurityKey key2) {
    final int index1 = _keys.indexOf(key1);
    if (index1 == -1)
      throw new IllegalArgumentException("Security " + key1 + " was not in the data set");
    final int index2 = _keys.indexOf(key2);
    if (index2 == -1)
      throw new IllegalArgumentException("Security " + key2 + " was not in the data set");
    return _matrix.getQuick(index1, index2);
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + (getCalculator() == null ? 0 : getCalculator().hashCode());
    result = prime * result + (getData() == null ? 0 : getData().hashCode());
    result = prime * result + (getSecurityKeys() == null ? 0 : getSecurityKeys().hashCode());
    result = prime * result + (getCovarianceMatrix() == null ? 0 : getCovarianceMatrix().hashCode());
    return result;
  }

  @Override
  public boolean equals(final Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    final StandardVaRCovarianceMatrix other = (StandardVaRCovarianceMatrix) obj;
    if (getCalculator() == null) {
      if (other.getCalculator() != null)
        return false;
    } else if (!getCalculator().equals(other.getCalculator()))
      return false;
    if (getData() == null) {
      if (other.getData() != null)
        return false;
    } else if (!getData().equals(other.getData()))
      return false;
    if (getSecurityKeys() == null) {
      if (other.getSecurityKeys() != null)
        return false;
    } else if (!getSecurityKeys().equals(other.getSecurityKeys()))
      return false;
    if (getCovarianceMatrix() == null) {
      if (other.getCovarianceMatrix() != null)
        return false;
    } else if (!getCovarianceMatrix().equals(other.getCovarianceMatrix()))
      return false;
    return true;
  }*/
}
{'fraction_non_alphanumeric': 0.11583895853423337, 'fraction_numerical': 0.007955641272902604, 'mean_word_length': 3.7249430523917995, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5565719', 'n_tokens_mistral': 2570, 'n_tokens_neox': 2421, 'n_words': 636}