1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.nickokiss.investor.function;
22
23 import java.math.BigDecimal;
24
25 import com.nickokiss.investor.calc.CashFlowStreamCalc;
26 import com.nickokiss.investor.calc.MathCalc;
27 import com.nickokiss.investor.fin.element.CashFlowStream;
28 import com.nickokiss.investor.fin.element.creator.StreamElementCreator;
29 import com.nickokiss.investor.util.TkFinConstructionException;
30
31
32
33
34
35 public class InfiniteStreamPVFunction implements Function {
36
37 private MathCalc mathCalc = new MathCalc();
38
39 private CashFlowStream cashFlowStream = null;
40 private StreamElementCreator streamElementCreator = null;
41 private BigDecimal nominalInterestRate = null;
42
43 public InfiniteStreamPVFunction(CashFlowStream cashFlowStream, StreamElementCreator streamElementCreator, BigDecimal nominalInterestRate) {
44 this.cashFlowStream = cashFlowStream;
45 this.streamElementCreator = streamElementCreator;
46 this.nominalInterestRate = nominalInterestRate;
47 }
48
49 @Override
50 public BigDecimal getValue(BigDecimal parameter) throws TkFinConstructionException {
51 int quantity = parameter.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
52 CashFlowStreamCalc calc = new CashFlowStreamCalc();
53 CashFlowStream cashFlowCycle = cashFlowStream.getCopy();
54 cashFlowCycle.addElements(streamElementCreator, quantity);
55 return calc.getInfinitePresentValue(cashFlowCycle, nominalInterestRate, mathCalc.ONE);
56 }
57
58 }