aboutsummaryrefslogtreecommitdiffstats
path: root/sql/dawn.sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql/dawn.sql')
-rw-r--r--sql/dawn.sql6
1 files changed, 4 insertions, 2 deletions
diff --git a/sql/dawn.sql b/sql/dawn.sql
index cbbb4087..597bb651 100644
--- a/sql/dawn.sql
+++ b/sql/dawn.sql
@@ -883,13 +883,15 @@ $$ LANGUAGE plpgsql;
CREATE OR REPLACE function tranche_factor(attach smallint, detach smallint,
index_factor float, cumulativeloss float)
RETURNS float AS $$
+-- index_factor and cumulativeloss are in percents, eg:
+-- tranche_factor(15::smallint, 25::smallint, 98, 0.71)
DECLARE
newattach float;
newdetach float;
BEGIN
-newattach:=LEAST(GREATEST((attach-100*cumulativeloss)/index_factor, 0), 1);
-newdetach:=LEAST(GREATEST((detach-100*cumulativeloss)/index_factor, 0), 1);
+newattach:=LEAST(GREATEST((attach-cumulativeloss)/index_factor, 0), 1);
+newdetach:=LEAST(GREATEST((detach-cumulativeloss)/index_factor, 0), 1);
RETURN (newdetach-newattach)/(detach-attach)*index_factor;
END;
$$ LANGUAGE plpgsql;