Пример #1
0
        public static List<Instrument> ReadInstruments(List<RiskFactor> RFactors)
        {
            // Reading instrument contracts for our portfolio

            List<Instrument> instruments = new List<Instrument>();
            DataSet Instrument_Data = ReadRange("Instruments");
            DataColumnCollection Column = Instrument_Data.Tables["Instruments"].Columns;
            DataRowCollection Rows = Instrument_Data.Tables["Instruments"].Rows;

            foreach (DataRow Row in Rows)
            {
                EquityRiskFactor RF = RFactors.Find(p => p.Equals(Convert.ToString(Row[0]))) as EquityRiskFactor;
                InstrumentContract contract = new InstrumentContract(Convert.ToString(Row[0]),
                                                                                Convert.ToString(Row[1]),
                                                                                Convert.ToDouble(Row[2]),
                                                                                Convert.ToDouble(Row[3]),
                                                                                Convert.ToDouble(Row[4]),
                                                                                RF.vol,
                                                                                RF.riskFreeRate);
                PricerFunction pricer = PricerFactory.CreatePricer(Convert.ToString(Row[1]));
                instruments.Add(new Instrument(pricer, contract));
            }

            return instruments;
        }
Пример #2
0
        public static  double pricePut(double date, int path, InstrumentContract instrumentContract, IScenario scenario)
        {   //Put Black-Scholes
            InstrumentContract Contract = instrumentContract as InstrumentContract;
            double dcf = (Contract.optionDate - date) / 365.25;
            if (dcf <= 0) return 0.0;
            double spot = scenario.getValue(Contract.underlyingID, date, path);
            double tmp = Contract.vol * Math.Sqrt(dcf);
            double d1 = (Math.Log(spot / Contract.strike) + (Contract.riskFreeRate + (Contract.vol * Contract.vol) * 0.5) * dcf) / tmp;
            double d2 = d1 - tmp;

            return (Contract.strike * Math.Exp(-Contract.riskFreeRate * dcf) * Functions.N(-d2)) -
                    (spot * Functions.N(-d1));
        }
Пример #3
0
 public static double priceForward(double date, int path, InstrumentContract instrumentContract, IScenario scenario)
 {
     InstrumentContract Contract = instrumentContract as InstrumentContract;
     double dcf = (Contract.optionDate - date) / 365.25;
     if (dcf <= 0) return 0.0;
     double Kdisc = Contract.strike * Math.Exp(-Contract.riskFreeRate * dcf);
     double spot = scenario.getValue(Contract.underlyingID, date, path);
     return spot - Kdisc;
 }
Пример #4
0
 // Constructor
 public Instrument(PricerFunction pricer, InstrumentContract instrumentContract)
 {
     _pricer = pricer;
     _instrumentContract = instrumentContract;
 }