<commit_before>package org.darcstarsolutions.finance.common.calculators;

import org.darcstarsolutions.finance.common.*;

import java.math.BigDecimal;

/**
 * Created by tetn on 10/16/14.
 */
public class AbstractInstrumentCalculator<T extends Instrument, U extends T> extends AbstractAssetCalculator<T, U> implements InstrumentCalculator<T, U> {

    protected AbstractInstrumentCalculator(AssetFactory<U> assetFactory) {
        super(assetFactory);
    }

    @Override
    public U determineParType(U instrument) {
        U newInstrument = getAssetFactory().copyAsset(instrument);
        BigDecimal parValue = newInstrument.getParValue();
        BigDecimal marketValue = newInstrument.getMarketValue();
        if ((parValue!= Instrument.NO_PAR_VALUE)&&(marketValue!=Instrument.NO_FACE_VALUE)){
            int comparison = parValue.compareTo(marketValue);
            if(comparison==0){
                newInstrument.setParType(ParType.AT);
            }else if(comparison < 0){
                newInstrument.setParType(ParType.BELOW);
            }
            else {
                newInstrument.setParType(ParType.ABOVE);
            }
        }
        else {
            newInstrument.setParType(ParType.NONE);
        }
        return newInstrument;
    }

    @Override
    public U calculateYield(U instrument) {
        U newInstrument = getAssetFactory().copyAsset(instrument);
        BigDecimal faceValue = newInstrument.getFaceValue();
        BigDecimal marketValue = newInstrument.getMarketValue();
        BigDecimal priceDifference = faceValue.subtract(marketValue);
        BigDecimal yield = priceDifference.divide(faceValue);
        newInstrument.setYield(yield);
        return newInstrument;
    }

    @Override
    public U calculateParValue(U instrument) {
        return null;
    }

    @Override
    public U calculateNetPresentValue(U instrument) {
        return null;
    }

    @Override
    public U calculateParValueAndDetermineParType(U instrument) {
        return null;
    }

    @Override
    public U add(U asset1, U asset2) {

        return null;
    }

    @Override
    public U subtract(U asset1, U asset2) {
        return null;
    }

    @Override
    public U negate(U asset) {
        return null;
    }
}<commit_msg>Updated API with Some Additional Functionality<commit_after>package org.darcstarsolutions.finance.common.calculators;

import org.darcstarsolutions.finance.common.*;

import java.math.BigDecimal;

/**
 * Created by tetn on 10/16/14.
 */
public abstract class AbstractInstrumentCalculator<T extends Instrument, U extends T> extends AbstractAssetCalculator<T, U> implements InstrumentCalculator<T, U> {

    protected AbstractInstrumentCalculator(AssetFactory<U> assetFactory) {
        this(assetFactory, CompoundingType.SIMPLE, CompoundingPeriod.ANNUAL);
    }

    protected AbstractInstrumentCalculator(AssetFactory<U> assetFactory, CompoundingType compoundingType, CompoundingPeriod compoundingPeriod) {
        super(assetFactory, compoundingType, compoundingPeriod);
    }


    @Override
    public U determineParType(U instrument) {
        U newInstrument = getAssetFactory().copyAsset(instrument);
        BigDecimal parValue = newInstrument.getParValue();
        BigDecimal marketValue = newInstrument.getMarketValue();
        ParType parType = determineParType(parValue, marketValue);
        newInstrument.setParType(parType);
        return newInstrument;
    }

    protected ParType determineParType(BigDecimal parValue, BigDecimal marketValue) {
        ParType parType = ParType.NONE;
        if ((parValue!= Instrument.NO_PAR_VALUE)&&(marketValue!=Instrument.NO_FACE_VALUE)){
            int comparison = parValue.compareTo(marketValue);
            if(comparison==0){
                parType = ParType.AT;
            }else if(comparison < 0){
                parType = ParType.BELOW;
            }
            else {
                parType = ParType.ABOVE;
            }
        } return parType;
    }

    @Override
    public U calculateYield(U instrument) {
        U newInstrument = getAssetFactory().copyAsset(instrument);
        BigDecimal faceValue = newInstrument.getFaceValue();
        BigDecimal marketValue = newInstrument.getMarketValue();
        BigDecimal priceDifference = faceValue.subtract(marketValue);
        BigDecimal yield = priceDifference.divide(faceValue);
        newInstrument.setYield(yield);
        return newInstrument;
    }

    @Override
    public U calculateParValue(U instrument) {
        U newInstrument = getAssetFactory().copyAsset(instrument);
        BigDecimal parValue = calculateInstrumentSpecificParValue(instrument);
        newInstrument.setParValue(parValue);
        return newInstrument;
    }

    protected abstract BigDecimal calculateInstrumentSpecificParValue(U instrument);

    @Override
    public U calculateNetPresentValue(U instrument) {
        U newInstrument = getAssetFactory().copyAsset(instrument);
        BigDecimal faceValue = newInstrument.getFaceValue();
        BigDecimal marketValue = newInstrument.getMarketValue();
        BigDecimal priceDifference = faceValue.subtract(marketValue);
        BigDecimal yield = priceDifference.divide(faceValue);
        newInstrument.setYield(yield);
        return newInstrument;
    }

    protected abstract BigDecimal calculateInstrumentSpecificNetPresentValue(U instrument);


    @Override
    public U calculateParValueAndDetermineParType(U instrument) {
        U newInstrument = calculateParValue(instrument);
        BigDecimal parValue = newInstrument.getParValue();
        BigDecimal marketValue = newInstrument.getMarketValue();
        ParType parType = determineParType(parValue, marketValue);
        newInstrument.setParType(parType);
        return newInstrument;
    }

}
{'fraction_non_alphanumeric': 0.08209982788296041, 'fraction_numerical': 0.0034423407917383822, 'mean_word_length': 3.0836261419536193, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 12, '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': '381835', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1527, 'n_words': 317}