Monthly Auto Loan Payment Amount - angularjs

I am trying to calculate an auto loan monthly payment amount of the front end using angularJS. My calcualtions are as follow and im not getting the right amount, the Results are returning 4
$scope.model.autoLoan.borrowAmount = 15000
$scope.model.autoLoan.interestRate = 3.25
$scope.model.autoLoan.loanLength = 60
var monthlyPayment = $scope.model.autoLoan.borrowAmount *
(($scope.model.autoLoan.interestRate / 12) *
(Math.pow((1 + ($scope.model.autoLoan.interestRate / 12)), $scope.model.autoLoan.loanLength))) /
(Math.pow((1 + ($scope.model.autoLoan.interestRate / 12)), $scope.model.autoLoan.loanLength) - 1);
console.log(monthlyPayment);
the console returns: 4062.502309286213 which should be retrunging something like 47.00. Not sure what I'm doing wrong here.

Related

Bybit API - How do I calculate qty in USDT Perpetual with leverage

I'm using bybit-api to create a conditional order but don't know how do I calculate quantity. Is it based on leveraged amount or original?
for example
I have balance of 50 USDT and want to use 100% per trade with following conditions.
BTC at price 44,089.50 with 50x leverage.
SHIB at price 0.030810 with 50x leverage.
How do I calculate the qty parameter?
https://bybit-exchange.github.io/docs/linear/#t-placecond
I trade Bitcoin through USDT Perpetuals (BTCUSDT). I've setup my own python API and created my own function to calculate quantity for cross margin:
def order_quantity(self, price:float, currency:str='USDT', leverage:float=50.0):
margin = self.get_wallet_balance(currency)
instrument = Instrument(self.query_instrument()[0], 'bybit')
if not price: # Market orders
last_trade = self.ws_get_last_trade() # private function to get last trade
lastprice = float(last_trade[-1]['price'])
else: # Limit orders
lastprice = price
totalbtc = float(margin[currency]['available_balance']) * (1 - instrument.maker_fee * leverage)
rawbtc = totalbtc / lastprice
btc = math.floor(rawbtc / instrument.lot_size) * instrument.lot_size
return min(btc,instrument.max_lot_size)
It is based on the leverage amount.
Your quantity should be :
qty = 50 USDT * 50 (leverage) / 44089 (BTC price) = 0.0567 BTC

React Native Timestamp query (firestore) not giving the right result

I have an query sorting by timestamp,
and I need to see only the data within last week
so I did
.dbRef
.where('regTime', '>', new Date( -7 * 24 * 60 * 60 * 1000)
but somehow not filtered by correct results.
anyone knows why?
seem to be less interesting / active programmers or people who like to help in react native,
so for future searchers:
let weekAgo = new Date();
let weekInMilliseconds = -7 * 24 * 60 * 60 * 1000;
weekAgo.setTime(weekAgo.getTime() + weekInMilliseconds);

How to convert timestap to hours and minutes in angularjs?

I want to count how many hours and minutes between two timestamp which are generated by Date.parse. After I get the difference, I need to convert it into hours and minutes like 2.10 (means, 2 hours and 10 minutes). Once I have read that to do it you need to divide it with 3600 so I tried this code but it just gives me 0.89 instead of 1.26.
var now = new Date();
var endTime = Date.parse(now)/1000;
var startTime = Date.parse("2018-03-16 10:29:17")/1000;
$scope.timestamp_difference = startTime - endTime;
$scope.hours = $scope.timestamp_difference/3600;
How to do it right?
In case you haven't heard, Momentjs makes working with dates and times pretty damn easy in javascript i updated code for you may hope it will helps you now
var date1 = moment('03/15/2018 11:00', 'MM/DD/YYYY hh:mm'),
date2 = moment('03/16/2018 10:00', 'MM/DD/YYYY hh:mm');
var duration = moment.duration(date2.diff(date1));
//you will get 23 hours 00 minute
alert(duration.asHours().toFixed(2))
http://jsfiddle.net/dp7rzmw5/9771/
Output: 23:00 hrs
function getTimeDifference(timestampDifference) {
var hours = ~~(timestampDifference / 3600);
var minuts = ~~((timestampDifference - hours * 3600) / 60);
var seconds = timestampDifference - hours * 3600 - minuts * 60;
return hours + '.' + minuts + '.' + seconds;
}
var minutes = "0" + Math.floor(timestampDifference / 60);
// get minutes
var seconds = "0" + Math.floor(timestampDifference - minutes * 60);
// get seconds
var hour = "0" + Math.floor(timestampDifference / 3600);
//get hour
if ( hour > 1 ) {
return hour.substr(-2) + ":" + minutes.substr(-2) + ":" + seconds.substr(-2);
} else {
return minutes.substr(-2) + ":" + seconds.substr(-2);
}
// check if the hour is greater then 1 than return time with hour else return minutes.

get the difference between 2 date & time by hours, minutes and seconds using cakephp

I'm trying to get the difference between a datetime and a current datetime using cakephp . I succeeded to get it but I want to convert it to only hours ,minutes and seconds .
here is my code :
$currDateTime = Time::now();
$date1 = $plan->start_day->format('Y-m-d');
$date2 = $currDateTime->format('Y-m-d');
$diff = abs(strtotime($date1) - strtotime($date2));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)) ;
$time1 = $plan->start_day->format('H:i:s');
$time2 = $currDateTime->format('H:i:s');
$seconds = abs(strtotime($time1) - strtotime($time2));
$hours = floor($seconds / 3600);
$mins = floor(($seconds - ($hours*3600)) / 60);
$secs = floor($seconds % 60);
the result is a difference in years, months, days, hours, minutes and seconds.
how can I convert it to only H:m:s ??
There's no need for all these calculations, simply create a DateInterval diff using the diff() method provided by the time object, and use the days, h, i, and s values it provides to create your desired output. The only calculation that would be required, would be to add the days in hours.
$diff = $currDateTime->diff($plan->start_day);
$formatted = sprintf('%02d:%02d:%02d', ($diff->days * 24) + $diff->h, $diff->i, $diff->s);
See also
PHP Manual > Date/Time > DateTimeInterface > DateTimeInterface::diff
PHP Manual > Date/Time > DateInterval

How to Get time 2 Hours from current time in IONIC

I need to book a vehicle.So i get date.BUt i didnt got the time.Actually i want to book at least 2 hours after current time.also i need to get full time from next day onwards please help me.Iam doing in Ionic framework and AngularJS
Thanks in Advance
var timeNow = new Date().getTime();
var twoHoursIntoFuture = new Date(time + 1000 * 60 * 60 * 2);
the new Date() creates a new date object from current time. getTime() gets the time in milliseconds since January 1st, 1970. Then we just add 2 hours into timeNow (1000 * 60 * 60 * 2 milliseconds) and make a new date object based on that.
Check http://www.w3schools.com/jsref/jsref_obj_date.asp for more date manipulation info.
this.myActualDate = new Date(new Date().getTime() + (3 * 24 * 60 * 60 * 1000)).toISOString().toString().substring(0, 10);
this.myMaxDate = new Date(new Date().getTime() + (368 * 24 * 60 * 60 * 1000)).toISOString();
<ion-datetime displayFormat="YYYY/MM/DD" pickerFormat="YYYY MMMM DDDD" min={{myActualDate}} max={{myMaxDate}} [(ngModel)]="myActualDate"
formControlName="booking_date" class="flex-date" required></ion-datetime>
You can modify this code to perform yours.
If you want to extend three days in actual date then you can edit 365 digit into 368.
It will add three days in your date.
I think it will also work for time.
If you edit hours , minutes and seconds.

Resources