I used the clause group by interval(pricetime, 5m, 'none', ,false) for aggregate calculations in DolphinDB. The output table uses the starting point of each window as the pricetime. How could I modify the code to replace it with the ending point of each window?
You can try DolphinDB function temporalAdd to add the window duration to the output pricetime. See the example:
t = table(13:01:00 13:02:00 13:03:00 13:04:00 13:04:59 13:05:00 13:07:00 13:09:00 13:09:59 13:10:00 as pricetime, rand(100, 10) as value)
res = select max(value) from t group by interval(pricetime, 5m, "none") as pricetime
update res set pricetime = temporalAdd(pricetime, 5m)
Write a Q-SQL query to multiply the price of BA.N by 2, GS.N by 3 and MSFT.O by 4 and call the column newPrice using vector conditional statement
tab2:`syms`prices!(`MSFT.O`GS.N`BA.N;45.15 191.10 178.50)
flip tab2
select syms,prices,newPrice:(prices*(4,3,2)) from flip tab2
I'm not sure using a vector conditional would be the easiest way to go about this. For example, you could use a simple dictionary to achieve a similar effect. First define a dictionary mapping your syms to their multipliers then use that dictionary in your select statement:
tab2: flip `syms`prices!(`MSFT.O`GS.N`BA.N;45.15 191.10 178.50)
d: `MSFT.O`GS.N`BA.N!4 3 2;
select syms, prices, newPrice: prices*d[syms] from tab2
syms prices newPrice
----------------------
MSFT.O 45.15 180.6
GS.N 191.1 573.3
BA.N 178.5 357
Vector conditionals can only return one of two results, depending on if the condition is true or false. To extend that limitation to what you want you could nest the conditionals inside each other. So like:
select syms, prices, newPrice: ?[syms=`MSFT.O; prices*4; ?[syms=`GS.N; prices*3; ?[syms=`BA.N;prices*2;prices]]] from tab2
But this quickly becomes unwieldy and doesn't scale well. If you added more syms, it would be easy to update the dictionary, but annoying to update the conditional.
You should create multipliers map
(`MSFT.O`GS.N`BA.N!2 3 4)
and multiply each price on value from the map based on row syms:
update newPrice: prices*(`MSFT.O`GS.N`BA.N!2 3 4)syms from flip tab2
I have two timetables, each of them have 4 columns, where the first 2 columns are of my particular interest. The first column is a date and the second is an hour.
How can I know which observations (by date an hour) are in the timetable 1 but not in the timetable 2 and, therefore, drop those observations from my timetable 1?
So for example, just by looking I realized that timetable1 included the day 25/05/2015 with hours 1 and 2, but the timetable 2 did not include them, therefore I would like to drop those observations from timetable 1.
I tried using the command groups_timetable1 = findgroups(timetable1.Date,timetable1.Hour);but unfortunately this command does not tell you a lot how to distinguish between observations.
Thank you!
call ismember to find one set of data in another.
to find multiple records as a group in another composite records, you call ismember(..., 'rows').
for example
baseline=[
100, 2.1
200, 7.5
120, 11.0
];
isin=ismember(baseline,[200, 7.5],'rows');
pos=find(isin)
if you have time date strings or datetime objects, please convert those to numerical values, such as by calling datenum or posixtime first.
You can use the timetable method innerjoin to do this. Like so:
% Fabricate some data
dates1 = datetime(2015, 5, ones(10,1));
hours1 = (1:10)';
timetable1 = timetable(dates1(:), hours1, rand(10,1), rand(10,1), ...
'VariableNames', {'Hour', 'Price', 'Volume'});
% Subselect a few rows for timetable2
timetable2 = timetable1([1:3, 6:10],:);
% Use innerjoin to pick rows where Time & Hour intersect:
innerjoin(timetable1, timetable2, 'Keys', {'Time', 'Hour'})
By default, the result of innerjoin contains the table variables from both input tables - that may or may not be what you want.
is it possible to iterate over columns with a fixed row/cell and to create a new column with the values. For example I want to create a column like that:
F1=A1
F2=B1
F3=C1
F4=D1
and so on
Write the formula
=MAX(OFFSET($A$1:$A$10000;0;ROW()-1))
in cell F1 and stretch it down.
The expression ROW()-1 will take the value 0 for F1, 1 for F2, 2 for F3, and so on, and the OFFSET() function uses these values to move from the range A1:A10000 to 0, 1, 2, and so on columns.
My question is probably really easy, but I am a mathematica beginner.
I have a dataset, lets say:
Column: Numbers from 1 to 10
Column Signs
Column Other signs.
{{1,2,3,4,5,6,7,8,9,10},{d,t,4,/,g,t,w,o,p,m},{g,h,j,k,l,s,d,e,w,q}}
Now I want to extract all rows for which column 1 provides an odd number. In other words I want to create a new dataset.
I tried to work with Select and OddQ as well as with the IF function, but I have absolutely no clue how to put this orders in the right way!
Taking a stab at what you might be asking..
(table = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} ,
Characters["abcdefghij"],
Characters["ABCDEFGHIJ"]}) // MatrixForm
table[[All, 1 ;; -1 ;; 2]] // MatrixForm
or perhaps this:
Select[table, OddQ[#[[1]]] &]
{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}
The convention in Mathematica is the reverse of what you use in your description.
Rows are first level sublists.
Let's take your original data
mytable = {{1,2,3,4,5,6,7,8,9,10},{d,t,4,"/",g,t,w,o,p,m},{g,h,j,k,l,s,d,e,w,q}}
Just as you suggested, Select and OddQ can do what you want, but on your table, transposed. So we transpose first and back:
Transpose[Select[Transpose[mytable], OddQ[First[#]]& ]]
Another way:
Mathematica functional command MapThread can work on synchronous lists.
DeleteCases[MapThread[If[OddQ[#1], {##}] &, mytable], Null]
The inner function of MapThread gets all elements of what you call a 'row' as variables (#1, #2, etc.). So it test the first column and outputs all columns or a Null if the test fails. The enclosing DeleteCases suppresses the unmatching "rows".