 finish off we're going to use that Monte Carlo simulation once again on a new application calculating out the minimum monthly payment for a loan so let's imagine I have some outstanding balance if many of you are college students watching this if you're in the class your college student but it's on YouTube so anyone can be watching it but let's imagine you took out a wonderful student loan that we all know and love of $20,000 and guess what that you got to pay that back that's America but it also has some interest rate attached to it roughly speaking I think it's like 2.7% annually so given that situation we could ask a simple question and without using financial formulas that are gonna kind of give us an approximation but they're one approximation what would be the minimum amount I would need to pay off or I would need to pay if I wanted to pay this off in let's say for example one year I know that's a lot to pay off in one year but just again where we're playing off of theory here how would we do this so again we have a simple formula for this and we use something like Monte Carlo to guess effectively we can design out something like a function called minimum monthly payment that takes in that balance and that rate now the first thing you're seeing here is I'm creating a sort of a constant this original balance is going to reset our balance every single time we finish a simulation the reason why is very similar to what we saw with our nested loop structures of where are we of resetting why so that we can do a process again so we're going to do that same process of being able to reset our value and very similar to what we saw with Newton's method where we are gonna make an initial guess what if I pay zero dollars will that magically pay off my loan in a year no of course not but it serves as our base of like okay we can grow from here so a a guess well I'll just call it sort of a guess with air quotes and then we just run our simulation every single time we see that balance is greater than zero after we're done running it reset it so in this case we're going to say once again we're only working off of one year but you could expand this to two years five years however many years you want you know pick the number of months and in our case we're going to say first I make my payment so whatever my balance was I'm going to pay fifty dollars to that so my balance is updated minus fifty dollars then apply interest so apply interest and arrest and again so the reason this is where sort of these orders for example could be flipped in that situation it depends on effectively when the interest on the loan is compounded is it compounded at the beginning of the month or the end of the month and I'm not getting into that nonsense but the question is basically does your payment happen first or does interest happen first have fun figuring that one out but the question once again is we do this 12 times run through it in our case run through every month if our balance is still greater than zero we did not effectively pay off our loan in the 12 months we attempted to reset balance so again we're just we start where we began with again our 20,000 and then increment payment by ten dollars this is only one approach there are a number of different approaches here or you could say let's increment by one dollar but I'm just short-handing it but effectively saying okay well zero dollars trying to pay off as our at zero dollars a month didn't pay off our loan so what if we paid ten dollars a month no then just playing this out you know verbally playing that out well no ten dollars a month didn't work what about 20 no one about 30 no what about 40 no what about 50 etc until we get to a value that actually works in our favor and so just so we can even see that in action I've built out this and I've added in some functions to format my money in my percentage sign so it looks nicer but that's you know in our case just a normal little thing and let's reset this so you don't just magically see the answer I know it was there and you can pause and you know but anyways so I've loaded in that memory and I have that same function just with more comments going on there but let's say for example let's say you know you didn't take all 20,000 that's actually a pretty smart play if you need $20,000 plus if you're working in all that stuff so let's say you accept $8,000 of your student loan it's still going to be at 2.7 roughly speaking percent interest so again okay I have $8,000 what would I need to pay a month to pay it off roughly speaking or what would I need to pay roughly each month to pay it off in one year so again I've set my variables I'm calculating out that payment and then just to kind of see what's going on here I'm gonna add in some flavor text to just draw this out a little to pay off your initial balance at your interest rate now this little bit here in the equaling zero or quotes this is effectively just a quick way in Python to say don't hit enter after you print instead of it be printing on two lines print it on one line okay so at our annual interest rate or at our percent interest in one year requires paying some amount of money a month okay to pay off $8,000 at 2.7% interest in one year requires paying roughly speaking $680 a month there you go that's a fun little calculator for some depressing times but again okay maybe you don't want to do 8,000 so we could expand this let's say I want to pay off a student loan in three years 36 months reset that to pay it off in three years okay to pay off that 8,000 loan at 2.2 hundred and forty dollars a month okay Google how much would I get for my kidneys on the black market