Update of /cvsroot/quantlibaddin/QuantLibAddin/qlo
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv11840/qlo
Added Files:
riskstatistics.cpp riskstatistics.hpp
Log Message:
--- NEW FILE: riskstatistics.hpp ---
/*
Copyright (C) 2006 Ferdinando Ametrano
Copyright (C) 2006 Duminuco Cristina
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it under the
terms of the QuantLib license. You should have received a copy of the
license along with this program; if not, please email qua...@li...
The license is also available online at http://quantlib.org/html/license.html
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#ifndef qla_riskstatistics_hpp
#define qla_riskstatistics_hpp
#include <oh/objhandler.hpp>
#include <ql/Math/riskstatistics.hpp>
namespace QuantLibAddin {
class RiskStatistics :
public ObjHandler::LibraryObject<QuantLib::RiskStatistics> {
public:
RiskStatistics(std::vector<QuantLib::Real> values,
std::vector<QuantLib::Real> weights);
};
#define TYPICAL_GAUSSIAN_2DOUBLE_STAT_FUNCTION(METHOD) \
inline double METHOD(double mean, double stdDev) { \
QuantLib::StatsHolder h(mean, stdDev); \
QuantLib::GenericGaussianStatistics< QuantLib::StatsHolder > s(h); \
return s.METHOD(); \
}
TYPICAL_GAUSSIAN_2DOUBLE_STAT_FUNCTION(gaussianDownsideVariance)
TYPICAL_GAUSSIAN_2DOUBLE_STAT_FUNCTION(gaussianDownsideDeviation)
#define TYPICAL_GAUSSIAN_3DOUBLE_STAT_FUNCTION(METHOD) \
inline double METHOD(double x, double mean, double stdDev) { \
QuantLib::StatsHolder h(mean, stdDev); \
QuantLib::GenericGaussianStatistics< QuantLib::StatsHolder > s(h); \
return s.METHOD(x); \
}
TYPICAL_GAUSSIAN_3DOUBLE_STAT_FUNCTION(gaussianRegret)
TYPICAL_GAUSSIAN_3DOUBLE_STAT_FUNCTION(gaussianPercentile)
TYPICAL_GAUSSIAN_3DOUBLE_STAT_FUNCTION(gaussianTopPercentile)
TYPICAL_GAUSSIAN_3DOUBLE_STAT_FUNCTION(gaussianPotentialUpside)
TYPICAL_GAUSSIAN_3DOUBLE_STAT_FUNCTION(gaussianValueAtRisk)
TYPICAL_GAUSSIAN_3DOUBLE_STAT_FUNCTION(gaussianExpectedShortfall)
TYPICAL_GAUSSIAN_3DOUBLE_STAT_FUNCTION(gaussianShortfall)
TYPICAL_GAUSSIAN_3DOUBLE_STAT_FUNCTION(gaussianAverageShortfall)
}
#endif
--- NEW FILE: riskstatistics.cpp ---
/*
Copyright (C) 2006 Ferdinando Ametrano
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it under the
terms of the QuantLib license. You should have received a copy of the
license along with this program; if not, please email qua...@li...
The license is also available online at http://quantlib.org/html/license.html
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#if defined(HAVE_CONFIG_H)
#include <qlo/config.hpp>
#endif
#include <qlo/riskstatistics.hpp>
namespace QuantLibAddin {
RiskStatistics::RiskStatistics(std::vector<QuantLib::Real> values,
std::vector<QuantLib::Real> weights)
{
libraryObject_ = boost::shared_ptr<QuantLib::RiskStatistics>(
new QuantLib::RiskStatistics());
QL_REQUIRE(weights.size()==0 || values.size()==weights.size(),
"Values and weights vectors must have the same number of elements.");
if (values.size()!=0) {
if (weights.size()!=0)
libraryObject_->addSequence(values.begin(),
values.end(),
weights.begin());
else
libraryObject_->addSequence(values.begin(),
values.end());
}
}
}
|