Ejemplo n.º 1
0
        public async Task <ActionResult <CouponPayment> > PostCouponPayment(CouponPayment couponPayment)
        {
            _context.CouponPayments.Add(couponPayment);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCouponPayment", new { id = couponPayment.CouponPaymentId }, couponPayment));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutCouponPayment(int id, CouponPayment couponPayment)
        {
            if (id != couponPayment.CouponPaymentId)
            {
                return(BadRequest());
            }

            _context.Entry(couponPayment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CouponPaymentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
 public static void nice3()
 {
     System.Diagnostics.Trace.TraceInformation(Thread.CurrentThread.ManagedThreadId.ToString() + "nice3");
     using (CouponPayment T = new CouponPayment())
     {
         Console.WriteLine("using");
     }
     using (Program p = new Program())
     {
         p.nice2();
     }
 }
Ejemplo n.º 4
0
        public static List <CouponPayment> enumtest(List <CouponPaymentType> orils)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("APAY", "PAY1");
            dic.Add("BPAY", "PAY1");
            dic.Add("CPAY", "PAY2");
            List <CouponPayment> ls = new List <CouponPayment>();

            foreach (CouponPaymentType t in orils)
            {
                string pay     = dic[t.ID];
                int    current = ls.FindIndex(x => x.PaymentCategory == pay);
                if (current == -1) //不存在支付大类,新建大类和小类
                {
                    CouponPayment cp = new CouponPayment();
                    cp.SubPaymentWayList = new List <SubCouponPayment>();
                    cp.PaymentCategory   = pay;

                    SubCouponPayment scp = new SubCouponPayment()
                    {
                        MaxActivityNum = t.Times,
                        PaymentWay     = t.ID,
                        StartEndNo     = new List <string>()
                    };
                    scp.StartEndNo.Add(string.Format("%d,%d", t.Start, t.End));
                    cp.SubPaymentWayList.Add(scp);

                    ls.Add(cp);
                }
                else         //存在支付大类
                {
                    int subcurrent = ls[current].SubPaymentWayList.FindIndex(x => x.PaymentWay == t.ID);
                    if (subcurrent == -1) //不存在支付小类,新建小类
                    {
                        SubCouponPayment scp = new SubCouponPayment()
                        {
                            MaxActivityNum = t.Times,
                            PaymentWay     = t.ID,
                            StartEndNo     = new List <string>()
                        };
                        scp.StartEndNo.Add(string.Format("%d,%d", t.Start, t.End));
                        ls[current].SubPaymentWayList.Add(scp);
                    }
                    else                //已经存在支付小类,卡号直接加入原卡段集合
                    {
                        ls[current].SubPaymentWayList[subcurrent].StartEndNo.Add(string.Format("%d,%d", t.Start, t.End));
                    }
                }
            }
            return(ls);
        }
Ejemplo n.º 5
0
            protected override void DeserializeSuccessFields(List <KeyValuePair <string, string> > values, IJsonParser jsonParser, XElement xml)
            {
                device_info          = GetValue(values, "device_info");
                openid               = GetValue(values, "openid");
                is_subscribe         = GetValue(values, "is_subscribe") == "Y";
                trade_type           = (TradeType)Enum.Parse(typeof(TradeType), GetValue(values, "trade_type"));
                trade_state          = (TradeState)Enum.Parse(typeof(TradeState), GetValue(values, "trade_state"));
                bank_type            = Bank.Find(GetValue(values, "bank_type"));
                total_fee            = GetIntValue(values, "total_fee") ?? 0;
                settlement_total_fee = GetIntValue(values, "settlement_total_fee");
                fee_type             = Currency.Find(GetValue(values, "fee_type"));
                cash_fee             = GetIntValue(values, "cash_fee") ?? 0;
                cash_fee_type        = Currency.Find(GetValue(values, "cash_fee_type"));
                coupon_fee           = GetIntValue(values, "coupon_fee");
                coupon_count         = GetIntValue(values, "coupon_count");
                transaction_id       = GetValue(values, "transaction_id");
                out_trade_no         = GetValue(values, "out_trade_no");
                attach               = GetValue(values, "attach");
                time_end             = DateTime.ParseExact(GetValue(values, "time_end"), "yyyMMddHHmmss", null);
                trade_state_desc     = GetValue(values, "trade_state_desc");

                if (coupon_count > 0)
                {
                    // ReSharper disable once PossibleInvalidOperationException
                    coupons = new CouponPayment[coupon_count.Value];

                    for (var n = 0; n < coupon_count.Value; n++)
                    {
                        var sn = "_$" + n.ToString("D");
                        coupons[n] = new CouponPayment
                        {
                            coupon_type = (CouponType)Enum.Parse(typeof(CouponType), GetValue(values, "coupon_type" + sn)),
                            coupon_id   = GetValue(values, "coupon_id" + sn),
                            coupon_fee  = GetIntValue(values, "coupon_fee" + sn) ?? 0,
                        };
                    }
                }
            }
Ejemplo n.º 6
0
        public void Pricing()
        {
            for (int i = 0; i < PRICES.Length; i++)
            {
                PILLAR_PUF[i] = new PointsUpFront(INDEX_COUPON, 1 - PRICES[i]);
            }
            int pos        = 1; // target CDX is 5Y
            CDS targentCDX = CDX[pos];
            int n          = PILLAR_PUF.Length;

            double[] indexPUF = new double[n];
            for (int i = 0; i < n; i++)
            {
                indexPUF[i] = PILLAR_PUF[i].getPointsUpFront();
            }

            defaultedNames = new int[] { 2, 15, 37, 51 };

            IntrinsicIndexDataBundle dataDefaulted = INTRINSIC_DATA.withDefault(defaultedNames);
            int    accrualDays    = targentCDX.getAccuredDays();
            double accruedPremium = targentCDX.getAccruedPremium(INDEX_COUPON) * NOTIONAL * dataDefaulted.getIndexFactor();

            /*
             * Using credit curves for constituent single name CDSs.
             * The curves are adjusted by using only the target CDX.
             */
            IntrinsicIndexDataBundle adjCurves = PSA.adjustCurves(indexPUF[pos], CDX[pos], INDEX_COUPON, YIELD_CURVE,
                                                                  dataDefaulted);

            cleanPV      = INDEX_CAL.indexPV(targentCDX, INDEX_COUPON, YIELD_CURVE, adjCurves) * NOTIONAL;
            dirtyPV      = INDEX_CAL.indexPV(targentCDX, INDEX_COUPON, YIELD_CURVE, adjCurves, CdsPriceType.DIRTY) * NOTIONAL; // should be consistent with 1 - PRICES[pos]
            expectedLoss = INDEX_CAL.expectedDefaultSettlementValue(targentCDX.getProtectionEnd(), adjCurves) * NOTIONAL;
            cleanRPV01   = INDEX_CAL.indexAnnuity(targentCDX, YIELD_CURVE, adjCurves);
            dirtyRPV01   = INDEX_CAL.indexAnnuity(targentCDX, YIELD_CURVE, adjCurves, CdsPriceType.DIRTY);
            durationWeightedAverageSpread = INDEX_CAL.intrinsicIndexSpread(targentCDX, YIELD_CURVE, adjCurves) *
                                            TEN_THOUSAND;
            parallelIR01 = INDEX_CAL.parallelIR01(targentCDX, INDEX_COUPON, YIELD_CURVE, adjCurves) * NOTIONAL;
            double[] jumpToDefault = INDEX_CAL.jumpToDefault(targentCDX, INDEX_COUPON, YIELD_CURVE, adjCurves);
            for (int i = 0; i < jumpToDefault.Length; ++i)
            {
                jumpToDefault[i] *= NOTIONAL;
            }
            recovery01 = INDEX_CAL.recovery01(targentCDX, INDEX_COUPON, YIELD_CURVE, adjCurves);

            //Build Cash flow
            QLNet.UnitedStates cal     = new QLNet.UnitedStates();
            CdsCoupon[]        coupons = targentCDX.getCoupons();
            int npayments = coupons.Count();

            cashflow = new List <CouponPayment>();
            for (int i = 0; i < npayments; i++)
            {
                CouponPayment cf = new CouponPayment();
                cf.Amount = (-coupons[i].getEffStart() + coupons[i].getEffEnd()) * NOTIONAL * INDEX_COUPON;
                cf.Amount = Math.Round(cf.Amount, 2);
                double days = coupons[i].getEffEnd() * 365;
                cf.CashFlowDate = i == 0? CdsAnalyticFactory.getNextIMMDate(TRADE_DATE):
                                  CdsAnalyticFactory.getNextIMMDate(cashflow[i - 1].CashFlowDate);
                cf.CashFlowDate = cal.adjust(cf.CashFlowDate);
                cashflow.Add(cf);
            }

            for (int i = 0; i < recovery01.Length; ++i)
            {
                recovery01[i] *= NOTIONAL;
            }
        }