trying to create a loan calculator on a website ( https://www.atlasfoundation.net/ ) and I am getting trouble in the coding of Python. The code is: - calculated-columns

trying to create a loan calculator on a website ( https://www.atlasfoundation.net/ ) and I am getting trouble in the coding of Python. The code is:
user enter the cost of the loan, the interest rate, and #the number of years for the loan
Calculate monthly payments with the following formula
M = L[i(1+i)n] / [(1+i)n-2]
M = monthly payment
L = Loan amount
i = interest rate (for an interest rate of 5%, i = 0.05)
n = number of payments
#Start of program
#Declare variables
monthlypayment = 0
loanamount = 0
interestrate = 0
numberofpayments = 0
loandurationinyears = 0
loanamount = raw_input("Lending Money ")
interestrate = raw_input("Interest Rates are? ")
loandurationinyears = raw_input("Time Duration in Years?")
#Convert the strings into floating numbers so we can use them in the formula
loandurationinyears = float(loandurationinyears)
loanamount = float(loanamount)
interestrate = float(interestrate)
#Since payments are once per month, number of payments is number of years for the loan
payments = loaninyears*12
#calculate the monthly payment based on the formula
payment = amount * interestrate * (7+ interestrate) * payments / ((1 + interestrate) * payments -1)
#Result to the program
print("Payment will be " + st(monthlypayment))
## Heading

Related

Margin level formula breakdown

I'm trying to make sense of the formula for margin level calculation as brought out here:
Margin Level = Total Asset Value / (Total Borrowed + Total Accrued Interest)
For example, if my collateral is 1 BTC, ETH/BTC price is 0.1 and I borrowed 10 ETH, how would the following values be calculated?
Total Asset Value
Total Borrowed
Total Accrued Interest
Is everything calculated in terms of base (ETH) or quote (BTC) asset?
Based on my intuition, I could come up with the following breakdown, but would like a confirmation.
For example, if hour = 1 (time of borrow) and eth_hourly_interest_rate = 0.001:
Total Asset Value = collateral + (borrowed * current_price) = 1 BTC + (10 ETH * 0.1) = 2 BTC
Total Borrowed = borrowed * price_at_borrow = 10 ETH * 0.1 = 1 BTC
Total Accrued Interest = hour * eth_hourly_interest_rate * current_price = 1 * 0.001 ETH * 0.1 = 0.0001 BTC
Therefore, margin level = 2 / (1 + 0.0001) = ~1.998
In this example, both current_price and price_at_borrow are the same for simplicity, but current_price would change in time while price_at_borrow will stay the same.
Total Accrued Interest for n hours = eth_hourly_interest_rate_hour(0,1) * eth_hourly_interest_rate_hour(1,n) * Total Borrowed * current price

How to get Budget amount from the beginning of the year through current day in Power BI

I need to calculate Projected Premium by Insurance Type.
The formula for calculation is:
Sum(Budget) - Sum(Budget thru current Day) * (1+BudgetVariance) + TotalPremium
BudgetVariance = (Premium - Budget tru current Day) / Budget tru current Day
Basically I got all variables I need (Thanks to Joe), but some of them don't calculate properly:
BudgetMTD =
VAR DaysOfMonth = MAXX(Dates, DAY(EOMONTH(Dates[Date], 0)))
VAR BudgetPerDayForMonth = SUM(BudgetData[Amount]) / DaysOfMonth
VAR DaysInMonthToToday = MAXX(Dates,
IF(Dates[Date] < TODAY(), DAY(Dates[Date]),
IF(Dates[Date] > TODAY(), 0,
DAY(TODAY())
)))
RETURN BudgetPerDayForMonth * DaysInMonthToToday
BudgetMTD should be 25,882,308 but it displays 30,148,763 (which is the total for 12 months).
Also BudgetVarianceMTD displays correctly for each month, but in a card I need it as:
(Premium - Budget tru current Day) / Budget tru current Day
Which is:
28,505,823 - 25,882,308 / 25,882,308 = 0.10136326
just a hint to get from beginning of the year to current day
DATEDIFF(month, '2017/01/01', GETDATE()) AS d

Python While loop Problems

I need a little help with this while loop. I have my Initial balance and a current balance. Is what I am trying to do is after the first initial balance the current balance needs to become the Initial and so on.
InitalPrice = float(input("Enter the Price of the Computer: "))
Month = 0
AnInterest = (InitalPrice - InitalPrice * .10) * .01 / 12
MonthlyPayment = (InitalPrice - InitalPrice * .10) * 0.05
Principal = MonthlyPayment - AnInterest
print("%0s%20s%20s%20s%13s%23s" %("Month", "Current Balance", "Interest Owed", "Principal Owed", "Payment", "Balance Remaining"))
while MonthlyPayment >= 0:
Month += 1
InitalPrice = InitalPrice - InitalPrice * .10
Balance = InitalPrice + AnInterest - MonthlyPayment
print("%0d Months%20.2f%20.3f%20.2f%13.2f%23.2f" %(Month, InitalPrice, AnInterest, Principal, MonthlyPayment, Balance))
if Balance <= 0:
break
Based on your description, I think this is more along the lines of what you are trying to do. I could be wrong about how the economics of a loan like this works, but I think you subtract the principal from the loan each month, recalculate your interest owed, and continue until you've payed off the entire balance. Let me know if this is wrong.
# Total price
price = float(input("Total computer cost:"))
# Price after down payment
remaining_price = (price * 0.9)
# Monthly payment (5 percent of remaining price)
monthly_payment = remaining_price * 0.05
# Interest owed for this month
interest_owed = remaining_price * (.12/12.0)
# Principal for this month
principal = monthly_payment - interest_owed
# Month
month = 0
# Print stuff
print("%0d Months%20.2f%20.3f%20.2f%13.2f%23.2f" %(month, price, interest_owed, principal, monthly_payment, remaining_price))
while remaining_price > 0:
month += 1
remaining_price -= principal
interest_owed = remaining_price * (.12/12.0)
principal = monthly_payment - interest_owed
print("%0d Months%20.2f%20.3f%20.2f%13.2f%23.2f" %(month, price, interest_owed, principal, monthly_payment, remaining_price))
There may be the edge case of the last month where you have officially paid off the balance, but I'm not sure how interest is calculated in that case.

excel NPV does not work properly

let us consider following example
Example: Invest $2,000 now, receive 3 yearly payments of $100 each, plus $2,500 in the 3rd year. Use 10% Interest Rate.
Let us work year by year (remembering to subtract what you pay out):
Now: PV = -$2,000
Year 1: PV = $100 / 1.10 = $90.91
Year 2: PV = $100 / 1.102 = $82.64
Year 3: PV = $100 / 1.103 = $75.13
Year 3 (final payment): PV = $2,500 / 1.103 = $1,878.29
Adding those up gets: NPV = -$2,000 + $90.91 + $82.64 + $75.13 + $1,878.29 = $126.97
Looks like a good investment.
i have tried to calculate same in excel
10%
100
100
100
2500
-2000
=NPV(A1,A2,A3,A4,A5)+A6
and got (43.78),why?please help me
You need to net your final year - 100 + 2500
The NPV function assumes each cell value is the money recieved at the end of its own year.
It is assuming that you are getting the 2500 a year after the last 100 dollar payment.
try this instead:
100
100
2600
NPV(.10,100,100,2600)-2000 = ~126.97

Excel Payment Formula

Can someone explain to me the PMT formula in excel?
=-PMT (
1) rate
2) nper
3) pv
4) [FV]
5) [Type] )
The above is the rough idea of what the pmt formula is. But am unsure about the ballooning payment and how to go about using this formula in excel.
Use the optional fv (future value) argument to record the balloon payment.
Loan = $200,000
Interest = 4.5%
Balloon = 120,000 after 10 years
Payments made monthly
=PMT(.045/12,10*12,-200000,120000)
Results in a payment of $1,279.11. After 120 payments, the loan balance will be $120,000. Note that the pv and fv argument signs must be opposite.
If your balloon payment isn't set but the term is
Loan = $200,000
Interest = 4.5%
Balloon = balance at 10 years
Monthly payment based on 30 year amortization
=PMT(.045/12,30*12,-200000)
=FV(0.045/12,10*12,1013.37,-200000)
The PMT function returns $1,013.37. This would be your payment to get the loan balance to zero after 30 years (360 payments). The FV function returns $160,178.96. This is the loan balance after 120 payments (10 years) of $1,013.37.

Resources