Assembla home | Assembla project page
 

Changeset 140

Show
Ignore:
Timestamp:
04/29/08 14:30:03 (2 months ago)
Author:
Vice
Message:

Cap & Floor another test done.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/QLNet/Test2008/T_CapFloor.cs

    r139 r140  
    183183         } 
    184184      } 
     185       
     186      [TestMethod()] 
     187      public void testStrikeDependency()  
     188      { 
     189 
     190         CommonVars vars = new CommonVars(); 
     191 
     192         int[] lengths = { 1, 2, 3, 5, 7, 10, 15, 20 }; 
     193         double[] vols = { 0.01, 0.05, 0.10, 0.15, 0.20 }; 
     194         double[] strikes = { 0.03, 0.04, 0.05, 0.06, 0.07 }; 
     195 
     196         Date startDate = vars.termStructure.link.referenceDate(); 
     197 
     198         for (int i=0; i<lengths.Length; i++)  
     199         { 
     200            for (int j=0; j<vols.Length; j++)  
     201            { 
     202               // store the results for different strikes... 
     203               List<double> cap_values = new List<double>(), floor_values = new List<double>(); 
     204 
     205               for (int k=0; k<strikes.Length; k++)  
     206               { 
     207                   List<CashFlow> leg = vars.makeLeg(startDate,lengths[i]); 
     208                   Instrument cap = vars.makeCapFloor(CapFloorType.Cap,leg, 
     209                                         strikes[k],vols[j]); 
     210                   cap_values.Add(cap.NPV()); 
     211                   Instrument floor = vars.makeCapFloor(CapFloorType.Floor,leg, 
     212                                         strikes[k],vols[j]); 
     213                   floor_values.Add(floor.NPV()); 
     214            } 
     215            // and check that they go the right way 
     216            for ( int k = 0 ; k < cap_values.Count-1 ; k++ ) 
     217            { 
     218               if (cap_values[k] < cap_values[k+1]) 
     219                Assert.Fail( 
     220                    "NPV is increasing with the strike in a cap: \n" 
     221                    + "    length:     " + lengths[i] + " years\n" 
     222                    + "    volatility: " + vols[j] + "\n" 
     223                    + "    value:      " + cap_values[k] 
     224                    + " at strike: " + strikes[k] + "\n" 
     225                    + "    value:      " + cap_values[k+1] 
     226                    + " at strike: " + strikes[k+1]); 
     227            } 
     228 
     229            // same for floors 
     230            for ( int k = 0 ; k < floor_values.Count-1 ; k++ ) 
     231            { 
     232               if (floor_values[k] > floor_values[k+1]) 
     233                Assert.Fail( 
     234                    "NPV is decreasing with the strike in a floor: \n" 
     235                    + "    length:     " + lengths[i] + " years\n" 
     236                    + "    volatility: " + vols[j] + "\n" 
     237                    + "    value:      " + floor_values[k] 
     238                    + " at strike: " + strikes[k] + "\n" 
     239                    + "    value:      " + floor_values[k+1] 
     240                    + " at strike: " + strikes[k+1]); 
     241            } 
     242        } 
     243    } 
     244} 
     245 
    185246   } 
    186247}