Kdb qstudio line plot - kdb

I have a table of the form
Timestamp, Symbol, Vol
and I would like to plot the aggregate daily volume per symbol in a line chart
select sum(Vol) by `date$Timestamp from Trades
gives me the plot for the daily volume. How can I get a line per symbol?
select sum(Vol) by `date$Timestamp, Symbol from Trades
Gives me two lines, one for Vol and one constant line for the max in symbols( symbols are int values)
And as a side question... How can I tell the plot to exclude missing dates in the time series or at least have values of 0 for those dates?

If you want to multi-graph then each line to draw needs to be a separate column of our output table. Which means you'd need to pivot your results table: https://code.kx.com/q/cookbook/pivoting-tables/
For example, something like this:
{P:exec distinct sym from x;exec P#(sym!size) by minute:minute from x}select sum size by sym,time.minute from lseTradeRT where sym in `AHT.L`BARC.L`BP.L`VOD.L
but in your case replace the time.minute with `date$Timestamp. You should also filter on only a handful of syms or else the graph is unmanageable.

Related

Dividing AVG of column1 by AVG of column2

I am trying to divide the average value of column1 by the average value of column 2, which will give me an average price from my data. I believe there is a problem with my syntax / structure of my code, or I am making a rookie mistake.
I have searched stack and cannot find many examples of dividing two averaged columns, and checked the postgres documentation.
The individual average query is working fine (as shown here)
SELECT (AVG(CAST("Column1" AS numeric(4,2))),2) FROM table1
But when I combine two of them in an attempt to divide, It simply does not work.
SELECT (AVG(CAST("Column1" AS numeric(4,2))),2) / (AVG(CAST("Column2" AS numeric(4,2))),2) FROM table1
I am receiving the following error; "ERROR: row comparison operator must yield type boolean, not type numeric". I have tried a few other variations which have mostly given me syntax errors.
I don't know what you are trying to do with your current approach. However, if you want to take the ratio of two averages, you could also just take the ratio of the sums:
SELECT SUM(CAST(Column1 AS numeric(4,2))) / SUM(CAST(Column2 AS numeric(4,2)))
FROM table1;
Note that SUM() just takes a single input, not two inputs. The reason why we can use the sums is that average would normalize both the numerator and denominator by the same amount, which is the number of rows in table1. Hence, this factor just cancels out.

Time series generation matlab

I have an excel worksheet with several entries of column data. The data is arranged in pairs such that the first column contains dates and the second contains time series data corresponding to that date. So for example time series 1 will be in columns A and B where is is the dates and B is the data. Column C is blank before columns D and E contain the entries for time series 2 and so on and so forth...
How do I merge these into a single file in Matlab where the dates match up? Specifically I would want the first column to contain the dates and the other columns to contain the data. I have tried to do this with fts and merge functions but so far failed..
You could grab the dates like this: dates = [raw{:,1}]' and the data like this data = reshape([raw{:, 2:3:end}]', size(raw,1), []); to get normal matlab matrices in case you want to manipulate them in matlab.
Otherwise if you just want to send them straight back to excel then:
data = [raw(:,1) reshape(raw(:, 2:3:end)];
xlswrite(...blablafilename_etc..., data);
But in this case you should have use a VBA macro :/

What type of SSRS chart will plot individual specified points?

I have a query that returns six specific values, let's call them xLow, xMed, xHigh, yLow, yMed, and yHigh.
I am supposed to add a graph to a report that plots five specific points. First is a box with corners (xLow, yLow), (xLow, yHigh), (xHigh, yLow), and (xHigh, yHigh) showing the range of possible values; then the single point (xMed, yMed) in the middle highlighting the typical value.
There is no "series" here, and this isn't exactly a Scatter Plot either. I just need to draw some dots (and if possible connect four of them with lines.)
I think your best option is to assume there is a series for the box and the mid range but then don't print the series box.
I'd play with many variations of a line chart with series to produce the box. You may need to have four series just to do this to make it look like a box.
I'm interested now and going to play.
I got a boost here from #glh, but as with several problems I've encountered with SSRS, I've found it far easier to solve via the query rather than the report properties. At least 80% in this case.
Basic idea of old query (within a stored proc):
SELECT xHigh, xLow, xMed, yHigh, yMed, yLow
FROM MyTable where MyPrimaryKey = #param
Basic idea of new query:
DECLARE #Holder TABLE (
ValueLevel varchar(4),
xVal DECIMAL (15,3),
yHigh DECIMAL (15,3),
yMed DECIMAL (15,3),
yLow DECIMAL (15,3)
)
INSERT INTO #Holder
SELECT 'Low' AS ValueLevel, xLow as xVal, yHigh, yMed, yLow
FROM MyTable where MyPrimaryKey = #param
-- Repeat insert for xMed and xHigh
SELECT * FROM #Holder
Now in the rdl, my chart is a simple line chart, with three value series corresponding to the three y-values, and one group series being xVal.
I used the ValueLevel from the temp table to place a conditional on the value fields, so I only get the corners and center, and not all nine points this query produces. For example, my expression for the yHigh series is
=IIF(Fields!ValueLevel.Value <> "EXP", Fields!yHigh.Value, nothing)
The only thing missing is the vertical connectors on the sides of the box.

The most effective way to use interp1 command in matlab with two columns

I have two columns (same size) that I have to interpolate in Matlab. First column is a vector of time in hours (9.5, 9.6 9.73 10.13 etc...) and the other column are stock prices associated to each element of the column "time in hours".
I wish to have some prices that are associated with each 15min, 30min, 45min, and 1hour (60min) that are missing in my price vector. And therefore, thee elements (15,30,45min and 60min) are also missing in my column of time per hours.
How can I linearly interpolate two columns in order to have the same size and then be able to associate a price at every 15min (X.25hour, X.5hour, X.75hour and X hour)?
Thank you!
It's a one line command:
interp_prices = interp1(time, prices, 0:0.25:max(time));

Getting the Sum of the Contents of Rows

I have a column with dollar amounts, such as:
$1.00
$4.00
$100.00
and so on. These values are put into the column by calculating the % of another column. I want to get the sum of all the dollar amounts of that column. I cant use Sum(data) because its static data in the column. Is there a way to get the sum easily?
Thanks!
There are a couple of different ways to deal with this:
If it's the same percentage being applied to each row, sum the original column and apply the same percentage to that sum.
If the original source of the data is from a database, do the percent calculation in your Dataset's SQL query, then use the Sum function in your Tablix as usual.
If these don't apply, you'll need to give more detailed information about your problem.