BlackStyleSwaptionEngine<Spec>::BlackStyleSwaptionEngine(
     const Handle<YieldTermStructure> &discountCurve, Volatility vol,
     const DayCounter &dc, Real displacement)
     : discountCurve_(discountCurve),
       vol_(boost::shared_ptr<SwaptionVolatilityStructure>(
           new ConstantSwaptionVolatility(0, NullCalendar(), Following, vol,
                                          dc, Spec().type, displacement))),
       displacement_(displacement) {
     registerWith(discountCurve_);
 }
Exemple #2
0
void FeedParser::parse_depends(XmlReader& xml, Dependencies& depends)
{
    while (xml.start_element())
    {
        std::string name = xml.name();
        if (name == "if")
        {
            depends.start_if(xml.attribute("test", project_ns));
            parse_depends(xml, depends);
            depends.end_if();
        }
        else if (name == "elseif")
        {
            depends.start_elseif(xml.attribute("test", project_ns));
            parse_depends(xml, depends);
            depends.end_if();
        }
        else if (name == "else")
        {
            depends.start_else();
            parse_depends(xml, depends);
            depends.end_if();
        }
        else if (name == "depends")
        {
            std::string dep = resolve_uri(spec.id, xml.attribute("href", project_ns));
            depends.depends(Spec(dep.c_str()));
        }
        else if (name == "conflicts")
        {
            std::string dep = resolve_uri(spec.id, xml.attribute("href", project_ns));
            depends.conflicts(Spec(dep.c_str()));
        }
        xml.skip();
    }
}
bool	FBXLoader::GetMaterial(KFbxGeometry* g, Object* o)
{
	int		m_count;
	KFbxNode*	n;

	m_count = 0;
	n = NULL;
	if (g)
	{
		n = g->GetNode();
		if (n)
			m_count = n->GetMaterialCount();
	}
	if (m_count > 0)
	{
		KFbxPropertyDouble3	double3;
		KFbxPropertyDouble1	double1;
		KFbxColor		col;
		Material*		mat;
		int			i;

		i = 0;
		while (i < m_count)
		{
			KFbxSurfaceMaterial*		_mat;
			const KFbxImplementation*	imp;
			KString				imp_type;

			_mat = n->GetMaterial(i);
			mat = new (std::nothrow) Material;
			if (mat == NULL)
			{
				std::cout << "[FbxLoader]{__GetMaterial} Error: Can not allocate memory \n";
				return (false);
			}
			mat->SetName((char*)_mat->GetName());
			imp = GetImplementation(_mat, ImplementationHLSL);
			imp_type = "HLSL";
			if (!imp)
			{
				imp = GetImplementation(_mat, ImplementationCGFX);
				imp_type = "CGFX";
			}
			if (_mat->GetClassId().Is(KFbxSurfacePhong::ClassId))
			{
				double3 = ((KFbxSurfacePhong*)_mat)->Ambient;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);

				Color Amb(double3);
				mat->SetAmbient(Amb);
				double3 = ((KFbxSurfacePhong*)_mat)->Diffuse;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Diff(double3);
				mat->SetDiffuse(Diff);
				double3 = ((KFbxSurfacePhong*)_mat)->Specular;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Spec(double3);
				mat->SetSpecular(Spec);
				double3 = ((KFbxSurfacePhong*)_mat)->Emissive;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Em(double3);
				mat->SetEmissive(Em);
				double1 = ((KFbxSurfacePhong*)_mat)->TransparencyFactor;
				mat->SetOpacity(1.0 - double1.Get());
				double1 = ((KFbxSurfacePhong*)_mat)->Shininess;
				mat->SetShininess(double1.Get());
				double1 = ((KFbxSurfacePhong*)_mat)->ReflectionFactor;
				mat->SetReflection(1.0 - double1.Get());
				mat->SetShadingModel(1);
			}
			else if (_mat->GetClassId().Is(KFbxSurfaceLambert::ClassId))
			{
				double3 = ((KFbxSurfaceLambert*)_mat)->Ambient;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Amb(double3);
				mat->SetAmbient(Amb);
				double3 = ((KFbxSurfaceLambert*)_mat)->Diffuse;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Diff(double3);
				mat->SetDiffuse(Diff);
				double3 = ((KFbxSurfaceLambert*)_mat)->Emissive;
				col.Set(double3.Get()[0], double3.Get()[1], double3.Get()[2]);
				Color Em(double3);
				mat->SetEmissive(Em);
				double1 = ((KFbxSurfaceLambert*)_mat)->TransparencyFactor;
				mat->SetOpacity(1.0 - double1.Get());
				mat->SetShadingModel(2);
			}
			o->AddMaterial(mat);
			++i;
		}
	}
	return (true);
}
    EscapeDetection::EscapeDetection(const std::string &fname) {
      pt::ptree tree;
      pt::read_xml(fname, tree);

      spec = Spec(tree);
    }
    void BlackStyleSwaptionEngine<Spec>::calculate() const {
        static const Spread basisPoint = 1.0e-4;

        Date exerciseDate = arguments_.exercise->date(0);

        // the part of the swap preceding exerciseDate should be truncated
        // to avoid taking into account unwanted cashflows
        VanillaSwap swap = *arguments_.swap;

        Rate strike = swap.fixedRate();

        // using the discounting curve
        // swap.iborIndex() might be using a different forwarding curve
        swap.setPricingEngine(boost::shared_ptr<PricingEngine>(new
            DiscountingSwapEngine(discountCurve_, false)));
        Rate atmForward = swap.fairRate();

        // Volatilities are quoted for zero-spreaded swaps.
        // Therefore, any spread on the floating leg must be removed
        // with a corresponding correction on the fixed leg.
        if (swap.spread()!=0.0) {
            Spread correction = swap.spread() *
                std::fabs(swap.floatingLegBPS()/swap.fixedLegBPS());
            strike -= correction;
            atmForward -= correction;
            results_.additionalResults["spreadCorrection"] = correction;
        } else {
            results_.additionalResults["spreadCorrection"] = 0.0;
        }
        results_.additionalResults["strike"] = strike;
        results_.additionalResults["atmForward"] = atmForward;

        // using the discounting curve
        swap.setPricingEngine(boost::shared_ptr<PricingEngine>(
                           new DiscountingSwapEngine(discountCurve_, false)));
        Real annuity;
        switch(arguments_.settlementType) {
          case Settlement::Physical: {
              annuity = std::fabs(swap.fixedLegBPS())/basisPoint;
              break;
          }
          case Settlement::Cash: {
              const Leg& fixedLeg = swap.fixedLeg();
              boost::shared_ptr<FixedRateCoupon> firstCoupon =
                  boost::dynamic_pointer_cast<FixedRateCoupon>(fixedLeg[0]);
              DayCounter dayCount = firstCoupon->dayCounter();
              Real fixedLegCashBPS =
                  CashFlows::bps(fixedLeg,
                                 InterestRate(atmForward, dayCount, Compounded, Annual),
                                 false, discountCurve_->referenceDate()) ;
              annuity = std::fabs(fixedLegCashBPS/basisPoint);
              break;
          }
          default:
            QL_FAIL("unknown settlement type");
        }
        results_.additionalResults["annuity"] = annuity;

        // the swap length calculation might be improved using the value date
        // of the exercise date
        Time swapLength =  vol_->swapLength(exerciseDate,
                                                   arguments_.floatingPayDates.back());
        results_.additionalResults["swapLength"] = swapLength;

        Real variance = vol_->blackVariance(exerciseDate,
                                                   swapLength,
                                                   strike);

        // once the deprecated methods allowing to override the displacement
        // are gone, we can avoid this and directly read the displacement
        // from the volatility structure
        Real displacement = displacement_ == Null<Real>()
                                ? vol_->shift(exerciseDate, swapLength)
                                : displacement_;

        Real stdDev = std::sqrt(variance);
        results_.additionalResults["stdDev"] = stdDev;
        Option::Type w = (arguments_.type==VanillaSwap::Payer) ?
                                                Option::Call : Option::Put;
        results_.value = Spec().value(w, strike, atmForward, stdDev, annuity,
                                                                displacement);

        Time exerciseTime = vol_->timeFromReference(exerciseDate);
        results_.additionalResults["vega"] = Spec().vega(
            strike, atmForward, stdDev, exerciseTime, annuity, displacement);
    }