Assembla home | Assembla project page
 

Changeset 175

Show
Ignore:
Timestamp:
05/22/08 13:24:54 (4 months ago)
Author:
snovik
Message:

New: SequenceStatistics?
New: Added some missing Matrix functionality
Fix: some fixes on ConvergenceStatistics?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/QLNet/QLNet/Math/Matrix.cs

    r110 r175  
    3636 
    3737        private double[,] data_; 
     38        public double this[int i, int j] { get { return data_[i, j]; } set { data_[i, j] = value; } } 
    3839        public Vector row(int r) { 
    3940            Vector result = new Vector(rows_); 
     
    4748                result[i] = data_[i, c]; 
    4849            return result; 
    49         }  
     50        } 
     51        public Vector diagonal() { 
     52            int arraySize = Math.Min(rows(), columns()); 
     53            Vector tmp = new Vector(arraySize); 
     54            for(int i = 0; i < arraySize; i++) 
     55                tmp[i] = data_[i,i]; 
     56            return tmp; 
     57        } 
    5058        #endregion 
    5159 
     
    9098        public static Matrix operator +(Matrix m1, Matrix m2) { return operMatrix(ref m1, ref m2, (x, y) => x + y); } 
    9199        public static Matrix operator -(Matrix m1, Matrix m2) { return operMatrix(ref m1, ref m2, (x, y) => x - y); } 
     100        public static Matrix operator *(double value, Matrix m1) { return operValue(ref m1, value, (x, y) => x * y); } 
     101        public static Matrix operator /(double value, Matrix m1) { return operValue(ref m1, value, (x, y) => x / y); } 
    92102        public static Matrix operator *(Matrix m1, double value) { return operValue(ref m1, value, (x, y) => x * y); } 
    93103        public static Matrix operator /(Matrix m1, double value) { return operValue(ref m1, value, (x, y) => x / y); } 
     
    150160            return result; 
    151161        } 
     162 
     163        public static Matrix outerProduct(List<double> v1begin, List<double> v2begin) { 
     164 
     165            int size1 = v1begin.Count; 
     166            if (!(size1>0)) throw new ApplicationException("null first vector"); 
     167 
     168            int size2 = v2begin.Count; 
     169            if(!(size2>0)) throw new ApplicationException("null second vector"); 
     170 
     171            Matrix result = new Matrix(size1, size2); 
     172 
     173            for (int i=0; i<v1begin.Count; i++) 
     174                for(int j=0; j<v2begin.Count; j++) 
     175                    result[i,j] = v1begin[i] * v2begin[j]; 
     176            return result; 
     177        } 
    152178    } 
    153179} 
  • trunk/QLNet/QLNet/Math/statistics/convergencestatistics.cs

    r174 r175  
    5656            where T : IGeneralStatistics, new() { 
    5757        public ConvergenceStatistics(T stats, DoublingConvergenceSteps rule) : base(stats, rule) { } 
     58        public ConvergenceStatistics() : base(new DoublingConvergenceSteps()) { } 
    5859        public ConvergenceStatistics(DoublingConvergenceSteps rule) : base(rule) { } 
    5960    } 
     
    7778        } 
    7879 
    79         //public ConvergenceStatistics(U rule = U()) { 
     80        public ConvergenceStatistics() : this(new U()) { } 
    8081        public ConvergenceStatistics(U rule) { 
    8182            samplingRule_ = rule; 
     
    8990        } 
    9091 
    91         //void add(const value_type& value, Real weight = 1.0); 
     92        public void add(double value) { add(value, 1); } 
    9293        public void add(double value, double weight) { 
    9394            impl_.add(value, weight); 
  • trunk/QLNet/QLNet/QLNet.csproj

    r174 r175  
    191191    <Compile Include="Math\statistics\incrementalstatistics.cs" /> 
    192192    <Compile Include="Math\statistics\riskstatistics.cs" /> 
     193    <Compile Include="Math\statistics\sequencestatistics.cs" /> 
    193194    <Compile Include="Math\transformedgrid.cs" /> 
    194195    <Compile Include="Math\Vector.cs" /> 
  • trunk/QLNet/Test2008/Test2008.csproj

    r172 r175  
    5959    <Compile Include="T_SampledCurve.cs" /> 
    6060    <Compile Include="T_Solvers.cs" /> 
     61    <Compile Include="T_Stats.cs" /> 
    6162    <Compile Include="T_Swaps.cs" /> 
    6263    <Compile Include="T_TermStructures.cs" />