Changeset 170
- Timestamp:
- 05/19/08 20:25:13 (4 months ago)
- Files:
-
- trunk/QLNet/QLNet/Currencies/ExchangeRate.cs (modified) (6 diffs)
- trunk/QLNet/QLNet/Math/randomnumbers/mt19937uniformrng.cs (modified) (2 diffs)
- trunk/QLNet/QLNet/Math/randomnumbers/randomsequencegenerator.cs (added)
- trunk/QLNet/QLNet/Math/randomnumbers/rngtraits.cs (added)
- trunk/QLNet/QLNet/Math/statistics (added)
- trunk/QLNet/QLNet/Math/statistics/generalstatistics.cs (added)
- trunk/QLNet/QLNet/Methods/montecarlo/sample.cs (modified) (1 diff)
- trunk/QLNet/QLNet/QLNet.csproj (modified) (3 diffs)
- trunk/QLNet/QLNet/Termstructures/InflationTermStructure.cs (modified) (3 diffs)
- trunk/QLNet/QLNet/Util (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/QLNet/QLNet/Currencies/ExchangeRate.cs
r61 r170 1 1 /* 2 2 Copyright (C) 2008 Andrea Maggiulli 3 Copyright (C) 2008 Siarhei Novik (snovik@gmail.com) 3 4 4 5 This file is part of QLNet Project http://www.qlnet.org … … 22 23 using System.Text; 23 24 24 namespace QLNet 25 { 25 namespace QLNet { 26 26 /// <summary> 27 27 /// Exchange rate between two currencies … … 29 29 /// tested against calculations. 30 30 /// </summary> 31 public class ExchangeRate 32 { 31 public class ExchangeRate { 33 32 private Currency source_; 34 33 private Currency target_; 35 34 private Nullable<double> rate_; 36 35 private Type type_; 37 private Pair<ExchangeRate, ExchangeRate> rateChain_;36 private KeyValuePair<ExchangeRate, ExchangeRate> rateChain_; 38 37 39 38 /// <summary> … … 130 129 131 130 case Type.Derived: 132 if (amount.currency == rateChain_. first.source || amount.currency == rateChain_.first.target)133 return rateChain_.second.exchange(rateChain_.first.exchange(amount));134 else if (amount.currency == rateChain_. second.source || amount.currency == rateChain_.second.target)135 return rateChain_.first.exchange(rateChain_.second.exchange(amount));131 if (amount.currency == rateChain_.Key.source || amount.currency == rateChain_.Key.target) 132 return rateChain_.Value.exchange(rateChain_.Key.exchange(amount)); 133 else if (amount.currency == rateChain_.Value.source || amount.currency == rateChain_.Value.target) 134 return rateChain_.Key.exchange(rateChain_.Value.exchange(amount)); 136 135 else 137 136 throw new Exception("exchange rate not applicable"); … … 151 150 ExchangeRate result = new ExchangeRate(); 152 151 result.type_ = Type.Derived; 153 result.rateChain_ = new Pair<ExchangeRate,ExchangeRate>(r1,r2);152 result.rateChain_ = new KeyValuePair<ExchangeRate,ExchangeRate>(r1,r2); 154 153 if (r1.source_ == r2.source_) 155 154 { … … 180 179 throw new Exception ("exchange rates not chainable"); 181 180 } 182 183 181 return result; 184 182 } 185 186 187 183 } 188 189 184 } trunk/QLNet/QLNet/Math/randomnumbers/mt19937uniformrng.cs
r168 r170 31 31 checking them against known good results. 32 32 */ 33 public class MersenneTwisterUniformRng { 33 public class MersenneTwisterUniformRng : IRNGTraits { 34 //typedef Sample<Real> sample_type; 35 34 36 /*! if the given seed is 0, a random seed will be chosen based on clock() */ 35 37 public MersenneTwisterUniformRng() : this(0) { } … … 60 62 mt[0] = 0x80000000UL; /*MSB is 1; assuring non-zero initial array*/ 61 63 } 64 65 public IRNGTraits factory(ulong seed) { return new MersenneTwisterUniformRng(seed); } 66 62 67 63 68 /*! returns a sample with weight 1.0 containing a random number on (0.0, 1.0)-real-interval */ trunk/QLNet/QLNet/Methods/montecarlo/sample.cs
r168 r170 26 26 /*! \ingroup mcarlo */ 27 27 public struct Sample<T> { 28 public Sample(T value , double weight) {29 value _ = value;30 weight _ = weight;28 public Sample(T value_, double weight_) { 29 value = value_; 30 weight = weight_; 31 31 } 32 T value_;33 double weight_;32 public T value; 33 public double weight; 34 34 } 35 35 } trunk/QLNet/QLNet/QLNet.csproj
r168 r170 162 162 <Compile Include="Math\Optimization\SteepestDescent.cs" /> 163 163 <Compile Include="Math\randomnumbers\mt19937uniformrng.cs" /> 164 <Compile Include="Math\randomnumbers\randomsequencegenerator.cs" /> 165 <Compile Include="Math\randomnumbers\rngtraits.cs" /> 164 166 <Compile Include="Math\randomnumbers\seedgenerator.cs" /> 165 167 <Compile Include="Math\SampledCurve.cs" /> … … 181 183 </Compile> 182 184 <Compile Include="Math\Solvers1d\Secant.cs" /> 185 <Compile Include="Math\statistics\generalstatistics.cs" /> 183 186 <Compile Include="Math\transformedgrid.cs" /> 184 187 <Compile Include="Math\Vector.cs" /> … … 337 340 <Compile Include="Types.cs" /> 338 341 <Compile Include="Utils.cs" /> 339 <Compile Include="Util\make_pair.cs" />340 342 </ItemGroup> 341 343 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> trunk/QLNet/QLNet/Termstructures/InflationTermStructure.cs
r136 r170 1 1 /* 2 2 Copyright (C) 2008 Toyin Akin (toyin_akin@hotmail.com) 3 Copyright (C) 2008 Siarhei Novik (snovik@gmail.com) 3 4 4 5 This file is part of QLNet Project http://www.qlnet.org … … 22 23 using System.Text; 23 24 24 namespace QLNet 25 { 26 27 public static partial class Utils 28 { 25 namespace QLNet { 26 public static partial class Utils { 29 27 //! utility function giving the inflation period for a given date 30 public static Pair<Date, Date> inflationPeriod(Date d, Frequency frequency) 31 { 32 28 public static KeyValuePair<Date, Date> inflationPeriod(Date d, Frequency frequency) { 33 29 Month month = (Month)d.Month; 34 30 int year = d.Year; … … 60 56 Date endDate = Date.endOfMonth(new Date(1, endMonth, year)); 61 57 62 return new Pair<Date, Date>(startDate, endDate);58 return new KeyValuePair<Date, Date>(startDate, endDate); 63 59 } 64 60 }