Exemplo 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++;
            }
        }
Exemplo n.º 2
0
 public CurrencySimulated(Currencies cur_enum, RandomNormal rand, double r)
 {
     this.cur_enum = cur_enum;
     this.r = r;
     this.rforeign = 0.01 + 0.05 * rand.NextDouble();
     this.sigma = 0.1;
     this.lastPrice = 1;
     this.lastDate = DateTime.MinValue;
     this.rand = rand;
     this.prices = new Dictionary<DateTime, double>();
 }