Exemple #1
0
        public override void Build(EngineFactory engineFactory)
        {
            Currency boughtCcy    = Parsers.ParseCurrency(_boughtCurrency);
            Currency soldCcy      = Parsers.ParseCurrency(_soldCurrency);
            Date     maturityDate = Parsers.ParseDate(_maturityDate);

            //QL_REQUIRE(tradeActions().empty(), "TradeActions not supported for FxForward");

            try
            {
                //DLOG("Build FxForward with maturity date " << QuantLib::io::iso_date(maturityDate));

                QLNet.Instrument instrument = new FxForward(_boughtAmount, boughtCcy, _soldAmount, soldCcy, maturityDate, false);

                //instrument_.reset(new VanillaInstrument(instrument));

                _npvCurrency = _soldCurrency;
                _notional    = _soldAmount;
                _maturity    = maturityDate;
            }
            catch (Exception ex)
            {
                //_instrument.reset();
                throw;
            }

            SimpleCashFlow cf1 = new SimpleCashFlow(_boughtAmount, maturityDate);
            SimpleCashFlow cf2 = new SimpleCashFlow(_soldAmount, maturityDate);

            _legs = new List <List <CashFlow> >()
            {
                new List <CashFlow> {
                    cf1, cf2
                }
            };

            _legCurrencies = new List <string> {
                _boughtCurrency, _soldCurrency
            };
            _legPayers = new List <bool> {
                false, true
            };

            // set Pricing engine
            EngineBuilder builder = engineFactory.Builder(_tradeType);

            QLNet.Utils.QL_REQUIRE(builder != null, () => "No builder found for " + _tradeType);
            FxForwardEngineBuilder fxBuilder = builder as FxForwardEngineBuilder;

            _instrument.setPricingEngine(fxBuilder.Engine(boughtCcy, soldCcy));

            //DLOG("FxForward leg 0: " << legs_[0][0]->date() << " " << legs_[0][0]->amount());
            //DLOG("FxForward leg 1: " << legs_[1][0]->date() << " " << legs_[1][0]->amount());
        }
Exemple #2
0
        public EngineBuilder Builder(string tradeType)
        {
            // Check that we have a model/engine for tradetype
            QLNet.Utils.QL_REQUIRE(_engineData.HasProduct(tradeType), () => "EngineFactory does not have a model/engine for trade type " + tradeType);

            string           model  = _engineData.Model(tradeType);
            string           engine = _engineData.Engine(tradeType);
            HashSet <string> set    = new HashSet <string>()
            {
                tradeType
            };
            Tuple <string, string, HashSet <string> > key = new Tuple <string, string, HashSet <string> >(model, engine, set);

            QLNet.Utils.QL_REQUIRE(_builders.ContainsKey(key), () => "No EngineBuilder for " + model + "/" + engine + "/" + tradeType);

            EngineBuilder builder = _builders[key];

            builder.Init(_market, _configurations, _engineData.ModelParameters(tradeType), _engineData.EngineParameters(tradeType));

            return(builder);
        }
Exemple #3
0
 public void RegisterBuilder(EngineBuilder builder)
 {
 }