All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fluxtion.server.lib.pnl.calculator.FeeInstrumentPosMtmAggregate Maven / Gradle / Ivy

The newest version!
/*
 * SPDX-FileCopyrightText: © 2024 Gregory Higgins 
 * SPDX-License-Identifier: AGPL-3.0-only
 */

package com.fluxtion.server.lib.pnl.calculator;

import com.fluxtion.runtime.dataflow.aggregate.AggregateFlowFunction;
import com.fluxtion.server.lib.pnl.FeeInstrumentPosMtm;
import com.fluxtion.server.lib.pnl.Trade;

public class FeeInstrumentPosMtmAggregate implements AggregateFlowFunction {
    private FeeInstrumentPosMtm feeInstrumentPosMtm = new FeeInstrumentPosMtm();

    @Override
    public FeeInstrumentPosMtm aggregate(Trade input) {
        final String bookName = input.getFeeInstrument().instrumentName();
        final double feePosition = input.getFee();
        feeInstrumentPosMtm.setBookName(bookName);
        feeInstrumentPosMtm.getFeesPositionMap().compute(input.getFeeInstrument(), (s, d) -> d == null ? feePosition : d + feePosition);
        return feeInstrumentPosMtm;
    }

    @Override
    public FeeInstrumentPosMtm get() {
        return feeInstrumentPosMtm;
    }

    @Override
    public FeeInstrumentPosMtm reset() {
        feeInstrumentPosMtm = new FeeInstrumentPosMtm();
        return feeInstrumentPosMtm;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy