示例#1
0
        public List <PricingResults> pricingUntilMaturity(List <DataFeed> listDataFeed)
        {
            if (oName.Equals(null) || oShares.Equals(null) || oMaturity == null || oStrike.Equals(null) || listDataFeed.Count == 0)
            {
                throw new NullReferenceException();  // TODO pls check if correct
            }
            List <PricingResults> listPrix = new List <PricingResults>();
            List <DataFeed>       listdf   = new List <DataFeed>(listDataFeed);

            //This line wad added.
            oSpot = new double[oShares.Length];
            BasketOption bask_o = new BasketOption(oName, oShares, oWeights, oMaturity, oStrike);

            while (listdf.Count > oObservation)
            {
                calculVolatility(listdf);
                for (int myShare = 0; myShare < oShares.Length; myShare++)
                {
                    oSpot[myShare] = (double)listdf[oObservation].PriceList[oShares[myShare].Id];
                }
                PricingResults pr = basketPricer.PriceBasket(bask_o, listdf[oObservation].Date, businessDays, oSpot, oVolatility, matriceCorr);
                if (listPrix.Count > 0)
                {
                    var prev = listPrix.Last();
                    if (Math.Abs(prev.Price - pr.Price) > 3.5)
                    {
                        var i = 0;
                    }
                }
                listPrix.Add(pr);
                listdf.RemoveAt(0);
            }

            return(listPrix);
        }
示例#2
0
        public PricingResults PriceResults(IOption option, Dictionary <string, decimal> priceMarket, DateTime dateDebut, IDataFeedProvider dataFeedProvider)
        {
            Pricer pricer = new Pricer();
            int    length = priceMarket.Count;

            double[] spot = new double[length];
            for (int i = 0; i < spot.Length; i++)
            {
                spot[i] = (double)priceMarket.ElementAt(i).Value;
            }
            if (option is VanillaCall)
            {
                VanillaCall    optionVanilla = (VanillaCall)option;
                PricingResults priceDelta    = pricer.PriceCall(optionVanilla, dateDebut, dataFeedProvider.NumberOfDaysPerYear, spot[0], volatilite);
                return(priceDelta);
            }
            else
            {
                BasketOption optionBasket = (BasketOption)option;
                double[]     volatilities = new double[optionBasket.Weights.Length];
                for (int i = 0; i < optionBasket.Weights.Length; i++)
                {
                    volatilities[i] = volatilite;
                }
                PricingResults priceDelta = pricer.PriceBasket(optionBasket, dateDebut, dataFeedProvider.NumberOfDaysPerYear, spot, volatilities, matrixCorrelation);
                return(priceDelta);
            }
        }
示例#3
0
        public override double CalculerPrix(int jour, AbstractData donnees, double[] spot, double[,] corr, double[] vol)
        {
            Pricer   pricer      = new Pricer();
            DateTime dateAvancee = donnees.listeDate[jour];
            double   prix        = pricer.PriceBasket((BasketOption)this.option, dateAvancee, 365, spot, vol, corr).Price;

            return(prix);
        }
示例#4
0
        public override double[] CalculerDeltas(int jour, AbstractData donnees, double[] vol, double[,] corr, double[] spot)
        {
            Pricer   pricer      = new Pricer();
            DateTime dateAvancee = donnees.listeDate[jour];

            double[] deltas = pricer.PriceBasket((BasketOption)this.option, dateAvancee, 365, spot, vol, corr).Deltas;
            return(deltas);
        }
示例#5
0
        public double PortfolioValue(BasketOption optionBasket, Share[] sharesBasket, int totalDays, double[] volatility, double[,] correlationMatrix, DateTime beginDate)
        {
            this.basket = optionBasket;
            SimulatedDataFeedProvider simulator        = new SimulatedDataFeedProvider();
            List <DataFeed>           simulationBasket = simulator.GetDataFeed(optionBasket, beginDate);
            int numberDaysPerYear = simulator.NumberOfDaysPerYear;

            int size = sharesBasket.Length;                                 // Number of Shares

            double[] spotsPrev = new double[size];                          // Array that will stock the spots values of the last rebalancing
            spotsPrev = fillSpots(simulationBasket[0], sharesBasket, size); // We initialize the array with the spots of the first day of analysis

            /* Calculation of the option price and the initial composition of the portfolio */
            Pricer         pricer        = new Pricer();
            PricingResults pricesResults = pricer.PriceBasket(optionBasket, beginDate, numberDaysPerYear, spotsPrev, volatility, correlationMatrix);
            double         priceBasket   = pricesResults.Price;

            double[] deltaPrev = new double[size];
            deltaPrev = pricesResults.Deltas;
            double cashRiskFreePrev = priceBasket - dotArrays(deltaPrev, spotsPrev, size);

            this.portfolioValue  = priceBasket;
            this.basketPriceInit = priceBasket;

            int index = 0;

            double[] delta             = new double[size];
            double[] spots             = new double[size];
            double   cashRiskFree      = 0;
            double   variationCashRisk = 0;
            double   freeRate          = 0;
            double   cashRisk          = 0;
            DateTime today;

            double[] optionValue    = new double[totalDays];
            double[] portfolioValue = new double[totalDays];
            double   payoff         = 0;

            /* Arrays used for the plot */
            optionValue[0]    = pricesResults.Price;
            portfolioValue[0] = this.portfolioValue;

            foreach (DataFeed data in simulationBasket)
            {
                if (index != 0 && index != totalDays)
                {
                    cashRisk          = 0;
                    variationCashRisk = 0;
                    today             = data.Date;

                    /* Update spots */
                    spots = fillSpots(data, sharesBasket, size);

                    /* Update priceResults */
                    pricesResults = pricer.PriceBasket(optionBasket, today, numberDaysPerYear, spots, volatility, correlationMatrix);

                    /* Update deltas */
                    delta = pricesResults.Deltas;

                    /* Update cashRisk */
                    cashRisk = dotArrays(delta, spots, size);

                    variationCashRisk = dotArrays(minusArrays(deltaPrev, delta, size), spots, size);
                    freeRate          = RiskFreeRateProvider.GetRiskFreeRateAccruedValue(1 / numberDaysPerYear);

                    /* Update cashRiskFree */
                    cashRiskFree = variationCashRisk + cashRiskFreePrev * freeRate;

                    /* Update portfolioValue */
                    this.portfolioValue = cashRiskFree + cashRisk;

                    /* Memorize the delta and the cashRiskFree calculated for the next balancing */
                    deltaPrev        = delta;
                    cashRiskFreePrev = cashRiskFree;

                    optionValue[index]    = pricesResults.Price;
                    portfolioValue[index] = this.portfolioValue;
                }
                else if (index == totalDays)
                {
                    payoff = optionBasket.GetPayoff(data.PriceList);
                }

                index++;
            }

            /* Partie traçage de courbes */
            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"C:\Users\ensimag\Desktop\PortfolioBasketOption.txt"))
            {
                for (int i = 0; i < totalDays; i++)
                {
                    // If the line doesn't contain the word 'Second', write the line to the file.
                    file.WriteLine(optionValue[i]);
                    file.WriteLine(portfolioValue[i]);
                }
            }

            return((this.portfolioValue - payoff) / this.basketPriceInit);
        }
示例#6
0
        protected override PricingResults ComputePricing(int dateIndex, double[] volatility, double[,] correlation)
        {
            var pricer = new Pricer();

            return(pricer.PriceBasket(Basket, MarketDataDates[dateIndex], 365, Spots[dateIndex], volatility, correlation));
        }