INFORMIX-SQL 7.3 Perform Screen:
Suppose I have a customer who wants to pay a $100 (7% tax included), what logic can I use
so that when the cashier clerk enters $100 in the tax included sale amount, it will
calculate the sale price and tax so that it adds up to $100.
I have the following 3 field tags in my Perform screen:
sprice = transaction.sale_price;
stax = transaction.sale_tax;
stotal = transaction.sale_total;
after editadd of transaction.sale_price
?...what goes here...?
If your problem is the formula then sprice = stotal * 100 / (100 + stax).
For example
$12345 * 100 / (100 + 7) = $11537.38
and adding 7% to $11537.38 gives you $12345.
Note of course that it may be impossible to find an exact amount of pennies that after adding a tax will give you a prescribed total.
To calculate disaggregated cost:
sprice = stotal / (1 + .07)
stax = sprice * .07
Finally round both figures. Depending on the rounding algorithm you may need to apply a penny offset if the resulting rounding operation is off by a cent so that all figures add up.
Basic algebra arithmetic:
93% = 93 per centum which is Latin for 93/100 = 0.93
Total receipt = p
Sale price + Tax = p
Sale price = 0.93p
Tax = 0.07p
4gl form:
sprice = transaction.sale_price,TYPE MONEY(7,2);
stax = transaction.sale_tax,TYPE MONEY(7,2);
stotal = transaction.sale_total,TYPE MONEY(7,2);
.....
INPUT ....
AFTER FIELD stotal
IF transaction.sale_total is NULL THEN
ERROR "Please enter total sale amount"
ELSE
LET transaction.sale_tax = 0.07 * transaction.sale_total
LET transaction.sale_price = 0.93 * transaction.sale_total
ENDIF
Related
According to the "Liqudity Math in uniswap v3", the liqudity of a position should be:
L = amt0 * (sqrt(upper) * sqrt(cprice)) / (sqrt(upper) - sqrt(cprice))
or
L = amt1 / (sqrt(cprice) - sqrt(lower))
I tried to calculate the liquidity of the below position on Arbitrum:
The nft token ID of the position is 69171, so I can get the liqudity by calling the contract(0xC36442b4a4522E871399CD717aBDD847Ab11FE88) on https://arbiscan.io
You can see it shows the liqudity is 50242219347523, and we can do more unit convertion:
Now I try to calcuate this number with the uniswap V3 math:
This is the output:
As we can see, the code output is very similar to the contract output, but if we look carefully, we will find the unit seems to be different. I know the unit of the contract ouput should be 'wei', but I don't know what the unit of the code results is. Can anybody help? Thanks.
I checked that position and pool. Best to query the current price from the pool's contract, for quick look the UI can be found at https://info.uniswap.org/#/arbitrum/pools/0x2f5e87c9312fa29aed5c179e456625d79015299c
The current price is shown as 11.9011 ETH per BTC, and there are 0.3122 BTC and 1.466 ETH in the pool. This gives:
price = 11.9011 * (1e18 / 1e8)
x = 0.3122 * 1e8
y = 1.466 * 1e18
The tick range of the position No. 69171 is 253300 to 259900. Use these values to calculate sp = sqrt(price) and the square roots of the price range boundaries, and from them, the liquidity:
sp = price ** 0.5
sa = 1.0001 ** (253300 // 2)
sb = 1.0001 ** (259900 // 2)
Lx = x * sp * sb / (sb - sp)
Ly = y / (sp - sa)
L = min(Lx, Ly)
The result Lx is 49905251975363.266 and Ly is 51071435112054.96. The Etherscan info shows liquidity L=50242219347523, in between these two values, which have a few % difference. A few % is an acceptable error given the imprecise input values used in this calculation; the UI shows the price and amount values in a rounded format.
I'm looking to calculate and plot the funding rate of Binance BTCUSDT Perpetual and have come across the following documentation page: https://www.binance.com/en/support/faq/360033525031
It states:
The Funding Rate formula:
"Funding Rate (F) = Average Premium Index (P) + clamp (interest rate - Premium Index (P), 0.05%, -0.05%)"
I'm obtaining the "Premium Index" just fine, just with "p = request.security("BINANCE:BTCUSDT_PREMIUM", "", close)*100"
However I'm currently struggling with how to obtain the:
"Time-to-funding weighted Average of Premium Index " which apparently is calculated with
"Average Premium Index (P) = (1 * Premium_Index_1 + 2 * Premium_Index_2 + 3 * Premium_Index_3 +···+·480 * Premium_index_480)/(1+2+3+···+480)"
(the funding period for Binance is 8 hours hence the average over 480 minutes)
My exact question is, how do I backtrack to the last funding timestamp of 00:00 / 08:00 / 16:00, then obtain an array / series data of the premium index at each of the last 480 minutes, so that I can then iterate over it to use the above formula for the time weighted average?
Thank you very much for any advice in advance. My apologies if the answer is obvious I'm very new to Pine Script.
I believe you can obtain the time weighted average premium like so:
premium = request.security("BINANCE:BTCUSDT_PREMIUM", "1", close)
new_funding_period = ta.change(time("480")) != 0
var int n = na
var float premium_sum = na
var int n_sum = na
if new_funding_period
n := 1
premium_sum := premium
n_sum := 1
else
n += 1
premium_sum += premium * n
n_sum += n
predicted_TWAP = premium_sum / n_sum
current_TWAP = ta.valuewhen(new_funding_period, predicted_TWAP[1], 0)
However, you are limited to performing the calculation on a 1 minute chart to obtain accurate results due to being unable to reliably retrieve the values from a security call from a lower timeframe when the chart is set to a higher timeframe than 1 minute.
I saw this code but I didn't understand how he calculated the interest rate . this contract mint tokens as an interest and transfer them to users who deposited to the contract (calculated according to the Hold time) I will be grateful if anyone can help ?
https://github.com/dappuniversity/dbank/blob/master/src/contracts/dBank.sol
//check user's hodl time
uint depositTime = block.timestamp - depositStart[msg.sender];
**//31668017 - interest(10% APY) per second for min. deposit amount (0.01 ETH), cuz:
//1e15(10% of 0.01 ETH) / 31577600 (seconds in 365.25 days)
//(etherBalanceOf[msg.sender] / 1e16) - calc. how much higher interest will be (based on deposit), e.g.:
//for min. deposit (0.01 ETH), (etherBalanceOf[msg.sender] / 1e16) = 1 (the same, 31668017/s)
//for deposit 0.02 ETH, (etherBalanceOf[msg.sender] / 1e16) = 2 (doubled, (2*31668017)/s)
uint interestPerSecond = 31668017 * (etherBalanceOf[msg.sender] / 1e16);
uint interest = interestPerSecond * depositTime;**
//send funds to user
msg.sender.transfer(etherBalanceOf[msg.sender]); //eth back to user
token.mint(msg.sender, interest); //interest to user
depositTime is the number of seconds from the last deposit.
interestPerSecond is calculated from the current ETH balance of the user deposited to the contract
And the interest amount is a simple multiplication between the two above.
Example:
The user has deposited 1 ETH exactly 30 days ago (2,592,000 seconds). This makes the
depositTime == 2592000
interestPerSecond == 31668017 * (etherBalanceOf[msg.sender] / 1e16) == 31668017 * (1000000000000000000 / 1e16) == 31668017 * 100 == 3166801700
interest == interestPerSecond * depositTime == 2592000 * 3166801700 == 8208350006400000
Now, the linked contract imports another contract - Token.sol, that imports the OpenZeppelin ERC20.sol.
The imported ERC20.sol defines 18 decimal places. So you need to account for 18 decimals to get the total amount of tokens that you get as the interest.
8208350006400000 / 1e18 == 0.00820835
So if you deposit 1 ETH 30 days ago, you get 0.00820835 of the token as an interest.
Ik keep getting wrong amounts when I want to sum prices and then add VAT to it.
I have the following situation:
Let's say I have 4 products and I want them show them on a invoice. Each products has the same price of 2.50.
I have the following code:
#products = Product.find([1,2,3,4])
On the invoice I have:
#products.each do |product|
%p
Price without VAT:
= number_to_currency(product.price) --> Gives € 2,50
%p
Price with 21% VAT:
= number_to_currency(product.price / 100 * 121) --> Gives € 3,03
This shows like this:
Price without VAT: € 2,50
Price with 21% VAT: € 3,03
Now I want to add a total line. I have tried something like this:
- sum = #products.sum( &:price ) --> Gives 10
%p
Total with 21% VAT:
= number_to_currency(sum / 100 * 121 ) --> Gives € 12,10 instead of € 12,12
What I try, I keep getting a total price including VAT on € 12.10 instead of € 12,12. (4 x € 3,03 = € 12,12)
I have the price in my database as:
t.decimal "price"
The price is stored as 2.5
Who can help me out with this?
One product's correct VAT amount:
(BigDecimal.new("2.5") / 100 * 121).to_f #=> 3.025
4 products correct VAT amount:
(BigDecimal.new("10") / 100 * 121).to_f #=> 12.10
Options:
don't round up and then you can calculate the total VAT from total sum
Round up, but then calculate total VAT as sum of VAT amounts per product
Applying what's said above, 1 product with VAT:
(product.price / 100 * 121).round(2)
all products with VAT:
products.sum { |p| (p.price / 100 * 121).round(2) }
I have a coupon model and i am trying to calculate how much you save from the original deal.
Coupons.rb
def original_deal
original_price
end
def our_deal
deal_price
end
def percentage_off
original_deal / our_deal * 100.ceil
end
Show.html
<%= number_to_percentage(#coupon.percentage_off, :precision => 2) %>
Coupon Info
original_price = £100.00
deal_price = £90.00
Results.
I get 111.11% as the answer. What am i missing?
Your discount percentage calculation is off. You need to find the difference between the original price and the new price. And divide it by the original price to get the discount percentage:
def percentage_off
(Float(original_deal - our_deal) / original_deal * 100).ceil
end
Your input example would now return (100 - 90) / 100 * 100 = 10
Here's an alternative, step-by-step calculation :)
original = 100.0
our = 90.0
our_relative = our / original # => 0.9
you_save = (1.0 - our_relative).round(2) # => 0.1
you_save_percents = (you_save * 100).round # => 10
The calculation is coming out correct. If you look at the values you provided and do the math you come up with the following equation:
100.00 / 90.00 = 1.11
then you do
1.11 * 100 = 111.11
If you want to calculate your savings percentage, try this:
(original_price - deal_price) / original_price * 100.ceil
Hopefully that helps you out.