anchor.diff:              InitialParamGuess       = initialParamGuess
               }
   
  -    /////////////////////////
  -    /// Gaussian function of the form "y = amp * exp( -1. * ( ( ( (x-meanX)**2. ) / (2.*std**2.)) ) )"
  +        /////////////////////////
  +        /// Gaussian function of the form "y = amp * exp( -1. * ( ( ( (x-meanX)**2. ) / (2.*std**2.)) ) )"
           let gaussModel = {
               ParameterNames= [|"amp";"meanX";"std"|]
               GetFunctionValue = (fun (parameterVector:Vector<float>) xValue -> parameterVector.[0] * exp( (-1.) * ( ( ( (xValue-parameterVector.[1])**2. ) / (2.*parameterVector.[2]**2.)) ) ))
  
positive.code:                                 gradientVector)
              }
  
      /// Logistic function of the form "y = L/(1+e^(k(t-x)))+N"
      /// Modified version of the Logistic function model with a variable curve minimum.
          let LogisticFunctionVarYDescending = {
              ParameterNames= [|"L - curve maximum";"k - Steepness"; "x0 xValue of midpoint"; "N - curve minimum"|]
              GetFunctionValue = (fun (parameterVector:Vector<float>) xValue -> 
  
negative.code:         //    MaximumIterations       = 10000
          //    InitialParamGuess       = [|n;k|]
          //    }
  
          module Finances = 
              // https://en.wikipedia.org/wiki/Fixed-income_attribution
  
              /// Nelson-Siegel is a curve fitting model that is frequently applied in finance to fit smoothed yield curves. 
              /// xData: The periods of available yield rates (time).
              /// yData: The observed yields.
              // model modified from: Forecasting the term structure of government bond yields, Diebolda and Li, 2006
              let nelsonSiegel = 
  
                  let parameterNames = [|"b0";"b1";"b2";"t"|]
                  //b0 and t1 must be positive
                  //function defining the model
                  let getFunctionValue =                 
                              fun (parameterVector: Vector<float>) m -> 
                              let b0 = parameterVector.[0]
                              let b1 = parameterVector.[1]
                              let b2 = parameterVector.[2]
                              let t  = parameterVector.[3]
                              b0+b1*((1.-exp(-m/t))/(m/t)) + b2*((1.-exp(-m/t))/(m/t)-exp(-m/t))
  
                  //partial derivatives of the function         
                  let getGradientValues =
                      fun (parameterVector:Vector<float>) (gradientVector: Vector<float>) m -> 
                          let b0 = parameterVector.[0]
                          let b1 = parameterVector.[1]
                          let b2 = parameterVector.[2]
                          let t = parameterVector.[3]
                          gradientVector.[0] <- 1.
                          gradientVector.[1] <- (t*(1.-exp(-m/t)))/m
                          gradientVector.[2] <- (t*(1.-exp(-m/t)))/m-exp(-m/t)
                          gradientVector.[3] <- (exp(-m/t)*((b2+b1)*t**2.*exp(m/t)+(-b2-b1)*t**2.+(-b2-b1)*m*t-b2*m**2.))/(m*t**2.)
                          gradientVector
                  createModel parameterNames getFunctionValue getGradientValues
                     
  
              (*
              Example Nelson Siegel model
              let actual = [|0.0928; 0.106; 0.1174; 0.1246; 0.1395; 0.1489; 0.1686; 0.1806|]
              let time = [|1.0; 2.0; 3.0; 5.0; 7.0; 10.0; 15.0; 25.0|]
              let solverOptionsNS = createSolverOption 0.0001 0.0001 5000 [|0.01;0.01;0.01;1.0|]
              let coefficientsNS = LevenbergMarquardt.estimatedParams nelsonSiegel solverOptionsNS 0.001 10. time actual
              let fittingFunctionNS = nelsonSiegel.GetFunctionValue coefficientsNS
              let expected = time |> Array.map fittingFunctionNS
              *) 
              
                  
              
              /// Nelson-Siegel-Svensson is a curve fitting model that is frequently applied in finance to fit smoothed yield curves and extends the Nelson Siegel model by a term introducing a second hump. 
              /// xData: The periods of available yield rates (time).
              /// yData: The observed yields.
              // model modified from: Forecasting the term structure of government bond yields, Diebolda and Li, 2006 
              // and Estimating and interpreting forward interest rates, Svensson, 1994
              let nelsonSiegelSvensson = 
                  let parameterNamesNSS = [|"b0";"b1";"b2";"b3";"t";"u"|]
                  //b0 and t1 must be positive
                              
                  let getFunctionValueNSS =                 
                      fun (parameterVector: Vector<float>) m -> 
                          let b0 = parameterVector.[0]
                          let b1 = parameterVector.[1]
                          let b2 = parameterVector.[2]
                          let b3 = parameterVector.[3]
                          let t = parameterVector.[4]
                          let u = parameterVector.[5]
                          b0+b1*((1.-exp(-m/t))/(m/t)) + b2*((1.-exp(-m/t))/(m/t)-exp(-m/t)) + b3*((1.-exp(-m/u))/(m/u)-exp(-m/u))                       
  
                  let getGradientValuesNSS =
                      fun (parameterVector:Vector<float>) (gradientVector: Vector<float>) m -> 
                          let b0 = parameterVector.[0]
                          let b1 = parameterVector.[1]
                          let b2 = parameterVector.[2]
                          let b3 = parameterVector.[3]
                          let t = parameterVector.[4]
                          let u = parameterVector.[5]
                          gradientVector.[0] <- 1.
                          gradientVector.[1] <- (t*(1.-exp(-m/t)))/m
                          gradientVector.[2] <- (t*(1.-exp(-m/t)))/m-exp(-m/t)
                          gradientVector.[3] <- (u*(1.-exp(-m/u)))/m-exp(-m/u)
                          gradientVector.[4] <- (exp(-m/t)*((b2+b1)*t**2.*exp(m/t)+(-b2-b1)*t**2.+(-b2-b1)*m*t-b2*m**2.))/(m*t**2.)
                          gradientVector.[5] <- b3*(-exp(-m/u)/u-(m*exp(-m/u))/u**2.+(1.-exp(-m/u))/m)
                          gradientVector
                     
                  createModel parameterNamesNSS getFunctionValueNSS getGradientValuesNSS
                          
              (*
              Example Nelson Siegel Svensson model
              let actual = [|0.0928; 0.106; 0.1174; 0.1246; 0.1395; 0.1489; 0.1686; 0.1806|]
              let time = [|1.0; 2.0; 3.0; 5.0; 7.0; 10.0; 15.0; 25.0|]
              let solverOptionsNSS = createSolverOption 0.0001 0.0001 5000 [|0.01;0.01;0.01;0.01;1.0;1.0|]
              let coefficientsNSS = LevenbergMarquardt.estimatedParams nelsonSiegelSvensson solverOptionsNSS 0.001 10. time actual
              let fittingFunctionNSS = nelsonSiegelSvensson.GetFunctionValue coefficientsNSS
              let expected = time |> Array.map fittingFunctionNSS
              *) 
  
  