Простая доходность

 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
var clear_price = 101;
var rating = 100;
var calculation_date = new Date("2015, 04, 21");
var maturity_date = new Date("2019, 12, 11");
var coupon = 6.78;
var full_years;
function getFullYears() {
var days = Math.floor((maturity_date.getTime() - calculation_date.getTime()) / 24 / 60 / 60 / 1000);
var year = calculation_date.getYear();
var full_days = 0;
var keys = 0;
for (var i = calculation_date.getYear(); i <= maturity_date.getYear(); i++)
{
if (year % 4 == 0)
{
if(year % 100 == 0)
{
if(year % 400 == 0)
{
full_days += 366;
}
else
{
full_days += 365;
}
}
else
{
full_days += 366;
}
}
else
{
full_days += 365;
}
year++;
keys++;
}
full_days = full_days / keys;
this.full_years = days / full_days;
}
function getYieldPrice() {
var yield_price = (this.coupon + (this.rating - this.clear_price) / this.full_years) / ((this.rating + clear_price) / (2 * this.rating));
document.write(yield_price);
}