powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Oracle [игнор отключен] [закрыт для гостей] / Расчет аннуитета
5 сообщений из 5, страница 1 из 1
Расчет аннуитета
    #39405193
Бакыт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Здравствуйте есть вот такой запрос который делает расчет аннуитетного платежа
Код: plsql
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.
with p as
 ( select 1000000 as debt_amt, to_date('01.03.2017','DD.MM.RRRR') as p_start_date, 12 as debt_term from dual)
, i as
 ( --select 3 as month_till, 0.01 as ir from dual union select 6, 10 from dual union all select 12, 30 from dual
    select (select debt_term from p) as month_till, 45 as ir from dual  
 )
, r as
 ( select ir, month_till, nvl(lead (month_till,1) over (partition by null order by month_till desc),0) + 1 as month_from from i)
, rc as
 ( select g.m, r.* , 1 / (1 + r.IR /100 / 12 ) as KPCost
   from (select level as m from dual connect by level <= (select debt_term from p) ) g
  left join r on g.m between r.month_from and month_till
 ) 
, coef as 
 ( select m, IR, KPCost, exp( sum ( ln(KPCost) ) over (ORDER BY m RANGE UNBOUNDED PRECEDING)) as sumKPCost from rc order by m
 )
, t (m, ir, main_debt, ttl_pay, profit_pay) as
 ( select  1 as m
         , (select to_char(ir,'999D99') || '%' from r where 1 between r.month_from and r.month_till) as ir
         , (select debt_amt from p) as main_debt
         , (select debt_amt / (select sum ( sumKPCost ) as MonthlyPay from coef) from p ) as ttl_pay
         , (select debt_amt from p)*(select ir/100/12 from r where 1 between r.month_from and r.month_till) as profit_pay 
   from dual
   union all
   select  m+1 as m
         , (select to_char(ir,'999D99') || '%' from r where m+1 between r.month_from and r.month_till) as ir   
         , main_debt-ttl_pay+profit_pay as main_debt
         , ttl_pay
         , (main_debt-ttl_pay+profit_pay)*(select ir/100/12 from r where m+1 between r.month_from and r.month_till) as profit_pay
   from t where m < (select debt_term from p)
 )
, ttl as 
(
 select add_months((select p_start_date from p),m) as pay_date, ttl_pay, profit_pay, ttl_pay-profit_pay as main_pay, main_debt-ttl_pay+profit_pay as rem_debt_amt from t order by 1 
)
select to_char(p_start_date,'DD.MM.RRRR') as "Дата платежа", 0 as "Платеж за период", 0 as "Вознаграждение", 0 as "Основной долг", debt_amt as "Остаток ости" from p
union all
select to_char(pay_date,'DD.MM.RRRR'), round(ttl_pay,2), round(profit_pay,2), round(main_pay,2), round(rem_debt_amt,2) from ttl
union all
select 'Итого', round(sum(ttl_pay),2), round(sum(profit_pay),2), round(sum(main_pay),2), null from ttl;



как этот запрос переделать чтобы строился график по следующим условиям:
выдан кредит 15.02.2017 на 12 месяцев с окончательным сроком погашения 05.02.2018 при этом хочет гасить по 5 числам месяца(когда зарплату получает)
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.02.2017 день выдачи
01.03.2017
01.04.2017
01.05.2017
01.06.2017
01.07.2017
01.08.2017
01.09.2017
01.10.2017
01.11.2017
01.12.2017
01.01.2018
01.02.2018
15.02.2018 окончательное погашение
...
Рейтинг: 0 / 0
Расчет аннуитета
    #39405217
Фотография SY
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Бакыт,

Код: plsql
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.
SQL> with t as (
  2             select date '2017-02-15' loan_date,12 loan_term from dual
  3            )
  4  select  case level
  5            when 1 then loan_date
  6            when loan_term + 2 then add_months(loan_date,loan_term)
  7            else add_months(trunc(loan_date,'mm'),level - 1)
  8          end dt
  9    from  t
 10    connect by level <= loan_term + 2 * sign(loan_date - trunc(loan_date,'mm'))
 11  /

DT
---------
15-FEB-17
01-MAR-17
01-APR-17
01-MAY-17
01-JUN-17
01-JUL-17
01-AUG-17
01-SEP-17
01-OCT-17
01-NOV-17
01-DEC-17
01-JAN-18
01-FEB-18
15-FEB-18

14 rows selected.

SQL>  



SY.
...
Рейтинг: 0 / 0
Расчет аннуитета
    #39405236
Бакыт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
SYБакыт,

Код: plsql
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.
SQL> with t as (
  2             select date '2017-02-15' loan_date,12 loan_term from dual
  3            )
  4  select  case level
  5            when 1 then loan_date
  6            when loan_term + 2 then add_months(loan_date,loan_term)
  7            else add_months(trunc(loan_date,'mm'),level - 1)
  8          end dt
  9    from  t
 10    connect by level <= loan_term + 2 * sign(loan_date - trunc(loan_date,'mm'))
 11  /

DT
---------
15-FEB-17
01-MAR-17
01-APR-17
01-MAY-17
01-JUN-17
01-JUL-17
01-AUG-17
01-SEP-17
01-OCT-17
01-NOV-17
01-DEC-17
01-JAN-18
01-FEB-18
15-FEB-18

14 rows selected.

SQL>  



SY.
Спасибо большое!!!
...
Рейтинг: 0 / 0
Расчет аннуитета
    #39405389
Бакыт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
сделал расчет ухожу в минус на последнем платеже
...
Рейтинг: 0 / 0
Расчет аннуитета
    #39405393
Бакыт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
если указать первый платеж на 1 апреля 2017 то, нормально считает
...
Рейтинг: 0 / 0
5 сообщений из 5, страница 1 из 1
Форумы / Oracle [игнор отключен] [закрыт для гостей] / Расчет аннуитета
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]