Mortgage calculator
up vote
0
down vote
favorite
my aim is to create mortgage calculator in python. I want it to calculate number of days between now, and fixed time in future. To get number od days, or months between two dates I use datetime , that you can see in my code. My problem is that i can't perform division operation on number of days returned by datetime function, because it is in wrong data type. Is there any option to change date type into integer?
import datetime
from datetime import date
import time
today=datetime.date.today()
d0=date(2021,11,29)
delta=d0-today
print(delta.days)
def diff_month(d1,d2,c1):
if c1=="monthly":
a=(d1.year - d2.year) * 12 + d1.month - d2.month
instalment = 1000000 / a
return (instalment)
if c1=="daily":
a=(d1-d2)
instalment=1000000/a.days
return (instalment)
# counter=diff_month(d0,today,"daily")
#instalment=1000000/counter
#print(type(counter))
#print(instalment)
print(diff_month(d0,today,"daily"))
Thanks in advance
edit:
Thanks for your advices, finally i do that in this way. The only problem is that monnthly payment is equal everytime, in reality it would not be equal, because number of days in each month is not constant, so i would rather use daily payment than monthly.
python date
add a comment |
up vote
0
down vote
favorite
my aim is to create mortgage calculator in python. I want it to calculate number of days between now, and fixed time in future. To get number od days, or months between two dates I use datetime , that you can see in my code. My problem is that i can't perform division operation on number of days returned by datetime function, because it is in wrong data type. Is there any option to change date type into integer?
import datetime
from datetime import date
import time
today=datetime.date.today()
d0=date(2021,11,29)
delta=d0-today
print(delta.days)
def diff_month(d1,d2,c1):
if c1=="monthly":
a=(d1.year - d2.year) * 12 + d1.month - d2.month
instalment = 1000000 / a
return (instalment)
if c1=="daily":
a=(d1-d2)
instalment=1000000/a.days
return (instalment)
# counter=diff_month(d0,today,"daily")
#instalment=1000000/counter
#print(type(counter))
#print(instalment)
print(diff_month(d0,today,"daily"))
Thanks in advance
edit:
Thanks for your advices, finally i do that in this way. The only problem is that monnthly payment is equal everytime, in reality it would not be equal, because number of days in each month is not constant, so i would rather use daily payment than monthly.
python date
2
But you do that correctly in your test before the function: call.dayson the timedelta object.
– Daniel Roseman
Nov 19 at 15:07
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
my aim is to create mortgage calculator in python. I want it to calculate number of days between now, and fixed time in future. To get number od days, or months between two dates I use datetime , that you can see in my code. My problem is that i can't perform division operation on number of days returned by datetime function, because it is in wrong data type. Is there any option to change date type into integer?
import datetime
from datetime import date
import time
today=datetime.date.today()
d0=date(2021,11,29)
delta=d0-today
print(delta.days)
def diff_month(d1,d2,c1):
if c1=="monthly":
a=(d1.year - d2.year) * 12 + d1.month - d2.month
instalment = 1000000 / a
return (instalment)
if c1=="daily":
a=(d1-d2)
instalment=1000000/a.days
return (instalment)
# counter=diff_month(d0,today,"daily")
#instalment=1000000/counter
#print(type(counter))
#print(instalment)
print(diff_month(d0,today,"daily"))
Thanks in advance
edit:
Thanks for your advices, finally i do that in this way. The only problem is that monnthly payment is equal everytime, in reality it would not be equal, because number of days in each month is not constant, so i would rather use daily payment than monthly.
python date
my aim is to create mortgage calculator in python. I want it to calculate number of days between now, and fixed time in future. To get number od days, or months between two dates I use datetime , that you can see in my code. My problem is that i can't perform division operation on number of days returned by datetime function, because it is in wrong data type. Is there any option to change date type into integer?
import datetime
from datetime import date
import time
today=datetime.date.today()
d0=date(2021,11,29)
delta=d0-today
print(delta.days)
def diff_month(d1,d2,c1):
if c1=="monthly":
a=(d1.year - d2.year) * 12 + d1.month - d2.month
instalment = 1000000 / a
return (instalment)
if c1=="daily":
a=(d1-d2)
instalment=1000000/a.days
return (instalment)
# counter=diff_month(d0,today,"daily")
#instalment=1000000/counter
#print(type(counter))
#print(instalment)
print(diff_month(d0,today,"daily"))
Thanks in advance
edit:
Thanks for your advices, finally i do that in this way. The only problem is that monnthly payment is equal everytime, in reality it would not be equal, because number of days in each month is not constant, so i would rather use daily payment than monthly.
python date
python date
edited Nov 19 at 17:02
asked Nov 19 at 15:06
Marcin
208
208
2
But you do that correctly in your test before the function: call.dayson the timedelta object.
– Daniel Roseman
Nov 19 at 15:07
add a comment |
2
But you do that correctly in your test before the function: call.dayson the timedelta object.
– Daniel Roseman
Nov 19 at 15:07
2
2
But you do that correctly in your test before the function: call
.days on the timedelta object.– Daniel Roseman
Nov 19 at 15:07
But you do that correctly in your test before the function: call
.days on the timedelta object.– Daniel Roseman
Nov 19 at 15:07
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Some suggestions:
On the line:
instalment=1000000/counter
You expect counter to contain the number of days. However, diff_month returns the number of months if c1 is "monthly". Fix this. make the function return the number of days in all cases.
The return value from diff_month is of type timedelta. Objects of this type have an attribute called days which is an integer, so you can write:
instalment=1000000/counter.days
I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
– Yakov Dan
Nov 19 at 16:55
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Some suggestions:
On the line:
instalment=1000000/counter
You expect counter to contain the number of days. However, diff_month returns the number of months if c1 is "monthly". Fix this. make the function return the number of days in all cases.
The return value from diff_month is of type timedelta. Objects of this type have an attribute called days which is an integer, so you can write:
instalment=1000000/counter.days
I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
– Yakov Dan
Nov 19 at 16:55
add a comment |
up vote
0
down vote
accepted
Some suggestions:
On the line:
instalment=1000000/counter
You expect counter to contain the number of days. However, diff_month returns the number of months if c1 is "monthly". Fix this. make the function return the number of days in all cases.
The return value from diff_month is of type timedelta. Objects of this type have an attribute called days which is an integer, so you can write:
instalment=1000000/counter.days
I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
– Yakov Dan
Nov 19 at 16:55
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Some suggestions:
On the line:
instalment=1000000/counter
You expect counter to contain the number of days. However, diff_month returns the number of months if c1 is "monthly". Fix this. make the function return the number of days in all cases.
The return value from diff_month is of type timedelta. Objects of this type have an attribute called days which is an integer, so you can write:
instalment=1000000/counter.days
Some suggestions:
On the line:
instalment=1000000/counter
You expect counter to contain the number of days. However, diff_month returns the number of months if c1 is "monthly". Fix this. make the function return the number of days in all cases.
The return value from diff_month is of type timedelta. Objects of this type have an attribute called days which is an integer, so you can write:
instalment=1000000/counter.days
answered Nov 19 at 15:19
Yakov Dan
381111
381111
I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
– Yakov Dan
Nov 19 at 16:55
add a comment |
I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
– Yakov Dan
Nov 19 at 16:55
I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
– Yakov Dan
Nov 19 at 16:55
I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
– Yakov Dan
Nov 19 at 16:55
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377447%2fmortgage-calculator%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
But you do that correctly in your test before the function: call
.dayson the timedelta object.– Daniel Roseman
Nov 19 at 15:07