Python While loop Problems - python-3.x

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.

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

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:

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

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

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

Calculate hours needed to balance account?

I have an accounts excel sheet where you input all your expenses, all your incomes (gst inclusive), and it calculates how you are placed (E.G. -$717.75 for the month).
I It also gives you the gst content to pay $taxableIncome*3)/23 and a rough guide as to how much income tax you should put away $taxableIncome*0.17.
You also tell the program what your hourly rate is.
I am wanting to add to the program to allow it to tell you that you need to work X more hours this month to balance.
This wouldn't be soo hard,
$deficit/$hourlyRate = hours needed to work except for each additional hour worked we need to add ($hourlyRate*3)/23 to the gst expense, and add $hourlyRate*0.17 to the income tax expense.
This is the part I don't quite get how to work out.
So given an hourly rate of $21.00+gst = $24.15/h and a deficit of $717.75 how can I work out how many more hours I would need to work?
basically I am wondering how I can do a formula of
0 <= [(x1+x2+x3...)-(y1+y2+y3...)] / z1
Where x1 must increase until the entire formula equals 0, but as x1 increases, so must y1 and y2
x. = Income Source
y. = Expense
z. = Hourly Rate (gst inclusive)
Note that while the excel formula would be useful I am not expecting people to do the work for me, just a generic overview in pseudocode will work.
So, set:
gross new wage incl. gst - new gst - new income tax) =
-(current income - current expense) or -(Y-E)
where -(Y-E) >= 0
gross new wage - (gross new wage * 3/23) - (gross new wage * 0.17) = -(Y-E)
gross new wage * (1 - 3/23 - 0.17) = -(Y-E)
gross new wage = -(Y-E) / (1 - 3/23 - 0.17)
new hours * gross wage rate (incl. gst) = -(Y-E) / (1 - 3/23 - 0.17)
new hours = (-(Y-E) / (1 - 3/23 - 0.17)) / gross wage rate
That works, doesn't it?

Resources