Load and display a timetable, T1
, that has nested tables containing stock information. The nested tables AAPL
and MSFT
are the variables of T1
. Each nested table has the stock prices at the open and close of trading, and the volume, for a different company.
T1 =
3x2 timetable
Dates AAPL MSFT
Open Close Volume Open Close Volume
___________ __________________________ __________________________
01-Jan-2017 64.539 71.704 107.17 66.429 91.77 78.7
01-Feb-2017 101.53 87.619 57.909 72.984 84.629 57.959
01-Mar-2017 60.381 76.464 72.067 78.127 76.492 82.883
To group the Open
, Close
, and Volume
variables together in nested tables of their own, use the inner2outer
function.
T2 =
3x3 timetable
Dates Open Close Volume
AAPL MSFT AAPL MSFT AAPL MSFT
___________ ________________ ________________ ________________
01-Jan-2017 64.539 66.429 71.704 91.77 107.17 78.7
01-Feb-2017 101.53 72.984 87.619 84.629 57.909 57.959
01-Mar-2017 60.381 78.127 76.464 76.492 72.067 82.883
Some calculations are more convenient with data from each stock grouped in the nested tables of T2
. For example, you can calculate the normalized volume for all stocks using T2.Volume
.
Use the Variables
property of T2
to convert T2.Volume
into a matrix. Then subtract the mean of T2.Volume
from T2.Volume
and return the result as a matrix.
normVolume =
28.1213 5.5193
-21.1397 -15.2217
-6.9817 9.7023
You also can use table functions on the nested tables. Calculate the mean closing price of all stocks using the varfun
function, returning the means in a table.
meanClose =
1x2 table
mean_AAPL mean_MSFT
_________ _________
78.596 84.297