Ejemplo n.º 1
0
        /**
         * Create a simulated asset from a real one.
         * It extract the name of real asset for "fake" one
         * and the first price (at first date) and simulate
         * at all dates from dates_simul.
         * 
         * getPrice(t) with t from dates_simul will then return
         * a simulated price
         * getPrice(t) with t before first date from dates_simul
         * will return real price of asset
         * getPrice(t) with all others date will throw exception
         **/
        public AssetSimulated(IAsset real, LinkedList<DateTime> dates_simul, RandomNormal rand)
        {
            this.real = real;
            prices = new Dictionary<DateTime, double>();
            first_date = dates_simul.First();
            r = 0.04;
                //real.getCurrency().getInterestRate(first_date, TimeSpan.Zero);
            // TODO
            //sigma = real.getVolatility(first_date);
            sigma = 0.2;

            // debug kevin
            double St = 75 + 50*rand.NextDouble();
            DateTime lastDate = first_date;
            //double S0 = real.getPrice(first_date);
            int i = 0;
            foreach (DateTime date in dates_simul)
            {
                double T = (date - lastDate).TotalDays / 365; // time in year
                double WT = Math.Sqrt(T) * rand.NextNormal();
                St = St * Math.Exp((r - sigma * sigma / 2) * T + sigma * WT);
                prices[date] = St;
                lastDate = date;
                i++;
            }
        }