Assembla home | Assembla project page
 

Changeset 170

Show
Ignore:
Timestamp:
05/19/08 20:25:13 (4 months ago)
Author:
snovik
Message:

New: More Monte Carlo (GeneralStatistics?)
Change: make_pair to .net equivalent

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/QLNet/QLNet/Currencies/ExchangeRate.cs

    r61 r170  
    11/* 
    22 Copyright (C) 2008 Andrea Maggiulli 
     3 Copyright (C) 2008 Siarhei Novik (snovik@gmail.com)  
    34   
    45 This file is part of QLNet Project http://www.qlnet.org 
     
    2223using System.Text; 
    2324 
    24 namespace QLNet 
    25 
     25namespace QLNet { 
    2626   /// <summary> 
    2727   /// Exchange rate between two currencies 
     
    2929   /// tested against calculations. 
    3030   /// </summary> 
    31    public class ExchangeRate 
    32    { 
     31   public class ExchangeRate { 
    3332      private Currency source_; 
    3433      private Currency target_; 
    3534      private Nullable<double> rate_; 
    3635      private Type type_; 
    37       private Pair<ExchangeRate, ExchangeRate> rateChain_; 
     36      private KeyValuePair<ExchangeRate, ExchangeRate> rateChain_; 
    3837 
    3938      /// <summary> 
     
    130129 
    131130            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)); 
    136135               else 
    137136                  throw new Exception("exchange rate not applicable"); 
     
    151150            ExchangeRate result = new ExchangeRate(); 
    152151            result.type_ = Type.Derived; 
    153             result.rateChain_ = new Pair<ExchangeRate,ExchangeRate>(r1,r2); 
     152            result.rateChain_ = new KeyValuePair<ExchangeRate,ExchangeRate>(r1,r2); 
    154153            if (r1.source_ == r2.source_)  
    155154            { 
     
    180179                throw new Exception ("exchange rates not chainable"); 
    181180            } 
    182              
    183181            return result; 
    184182        } 
    185  
    186  
    187183   } 
    188  
    189184} 
  • trunk/QLNet/QLNet/Math/randomnumbers/mt19937uniformrng.cs

    r168 r170  
    3131              checking them against known good results. 
    3232    */ 
    33     public class MersenneTwisterUniformRng { 
     33    public class MersenneTwisterUniformRng : IRNGTraits { 
     34        //typedef Sample<Real> sample_type; 
     35 
    3436        /*! if the given seed is 0, a random seed will be chosen based on clock() */ 
    3537        public MersenneTwisterUniformRng() : this(0) { } 
     
    6062            mt[0] = 0x80000000UL; /*MSB is 1; assuring non-zero initial array*/ 
    6163        } 
     64 
     65        public IRNGTraits factory(ulong seed) { return new MersenneTwisterUniformRng(seed); } 
     66 
    6267 
    6368        /*! 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  
    2626    /*! \ingroup mcarlo */ 
    2727    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_
    3131        } 
    32         T value_
    33         double weight_
     32        public T value
     33        public double weight
    3434    } 
    3535} 
  • trunk/QLNet/QLNet/QLNet.csproj

    r168 r170  
    162162    <Compile Include="Math\Optimization\SteepestDescent.cs" /> 
    163163    <Compile Include="Math\randomnumbers\mt19937uniformrng.cs" /> 
     164    <Compile Include="Math\randomnumbers\randomsequencegenerator.cs" /> 
     165    <Compile Include="Math\randomnumbers\rngtraits.cs" /> 
    164166    <Compile Include="Math\randomnumbers\seedgenerator.cs" /> 
    165167    <Compile Include="Math\SampledCurve.cs" /> 
     
    181183    </Compile> 
    182184    <Compile Include="Math\Solvers1d\Secant.cs" /> 
     185    <Compile Include="Math\statistics\generalstatistics.cs" /> 
    183186    <Compile Include="Math\transformedgrid.cs" /> 
    184187    <Compile Include="Math\Vector.cs" /> 
     
    337340    <Compile Include="Types.cs" /> 
    338341    <Compile Include="Utils.cs" /> 
    339     <Compile Include="Util\make_pair.cs" /> 
    340342  </ItemGroup> 
    341343  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 
  • trunk/QLNet/QLNet/Termstructures/InflationTermStructure.cs

    r136 r170  
    11/* 
    22 Copyright (C) 2008 Toyin Akin (toyin_akin@hotmail.com) 
     3 Copyright (C) 2008 Siarhei Novik (snovik@gmail.com) 
    34   
    45 This file is part of QLNet Project http://www.qlnet.org 
     
    2223using System.Text; 
    2324 
    24 namespace QLNet 
    25 
    26  
    27     public static partial class Utils 
    28     { 
     25namespace QLNet { 
     26    public static partial class Utils { 
    2927        //! 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) { 
    3329            Month month = (Month)d.Month; 
    3430            int year = d.Year; 
     
    6056            Date endDate = Date.endOfMonth(new Date(1, endMonth, year)); 
    6157 
    62             return new Pair<Date, Date>(startDate, endDate); 
     58            return new KeyValuePair<Date, Date>(startDate, endDate); 
    6359        } 
    6460    }