-
Notifications
You must be signed in to change notification settings - Fork 0
/
ElementarySecurity.java
104 lines (83 loc) · 2.3 KB
/
ElementarySecurity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.mbuse.finance.binominal.security;
import de.mbuse.finance.binominal.Binominal;
import de.mbuse.finance.binominal.LatticeConfiguration;
import de.mbuse.finance.binominal.Security;
import de.mbuse.finance.binominal.rate.Rate;
/**
* @author mbuse
*/
public class ElementarySecurity implements Security {
private LatticeConfiguration lattice;
public ElementarySecurity(LatticeConfiguration lattice) {
this.lattice = lattice;
}
public LatticeConfiguration getLattice() {
return lattice;
}
public Double getPrice() {
return 1.0;
}
public Double getValue(int t, int u) {
assert t >= u && u >= 0;
Double qu = lattice.getRiskFreePropabilityForUp();
Double qd = lattice.getRiskFreePropabilityForDown();
Rate rate = lattice.getRate();
if (t==0 && u==0) {
return getPrice();
}
else if (u==0) {
return qu * getValue(t-1, 0)/rate.getRateFactor(t-1, 0);
}
else if (u==t) {
return qd * getValue(t-1, u-1)/rate.getRateFactor(t-1, u-1);
}
else {
return qu * getValue(t-1, u-1)/rate.getRateFactor(t-1, u-1)
+ qd * getValue(t-1, u)/rate.getRateFactor(t-1, u);
}
}
public Double calculatePrice(Binominal<Double> payoffs, int maxt) {
Double price = .0;
for (int t=0; t<= maxt; t++) {
for (int u=0; u<=t; u++) {
price += payoffs.getValue(t, u) * getValue(t, u);
}
}
return price;
}
/**
* The price of a Zero-Coupon-Bond that matures at time t.
* The face-value of this bond is set to 1.
*
* This price is given by:
*
* P(t) = SUM_u=0..t ( getValue(t, u) )
**/
public Double getZCBPrice(int t) {
assert t >= 0;
double price = 0.0;
for (int i=0; i<=t; i++) {
price += getValue(t, i);
}
return price;
}
/**
* An array of Zero-Coupon-Bond prices, starting with t=0 and ending with t=maxT
* @return
*/
public double[] getZCBPrices(int maxT) {
double[] prices = new double[maxT + 1];
for (int t=0; t<=maxT; t++) {
prices[t] = getZCBPrice(t);
}
return prices;
}
@Override
public String toString() {
return "Elementary Security (lattice: " + lattice + ")";
}
}