Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CDS"/> class.
 /// </summary>
 /// <param name="refEntity">The reference entity whose default is covered by this CDS.</param>
 /// <param name="ccy">The currency of the cashflows of the premium and default legs.</param>
 /// <param name="paymentDates">The payment dates on which the premium is paid.</param>
 /// <param name="notionals">The notionals that define the protection amount in the period until each payment date and the basis on which the premiums are calculated.</param>
 /// <param name="rates">The simple rates that apply until the default time.  Used to calculate the premium flows.</param>
 /// <param name="accrualFractions">The accrual fractions used to calculate the premiums paid on the <paramref name="paymentDates"/>.</param>
 /// <param name="boughtProtection">If set to <c>true</c> then protection has been bought and the premium will be paid.</param>
 public CDS(ReferenceEntity refEntity, Currency ccy, Date[] paymentDates, double[] notionals,
            double[] rates, double[] accrualFractions, bool boughtProtection)
 {
     _defaultRecovery  = new DefaultRecovery(refEntity);
     _defaultTime      = new DefaultTime(refEntity);
     _ccy              = ccy;
     _paymentDates     = paymentDates;
     _notionals        = notionals;
     _rates            = rates;
     _accrualFractions = accrualFractions;
     _cfMultiplier     = boughtProtection ? -1.0 : 1.0;
 }
Exemplo n.º 2
0
 private void UpdateTimer()
 {
     //Назад
     if (!Paused)
     {
         Time = TimeSpan.Zero;//TimeSpan.FromMilliseconds(Time.Milliseconds);
         if (Reverse)
         {
             Time = DefaultTime.Add(Time);
         }
     }
 }
Exemplo n.º 3
0
 private LocalDateTimeBuilder(DefaultTime defTime, Func <DateTime, DateTime> adaptDate)
 {
     _defTime   = defTime;
     _adaptDate = adaptDate;
 }
Exemplo n.º 4
0
 public static DefaultTimeFunction GetFunction(DefaultTime defaultTime)
 {
     dict.TryGetValue(defaultTime, out DefaultTimeFunction function);
     return(function);
 }
Exemplo n.º 5
0
        public PrimitiveFieldMapping(Type type, string fieldName, string indexName, DataMapping mapping, bool isNullable, string dbType, object defaultValue, bool isIdentity, bool isPrimaryKey)
            : base(type, fieldName, indexName, mapping, isNullable, dbType)
        {
            if (type != typeof(string))
            {
                Type itemstype = Type.GetType("System.Nullable`1");
                _nullableType = itemstype.MakeGenericType(type);
            }
            else
            {
                _nullableType = type;
            }
            if (defaultValue != null)
            {
                Type defaultValueType = defaultValue.GetType();
                if (_typeCode == TypeCode.DateTime)
                {
                    if (defaultValueType == typeof(DefaultTime))
                    {
                        DefaultTime defaultTime = (DefaultTime)defaultValue;
                        this._defaultTimeFunction = DefaultTimeFunction.GetFunction(defaultTime);
                        if (defaultTime == DefaultTime.TimeStamp || defaultTime == DefaultTime.UtcTimeStamp)
                        {
                            isTimeStamp = true;
                        }
                        this._defaultValue = this._defaultTimeFunction;
                    }
                    else if (defaultValueType == typeof(DateTime))
                    {
                        this._defaultValue = defaultValue;
                    }
                    else if (defaultValueType == typeof(string))
                    {
                        string str = defaultValue as string;
                        if (DateTime.TryParse(str, out DateTime dt))
                        {
                            this._defaultValue = dt;
                        }
                    }
                }
                else if (defaultValueType == type)
                {
                    this._defaultValue = defaultValue;
                }
                else
                {
                    this._defaultValue = Convert.ChangeType(defaultValue, type);
                }
            }
            if (isIdentity)
            {
                if (_typeCode == TypeCode.Int32 || _typeCode == TypeCode.Int64 || _typeCode == TypeCode.UInt32 || _typeCode == TypeCode.UInt64)
                {
                    _isIdentity = true;
                }
                else
                {
                    throw new LightDataException(string.Format(SR.DataMappingUnsupportIdentityFieldType, ObjectType, fieldName, type));
                }
            }

            _isPrimaryKey = isPrimaryKey;
            switch (_typeCode)
            {
            case TypeCode.String:
                _minValue = string.Empty;
                break;

            case TypeCode.Boolean:
                _minValue = false;
                break;

            case TypeCode.Byte:
                _minValue = byte.MinValue;
                break;

            case TypeCode.SByte:
                _minValue = MinSByte;
                break;

            case TypeCode.DateTime:
                _minValue = DateTime.MinValue;
                break;

            case TypeCode.Char:
                _minValue = Char.MinValue;
                break;

            case TypeCode.Int16:
                _minValue = MinInt16;
                break;

            case TypeCode.Int32:
                _minValue = MinInt32;
                break;

            case TypeCode.Int64:
                _minValue = MinInt64;
                break;

            case TypeCode.UInt16:
                _minValue = UInt16.MinValue;
                break;

            case TypeCode.UInt32:
                _minValue = UInt32.MinValue;
                break;

            case TypeCode.UInt64:
                _minValue = UInt64.MinValue;
                break;

            case TypeCode.Decimal:
                _minValue = MinDecimal;
                break;

            case TypeCode.Single:
                _minValue = MinSingle;
                break;

            case TypeCode.Double:
                _minValue = MinDouble;
                break;
            }
        }