Changeset 225
- Timestamp:
- 07/15/08 05:45:12 (1 year ago)
- Files:
-
- trunk/QLNet/QLNet.sln (modified) (1 diff)
- trunk/QLNet/QLNet.vsmdi (modified) (2 diffs)
- trunk/QLNet/QLNet/Error.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Indexes/Ibor/DailyTenorLibor.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Indexes/Ibor/Euribor.cs (modified) (4 diffs)
- trunk/QLNet/QLNet/Indexes/Ibor/Eurlibor.cs (modified) (4 diffs)
- trunk/QLNet/QLNet/Indexes/Ibor/Usdlibor.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Instruments/Bonds/Fixedratebond.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Instruments/Bonds/FloatingRateBond.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Math/Matrix.cs (modified) (2 diffs)
- trunk/QLNet/QLNet/Math/matrixutilities/choleskydecomposition.cs (added)
- trunk/QLNet/QLNet/Math/matrixutilities/pseudosqrt.cs (added)
- trunk/QLNet/QLNet/Math/matrixutilities/svd.cs (modified) (4 diffs)
- trunk/QLNet/QLNet/Math/matrixutilities/symmetricschurdecomposition.cs (added)
- trunk/QLNet/QLNet/Methods/montecarlo/earlyexercisepathpricer.cs (modified) (2 diffs)
- trunk/QLNet/QLNet/Methods/montecarlo/longstaffschwartzpathpricer.cs (modified) (3 diffs)
- trunk/QLNet/QLNet/Methods/montecarlo/montecarlomodel.cs (modified) (2 diffs)
- trunk/QLNet/QLNet/Methods/montecarlo/multipath.cs (modified) (2 diffs)
- trunk/QLNet/QLNet/Methods/montecarlo/path.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Methods/montecarlo/pathpricer.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Methods/montecarlo/sample.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Pricingengines/mclongstaffschwartzengine.cs (modified) (4 diffs)
- trunk/QLNet/QLNet/Pricingengines/mcsimulation.cs (modified) (2 diffs)
- trunk/QLNet/QLNet/Pricingengines/vanilla/mcamericanengine.cs (modified) (5 diffs)
- trunk/QLNet/QLNet/Pricingengines/vanilla/mceuropeanengine.cs (modified) (3 diffs)
- trunk/QLNet/QLNet/QLNet.csproj (modified) (3 diffs)
- trunk/QLNet/QLNet/Time/Date.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Time/DayCounters/ActualActual.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Time/Period.cs (modified) (11 diffs)
- trunk/QLNet/QLNet/processes/stochasticprocessarray.cs (added)
- trunk/QLNet/Test2008/T_Matrices.cs (added)
- trunk/QLNet/Test2008/T_Mclongstaffschwartzengine.cs (added)
- trunk/QLNet/Test2008/Test2008.csproj (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/QLNet/QLNet.sln
r187 r225 51 51 {96693C81-8F03-4FCF-AC22-470820236A8A}.Release|Any CPU.ActiveCfg = Release|Any CPU 52 52 {96693C81-8F03-4FCF-AC22-470820236A8A}.Release|Any CPU.Build.0 = Release|Any CPU 53 {6F0131DC-A031-4422-85AD-C8C497AE244F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU54 {6F0131DC-A031-4422-85AD-C8C497AE244F}.Debug|Any CPU.Build.0 = Debug|Any CPU53 {6F0131DC-A031-4422-85AD-C8C497AE244F}.Debug|Any CPU.ActiveCfg = Release|Any CPU 54 {6F0131DC-A031-4422-85AD-C8C497AE244F}.Debug|Any CPU.Build.0 = Release|Any CPU 55 55 {6F0131DC-A031-4422-85AD-C8C497AE244F}.Release|Any CPU.ActiveCfg = Release|Any CPU 56 56 {6F0131DC-A031-4422-85AD-C8C497AE244F}.Release|Any CPU.Build.0 = Release|Any CPU trunk/QLNet/QLNet.vsmdi
r204 r225 10 10 <TestList name="Swap" id="1fb9da58-c37b-40da-9772-c8899ed4f8c6" parentListId="8c43106b-9dc1-4907-a29f-aa66a61bf5b6"> 11 11 <TestLinks> 12 <TestLink id=" 019427b9-dea4-5598-dd43-a00afdcf7984" name="testCachedValue" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" />12 <TestLink id="bfdd9348-cf70-0cc9-aefe-30e8f235d572" name="testSpreadDependency" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 13 13 <TestLink id="cd832602-6407-a10e-5585-88a96542e91e" name="testInArrears" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 14 14 <TestLink id="4a7f54ba-aa40-17eb-4f2c-4e956babf8b3" name="testRateDependency" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 15 15 <TestLink id="6d8e3375-fefb-38b0-2f10-3bb7dcdc7cc6" name="testFairRate" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 16 <TestLink id=" bfdd9348-cf70-0cc9-aefe-30e8f235d572" name="testSpreadDependency" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" />16 <TestLink id="019427b9-dea4-5598-dd43-a00afdcf7984" name="testCachedValue" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 17 17 <TestLink id="f909c484-4167-4782-e0bc-cd5f18e918ba" name="testFairSpread" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 18 </TestLinks> 19 </TestList> 20 <TestList name="Matrices" id="25633d76-5f09-440e-8201-24fb89c87f80" parentListId="8c43106b-9dc1-4907-a29f-aa66a61bf5b6"> 21 <TestLinks> 22 <TestLink id="b4704ed2-b5d7-2ec0-af5e-d8f52bdc6660" name="testEigenvectors" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 18 23 </TestLinks> 19 24 </TestList> … … 84 89 <TestList name="American Option" id="da9a808d-acf7-4baf-9dfb-e4b091d30fef" parentListId="8c43106b-9dc1-4907-a29f-aa66a61bf5b6"> 85 90 <TestLinks> 86 <TestLink id=" 33c4d801-48ac-44c4-329e-d6fe84f5e034" name="testJuValues" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" />91 <TestLink id="2bbf531b-68cb-84c0-a06f-6bedfb89f20f" name="testBaroneAdesiWhaleyValues" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 87 92 <TestLink id="3be50179-04ee-902d-73d8-3c94e9305a67" name="testFdShoutGreeks" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 88 93 <TestLink id="783f96db-cce8-bf61-b280-f5010f7d7eb3" name="testFdValues" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 89 94 <TestLink id="1e42c90a-8e82-1369-9ed9-52b036b1c07e" name="testBjerksundStenslandValues" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 90 95 <TestLink id="9f4ff6f8-9938-8ecb-5608-7dbc928cbda3" name="testFdAmericanGreeks" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 91 <TestLink id=" 2bbf531b-68cb-84c0-a06f-6bedfb89f20f" name="testBaroneAdesiWhaleyValues" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" />96 <TestLink id="33c4d801-48ac-44c4-329e-d6fe84f5e034" name="testJuValues" storage="test2008\bin\debug\test2008.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, PublicKeyToken=b03f5f7f11d50a3a" /> 92 97 </TestLinks> 93 98 </TestList> trunk/QLNet/QLNet/Error.cs
r217 r225 23 23 namespace QLNet { 24 24 public class Error { 25 public static ArgumentException UnknownTimeUnit(TimeUnit u) {26 return new ArgumentException("Unknown TimeUnit: " + u); }27 25 public static ArgumentException UnknownFrequency(Frequency f) { 28 26 return new ArgumentException("Unknown frequency: " + f); } trunk/QLNet/QLNet/Indexes/Ibor/DailyTenorLibor.cs
r111 r225 23 23 24 24 namespace QLNet { 25 //! base class for O/N-S/N BBA LIBOR indexes but the EUR ones 26 // ! One day deposit LIBOR fixed by BBA. 27 // 28 // See <http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1414>. 29 // 30 public class DailyTenorLibor : IborIndex { 31 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : 32 // no o/n or s/n fixings (as the case may be) will take place 33 // when the principal centre of the currency concerned is 34 // closed but London is open on the fixing day. 35 public DailyTenorLibor(string familyName, int settlementDays, Currency currency, Calendar financialCenterCalendar, 36 DayCounter dayCounter) 37 : this(familyName, settlementDays, currency, financialCenterCalendar, dayCounter, new Handle<YieldTermStructure>()) { 38 } 25 39 26 //! base class for O/N-S/N BBA LIBOR indexes but the EUR ones 27 // ! One day deposit LIBOR fixed by BBA. 28 // 29 // See <http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1414>. 30 // 31 public class DailyTenorLibor : IborIndex 32 { 33 34 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : 35 // no o/n or s/n fixings (as the case may be) will take place 36 // when the principal centre of the currency concerned is 37 // closed but London is open on the fixing day. 38 39 public DailyTenorLibor(string familyName, int settlementDays, Currency currency, Calendar financialCenterCalendar, DayCounter dayCounter) : this(familyName, settlementDays, currency, financialCenterCalendar, dayCounter, new Handle<YieldTermStructure>()) 40 { 41 } 42 43 public DailyTenorLibor(string familyName, int settlementDays, Currency currency, Calendar financialCenterCalendar, DayCounter dayCounter, Handle<YieldTermStructure> h) 44 : base(familyName, new Period(1, TimeUnit.Days), settlementDays, currency, new JointCalendar(new UnitedKingdom(UnitedKingdom.Market.Exchange), financialCenterCalendar, JointCalendar.JointCalendarRule.JoinHolidays), 45 Utils.liborConvention(new Period(1, TimeUnit.Days)), 46 Utils.liborEOM(new Period(1, TimeUnit.Days)), dayCounter, h) 47 { 48 if (!(currency!= new EURCurrency())) 40 public DailyTenorLibor(string familyName, int settlementDays, Currency currency, Calendar financialCenterCalendar, 41 DayCounter dayCounter, Handle<YieldTermStructure> h) 42 : base(familyName, new Period(1, TimeUnit.Days), settlementDays, currency, 43 new JointCalendar(new UnitedKingdom(UnitedKingdom.Market.Exchange), financialCenterCalendar, JointCalendar.JointCalendarRule.JoinHolidays), 44 Utils.liborConvention(new Period(1, TimeUnit.Days)), Utils.liborEOM(new Period(1, TimeUnit.Days)), dayCounter, h) { 45 if (!(currency != new EURCurrency())) 49 46 throw new ApplicationException("for EUR Libor dedicated EurLibor constructor must be used"); 50 }51 }47 } 48 } 52 49 } trunk/QLNet/QLNet/Indexes/Ibor/Euribor.cs
r61 r225 23 23 24 24 namespace QLNet { 25 26 // %Euribor index 27 // Euribor rate fixed by the ECB. 28 // This is the rate fixed by the ECB. Use EurLibor if you're interested in the London fixing by BBA. 29 public class Euribor : IborIndex { 30 public Euribor(Period tenor) : this(tenor, new Handle<YieldTermStructure>()) { } 31 public Euribor(Period tenor, Handle<YieldTermStructure> h) : 32 base("Euribor", tenor, 2, // settlementDays 33 new EURCurrency(), new TARGET(), 34 euriborConvention(tenor), euriborEOM(tenor), 35 new Actual360(), h) { } 36 37 private static BusinessDayConvention euriborConvention(Period p) { 25 public static partial class Utils { 26 public static BusinessDayConvention euriborConvention(Period p) { 38 27 switch (p.units()) { 39 28 case TimeUnit.Days: … … 44 33 return BusinessDayConvention.ModifiedFollowing; 45 34 default: 46 throw Error.UnknownTimeUnit(p.units());35 throw new ArgumentException("Unknown TimeUnit: " + p.units()); 47 36 } 48 37 } 49 38 50 p rivatestatic bool euriborEOM(Period p) {39 public static bool euriborEOM(Period p) { 51 40 switch (p.units()) { 52 41 case TimeUnit.Days: … … 57 46 return true; 58 47 default: 59 throw Error.UnknownTimeUnit(p.units());48 throw new ArgumentException("Unknown TimeUnit: " + p.units()); 60 49 } 61 50 } 51 } 52 /// <summary> 53 /// %Euribor index 54 /// Euribor rate fixed by the ECB. 55 /// This is the rate fixed by the ECB. Use EurLibor if you're interested in the London fixing by BBA. 56 /// </summary> 57 public class Euribor : IborIndex { 58 public Euribor(Period tenor) : this(tenor, new Handle<YieldTermStructure>()) { } 59 public Euribor(Period tenor, Handle<YieldTermStructure> h) : 60 base("Euribor", tenor, 2, // settlementDays 61 new EURCurrency(), new TARGET(), 62 Utils.euriborConvention(tenor), Utils.euriborEOM(tenor), 63 new Actual360(), h) { } 64 } 65 66 //! Actual/365 %Euribor index 67 /*! Euribor rate adjusted for the mismatch between the actual/360 68 convention used for Euribor and the actual/365 convention 69 previously used by a few pre-EUR currencies. 70 */ 71 public class Euribor365 : IborIndex { 72 public Euribor365(Period tenor) : this(tenor, new Handle<YieldTermStructure>()) { } 73 public Euribor365(Period tenor, Handle<YieldTermStructure> h) 74 : base("Euribor365", tenor, 75 2, // settlement days 76 new EURCurrency(), new TARGET(), Utils.euriborConvention(tenor), Utils.euriborEOM(tenor), 77 new Actual365Fixed(), h) { 78 if (tenor.units() == TimeUnit.Days) 79 throw new ApplicationException("for daily tenors (" + tenor + ") dedicated DailyTenor constructor must be used"); 80 } 81 } 82 83 84 //! Daily tenor %Euribor index 85 /*! Euribor rate fixed by the ECB. 86 87 \warning This is the rate fixed by the ECB. Use EurLibor 88 if you're interested in the London fixing by BBA. 89 */ 90 public class DailyTenorEuribor : IborIndex { 91 public DailyTenorEuribor(int settlementDays) : this(settlementDays, new Handle<YieldTermStructure>()) { } 92 public DailyTenorEuribor(int settlementDays, Handle<YieldTermStructure> h) 93 : base("Euribor", new Period(1, TimeUnit.Days), settlementDays, 94 new EURCurrency(), new TARGET(), 95 Utils.euriborConvention(new Period(1, TimeUnit.Days)), Utils.euriborEOM(new Period(1, TimeUnit.Days)), 96 new Actual360(), h) { } 97 } 98 99 //! Daily tenor Actual/365 %Euribor index 100 /*! Euribor rate adjusted for the mismatch between the actual/360 101 convention used for Euribor and the actual/365 convention 102 previously used by a few pre-EUR currencies. 103 */ 104 public class DailyTenorEuribor365 : IborIndex { 105 public DailyTenorEuribor365(int settlementDays) : this(settlementDays, new Handle<YieldTermStructure>()) { } 106 public DailyTenorEuribor365(int settlementDays, Handle<YieldTermStructure> h) 107 : base("Euribor365", new Period(1, TimeUnit.Days), 108 settlementDays, 109 new EURCurrency(), new TARGET(), 110 Utils.euriborConvention(new Period(1, TimeUnit.Days)), Utils.euriborEOM(new Period(1, TimeUnit.Days)), 111 new Actual365Fixed(), h) {} 112 } 113 114 //! 1-week %Euribor index 115 public class EuriborSW : Euribor { 116 public EuriborSW() : this(new Handle<YieldTermStructure>()) { } 117 public EuriborSW(Handle<YieldTermStructure> h) : base(new Period(1, TimeUnit.Weeks), h) { } 118 } 119 120 //! 2-weeks %Euribor index 121 public class Euribor2W : Euribor { 122 public Euribor2W() : this(new Handle<YieldTermStructure>()) { } 123 public Euribor2W(Handle<YieldTermStructure> h) : base(new Period(2, TimeUnit.Weeks), h) { } 124 } 125 126 //! 3-weeks %Euribor index 127 public class Euribor3W : Euribor { 128 public Euribor3W() : this(new Handle<YieldTermStructure>()) { } 129 public Euribor3W(Handle<YieldTermStructure> h) : base(new Period(3, TimeUnit.Weeks), h) { } 130 } 131 132 //! 1-month %Euribor index 133 public class Euribor1M : Euribor { 134 public Euribor1M() : this(new Handle<YieldTermStructure>()) { } 135 public Euribor1M(Handle<YieldTermStructure> h) : base(new Period(1, TimeUnit.Months), h) { } 136 } 137 138 //! 2-months %Euribor index 139 public class Euribor2M : Euribor { 140 public Euribor2M() : this(new Handle<YieldTermStructure>()) { } 141 public Euribor2M(Handle<YieldTermStructure> h) : base(new Period(2, TimeUnit.Months), h) { } 62 142 } 63 143 … … 65 145 public class Euribor3M : Euribor { 66 146 public Euribor3M() : this(new Handle<YieldTermStructure>()) { } 67 public Euribor3M(Handle<YieldTermStructure> h) 68 : base(new Period(3, TimeUnit.Months), h) {} 147 public Euribor3M(Handle<YieldTermStructure> h) : base(new Period(3, TimeUnit.Months), h) {} 69 148 } 149 150 // 4-months %Euribor index 151 public class Euribor4M : Euribor { 152 public Euribor4M() : this(new Handle<YieldTermStructure>()) { } 153 public Euribor4M(Handle<YieldTermStructure> h) : base(new Period(4, TimeUnit.Months), h) { } 154 } 155 156 // 5-months %Euribor index 157 public class Euribor5M : Euribor { 158 public Euribor5M() : this(new Handle<YieldTermStructure>()) { } 159 public Euribor5M(Handle<YieldTermStructure> h) : base(new Period(5, TimeUnit.Months), h) { } 160 } 161 70 162 // 6-months %Euribor index 71 163 public class Euribor6M : Euribor { 72 164 public Euribor6M() : this(new Handle<YieldTermStructure>()) { } 73 public Euribor6M(Handle<YieldTermStructure> h) 74 : base(new Period(6, TimeUnit.Months), h) { } 165 public Euribor6M(Handle<YieldTermStructure> h) : base(new Period(6, TimeUnit.Months), h) { } 75 166 } 76 167 } trunk/QLNet/QLNet/Indexes/Ibor/Eurlibor.cs
r111 r225 23 23 24 24 namespace QLNet { 25 26 public static partial class Utils 27 { 28 public static BusinessDayConvention eurliborConvention(Period p) 29 { 30 switch (p.units()) 31 { 25 public static partial class Utils { 26 public static BusinessDayConvention eurliborConvention(Period p) { 27 switch (p.units()) { 32 28 case TimeUnit.Days: 33 29 case TimeUnit.Weeks: … … 37 33 return BusinessDayConvention.ModifiedFollowing; 38 34 default: 39 throw Error.UnknownTimeUnit(p.units());35 throw new ArgumentException("Unknown TimeUnit: " + p.units()); 40 36 } 41 37 } 42 38 43 public static bool eurliborEOM(Period p) 44 { 45 switch (p.units()) 46 { 39 public static bool eurliborEOM(Period p) { 40 switch (p.units()) { 47 41 case TimeUnit.Days: 48 42 case TimeUnit.Weeks: … … 52 46 return true; 53 47 default: 54 throw Error.UnknownTimeUnit(p.units());48 throw new ArgumentException("Unknown TimeUnit: " + p.units()); 55 49 } 56 50 } 57 51 } 58 52 59 //! base class for all BBA %EUR %LIBOR indexes but the O/N 60 // ! Euro LIBOR fixed by BBA. 61 // 62 // See <http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1414>. 63 // 64 // \warning This is the rate fixed in London by BBA. Use Euribor if 65 // you're interested in the fixing by the ECB. 66 // 67 public class EURLibor : IborIndex 68 {53 /// <summary> 54 /// base class for all BBA %EUR %LIBOR indexes but the O/N 55 /// ! Euro LIBOR fixed by BBA. 56 /// 57 /// See <http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1414>. 58 /// 59 /// \warning This is the rate fixed in London by BBA. Use Euribor if 60 /// you're interested in the fixing by the ECB. 61 /// </summary> 62 public class EURLibor : IborIndex { 69 63 private Calendar target_; 70 64 71 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 :72 // JoinBusinessDays is the fixing calendar for73 // all indexes but o/n65 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : 66 // JoinBusinessDays is the fixing calendar for 67 // all indexes but o/n 74 68 75 69 public EURLibor(Period tenor) 76 70 : base("EURLibor", tenor, 2, new EURCurrency(), new JointCalendar(new UnitedKingdom(UnitedKingdom.Market.Exchange), new TARGET(), 77 71 JointCalendar.JointCalendarRule.JoinHolidays), 78 Utils.eurliborConvention(tenor), Utils.eurliborEOM(tenor), new Actual360(), 79 new Handle<YieldTermStructure>()) 80 { 72 Utils.eurliborConvention(tenor), Utils.eurliborEOM(tenor), new Actual360(), 73 new Handle<YieldTermStructure>()) { 81 74 target_ = new TARGET(); 82 75 if (!(tenor.units() != TimeUnit.Days)) … … 84 77 } 85 78 86 public EURLibor(Period tenor, Handle<YieldTermStructure> h) 79 public EURLibor(Period tenor, Handle<YieldTermStructure> h) 87 80 : base("EURLibor", tenor, 2, new EURCurrency(), new JointCalendar(new UnitedKingdom(UnitedKingdom.Market.Exchange), new TARGET(), 88 81 JointCalendar.JointCalendarRule.JoinHolidays), 89 Utils.eurliborConvention(tenor), Utils.eurliborEOM(tenor), new Actual360(), h) 90 { 91 target_ = new TARGET(); 92 if (!(tenor.units()!= TimeUnit.Days)) 82 Utils.eurliborConvention(tenor), Utils.eurliborEOM(tenor), new Actual360(), h) { 83 target_ = new TARGET(); 84 if (!(tenor.units() != TimeUnit.Days)) 93 85 throw new ApplicationException("for daily tenors (" + tenor + ") dedicated DailyTenor constructor must be used"); 94 } 95 96 // ! \name Date calculations 97 // 98 // see http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 99 // @{ 100 // 101 public override Date valueDate(Date fixingDate) 102 { 103 104 if (!(isValidFixingDate(fixingDate))) 86 } 87 88 // ! \name Date calculations 89 // 90 // see http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 91 // @{ 92 // 93 public override Date valueDate(Date fixingDate) { 94 95 if (!(isValidFixingDate(fixingDate))) 105 96 throw new ApplicationException("Fixing date " + fixingDate + " is not valid"); 106 107 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : 108 // In the case of EUR the Value Date shall be two TARGET 109 // business days after the Fixing Date. 110 return target_.advance(fixingDate, fixingDays_, TimeUnit.Days); 111 } 112 public override Date maturityDate(Date valueDate) 113 { 114 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : 115 // In the case of EUR only, maturity dates will be based on days in 116 // which the Target system is open. 117 return target_.advance(valueDate, tenor_, convention_, endOfMonth()); 118 } 119 } 120 121 //! base class for the one day deposit BBA %EUR %LIBOR indexes 122 // ! Euro O/N LIBOR fixed by BBA. It can be also used for T/N and S/N 123 // indexes, even if such indexes do not have BBA fixing. 124 // 125 // See <http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1414>. 126 // 127 // \warning This is the rate fixed in London by BBA. Use Euribor if 128 // you're interested in the fixing by the ECB. 129 // 130 public class DailyTenorEURLibor : IborIndex 131 { 132 133 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : 134 // no o/n or s/n fixings (as the case may be) will take place 135 // when the principal centre of the currency concerned is 136 // closed but London is open on the fixing day. 137 public DailyTenorEURLibor(int settlementDays) : this(settlementDays, new Handle<YieldTermStructure>()) 138 { 139 } 97 98 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : 99 // In the case of EUR the Value Date shall be two TARGET 100 // business days after the Fixing Date. 101 return target_.advance(fixingDate, fixingDays_, TimeUnit.Days); 102 } 103 public override Date maturityDate(Date valueDate) { 104 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : 105 // In the case of EUR only, maturity dates will be based on days in 106 // which the Target system is open. 107 return target_.advance(valueDate, tenor_, convention_, endOfMonth()); 108 } 109 } 110 111 //! base class for the one day deposit BBA %EUR %LIBOR indexes 112 // ! Euro O/N LIBOR fixed by BBA. It can be also used for T/N and S/N 113 // indexes, even if such indexes do not have BBA fixing. 114 // 115 // See <http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1414>. 116 // 117 // \warning This is the rate fixed in London by BBA. Use Euribor if 118 // you're interested in the fixing by the ECB. 119 // 120 public class DailyTenorEURLibor : IborIndex { 121 122 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : 123 // no o/n or s/n fixings (as the case may be) will take place 124 // when the principal centre of the currency concerned is 125 // closed but London is open on the fixing day. 126 public DailyTenorEURLibor(int settlementDays) 127 : this(settlementDays, new Handle<YieldTermStructure>()) { 128 } 140 129 public DailyTenorEURLibor() 141 130 : base("EURLibor", new Period(1, TimeUnit.Days), 0, new EURCurrency(), new TARGET(), 142 Utils.eurliborConvention(new Period(1, TimeUnit.Days)), Utils.eurliborEOM(new Period(1, TimeUnit.Days)), new Actual360(), new Handle<YieldTermStructure>()) 143 { 144 } 131 Utils.eurliborConvention(new Period(1, TimeUnit.Days)), Utils.eurliborEOM(new Period(1, TimeUnit.Days)), new Actual360(), new Handle<YieldTermStructure>()) { 132 } 145 133 public DailyTenorEURLibor(int settlementDays, Handle<YieldTermStructure> h) 146 134 : base("EURLibor", new Period(1, TimeUnit.Days), settlementDays, new EURCurrency(), new TARGET(), 147 Utils.eurliborConvention(new Period(1, TimeUnit.Days)), Utils.eurliborEOM(new Period(1, TimeUnit.Days)), new Actual360(), h) 148 { 149 } 150 } 151 152 //! Overnight %EUR %Libor index 153 public class EURLiborON : DailyTenorEURLibor 154 { 155 public EURLiborON() : base(0, new Handle<YieldTermStructure>()) 156 { 157 } 158 159 public EURLiborON(Handle<YieldTermStructure> h) : base(0, h) 160 { 161 } 162 } 163 164 //! 1-week %EUR %Libor index 165 public class EURLiborSW : EURLibor 166 { 167 public EURLiborSW() : base(new Period(1, TimeUnit.Weeks), new Handle<YieldTermStructure>()) 168 { 169 } 170 public EURLiborSW(Handle<YieldTermStructure> h) : base(new Period(1, TimeUnit.Weeks), h) 171 { 172 } 173 } 174 175 //! 2-weeks %EUR %Libor index 176 public class EURLibor2W : EURLibor 177 { 178 public EURLibor2W() : base(new Period(2, TimeUnit.Weeks), new Handle<YieldTermStructure>()) 179 { 180 } 181 public EURLibor2W(Handle<YieldTermStructure> h) : base(new Period(2, TimeUnit.Weeks), h) 182 { 183 } 184 } 185 186 187 //! 1-month %EUR %Libor index 188 public class EURLibor1M : EURLibor 189 { 190 public EURLibor1M() : base(new Period(1, TimeUnit.Months), new Handle<YieldTermStructure>()) 191 { 192 } 193 public EURLibor1M(Handle<YieldTermStructure> h) : base(new Period(1, TimeUnit.Months), h) 194 { 195 } 196 } 197 198 //! 2-months %EUR %Libor index 199 public class EURLibor2M : EURLibor 200 { 201 public EURLibor2M() : base(new Period(2, TimeUnit.Months), new Handle<YieldTermStructure>()) 202 { 203 } 204 public EURLibor2M(Handle<YieldTermStructure> h) : base(new Period(2, TimeUnit.Months), h) 205 { 206 } 207 } 208 209 //! 3-months %EUR %Libor index 210 public class EURLibor3M : EURLibor 211 { 212 public EURLibor3M() : base(new Period(3, TimeUnit.Months), new Handle<YieldTermStructure>()) 213 { 214 } 215 public EURLibor3M(Handle<YieldTermStructure> h) : base(new Period(3, TimeUnit.Months), h) 216 { 217 } 218 } 219 220 //! 4-months %EUR %Libor index 221 public class EURLibor4M : EURLibor 222 { 223 public EURLibor4M() : base(new Period(4, TimeUnit.Months), new Handle<YieldTermStructure>()) 224 { 225 } 226 public EURLibor4M(Handle<YieldTermStructure> h) : base(new Period(4, TimeUnit.Months), h) 227 { 228 } 229 } 230 231 //! 5-months %EUR %Libor index 232 public class EURLibor5M : EURLibor 233 { 234 public EURLibor5M() : base(new Period(5, TimeUnit.Months), new Handle<YieldTermStructure>()) 235 { 236 } 237 public EURLibor5M(Handle<YieldTermStructure> h) : base(new Period(5, TimeUnit.Months), h) 238 { 239 } 240 } 241 242 //! 6-months %EUR %Libor index 243 public class EURLibor6M : EURLibor 244 { 245 public EURLibor6M() : base(new Period(6, TimeUnit.Months), new Handle<YieldTermStructure>()) 246 { 247 } 248 public EURLibor6M(Handle<YieldTermStructure> h) : base(new Period(6, TimeUnit.Months), h) 249 { 250 } 251 } 252 253 //! 7-months %EUR %Libor index 254 public class EURLibor7M : EURLibor 255 { 256 public EURLibor7M() : base(new Period(7, TimeUnit.Months), new Handle<YieldTermStructure>()) 257 { 258 } 259 public EURLibor7M(Handle<YieldTermStructure> h) : base(new Period(7, TimeUnit.Months), h) 260 { 261 } 262 } 263 264 //! 8-months %EUR %Libor index 265 public class EURLibor8M : EURLibor 266 { 267 public EURLibor8M() : base(new Period(8, TimeUnit.Months), new Handle<YieldTermStructure>()) 268 { 269 } 270 public EURLibor8M(Handle<YieldTermStructure> h) : base(new Period(8, TimeUnit.Months), h) 271 { 272 } 273 } 274 275 //! 9-months %EUR %Libor index 276 public class EURLibor9M : EURLibor 277 { 278 public EURLibor9M() : base(new Period(9, TimeUnit.Months), new Handle<YieldTermStructure>()) 279 { 280 } 281 public EURLibor9M(Handle<YieldTermStructure> h) : base(new Period(9, TimeUnit.Months), h) 282 { 283 } 284 } 285 286 //! 10-months %EUR %Libor index 287 public class EURLibor10M : EURLibor 288 { 289 public EURLibor10M() : base(new Period(10, TimeUnit.Months), new Handle<YieldTermStructure>()) 290 { 291 } 292 public EURLibor10M(Handle<YieldTermStructure> h) : base(new Period(10, TimeUnit.Months), h) 293 { 294 } 295 } 296 297 //! 11-months %EUR %Libor index 298 public class EURLibor11M : EURLibor 299 { 300 public EURLibor11M() : base(new Period(11, TimeUnit.Months), new Handle<YieldTermStructure>()) 301 { 302 } 303 public EURLibor11M(Handle<YieldTermStructure> h) : base(new Period(11, TimeUnit.Months), h) 304 { 305 } 306 } 307 308 //! 1-year %EUR %Libor index 309 public class EURLibor1Y : EURLibor 310 { 311 public EURLibor1Y() : base(new Period(1, TimeUnit.Years), new Handle<YieldTermStructure>()) 312 { 313 } 314 public EURLibor1Y(Handle<YieldTermStructure> h) : base(new Period(1, TimeUnit.Years), h) 315 { 316 } 317 } 135 Utils.eurliborConvention(new Period(1, TimeUnit.Days)), Utils.eurliborEOM(new Period(1, TimeUnit.Days)), new Actual360(), h) { 136 } 137 } 138 139 //! Overnight %EUR %Libor index 140 public class EURLiborON : DailyTenorEURLibor { 141 public EURLiborON() 142 : base(0, new Handle<YieldTermStructure>()) { 143 } 144 145 public EURLiborON(Handle<YieldTermStructure> h) 146 : base(0, h) { 147 } 148 } 149 150 //! 1-week %EUR %Libor index 151 public class EURLiborSW : EURLibor { 152 public EURLiborSW() 153 : base(new Period(1, TimeUnit.Weeks), new Handle<YieldTermStructure>()) { 154 } 155 public EURLiborSW(Handle<YieldTermStructure> h) 156 : base(new Period(1, TimeUnit.Weeks), h) { 157 } 158 } 159 160 //! 2-weeks %EUR %Libor index 161 public class EURLibor2W : EURLibor { 162 public EURLibor2W() 163 : base(new Period(2, TimeUnit.Weeks), new Handle<YieldTermStructure>()) { 164 } 165 public EURLibor2W(Handle<YieldTermStructure> h) 166 : base(new Period(2, TimeUnit.Weeks), h) { 167 } 168 } 169 170 171 //! 1-month %EUR %Libor index 172 public class EURLibor1M : EURLibor { 173 public EURLibor1M() 174 : base(new Period(1, TimeUnit.Months), new Handle<YieldTermStructure>()) { 175 } 176 public EURLibor1M(Handle<YieldTermStructure> h) 177 : base(new Period(1, TimeUnit.Months), h) { 178 } 179 } 180 181 //! 2-months %EUR %Libor index 182 public class EURLibor2M : EURLibor { 183 public EURLibor2M() 184 : base(new Period(2, TimeUnit.Months), new Handle<YieldTermStructure>()) { 185 } 186 public EURLibor2M(Handle<YieldTermStructure> h) 187 : base(new Period(2, TimeUnit.Months), h) { 188 } 189 } 190 191 //! 3-months %EUR %Libor index 192 public class EURLibor3M : EURLibor { 193 public EURLibor3M() 194 : base(new Period(3, TimeUnit.Months), new Handle<YieldTermStructure>()) { 195 } 196 public EURLibor3M(Handle<YieldTermStructure> h) 197 : base(new Period(3, TimeUnit.Months), h) { 198 } 199 } 200 201 //! 4-months %EUR %Libor index 202 public class EURLibor4M : EURLibor { 203 public EURLibor4M() 204 : base(new Period(4, TimeUnit.Months), new Handle<YieldTermStructure>()) { 205 } 206 public EURLibor4M(Handle<YieldTermStructure> h) 207 : base(new Period(4, TimeUnit.Months), h) { 208 } 209 } 210 211 //! 5-months %EUR %Libor index 212 public class EURLibor5M : EURLibor { 213 public EURLibor5M() 214 : base(new Period(5, TimeUnit.Months), new Handle<YieldTermStructure>()) { 215 } 216 public EURLibor5M(Handle<YieldTermStructure> h) 217 : base(new Period(5, TimeUnit.Months), h) { 218 } 219 } 220 221 //! 6-months %EUR %Libor index 222 public class EURLibor6M : EURLibor { 223 public EURLibor6M() 224 : base(new Period(6, TimeUnit.Months), new Handle<YieldTermStructure>()) { 225 } 226 public EURLibor6M(Handle<YieldTermStructure> h) 227 : base(new Period(6, TimeUnit.Months), h) { 228 } 229 } 230 231 //! 7-months %EUR %Libor index 232 public class EURLibor7M : EURLibor { 233 public EURLibor7M() 234 : base(new Period(7, TimeUnit.Months), new Handle<YieldTermStructure>()) { 235 } 236 public EURLibor7M(Handle<YieldTermStructure> h) 237 : base(new Period(7, TimeUnit.Months), h) { 238 } 239 } 240 241 //! 8-months %EUR %Libor index 242 public class EURLibor8M : EURLibor { 243 public EURLibor8M() 244 : base(new Period(8, TimeUnit.Months), new Handle<YieldTermStructure>()) { 245 } 246 public EURLibor8M(Handle<YieldTermStructure> h) 247 : base(new Period(8, TimeUnit.Months), h) { 248 } 249 } 250 251 //! 9-months %EUR %Libor index 252 public class EURLibor9M : EURLibor { 253 public EURLibor9M() 254 : base(new Period(9, TimeUnit.Months), new Handle<YieldTermStructure>()) { 255 } 256 public EURLibor9M(Handle<YieldTermStructure> h) 257 : base(new Period(9, TimeUnit.Months), h) { 258 } 259 } 260 261 //! 10-months %EUR %Libor index 262 public class EURLibor10M : EURLibor { 263 public EURLibor10M() 264 : base(new Period(10, TimeUnit.Months), new Handle<YieldTermStructure>()) { 265 } 266 public EURLibor10M(Handle<YieldTermStructure> h) 267 : base(new Period(10, TimeUnit.Months), h) { 268 } 269 } 270 271 //! 11-months %EUR %Libor index 272 public class EURLibor11M : EURLibor { 273 public EURLibor11M() 274 : base(new Period(11, TimeUnit.Months), new Handle<YieldTermStructure>()) { 275 } 276 public EURLibor11M(Handle<YieldTermStructure> h) 277 : base(new Period(11, TimeUnit.Months), h) { 278 } 279 } 280 281 //! 1-year %EUR %Libor index 282 public class EURLibor1Y : EURLibor { 283 public EURLibor1Y() 284 : base(new Period(1, TimeUnit.Years), new Handle<YieldTermStructure>()) { 285 } 286 public EURLibor1Y(Handle<YieldTermStructure> h) 287 : base(new Period(1, TimeUnit.Years), h) { 288 } 289 } 318 290 319 291 trunk/QLNet/QLNet/Indexes/Ibor/Usdlibor.cs
r144 r225 33 33 : base("USDLibor", tenor, 2, new USDCurrency(), new UnitedStates(UnitedStates.Market.NYSE), new Actual360(), h) { } 34 34 } 35 36 //! Overnight %USD %Libor index 37 public class USDLiborON : DailyTenorLibor { 38 public USDLiborON() : this(new Handle<YieldTermStructure>()) { } 39 public USDLiborON(Handle<YieldTermStructure> h) 40 : base("USDLibor", 0, new USDCurrency(), new UnitedStates(UnitedStates.Market.NYSE), new Actual360(), h) {} 41 } 35 42 } trunk/QLNet/QLNet/Instruments/Bonds/Fixedratebond.cs
r218 r225 27 27 protected DayCounter dayCounter_; 28 28 29 //BusinessDayConvention paymentConvention = Following, 30 //Real redemption = 100.0, 31 //const Date& issueDate = Date()); 32 public FixedRateBond(int settlementDays, double faceAmount, Schedule schedule, List<double> coupons, 33 DayCounter accrualDayCounter) 34 : this(settlementDays, faceAmount, schedule, coupons, accrualDayCounter, BusinessDayConvention.Following, 100, null) { } 29 35 public FixedRateBond(int settlementDays, double faceAmount, Schedule schedule, List<double> coupons, 30 36 DayCounter accrualDayCounter, BusinessDayConvention paymentConvention, trunk/QLNet/QLNet/Instruments/Bonds/FloatingRateBond.cs
r218 r225 26 26 //! \test calculations are tested by checking results against cached values. 27 27 public class FloatingRateBond : Bond { 28 //public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter accrualDayCounter, 29 // BusinessDayConvention paymentConvention = Following, 30 // int fixingDays = Null<Natural>(), 31 // List<double> gearings = std::vector<Real>(1, 1.0), 32 // List<double> spreads = std::vector<Spread>(1, 0.0), 33 // List<double> caps = std::vector<Rate>(), 34 // List<double> floors = std::vector<Rate>(), 35 // bool inArrears = false, 36 // double redemption = 100.0, 37 // Date issueDate = Date()) 28 public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter) 29 : this(settlementDays, faceAmount, schedule, index, paymentDayCounter, BusinessDayConvention.Following, 30 0, new List<double>() { 1 }, new List<double>() { 1 }, new List<double>(), new List<double>(), 31 false, 100, null) { } 38 32 public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter, 39 33 BusinessDayConvention paymentConvention, int fixingDays, List<double> gearings, List<double> spreads, trunk/QLNet/QLNet/Math/Matrix.cs
r224 r225 79 79 } 80 80 81 public Matrix( refMatrix from) {82 data_ = !from.empty() ? new double[from.rows_, from.columns_]: null;81 public Matrix(Matrix from) { 82 data_ = !from.empty() ? from.data_ : null; 83 83 rows_ = from.rows_; 84 84 columns_ = from.columns_; 85 86 for (int i = 0; i < rows_; i++)87 for (int j = 0; j < columns_; j++)88 data_[i, j] = from.data_[i, j];89 85 } 90 // Matrix(const Disposable<Matrix>&);91 86 #endregion 92 87 … … 175 170 } 176 171 172 public void fill(double value) { 173 for (int i = 0; i < rows(); i++) 174 for (int j = 0; j < columns(); j++) 175 data_[j, i] = value; 176 } 177 177 178 public void swap(int i1, int j1, int i2, int j2) { 178 179 double t = this[i2, j2]; trunk/QLNet/QLNet/Math/matrixutilities/svd.cs
r224 r225 67 67 // we're sure that m_ >= n_ 68 68 s_ = new Vector(n_); 69 U_ = new Matrix(m_, n_ , 0.0);69 U_ = new Matrix(m_, n_); 70 70 V_ = new Matrix(n_, n_); 71 71 Vector e = new Vector(n_); … … 117 117 } 118 118 if (k < nct) { 119 120 119 // Place the transformation in U for subsequent back multiplication. 121 120 for (i = k; i < m_; i++) { … … 124 123 } 125 124 if (k < nrt) { 126 127 125 // Compute the k-th row transformation and place the k-th super-diagonal in e[k]. 128 126 // Compute 2-norm without under/overflow. … … 142 140 e[k] = -e[k]; 143 141 if ((k + 1 < m_) & (e[k] != 0.0)) { 144 145 142 // Apply the transformation. 146 143 for (i = k + 1; i < m_; i++) { trunk/QLNet/QLNet/Methods/montecarlo/earlyexercisepathpricer.cs
r223 r225 23 23 24 24 namespace QLNet { 25 public interface IPath : ICloneable { 26 int length(); 27 } 28 25 29 //! base class for early exercise path pricers 26 30 /*! Returns the value of an option on a given path and given time. 27 28 \ingroup mcarlo29 31 */ 30 31 public static class EarlyExerciseTraits<PathType> where PathType : Path { 32 public static class EarlyExerciseTraits<PathType> where PathType : IPath { 32 33 //typedef Real StateType; 33 34 public static int pathLength(PathType path) { return path.length(); } … … 36 37 37 38 // template<class PathType, class TimeType=Size, class ValueType=Real> 38 public interface EarlyExercisePathPricer<PathType>{39 public interface IEarlyExercisePathPricer<PathType, StateType> where PathType : IPath { 39 40 // typedef typename EarlyExerciseTraits<PathType>::StateType StateType; 40 41 41 42 double value(PathType path, int t); 42 43 43 double state(PathType path, int t);44 List<Func< double, double>> basisSystem();44 StateType state(PathType path, int t); 45 List<Func<StateType, double>> basisSystem(); 45 46 } 46 47 } trunk/QLNet/QLNet/Methods/montecarlo/longstaffschwartzpathpricer.cs
r224 r225 35 35 reproducing results available in web/literature 36 36 */ 37 public class LongstaffSchwartzPathPricer<PathType> : PathPricer<PathType> where PathType : Path, ICloneable{37 public class LongstaffSchwartzPathPricer<PathType> : PathPricer<PathType> where PathType : IPath { 38 38 protected bool calibrationPhase_; 39 protected EarlyExercisePathPricer<PathType> pathPricer_;39 protected IEarlyExercisePathPricer<PathType, double> pathPricer_; 40 40 41 41 protected List<Vector> coeff_; … … 45 45 protected List<Func<double, double>> v_; 46 46 47 public LongstaffSchwartzPathPricer(TimeGrid times, EarlyExercisePathPricer<PathType> pathPricer,47 public LongstaffSchwartzPathPricer(TimeGrid times, IEarlyExercisePathPricer<PathType, double> pathPricer, 48 48 YieldTermStructure termStructure) { 49 49 calibrationPhase_ = true; … … 60 60 61 61 62 public overridedouble value(PathType path) {62 public double value(PathType path) { 63 63 if (calibrationPhase_) { 64 64 // store paths for the calibration trunk/QLNet/QLNet/Methods/montecarlo/montecarlomodel.cs
r215 r225 52 52 53 53 private PathGenerator<IRNG> pathGenerator_; 54 private PathPricer< Path> pathPricer_;54 private PathPricer<IPath> pathPricer_; 55 55 private S sampleAccumulator_; 56 56 private bool isAntitheticVariate_; 57 private PathPricer< Path> cvPathPricer_;57 private PathPricer<IPath> cvPathPricer_; 58 58 private double cvOptionValue_; 59 59 private bool isControlVariate_; … … 66 66 // result_type cvOptionValue = result_type(), 67 67 // PathGenerator<IRNG> cvPathGenerator = path_generator_type()) { 68 public MonteCarloModel(PathGenerator<IRNG> pathGenerator, PathPricer< Path> pathPricer, S sampleAccumulator,68 public MonteCarloModel(PathGenerator<IRNG> pathGenerator, PathPricer<IPath> pathPricer, S sampleAccumulator, 69 69 bool antitheticVariate) 70 70 : this(pathGenerator, pathPricer, sampleAccumulator, antitheticVariate, null, 0, null) { } 71 public MonteCarloModel(PathGenerator<IRNG> pathGenerator, PathPricer< Path> pathPricer, S sampleAccumulator,72 bool antitheticVariate, PathPricer< Path> cvPathPricer, double cvOptionValue,71 public MonteCarloModel(PathGenerator<IRNG> pathGenerator, PathPricer<IPath> pathPricer, S sampleAccumulator, 72 bool antitheticVariate, PathPricer<IPath> cvPathPricer, double cvOptionValue, 73 73 PathGenerator<IRNG> cvPathGenerator) { 74 74 pathGenerator_ = pathGenerator; trunk/QLNet/QLNet/Methods/montecarlo/multipath.cs
r192 r225 29 29 \ingroup mcarlo 30 30 */ 31 public class MultiPath {31 public class MultiPath : IPath { 32 32 private List<Path> multiPath_; 33 33 … … 44 44 //! \name inspectors 45 45 public int assetNumber() { return multiPath_.Count; } 46 public int length() { return pathSize(); } 46 47 public int pathSize() { return multiPath_[0].length(); } 47 48 48 49 //! \name read/write access to components 49 50 public Path this[int j] { get { return multiPath_[j]; } set { multiPath_[j] = value; } } 51 52 // ICloneable interface 53 public object Clone() { 54 MultiPath temp = (MultiPath)this.MemberwiseClone(); 55 temp.multiPath_ = new List<Path>(this.multiPath_); 56 return temp; 57 } 50 58 } 51 59 } trunk/QLNet/QLNet/Methods/montecarlo/path.cs
r224 r225 28 28 \note the path includes the initial asset value as its first point. 29 29 */ 30 public class Path : ICloneable {30 public class Path : ICloneable, IPath { 31 31 private TimeGrid timeGrid_; 32 32 private Vector values_; trunk/QLNet/QLNet/Methods/montecarlo/pathpricer.cs
r194 r225 28 28 \ingroup mcarlo 29 29 */ 30 public classPathPricer<PathType> {31 public virtual double value(PathType pt) { throw new NotSupportedException(); }30 public interface PathPricer<PathType> { 31 double value(PathType pt); 32 32 } 33 33 } trunk/QLNet/QLNet/Methods/montecarlo/sample.cs
r224 r225 25 25 //! weighted sample 26 26 /*! \ingroup mcarlo */ 27 // todo check for Sample for value types and Sample for object types to take care of proper object copying 27 28 public struct Sample<T> { 28 29 public T value; trunk/QLNet/QLNet/Pricingengines/mclongstaffschwartzengine.cs
r198 r225 33 33 reproducing results available in web/literature 34 34 */ 35 public abstract class MCLongstaffSchwartzEngine<GenericEngine, MC, RNG> 36 : MCLongstaffSchwartzEngine<GenericEngine, MC, RNG, Statistics> 37 where GenericEngine : IPricingEngine, new() 38 where RNG : IRSG, new() { 39 protected MCLongstaffSchwartzEngine(StochasticProcess process, int timeSteps, int timeStepsPerYear, 40 bool brownianBridge, bool antitheticVariate, bool controlVariate, 41 int requiredSamples, double requiredTolerance, int maxSamples, 42 ulong seed, int nCalibrationSamples) : 43 base(process, timeSteps, timeStepsPerYear, brownianBridge, antitheticVariate, controlVariate, 44 requiredSamples, requiredTolerance, maxSamples, seed, nCalibrationSamples) { } 45 } 35 46 public abstract class MCLongstaffSchwartzEngine<GenericEngine, MC, RNG, S> : McSimulation<MC, RNG, S>, IPricingEngine 36 47 where GenericEngine : IPricingEngine, new() … … 53 64 protected int nCalibrationSamples_; 54 65 55 protected LongstaffSchwartzPathPricer< Path> pathPricer_;66 protected LongstaffSchwartzPathPricer<IPath> pathPricer_; 56 67 57 68 … … 106 117 } 107 118 108 protected override PathPricer< Path> pathPricer() {119 protected override PathPricer<IPath> pathPricer() { 109 120 if (pathPricer_ == null) 110 121 throw new ApplicationException("path pricer unknown"); … … 119 130 } 120 131 121 protected abstract LongstaffSchwartzPathPricer< Path> lsmPathPricer();132 protected abstract LongstaffSchwartzPathPricer<IPath> lsmPathPricer(); 122 133 123 134 #region PricingEngine trunk/QLNet/QLNet/Pricingengines/mcsimulation.cs
r194 r225 112 112 throw new ApplicationException("engine does not provide control-variation price"); 113 113 114 PathPricer< Path> controlPP = this.controlPathPricer();114 PathPricer<IPath> controlPP = this.controlPathPricer(); 115 115 if (controlPP == null) 116 116 throw new ApplicationException("engine does not provide control-variation path pricer"); … … 135 135 136 136 137 protected abstract PathPricer< Path> pathPricer();137 protected abstract PathPricer<IPath> pathPricer(); 138 138 protected abstract PathGenerator<IRNG> pathGenerator(); 139 139 protected abstract TimeGrid timeGrid(); 140 protected virtual PathPricer< Path> controlPathPricer() { return null; }140 protected virtual PathPricer<IPath> controlPathPricer() { return null; } 141 141 protected virtual PathGenerator<IRNG> controlPathGenerator() { return null; } 142 142 protected virtual IPricingEngine controlPricingEngine() { return null; } trunk/QLNet/QLNet/Pricingengines/vanilla/mcamericanengine.cs
r224 r225 50 50 51 51 52 protected override LongstaffSchwartzPathPricer< Path> lsmPathPricer() {52 protected override LongstaffSchwartzPathPricer<IPath> lsmPathPricer() { 53 53 GeneralizedBlackScholesProcess process = process_ as GeneralizedBlackScholesProcess; 54 54 if (process == null) … … 63 63 AmericanPathPricer earlyExercisePathPricer = new AmericanPathPricer(arguments_.payoff, polynomOrder_, polynomType_); 64 64 65 return new LongstaffSchwartzPathPricer< Path>(timeGrid(), earlyExercisePathPricer, process.riskFreeRate());65 return new LongstaffSchwartzPathPricer<IPath>(timeGrid(), earlyExercisePathPricer, process.riskFreeRate()); 66 66 } 67 67 … … 91 91 } 92 92 93 protected override PathPricer< Path> controlPathPricer() {93 protected override PathPricer<IPath> controlPathPricer() { 94 94 StrikedTypePayoff payoff = arguments_.payoff as StrikedTypePayoff; 95 95 if(payoff == null) … … 106 106 107 107 108 public class AmericanPathPricer : EarlyExercisePathPricer<Path> {108 public class AmericanPathPricer : IEarlyExercisePathPricer<IPath, double> { 109 109 protected double scalingValue_; 110 110 protected Payoff payoff_; … … 134 134 135 135 // scale values of the underlying to increase numerical stability 136 public double state( Path path, int t) { return path[t]*scalingValue_; }137 public double value( Path path, int t) { return payoff(state(path, t)); }136 public double state(IPath path, int t) { return (path as Path)[t]*scalingValue_; } 137 public double value(IPath path, int t) { return payoff(state(path, t)); } 138 138 public List<Func<double, double>> basisSystem() { return v_; } 139 139 protected double payoff(double state) { return payoff_.value(state / scalingValue_); } trunk/QLNet/QLNet/Pricingengines/vanilla/mceuropeanengine.cs
r197 r225 40 40 requiredSamples, requiredTolerance, maxSamples, seed) { } 41 41 42 protected override PathPricer< Path> pathPricer() {42 protected override PathPricer<IPath> pathPricer() { 43 43 PlainVanillaPayoff payoff = arguments_.payoff as PlainVanillaPayoff; 44 44 if (payoff == null) … … 132 132 133 133 134 public class EuropeanPathPricer : PathPricer< Path> {134 public class EuropeanPathPricer : PathPricer<IPath> { 135 135 private PlainVanillaPayoff payoff_; 136 136 private double discount_; … … 143 143 } 144 144 145 public override double value(Path path) {145 public double value(IPath path) { 146 146 if (!(path.length() > 0)) 147 147 throw new ApplicationException("the path cannot be empty"); 148 return payoff_.value( path.back()) * discount_;148 return payoff_.value((path as Path).back()) * discount_; 149 149 } 150 150 } trunk/QLNet/QLNet/QLNet.csproj
r223 r225 3 3 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 4 4 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 5 <ProductVersion>9.0. 21022</ProductVersion>5 <ProductVersion>9.0.30428</ProductVersion> 6 6 <SchemaVersion>2.0</SchemaVersion> 7 7 <ProjectGuid>{F6E762BD-DCDF-4CA0-ABAD-CB21C7D03BEC}</ProjectGuid> … … 159 159 <Compile Include="Math\linearleastsquaresregression.cs" /> 160 160 <Compile Include="Math\Matrix.cs" /> 161 <Compile Include="Math\matrixutilities\choleskydecomposition.cs" /> 162 <Compile Include="Math\matrixutilities\pseudosqrt.cs" /> 161 163 <Compile Include="Math\matrixutilities\svd.cs" /> 164 <Compile Include="Math\matrixutilities\symmetricschurdecomposition.cs" /> 162 165 <Compile Include="Math\Optimization\ArmijoLineSearch.cs" /> 163 166 <Compile Include="Math\Optimization\ConjugateGradient.cs" /> … … 294 297 <Compile Include="processes\Ornsteinuhlenbeckprocess.cs" /> 295 298 <Compile Include="processes\Squarerootprocess.cs" /> 299 <Compile Include="processes\stochasticprocessarray.cs" /> 296 300 <Compile Include="Properties\AssemblyInfo.cs" /> 297 301 <Compile Include="Quotes\Quote.cs" /> trunk/QLNet/QLNet/Time/Date.cs
r217 r225 90 90 case TimeUnit.Years: { DateTime t = d.date; return new Date(t.AddYears(n)); } 91 91 default: 92 throw Error.UnknownTimeUnit(u);92 throw new ArgumentException("Unknown TimeUnit: " + u); 93 93 } 94 94 } trunk/QLNet/QLNet/Time/DayCounters/ActualActual.cs
r61 r225 24 24 //! Actual/Actual day count 25 25 /*! The day count can be calculated according to: 26 - the ISDA convention, also known as "Actual/Actual (Historical)", "Actual/Actual", "Act/Act", and according to ISDA also "Actual/365", "Act/365", and "A/365"; 26 - the ISDA convention, also known as "Actual/Actual (Historical)", "Actual/Actual", "Act/Act", 27 and according to ISDA also "Actual/365", "Act/365", and "A/365"; 27 28 - the ISMA and US Treasury convention, also known as "Actual/Actual (Bond)"; 28 29 - the AFB convention, also known as "Actual/Actual (Euro)". trunk/QLNet/QLNet/Time/Period.cs
r61 r225 21 21 using System.Text; 22 22 23 namespace QLNet 24 { 25 public class Period 26 { 23 namespace QLNet { 24 public class Period { 27 25 private int length_; 28 26 private TimeUnit unit_; … … 34 32 public Period() { length_ = 0; unit_ = TimeUnit.Days; } 35 33 public Period(int n, TimeUnit u) { length_ = n; unit_ = u; } 36 public Period(Frequency f) 37 { 38 switch (f) 39 { 34 public Period(Frequency f) { 35 switch (f) { 40 36 case Frequency.Once: 41 37 case Frequency.NoFrequency: … … 69 65 } 70 66 71 public Frequency frequency() 72 { 67 public Frequency frequency() { 73 68 int length = System.Math.Abs(length_); // unsigned version 74 69 75 70 if (length == 0) return Frequency.NoFrequency; 76 switch (unit_) 77 { 71 switch (unit_) { 78 72 case TimeUnit.Years: 79 73 if (length != 1) throw Error.CannotInitiateFrequency(this); … … 93 87 return Frequency.Daily; 94 88 default: 95 throw Error.UnknownTimeUnit(unit_); 96 } 97 } 98 99 public void normalize() 100 { 89 throw new ArgumentException("Unknown TimeUnit: " + unit_); 90 } 91 } 92 93 public void normalize() { 101 94 if (length_ != 0) 102 switch (unit_) 103 { 95 switch (unit_) { 104 96 case TimeUnit.Days: 105 if ((length_ % 7) == 0) 106 { 97 if ((length_ % 7) == 0) { 107 98 length_ /= 7; 108 99 unit_ = TimeUnit.Weeks; … … 110 101 break; 111 102 case TimeUnit.Months: 112 if ((length_ % 12) == 0) 113 { 103 if ((length_ % 12) == 0) { 114 104 length_ /= 12; 115 105 unit_ = TimeUnit.Years; … … 120 110 break; 121 111 default: 122 throw Error.UnknownTimeUnit(unit_);112 throw new ArgumentException("Unknown TimeUnit: " + unit_); 123 113 } 124 114 } … … 133 123 public static bool operator >=(Period p1, Period p2) { return !(p1 < p2); } 134 124 public static bool operator >(Period p1, Period p2) { return p2 < p1; } 135 public static bool operator <(Period p1, Period p2) 136 { 125 public static bool operator <(Period p1, Period p2) { 137 126 // special cases 138 127 if (p1.length() == 0) return (p2.length() > 0); … … 155 144 156 145 // required by operator < 157 struct pair 158 { 146 struct pair { 159 147 public int lo, hi; 160 public pair(Period p) 161 { 162 switch (p.units()) 163 { 148 public pair(Period p) { 149 switch (p.units()) { 164 150 case TimeUnit.Days: 165 151 lo = hi = p.length(); break; … … 171 157 lo = 365 * p.length(); hi = 366 * p.length(); break; 172 158 default: 173 throw Error.UnknownTimeUnit(p.units());159 throw new ArgumentException("Unknown TimeUnit: " + p.units()); 174 160 } 175 161 } … … 178 164 public override bool Equals(object o) { return this == (Period)o; } 179 165 public override int GetHashCode() { return 0; } 180 public override string ToString() 181 { 166 public override string ToString() { 182 167 return "TimeUnit: " + unit_.ToString() + ", length: " + length_.ToString(); 183 168 } 184 public string ToShortString() 185 { 169 public string ToShortString() { 186 170 string result = ""; 187 171 int n = length(); 188 172 int m = 0; 189 switch (units()) 190 { 173 switch (units()) { 191 174 case TimeUnit.Days: 192 if (n >= 7) 193 { 175 if (n >= 7) { 194 176 m = n / 7; 195 177 result += m + "W"; … … 203 185 return result + n + "W"; 204 186 case TimeUnit.Months: 205 if (n >= 12) 206 { 187 if (n >= 12) { 207 188 m = n / 12; 208 189 result += n / 12 + "Y"; trunk/QLNet/Test2008/Test2008.csproj
r224 r225 42 42 <ItemGroup> 43 43 <Compile Include="T_LinearLeastSquaresRegression.cs" /> 44 <Compile Include="T_Matrices.cs" /> 45 <Compile Include="T_Mclongstaffschwartzengine.cs" /> 44 46 <Compile Include="T_Optimizers.cs" /> 45 47 <Compile Include="Properties\AssemblyInfo.cs" />