Hi all,
A basic question here. I have a VIX 2014 dataset, which is shown as:
date | tau | K | call_option_price | S | r | put_option_price |
2014/1/2 | 16 | 1735 | 98.6 | 1831.98 | 0.0018 | 2.175 |
2014/1/2 | 16 | 1740 | 93.9 | 1831.98 | 0.0018 | 2.175 |
2014/1/2 | 16 | 1745 | 88.85 | 1831.98 | 0.0018 | 2.525 |
2014/1/2 | 16 | 1750 | 84.05 | 1831.98 | 0.0018 | 2.6 |
2014/1/2 | 16 | 1755 | 79.4 | 1831.98 | 0.0018 | 2.825 |
...
2014/1/2 | 36 | 1740 | 97.7 | 1831.98 | 0.0022 | 7.6 |
2014/1/2 | 36 | 1745 | 93.4 | 1831.98 | 0.0022 | 8.05 |
2014/1/2 | 36 | 1750 | 89 | 1831.98 | 0.0022 | 8.55 |
2014/1/2 | 36 | 1755 | 84.6 | 1831.98 | 0.0022 | 9.15 |
2014/1/2 | 36 | 1760 | 80.25 | 1831.98 | 0.0022 | 9.8 |
2014/1/2 | 36 | 1765 | 75.95 | 1831.98 | 0.0022 | 10.45 |
2014/1/2 | 36 | 1770 | 71.5 | 1831.98 | 0.0022 | 11.25 |
...
2014/1/3 | 15 | 1735 | 97.25 | 1831.37 | 0.0018 | 1.625 |
2014/1/3 | 15 | 1740 | 92.6 | 1831.37 | 0.0018 | 1.775 |
2014/1/3 | 15 | 1745 | 87.5 | 1831.37 | 0.0018 | 1.925 |
2014/1/3 | 15 | 1750 | 82.65 | 1831.37 | 0.0018 | 1.925 |
2014/1/3 | 15 | 1755 | 77.8 | 1831.37 | 0.0018 | 2.25 |
2014/1/3 | 15 | 1760 | 73 | 1831.37 | 0.0018 | 2.45 |
2014/1/3 | 15 | 1765 | 68.45 | 1831.37 | 0.0018 | 2.75 |
2014/1/3 | 15 | 1770 | 63.75 | 1831.37 | 0.0018 | 3.05 |
2014/1/3 | 15 | 1775 | 59.05 | 1831.37 | 0.0018 | 3.375 |
2014/1/3 | 15 | 1780 | 54.25 | 1831.37 | 0.0018 | 3.7 |
...
2014/1/3 | 35 | 1740 | 96.45 | 1831.37 | 0.0022 | 6.9 |
2014/1/3 | 35 | 1745 | 92.45 | 1831.37 | 0.0022 | 7.3 |
2014/1/3 | 35 | 1750 | 87.95 | 1831.37 | 0.0022 | 7.85 |
2014/1/3 | 35 | 1755 | 83.55 | 1831.37 | 0.0022 | 8.35 |
2014/1/3 | 35 | 1760 | 79.2 | 1831.37 | 0.0022 | 9 |
2014/1/3 | 35 | 1765 | 74.9 | 1831.37 | 0.0022 | 9.7 |
2014/1/3 | 35 | 1770 | 70.65 | 1831.37 | 0.0022 | 10.4 |
2014/1/3 | 35 | 1775 | 66.5 | 1831.37 | 0.0022 | 11.2 |
2014/1/3 | 35 | 1780 | 62.4 | 1831.37 | 0.0022 | 12.1 |
2014/1/3 | 35 | 1785 | 58.35 | 1831.37 | 0.0022 | 13.05 |
The data is imported by proc import. Just focus the variable 'tau', where is defined as the near-term expiration (T1) by tau=16 for 2014/1/2 and next-term expiration (T2) by tau=36 for 2014/1/2. Similarly, the T1 for 2014/1/3 is 15 and T2 for the same day is 35.
The question is, how can I extract the T1 and T2 with corresponding other variables in the same row separately into two different tables or matrixes? and make it is available to conduct matrix calculation, such as i = 0 to n,
Y = a*T1[ i ] * b*T2[ i ] (Just a simple example, I have to conduct a complex calculation then)?
Thank you.
I think you are asking how to extract the unique values of tau. Basically, this is a form of BY-group analysis. The easiest way (conceptually) is to use the UNIQUE-LOC technique to extract the rows that correspond to each level of the tau variable. The link includes an example.
For your data, you would locate the observations for each level of tau and then extract the relevant rows into a matrix. You didn't supply your IML program, but it might look something like this:
do i = 1 to ncol(u); /* 4. For each level... */ idx = loc(tau=u[i]); /* 5. Find observations in level */ A = x[idx, ]; /* 6. Extract rows of the X matrix into A */
/* now process and compute with the A matrix */ end;
It is not clear to me if you want to also read/process each date separately. If so, there is a slightly more complicated version of the UNIQUE-LOC technique that handles multiple BY-group variables.
Here's a simple example of IML code that subsets the input data set base upon a WHERE clause, that you can modify. It refers to a SAS dataset named SASHELP.CLASS, which you have. https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=imlug&docsetTarget=imlug_...
use Sashelp.Class var{name sex age} where(age>10);
Alternatively, you can place a WHERE clause in the IML READ statement. https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=imlug&docsetTarget=imlug_...
read all var {Weight} where(Sex='M'); /* vector of male weights */
I think you are asking how to extract the unique values of tau. Basically, this is a form of BY-group analysis. The easiest way (conceptually) is to use the UNIQUE-LOC technique to extract the rows that correspond to each level of the tau variable. The link includes an example.
For your data, you would locate the observations for each level of tau and then extract the relevant rows into a matrix. You didn't supply your IML program, but it might look something like this:
do i = 1 to ncol(u); /* 4. For each level... */ idx = loc(tau=u[i]); /* 5. Find observations in level */ A = x[idx, ]; /* 6. Extract rows of the X matrix into A */
/* now process and compute with the A matrix */ end;
It is not clear to me if you want to also read/process each date separately. If so, there is a slightly more complicated version of the UNIQUE-LOC technique that handles multiple BY-group variables.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.