When it comes to 24h Change on a specific Pair,
How is this calculated?
If it's price at current time compared to price 24 hours ago, then for example:
the current price of BTC 9431 now (6/16/2020 5pm) is compared to the price of 9357 on 6/15/2020 at 5pm?
and an hour later (6pm) if I see it again will be compared to the price on 6/15/2020/6pm?
let say
t_0 (price now ), t_24(price 24hours ago)
so pirce_change(%)= ((price(t_0)-price(t_24))/price(t_0))*100
I refer you to this link: https://bitcoin.stackexchange.com/questions/67438/24-hour-price-change-mean
The 24h % change is the difference between the current price and the
price 24 hours ago.
The current price of bitcoin is $14988 and was $14937 24h ago. So the
24h change is +0.3%, even if there was a huge spike between this
period of time.
Related
I have a price series in a dataframe, with a datetime index. Just appending the top 5 rows of the price series, but I basically have data all the way from 2020-04-01.
Date
CTH3 Comdty
2022-11-28
78.95
2022-11-25
80.18
2022-11-23
82.90
2022-11-22
82.42
2022-11-21
79.78
So for example, the weekly return for 2002-11-28 should be based on the price from 5 business days ago, i.e. 2022-11-21, and so (78.95 - 79.78)/79.78 = -1.04%
I would like to calculate week-on-week (WoW) return, month-on-month (MoM) return, year-on-year (YoY) return for each day. For MoM and YoY, it should be based on the price from exactly 1 month or 1 year ago respectively, but if that day is not a business day and there is no price, then to take the price from day before and so on. For this I know I can use .ffill or .bfill in some way.
My current thinking is to use .loc and use a for loop to input the 1 week ago, 1 month ago, and 1 year ago prices as 3 different columns and then proceed to do the % calculation. But this seems a tad bit tedious. How would I go about doing this in a more efficient way?
Instead of .iloc, you can also try .iat.
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iat.html
is it possible to have date_diff with specific start and end time?
let say my store are open from 8AM - 10PM, which is 14 Hours.
and I have a lot of stuff to sell during that time. One of the SKU is out of stock from 2022-11-01 06.00 PM until tomorrow 2022-11-02 11.00 AM.
Instead of calculate 24 hours, I just want to calculate only from opening store until it closed or until its restock. Meaning from 6PM to 11AM is 8 Hours
my query
select date_diff('2022-11-02 11.00 AM', '2022-11-02 06.00 PM', hour) from table
with the result 17 hours instead of 8 hours
There isn't a way to configure DATE_DIFF to do this for you, but it's possible to do what you want, with some effort.
You should convert your dates to timestamps (TIMESTAMP(yourdate) or CAST(yourdate AS TIMESTAMP)) and use TIMESTAMP_DIFF instead.
This will allow you to work with smaller intervals than days.
For your calculation, you ultimately need to find the total time difference between the two timestamps and then subtract the out-of-hours timeframe.
However, calculating the latter is not as simple as taking the difference in days and multiplying by 8 hours (10pm-6am), because your out-of-hours calculation has to account for weekends and possibly holidays etc. Hence it can get quite complex, which is where the solution in my first link might come in.
I have a table with daily snapshot data that has a date and amount column. I'm converting this to a monthly snapshot table. Every record in this monthly table should look like what you see in the table below at 31-01.
If on the last day of the month the amount is negative, amount_negative_lastday_of_month = True. The part I can't figure out is the first_date_negative_amount. If the amount_negative_lastday_of_month = True, I want to get the first day on which the amount became negative for that specific period where the amount was negative. In the table below that would be 28-01-2021.
If this period of amount < 0 continuous on until the end of February, we will see the exact same in the Feb. monthly snapshot where amount_negative_lastday_of_month = True and amount_negative_lastday_of_month = 28-01-2021.
If this period of negative amount is over, and in a few months a new period of negative amount begins, I want to do the same again.
The problem is that I can't figure out how to group/window my data by varying periods of time where a certain condition is met (amount < 0).
How can I query this?
date
amount
last_day_of_month
amount_negative_lastday
first_date_negative_amount
26-1-2021
-10
27-1-2021
200
28-1-2021
-200
29-1-2021
-200
30-1-2021
-200
31-1-2021
-100
31-1-2021
TRUE
28-1-2021
1-2-2021
-122
2-2-2021
-222
3-2-2021
-322
As an example I have 5 different stocks, where I only use end of day prices. The stocks do not change price often, maybe a couple of times per month.
I want a easy way to count the number of days the stocks have been unchanged, using the last available price.
One of the stocks may be "XYZ", the latest price is 103. Last time the price was changed was 23.10.2021, and the price went down from 104 to 103. How to automatically count the number of days the price has been at 103 in SQL?
I'm launching a small service and plan to charge monthly (eg- will be advertised as $10 monthly). I'm working on the billing module right now but was wondering about a small bit:
I plan to bill customers when they first register and then at regular intervals thereafter. Getting to my question- Some months have less than 30 days. Does monthly billing imply exactly a 30 day interval or would anything between 28-30 days be considered a monthly interval?
I was planning on doing 30 because it seems that's what customers would expect, but I'm also curious if some companies charge at a fixed interval other than 30 days.
Billing monthly is assumed to be 12 times per year, not once every thirty days.
Preferably, billing should be on the anniversary of the original billing date of the month. If the current month has fewer days than the original billing DOM, bill on the last day of the current month, but on the next month, bill again on the anniversary day.