Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • cubic B-spline for Call options

    Hi,

    I have a time series database of Call options so on each day I have option price of different moneyness for example for january 1, 2015 i have the following data
    date moneyness call price
    01/01/15 0,960736871 0,1
    01/01/15 0,969238937 0,24
    01/01/15 0,977892876 0,58
    01/01/15 0,986702681 1,22
    01/01/15 0,995672703 2,24
    01/01/15 1,004807353 3,6
    01/01/15 1,014111161 5,35
    01/01/15 1,023588777 7,55
    01/01/15 1,033245325 9,6
    01/01/15 1,043085694 11,95
    01/01/15 1,053115368 14,4
    01/01/15 1,063339829 17
    01/01/15 1,073764682 19,25
    01/01/15 1,084396005 21,95
    my purpose is to interpolate Call prices for only 3 values of moneyness (0.97 ; 1 ; 1.06)
    to do so I have use the following stata code :

    rename moneyness x
    rename call_price y
    mata
    X = st_data(. ,"x")
    Y = st_data(. ,"y")
    XX = st_data(.,"xx")
    A = spline3(X,Y)
    B = spline3eval(A,XX)
    yy=st_addvar("float", "yy")
    st_store(. ,yy,B)
    end
    browse

    and i get this :
    date moneyness call price xx yy
    01/01/15 0,960736871 0,1 0,970000029 0,260024935
    01/01/15 0,969238937 0,24 1 2,846917629
    01/01/15 0,977892876 0,58 1,059999943 16,18859863
    01/01/15 0,986702681 1,22
    01/01/15 0,995672703 2,24
    01/01/15 1,004807353 3,6
    01/01/15 1,014111161 5,35
    01/01/15 1,023588777 7,55
    01/01/15 1,033245325 9,6
    01/01/15 1,043085694 11,95
    01/01/15 1,053115368 14,4
    01/01/15 1,063339829 17
    01/01/15 1,073764682 19,25
    01/01/15 1,084396005 21,95
    Now I want to do the same thing but with data in different dates so for each date(january 1, 2015 and january 2, 2015 for example) I want to apply the spline code and get 3 prices for each moneyness value but I dont know how to do it...
    date moneyness call price xx yy
    01/01/15 0,960736871 0,1 0,970000029 0,260024935
    01/01/15 0,969238937 0,24 1 2,846917629
    01/01/15 0,977892876 0,58 1,059999943 16,18859863
    01/01/15 0,986702681 1,22
    01/01/15 0,995672703 2,24
    01/01/15 1,004807353 3,6
    01/01/15 1,014111161 5,35
    01/01/15 1,023588777 7,55
    01/01/15 1,033245325 9,6
    01/01/15 1,043085694 11,95
    01/01/15 1,053115368 14,4
    01/01/15 1,063339829 17
    01/01/15 1,073764682 19,25
    01/01/15 1,084396005 21,95
    02/01/15 0,952399979 24,15 0,97 ?
    02/01/15 0,976302977 26,5 1 ?
    02/01/15 1,017591858 28,8 1,06 ?
    02/01/15 1,079113436 31,5
    02/01/15 1,140874982 34,15
    02/01/15 1,152884245 35,9
    02/01/15 1,165148973 39,5
    02/01/15 1,177677393 41,65
    02/01/15 1,190478206 44,25
    02/01/15 1,203560472 45,9
    02/01/15 1,21693337 48,8
    Thank you very much for any help!

    Best regards,
    Emna



  • #2
    It would help if you use code tags to enter the data, as I have done below, or use -dataex- from SSC or in 15.1, as explained in the FAQ. I used short variable names and assumed the dates were DMY.

    Code:
    clear
    input str8 dmy m c
    "01/01/15"    0.960736871    0.1
    "01/01/15"    0.969238937    0.24
    "01/01/15"    0.977892876    0.58
    "01/01/15"    0.986702681    1.22
    "01/01/15"    0.995672703    2.24
    "01/01/15"    1.004807353    3.6
    "01/01/15"    1.014111161    5.35
    "01/01/15"    1.023588777    7.55
    "01/01/15"    1.033245325    9.6
    "01/01/15"    1.043085694    11.95
    "01/01/15"    1.053115368    14.4
    "01/01/15"    1.063339829    17
    "01/01/15"    1.073764682    19.25
    "01/01/15"    1.084396005    21.95
    "02/01/15"    0.952399979    24.15    
    "02/01/15"    0.976302977    26.5    
    "02/01/15"    1.017591858    28.8    
    "02/01/15"    1.079113436    31.5        
    "02/01/15"    1.140874982    34.15        
    "02/01/15"    1.152884245    35.9        
    "02/01/15"    1.165148973    39.5        
    "02/01/15"    1.177677393    41.65        
    "02/01/15"    1.190478206    44.25        
    "02/01/15"    1.203560472    45.9        
    "02/01/15"    1.21693337    48.8    
    end
    gen d = date(dmy, "DMY", 2050)
    gen yhat = .

    Now I am not entirely sure I understand what you need, but if it is a matter of repeating the spline interpolation for each day, you could try the following:

    Code:
        
    mata:
        d = st_data(., "d")
        m = st_data(., "m")
        c = st_data(., "c")
        days = uniqrows(d)
        for(i = 1; i <= length(day); i++) {    
            j = selectindex(d :== day[i])
            s = spline3(m[j], c[j])
            yhat = spline3eval(s, (0.97, 1, 1.06)); yhat
            st_store(j[1::3], "yhat", yhat')
        }
    end
    Which gives me
    Code:
        +-------------------------------------------+
      1 |  .2600241411   2.846916332    16.1845661  |
        +-------------------------------------------+
                     1             2             3
        +-------------------------------------------+
      1 |   25.9461972   27.99189988   30.77835012  |
        +-------------------------------------------+
    The values of m and c must be monotone increasing within each day. I stored the interpolated values in the first three rows of each day.

    Comment


    • #3
      Hi German,
      This is exactly what I want. Thank you very much for your response
      Best regards,
      Emna

      Comment

      Working...
      X