Пример #1
0
 public void UpdatePortfolioValue(DataFeed priceAsset_t, int nbJourParAn, int periodeRebalancement)
 {
     this.portfolioValue = 0;
     foreach (string id in priceAsset.Keys)
     {
         this.portfolioValue += Convert.ToDecimal(composition[id]) * priceAsset_t.PriceList[id];
     }
     this.portfolioValue += this.liquidity * Convert.ToDecimal(RiskFreeRateProvider.GetRiskFreeRateAccruedValue(DayCount.ConvertToDouble(periodeRebalancement, nbJourParAn)));
 }
Пример #2
0
        public double getPrixPortefeuille(double[] spot, int now, AbstractData donnees)
        {
            // Recupere la valeur du portefeuille à l'instant actuel
            var result = 0.0;
            int i      = 0;

            foreach (var par in this.nbActions)
            {
                result += par * spot[i];
                i++;
            }
            int span = (donnees.listeDate[now] - donnees.listeDate[date]).Days;;

            result += tauxSansRisque * RiskFreeRateProvider.GetRiskFreeRateAccruedValue(DayCount.ConvertToDouble(span, 365));
            return(result);
        }
Пример #3
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);
        }
Пример #4
0
        private void updateResults(List <DataFeed> pricingData, int periodIndex, int nRebalancingDays)
        {
            CompletePricingResults pricingResult = optionPricer.getPricingResults(pricingData);

            double[] newDeltas = pricingResult.Deltas;
            double[] spots     = pricingResult.Spots;
            double   optPrice  = pricingResult.Price;

            if (periodIndex == 0)
            {
                Array.Copy(newDeltas, deltas, newDeltas.Length);
            }

            double riskyAsset = 0;

            for (int i = 0; i < spots.Length; i++)
            {
                riskyAsset += deltas[i] * spots[i];
            }

            if (periodIndex == 0)
            {
                results.PortfolioValue = optPrice;
            }
            else
            {
                results.PortfolioValue = riskyAsset + results.Portfolio.NonRiskyAsset * RiskFreeRateProvider.GetRiskFreeRateAccruedValue(nRebalancingDays / 365.0);
            }

            double nonRiskyAsset = results.PortfolioValue - riskyAsset;

            results.Portfolio     = new HedgingPortfolio(riskyAsset, nonRiskyAsset);
            results.Payoff        = optionPricer.Opt.GetPayoff(pricingData.Last().PriceList);
            results.TrackingError = (results.PortfolioValue - results.Payoff) / optPrice;
            results.Date          = pricingData.Last().Date;

            deltas = newDeltas;
        }
Пример #5
0
 public void UpdateValue(double[] spot)
 {
     Value = Scalaire(Deltas, spot) + FreeRiskDelta * RiskFreeRateProvider.GetRiskFreeRateAccruedValue(1.0 / 365);
 }