コード例 #1
0
        public static void Main(string[] args)
        {
            var      simulatedData = new SimulatedDataProvider();
            DateTime from          = new DateTime(2018, 09, 04);
            Share    share1        = new Share("vod.l", "vod.l");
            Share    share2        = new Share("ftse", "ftse");
            string   nameBasket    = "Basket";
            double   strikeBasket  = 9;

            Share[]         sharesBasket    = { share1, share2 };
            Double[]        weights         = { 0.3, 0.7 };
            DateTime        maturityBasket  = new DateTime(2019, 09, 04);
            BasketOption    optionBasket    = new BasketOption(nameBasket, sharesBasket, weights, maturityBasket, strikeBasket);
            PortfolioBasket portfolioBasket = new PortfolioBasket();
            int             totalDays       = DayCount.CountBusinessDays(from, maturityBasket);

            double[] volatility = new double[2];
            volatility[0] = 0.4;
            volatility[1] = 0.4;
            double[,] correlationMatrix = new double[2, 2];
            correlationMatrix[0, 0]     = 1;
            correlationMatrix[1, 1]     = 0.1;
            correlationMatrix[0, 1]     = 1;
            correlationMatrix[1, 0]     = 0.1;
            double valeur = portfolioBasket.PortfolioValue(optionBasket, sharesBasket, totalDays, volatility, correlationMatrix, from);

            Console.WriteLine("Valeur Gain normalisée = " + valeur);
        }
コード例 #2
0
ファイル: HedgingTool.cs プロジェクト: mounirq/projectNET
        public void update()
        {
            this.optionValue    = new List <double>();
            this.portfolioValue = new List <double>();
            this.dateValue      = new List <string>();
            IOption option = null;

            try
            {
                option = constructOption();
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message.ToString());
                return;
            }

            List <DataFeed> dataFeeds;

            userInput.StartDate = Tools.NextBusinessDay(userInput.StartDate);

            DateTime startDateOfEstimation = Tools.MinusBusinessDays(userInput.StartDate, userInput.EstimationWindow);

            if (userInput.DataType.GetType() == typeof(HistoricalDataProvider))
            {
                HistoricalDataProvider historicalData = new HistoricalDataProvider();
                DateTime minDate = historicalData.GetMinDate();
                DateTime maxDate = historicalData.GetMaxDate();
                if (startDateOfEstimation < minDate || userInput.Maturity > maxDate)
                {
                    throw new ArgumentException("Unavailable historical data for the selected dates and estimationWindow, they must be between : " +
                                                minDate.ToString("dd/MM/yyyy") + " and " + maxDate.ToString("dd/MM/yyyy"));
                }
                dataFeeds = historicalData.GetDataFeeds(option, startDateOfEstimation);
            }
            else
            {
                SimulatedDataProvider simulatedData = new SimulatedDataProvider();
                dataFeeds = simulatedData.GetDataFeeds(option, startDateOfEstimation);
            }

            /* First step */
            ParametersEstimation parameters = new ParametersEstimation(dataFeeds, userInput.StartDate, userInput.EstimationWindow);

            DateTime  currentDay = userInput.StartDate;
            Portfolio portfolio  = new Portfolio();

            Pricer pricer = new Pricer();

            Share[] underlyingsShares = ShareTools.GenerateShares(userInput.UnderlyingsIds);

            double[] returnedValue = portfolio.estimatePortfolioFirstDay(parameters, underlyingsShares, option, currentDay, dataFeeds[userInput.EstimationWindow], pricer);
            optionValue.Add(returnedValue[0]);
            portfolioValue.Add(returnedValue[1]);
            dateValue.Add(currentDay.ToString("dd/MM/yyyy"));

            List <DataFeed> dataFeedSkipped = dataFeeds.Skip(userInput.EstimationWindow).ToList();

            int i = 1;

            foreach (DataFeed data in dataFeedSkipped)
            {
                if (i % userInput.RebalancementFrequency == 0 && !data.Date.Equals(dataFeedSkipped.Last().Date))
                {
                    currentDay    = data.Date;
                    parameters    = new ParametersEstimation(dataFeeds, currentDay, userInput.EstimationWindow);
                    returnedValue = portfolio.updatePortfolio(userInput.RebalancementFrequency, parameters, underlyingsShares, option, currentDay, data, pricer);
                    optionValue.Add(returnedValue[0]);
                    portfolioValue.Add(returnedValue[1]);
                    dateValue.Add(currentDay.ToString("dd/MM/yyyy"));
                }
                i++;
            }

            /* Last Step */
            DataFeed maturityData = dataFeedSkipped.Last();

            normalizedGain = portfolio.calculateGain(userInput.RebalancementFrequency, maturityData, underlyingsShares, option);
        }