コード例 #1
0
        public FinancialProduct GetSingleProductInfo(string code, string key, string productID)
        {
            BPiaoBao.Common.CashbagHelper ch         = new BPiaoBao.Common.CashbagHelper(webURLProduct + "GetSingleProductInfo", "GET");
            Dictionary <string, string>   dictionary = new Dictionary <string, string>();

            dictionary.Add("code", code);
            dictionary.Add("key", key);
            dictionary.Add("productID", productID);
            dictionary.Add("currentTime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            string data   = ch.ParamsURLEncode(dictionary);
            var    result = ch.GetBackJsonData(data);

            if (result.status == false)
            {
                throw new CashBagException(result.message.ToString());
            }
            result = result.result;
            var fp = new FinancialProduct()
            {
                ProductId          = result.FinancingProductID,
                Name               = result.ProductName,
                Description        = result.Content,
                IconUrl            = result.ImageUrl,
                ReturnRate         = result.ReturnRate,
                Day                = result.Day,
                LimitAmount        = result.LimitAmount,
                EndDate            = result.EndDate,
                ValidDate          = result.ValidDate,
                InterestRate       = result.InterestRate,
                CreateDate         = result.CreateDate,
                CanSettleInAdvance = result.CanSettleInAdvance
            };

            return(fp);
        }
コード例 #2
0
ファイル: DataModelExtensions.cs プロジェクト: paullucban/Apv
 public static FinancialProductDto ConvertModelDto(this FinancialProduct source)
 {
     return(new FinancialProductDto()
     {
         id = source.id,
         name = source.name,
         description = source.description
     });
 }
コード例 #3
0
        public FinancialCalculation(FinancialProduct product, double vehiclePrice, double downPayment, double residual, int numberMonths, double rate)
        {
            _product      = product;
            _vehiclePrice = vehiclePrice;
            _downPayment  = downPayment;
            _residual     = residual;
            _numberMonths = numberMonths;
            _rate         = rate;

            _financedAmount = _vehiclePrice - _downPayment;

            MonthlyPaymentCalculation();
        }
コード例 #4
0
        public void CalculoFinanceiroTestCredito()
        {
            FinancialProduct produto        = FinancialProduct.Credit;
            double           pvp            = 9900;
            double           entradaInicial = 0;
            double           residual       = 0;
            int    duracacao = 18;
            double taxa      = 4.836;

            double prestacaoEsperada = 571.30;

            FinancialCalculation calculoFinanceiro = new FinancialCalculation(produto, pvp, entradaInicial, residual, duracacao, taxa);

            Assert.AreEqual(prestacaoEsperada, calculoFinanceiro.MonthlyPayment);
        }
コード例 #5
0
        public IEnumerable <FinancialProduct> GetActiveProduct(string code, string key, string quantity)
        {
            BPiaoBao.Common.CashbagHelper ch         = new BPiaoBao.Common.CashbagHelper(webURLProduct + "GetActiveProduct", "GET");
            Dictionary <string, string>   dictionary = new Dictionary <string, string>();

            dictionary.Add("code", code);
            dictionary.Add("key", key);
            dictionary.Add("quantity", quantity);
            dictionary.Add("currentTime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            string data   = ch.ParamsURLEncode(dictionary);
            var    result = ch.GetBackJsonData(data);

            if (result.status == false)
            {
                throw new CashBagException(result.message.ToString());
            }
            List <FinancialProduct> lists = new List <FinancialProduct>();
            var rows = JArray.FromObject(result.result);

            foreach (var item in rows)
            {
                FinancialProduct fp = new FinancialProduct()
                {
                    ProductId          = item.FinancingProductID,
                    Name               = item.ProductName,
                    Description        = item.Content,
                    IconUrl            = item.ImageUrl,
                    Abstract           = "",
                    ReturnRate         = item.ReturnRate,
                    Day                = item.Day,
                    LimitAmount        = item.LimitAmount ?? 0,
                    MaxAmount          = item.MaxAmount,
                    CurrentAmount      = item.CurrentAmount,
                    EndDate            = item.EndDate,
                    ValidDate          = item.ValidDate,
                    InterestRate       = item.InterestRate,
                    CreateDate         = item.CreateDate,
                    CanSettleInAdvance = item.CanSettleInAdvance
                };
                lists.Add(fp);
            }
            return(lists);
        }
コード例 #6
0
        /// <summary>
        /// The method "Price" is dedicated to compute the price of the European Call or Put
        /// </summary>
        /// <param name=product>The product to be priced</param>
        /// <returns>The expected price</returns>
        public override double Price(FinancialProduct product)
        {
            double result = 0;

            EuropeanOption euroOption = (product as EuropeanOption);

            if (euroOption != null)
            {
                //do something with it

                double d1 = (Log(euroOption.S / euroOption.K) + (euroOption.R + 0.5 * Pow(euroOption.Sigma, 2)) * euroOption.T) / (euroOption.Sigma * Sqrt(euroOption.T));
                double d2 = (Log(euroOption.S / euroOption.K) + (euroOption.R - 0.5 * Pow(euroOption.Sigma, 2)) * euroOption.T) / (euroOption.Sigma * Sqrt(euroOption.T));

                if (euroOption.OptionType == Constants.EuroOptionType.Call)
                {
                    result = (euroOption.S * Cndf(d1) - euroOption.K * Exp(-euroOption.R * euroOption.T) * Cndf(d2));
                }
                else if (euroOption.OptionType == Constants.EuroOptionType.Put)
                {
                    result = (euroOption.K * Exp(-euroOption.R * euroOption.T) * Cndf(-d2) - euroOption.S * Cndf(-d1));
                }
            }
            return(Math.Round(result, iPrecision));
        }
コード例 #7
0
ファイル: Pricer.cs プロジェクト: medamineblidi/OptionPricer
 public abstract double Price(FinancialProduct product);
コード例 #8
0
        /// <summary>
        /// The method CheckInputData represents parts that check the input data, converts them to the suitable formats
        /// and build the product to be priced later,
        /// it contains the definition of the input part, the verification of these ones and the display of the output results
        /// </summary>
        /// <param name=product>The product to be build and returned</param>
        /// <param name=iPrecision>The precision of Round of the final result, </param>
        /// <param name=strErrorMsg>The error Message that will be returned in case of issue</param>
        /// <returns>bool: the method was successfully finished or not</returns>
        private bool CheckInputData(out FinancialProduct product, ref int iPrecision, ref string strErrorMsg)
        {
            string strStockPrice           = StockPriceTextBox.Text.ToString();
            string strStrikePrice          = strikePriceTextBox.Text.ToString();
            string strTimeToMaturity       = timeToMatTextBox.Text.ToString();
            string strStdDerivUnderlying   = StdDerivUnderlyingTextBox.Text.ToString();
            string strRiskFreeInterestRate = RiskFreeInterestRateTextBox.Text.ToString();
            string strFloatPrecision       = floatPrecisionTextBox.Text.ToString();

            double dStockPrice           = 0;
            double dStrikePrice          = 0;
            double dTimeToMaturity       = 0;
            double dStdDerivUnderlying   = 0;
            double dRiskFreeInterestRate = 0;
            bool   bDataInput            = true;

            Constants.Culture culture = 0;

            if (cultureComboBox.SelectedIndex > -1)
            {
                if (cultureComboBox.SelectedItem.ToString().Equals(Constants.CULTURE_GB))
                {
                    culture = Constants.Culture.GB;
                }
                else if (cultureComboBox.SelectedItem.ToString().Equals(Constants.CULTURE_FR))
                {
                    culture = Constants.Culture.FR;
                }
                else if (cultureComboBox.SelectedItem.ToString().Equals(Constants.CULTURE_ES))
                {
                    culture = Constants.Culture.ES;
                }
            }
            else
            {
                product     = null;
                strErrorMsg = "Please select a choice in the culture box";
                Console.WriteLine("Please select a choice in the culture box ");
                return(false);
            }

            if (bDataInput)
            {
                if (ConvertStringToDouble(strStockPrice, culture, out dStockPrice))
                {
                    Console.WriteLine("StockPrice --> {0}", dStockPrice);
                }
                else
                {
                    strErrorMsg = "Please insert a correct format for the field Stock price, the suitable format is float";
                    Console.WriteLine("Unable to parse StockPrice '{0}'.", strStockPrice);
                    product = null;
                    return(false);
                }
            }

            if (bDataInput)
            {
                if (ConvertStringToDouble(strStrikePrice, culture, out dStrikePrice))
                {
                    Console.WriteLine("StrikePrice --> {0}", dStrikePrice);
                }
                else
                {
                    strErrorMsg = "Please insert a correct format for the field Strike price, the suitable format is float";
                    Console.WriteLine("Unable to parse StrikePrice '{0}'.", strStrikePrice);
                    product = null;
                    return(false);
                }
            }
            if (bDataInput)
            {
                if (ConvertStringToDouble(strTimeToMaturity, culture, out dTimeToMaturity))
                {
                    Console.WriteLine("TimeToMaturity --> {0}", dTimeToMaturity);
                }
                else if (EvaluateDoubleWithSplit(strTimeToMaturity, culture, out dTimeToMaturity))
                {
                    Console.WriteLine("TimeToMaturity --> {0}", dTimeToMaturity);
                }
                else
                {
                    strErrorMsg = "Please insert a correct format for the field Time to maturity in years, the suitable format is integer";
                    Console.WriteLine("Unable to parse TimeToMaturity '{0}'.", strTimeToMaturity);
                    product = null;
                    return(false);
                }
            }
            if (bDataInput)
            {
                if (ConvertStringToDouble(strStdDerivUnderlying, culture, out dStdDerivUnderlying))
                {
                    Console.WriteLine("StdDerivUnderlying --> {0}", dStdDerivUnderlying);
                }
                else
                {
                    strErrorMsg = "Please insert a correct format for the field Standard deviation of underlying stock, the suitable format is float";
                    Console.WriteLine("Unable to parse StdDerivUnderlying '{0}'.", strStdDerivUnderlying);
                    product = null;
                    return(false);
                }
            }
            if (bDataInput)
            {
                if (ConvertStringToDouble(strRiskFreeInterestRate, culture, out dRiskFreeInterestRate))
                {
                    Console.WriteLine("RiskFreeInterestRate --> {0}", dRiskFreeInterestRate);
                }
                else
                {
                    strErrorMsg = "Please insert a correct format for the field Risk-free interest rate, the suitable format is float";
                    Console.WriteLine("Unable to parse RiskFreeInterestRate '{0}'.", strRiskFreeInterestRate);
                    product = null;
                    return(false);
                }
            }

            Constants.EuroOptionType euroOptionType = 0;
            if (bDataInput)
            {
                if (optionTypeComboBox.SelectedIndex > -1)
                {
                    if (optionTypeComboBox.SelectedItem.ToString().Equals(Constants.CALL))
                    {
                        euroOptionType = Constants.EuroOptionType.Call; // todo if
                    }
                    else if (optionTypeComboBox.SelectedItem.ToString().Equals(Constants.PUT))
                    {
                        euroOptionType = Constants.EuroOptionType.Put; // todo if
                    }
                }
                else
                {
                    strErrorMsg = "Please select a choice in the Option type box";
                    Console.WriteLine("Please select a choice in the Option type box");
                    product = null;
                    return(false);
                }
            }

            if (bDataInput)
            {
                if (int.TryParse(strFloatPrecision, out iPrecision))
                {
                    Console.WriteLine("RiskFreeInterestRate --> {0}", iPrecision);
                }
                else
                {
                    strErrorMsg = "Please insert a correct format for the field Risk-free interest rate, the suitable format is float";
                    Console.WriteLine("Unable to parse RiskFreeInterestRate '{0}'.", strFloatPrecision);
                    product = null;
                    return(false);
                }
            }

            product = new EuropeanOption(dStockPrice, dStrikePrice, dTimeToMaturity, dStdDerivUnderlying, dRiskFreeInterestRate, euroOptionType);
            return(bDataInput);
        }
コード例 #9
0
        private FinancialAccountProduct CreateFinancialAccountProduct(FinancialAccount financialAccount, FinancialProduct financialProduct, DateTime today)
        {
            FinancialAccountProduct financialAccountProductNew1 = new FinancialAccountProduct();
            financialAccountProductNew1.FinancialAccount = financialAccount;
            financialAccountProductNew1.FinancialProduct = financialProduct;
            financialAccountProductNew1.EffectiveDate = today;

            return financialAccountProductNew1;
        }