Sumproduct in Netezza - netezza

I want to calculate sumproduct in netezza table, where one column is fixed. In frist column (A) I have some numbers in DISCOUNT are discount factors. As a result I want to get sumproduct bewteen A and DISCOUNT, where DISCOUNT always start from first row.
Number in RESULTS:
14,54535 = 5/(1+2%)+3/(1+3%)+7/(1+4%),
9.737293 = 3/(1+2%)+7/(1+3%)
6.862745 = 7/(1+2%)
Always when copunting the next number in columns RESULT, we ignore the previous values from A, but always use the DISCOUNT from MATURITY=1 forward.
MATURITY
A
R
DISCOUNT
RESULT
1
5
2%
98.0392...%
14,54535...
2
3
3%
97.0874...%
9.737293...
3
7
4%
97.0874...%
6.862745...
Is the any way to do that in Neteza? Without using multiple joins for rates/discounts? Since the dimension of data can vary.

Related

How to subtract two columns data for all the rows

I have a table as below
id pausetime resumetime
-----------------------------------------------------
1 2021-09-22 14:21:34.023 2021-09-22 14:25:37.030
2 2021-09-22 14:37:47.810 2021-09-22 14:40:58.817
I want to subtract resumetime from pausetime for all the rows, then add that time so that I can get the total time between resume and pause, number of rows can be different .
How can I do that ?
I tried this
select
dbo.TimeDifference(cast(resumetime as time),
cast(pausetime as time)
but I have to do it for all the rows.
Please help me out.
We can use DATEDIFF here along with SUM:
SELECT SUM(DATEDIFF(ss, pausetime, resumetime)) AS total_diff_in_seconds

How to speed up LIMIT & OFFSET query in a big database

I have a table which can contain up to billions rows
CREATE TABLE "Log4DataUsb" (
"Time" integer primary key not null ,
"Microseconds" integer ,
"Current" integer ,
"Voltage" integer )
Usually a user will want to query the data within a specific range, for example Time <= 123456789 and Time >= 0, because this may return billions rows, I want to segment the rows and only return a batch each time, like LIMIT 10,000, LIMITE 10,000 OFFSET X until it reaches the end of this time-range query.
I notice that when the number of rows goes up, this query can be quite slow, executing the queries below will take seconds even though I just want to move to the next batch.
SELECT * FROM TABLE WHERE Time <= 123456789 and Time >= 0 LIMIT 10,000
SELECT * FROM TABLE WHERE Time <= 123456789 and Time >= 0 LIMIT 10,000 OFFSET 10,0000
If the database is supposed to have 2 billion rows in total, is there any way it can largely increase the query performance?

how to calculate vwap price for a specified notional amount in kdb?

I have the following example table in kdb.
mkt:([] date:2018.05.05 2018.05.05 2018.05.05 2018.05.05; time:2018.05.05D01:30:00 2018.05.05D01:30:01 2018.05.05D01:30:01 2018.05.05D01:30:02; bid:((1.2110 1.21105);(1.2111 1.2109 1.2112);(1.2111 1.2109);(1.2110 1.21105)); bidSize:((3000000 1000000);(500000 1000000 1000000);(1000000 2000000);(1000000 1000000)); ask:((1.2111 1.21115);(1.2112 1.2110 1.2113);(1.2112 1.2110);(1.2111 1.21115)); askSize:((3000000 1000000);(500000 1000000 1000000);(1000000 2000000);(1000000 1000000)))
I have this as a solution but the numbers won't be the most accurate.
table:select date, time, bid:{x wavg y}'[bidSize;bid], bidSize: sum each bidSize, ask:{x wavg y}'[askSize;ask], askSize:sum each askSize from mkt
table: update cumulBidSize: sums bidSize, cumulAskSize: sums askSize from table
1#select from table where cumlBidSize>=5000000
I want to be able to have a function when given a specific size (e.g. 5000000), calculate the vwap for that size. How am I able to cycle through the data in the cell until i get 5000000?
You can use this to calculate the avg bid only for rows where the total bidSize is greater than or equal to a specified size:
{[x]select {x wavg y}'[sum each bidSize;bid] from mkt where x<=sum each bidSize}[4000000]
You can use this if you want to calculate the average price for only prices with an associate size greater than or equal to a specified size:
{select bidSize wavg bid from ungroup mkt where bidSize>=x}[2000000]
Hope this helps,
James

Checking existence of dimension in MDX

How I can check if one dimension exist on axis in MDX statetment?
I need to check how many time units (days, weeks, months...) exist on axis1 and use it to calculate measure. Here is example, what should happen, I take some dimensions:
days -> [Measures].[A] = [Measures].[B] / number of members in axis 1, from only date dimension (365)
months -> [Measures].[A] = [Measures].[B] / number of members in axis 1, from only date dimension (12)
months, product group -> [Measures].[A] = [Measures].[B] / number of members in axis 1, from only date dimension (12)
So dimension different than date dimension should't affect calcutation. I only need to get count on members from [Date] dimension.
A simple example is counting of days:
With
Member [Measures].[Members on rows] AS
Axis(1).Count
Select
Non Empty [Measures].[Members on rows] on columns,
Non Empty [Date].[Day].[Day].Members on rows
From [Sales]
Where [Date].[Month].[Month].&[201701]
But you'll get only row count, you can't predict what's going on with an axis. Also you may check whether the whole attribute count = the report attribute count:
Count(existing [Date].[Day].[Day].Members) = Count([Date].[Day].[Day].Members)
If it returns true, most likely that means you don't use filter the [Date].[Day] hierarchy within your report.

Array formula using multiplication and division across 3 columns

I have Inventory data that is in the following format:
Column D | Column E | Column F
Pack Qty | Pack Price | Total Qty
This is followed by multiple rows with various numerical values, with the odd blank row.
To calculate the stock value of any particular product/line, I use =F2/D2*E2.
To calculate the total value of stock I tried {=Sum(F:F/D:D*E:E)} but it returns a #Div/0! error.
As mentioned, some rows are blank. Some items have 0 price, others have 0 stock on hand.
I would like to avoid having to total each line in a new column then total that column.
Try this:
{=SUM(IFERROR(F:F/D:D*E:E,0))}
You can simply wrap your division inside IFERROR() and return 0.
{=SUM(IFERROR(F:F/D:D,0)*E:E)}

Resources