Commit 52eaf8ba authored by Jukka-Pekka Iivonen's avatar Jukka-Pekka Iivonen Committed by jpekka

Fixed frequency two and four. This functions should work now completely.

2000-07-18  Jukka-Pekka Iivonen  <iivonen@iki.fi>

	* src/functions/fn-financial.c (coupnum): Fixed frequency two and
	four.  This functions should work now completely.
parent f06b9ee5
2000-07-18 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c (coupnum): Fixed frequency two and
four. This functions should work now completely.
2000-07-16 Jody Goldberg <jgoldberg@home.com>
* src/border.c (style_border_draw) : Improve the look of diagonal double
......
2000-07-18 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c (coupnum): Fixed frequency two and
four. This functions should work now completely.
2000-07-16 Jody Goldberg <jgoldberg@home.com>
* src/border.c (style_border_draw) : Improve the look of diagonal double
......
2000-07-18 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c (coupnum): Fixed frequency two and
four. This functions should work now completely.
2000-07-16 Jody Goldberg <jgoldberg@home.com>
* src/border.c (style_border_draw) : Improve the look of diagonal double
......
2000-07-18 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c (coupnum): Fixed frequency two and
four. This functions should work now completely.
2000-07-16 Jody Goldberg <jgoldberg@home.com>
* src/border.c (style_border_draw) : Improve the look of diagonal double
......
2000-07-18 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c (coupnum): Fixed frequency two and
four. This functions should work now completely.
2000-07-16 Jody Goldberg <jgoldberg@home.com>
* src/border.c (style_border_draw) : Improve the look of diagonal double
......
2000-07-18 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c (coupnum): Fixed frequency two and
four. This functions should work now completely.
2000-07-16 Jody Goldberg <jgoldberg@home.com>
* src/border.c (style_border_draw) : Improve the look of diagonal double
......
2000-07-18 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c (coupnum): Fixed frequency two and
four. This functions should work now completely.
2000-07-16 Jody Goldberg <jgoldberg@home.com>
* src/border.c (style_border_draw) : Improve the look of diagonal double
......
......@@ -367,41 +367,6 @@ coupdaybs(GDate *settlement, GDate *maturity, int freq, int basis)
}
}
static int
coupnum(GDate *settlement, GDate *maturity, int freq, int basis)
{
int years, months, days;
GDateYear sy;
GDateMonth sm;
GDateDay sd;
sy = g_date_year (settlement);
sm = g_date_month (settlement);
sd = g_date_day (settlement);
years = g_date_year (maturity) - sy;
months = g_date_month (maturity) - sm;
days = g_date_day (maturity) - sd
+ (g_date_is_leap_year (sy) && sd==28 && sm==2);
if (freq == 1)
return years + (months > 0) + (months == 0 && days > 0);
else if (freq == 2)
return years*2
+ (months > 6) + (months == 6 && days > 0)
+ (months > 0) + (months == 0 && days > 0)
- (months <= -6);
else
return years*4
+ (months > 9) + (months == 9 && days > 0)
+ (months > 6) + (months == 6 && days > 0)
+ (months > 3) + (months == 3 && days > 0)
+ (months > 0) + (months == 0 && days > 0)
- (months <= -3)
- (months <= -6)
- (months <= -9);
}
static GDateDay
days_in_month(GDateYear year, GDateMonth month)
{
......@@ -429,6 +394,46 @@ days_in_month(GDateYear year, GDateMonth month)
}
}
static int
coupnum(GDate *settlement, GDate *maturity, int freq, int basis)
{
int years, months, days;
GDateYear sy, my;
GDateMonth sm, mm;
GDateDay sd, md;
sy = g_date_year (settlement);
sm = g_date_month (settlement);
sd = g_date_day (settlement);
my = g_date_year (maturity);
mm = g_date_month (maturity);
md = g_date_day (maturity);
years = my - sy;
months = mm - sm;
if (md == days_in_month (my, mm) && sd == days_in_month (sy, sm))
days = 0;
else
days = md - sd + (g_date_is_leap_year (sy) && sd==28 && sm==2);
if (freq == 1)
return years + (months > 0) + (months == 0 && days > 0);
else if (freq == 2)
return years*2
+ (months > 6) + (months == 6 && days > 0)
+ (months > 0) + (months == 0 && days > 0)
- (months < -6) - (months == -6 && days < 0);
else
return years*4
+ (months > 9) + (months == 9 && days > 0)
+ (months > 6) + (months == 6 && days > 0)
+ (months > 3) + (months == 3 && days > 0)
+ (months > 0) + (months == 0 && days > 0)
- (months < -3) - (months == -3 && days < 0)
- (months < -6) - (months == -6 && days < 0)
- (months < -9) - (months == -9 && days < 0);
}
static GDate *
coupncd(GDate *settlement, GDate *maturity, int freq, int basis)
{
......
......@@ -367,41 +367,6 @@ coupdaybs(GDate *settlement, GDate *maturity, int freq, int basis)
}
}
static int
coupnum(GDate *settlement, GDate *maturity, int freq, int basis)
{
int years, months, days;
GDateYear sy;
GDateMonth sm;
GDateDay sd;
sy = g_date_year (settlement);
sm = g_date_month (settlement);
sd = g_date_day (settlement);
years = g_date_year (maturity) - sy;
months = g_date_month (maturity) - sm;
days = g_date_day (maturity) - sd
+ (g_date_is_leap_year (sy) && sd==28 && sm==2);
if (freq == 1)
return years + (months > 0) + (months == 0 && days > 0);
else if (freq == 2)
return years*2
+ (months > 6) + (months == 6 && days > 0)
+ (months > 0) + (months == 0 && days > 0)
- (months <= -6);
else
return years*4
+ (months > 9) + (months == 9 && days > 0)
+ (months > 6) + (months == 6 && days > 0)
+ (months > 3) + (months == 3 && days > 0)
+ (months > 0) + (months == 0 && days > 0)
- (months <= -3)
- (months <= -6)
- (months <= -9);
}
static GDateDay
days_in_month(GDateYear year, GDateMonth month)
{
......@@ -429,6 +394,46 @@ days_in_month(GDateYear year, GDateMonth month)
}
}
static int
coupnum(GDate *settlement, GDate *maturity, int freq, int basis)
{
int years, months, days;
GDateYear sy, my;
GDateMonth sm, mm;
GDateDay sd, md;
sy = g_date_year (settlement);
sm = g_date_month (settlement);
sd = g_date_day (settlement);
my = g_date_year (maturity);
mm = g_date_month (maturity);
md = g_date_day (maturity);
years = my - sy;
months = mm - sm;
if (md == days_in_month (my, mm) && sd == days_in_month (sy, sm))
days = 0;
else
days = md - sd + (g_date_is_leap_year (sy) && sd==28 && sm==2);
if (freq == 1)
return years + (months > 0) + (months == 0 && days > 0);
else if (freq == 2)
return years*2
+ (months > 6) + (months == 6 && days > 0)
+ (months > 0) + (months == 0 && days > 0)
- (months < -6) - (months == -6 && days < 0);
else
return years*4
+ (months > 9) + (months == 9 && days > 0)
+ (months > 6) + (months == 6 && days > 0)
+ (months > 3) + (months == 3 && days > 0)
+ (months > 0) + (months == 0 && days > 0)
- (months < -3) - (months == -3 && days < 0)
- (months < -6) - (months == -6 && days < 0)
- (months < -9) - (months == -9 && days < 0);
}
static GDate *
coupncd(GDate *settlement, GDate *maturity, int freq, int basis)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment