MATLAB Financial Data Algorithm

149 views Asked by At

So I have a massive excel spreadsheet of historical options data of the S&P 100 at different dates between 2010 and the present date. I am seeking to find the probability density function of the stock at each of these dates.

The method for finding this function is to take the second derivative of the call price (listed in column 5) with respect to the strike price. I want my MATLAB script to work as follows:

  1. Use the curvefitting toolbox spline fitting function to create a curve of the call price with respect to the strike price at each date. There is about 10 points for each date.

  2. Use the differentiate function to get maybe 50 points for the 2nd derivative to estimate the 2nd derivative function.

  3. Use Riemann integration on these points to compute the integral for the expected value.

My main issues are with grouping of the table. I've done research and think I'll have to use rowfun probably, but I'm really not very experienced with working with data like this.

Any help would be HIGHLY appreciated!

A sample of the data set:

Data table

1

There are 1 answers

0
chipaudette On

Are you doing steps (1) through (3) simply to compute the "best" 2nd derivative value for that date? If so, there's a much simpler way to do it. In pseudo-code, it would look like:

%assume that all_dates is a Matlab datenum that encodes both
%the date and the time as a floating point value

%find just those values for your day that you care about
I = find(todays_date == floor(all_dates));
todays_data = all_data(I);
todays_datenums = all_dates(I);

%find the best-fit parabola to today's data
N_fit = 2;  %2nd order is a parabola
p = polyfit(todays_datenums, todays_data,N_fit); 

%compute the 2nd derivative
p_1st = polyder(p);      %first derivative, form is y = p(1)*todays_datenum+p(2)
p_2nd = polyder(p_1st);  %second derivative

Because you only fit a parabola, the p_2nd will be a single value. This is your best estimate of the 2nd derivative of that day's data. The units will be dollars (?) per day.