Kalotay
Analytics
A Division of Andrew Kalotay Associates, Inc.
|
BondOAS™ Library API Documentation |
BondOAS™ is a rigorously developed, continuously enhanced, thoroughly
tested valuation engine for the universe of fixed coupon bonds. The
BondOAS™ library is a thread-safe library written in C/C++. The library
is released as both static and dynamic libraries for multiple architectures
including 32 and 64 bit Linux, Windows, and SunOS. BondOAS™ has APIs for
C++, C, Java, and C#. See
BondOAS™ Overview for additional
information.
C++ API — akaapi.hpp
Note: all objects are defined within the namespace 'AndrewKalotayAssociates'
class
Status {
protected:
class StatusData *statusdata;
public:
Status();
~
Status();
public:
int
Error() const;
int
WarningCount() const;
int
Warning(int idx) const;
static const char *
ErrorString(int);
const char *
ErrorString() const { return
ErrorString(
Error()); };
const char *
WarningString(int idx) const {
return
ErrorString(
Warning(idx));
};
void
Clear();
};
class Date;
class ConstantString;
class
Initialization : public
Status {
private:
Initialization(const
Initialization &) { };
Initialization &
operator=(const
Initialization &) { return *this; };
public:
Initialization();
Initialization(long key, const char *uname);
Initialization(const char *keyfilename);
~
Initialization();
void
ShutdownAutomatically(bool);
static void
Shutdown();
int
Authorize(long key, const char *uname);
int
Authorize(const char *keyfilename = "./akalib.key");
Date Expiration() const;
static double
Version();
static const char *
VersionString();
};
class MuniCurve;
class
InterestRateModel : public
Status {
private:
friend class
Value;
friend class
ValueAfterTax;
friend class
InterestRateScenario;
friend class
Compatibility;
class InterestRateModelData *data;
public:
enum
INPUTTYPE { FACTORCURVE, PARCURVE };
explicit
InterestRateModel(
INPUTTYPE = PARCURVE);
~
InterestRateModel();
InterestRateModel(const
InterestRateModel &, double forward_period = 0);
InterestRateModel &
operator=(const
InterestRateModel &);
const
ConstantString ToXML() const;
explicit
InterestRateModel(const char *XML);
InterestRateModel(const
MuniCurve &);
bool
SetRate(double year, double rate);
bool
SetFactor(double year, double factor);
bool
SetZeroRate(double year, double zerorate);
void
RemovePoint(double year);
void
RemoveAllPoints();
double
GetRate(double year) const;
int
RateCount() const;
double
GetRateForIndex(int index) const;
double
GetYearForIndex(int index) const;
double
GetFactor(double year) const;
static double
ZeroToFactor(double rate, double year);
static double
FactorToZero(double discount, double year);
bool
SetVolatility(double);
double
GetVolatility() const;
bool
SetAlpha(double);
double
GetAlpha() const;
bool
SetLongVolatility(double);
double
GetLongVolatility() const;
INPUTTYPE GetInputType() const;
bool
IsParCurve() const { return
GetInputType() == PARCURVE; };
int
Solve();
double
Discount(double value, double fromtime, double oas = 0) const;
double
GetVolatility(double fromtime) const;
void
EnableCompatibility();
};
class
MuniCurve {
public:
MuniCurve();
~
MuniCurve();
const
ConstantString ToXML() const;
bool
SetYield(double year, double rate);
bool
SetNonCallPeriod(double);
bool
SetCoupon(double year, double coupon);
void
RemovePoint(double year);
int
YieldCount() const;
double
GetYieldForIndex(int index) const;
double
GetCouponForIndex(int index) const;
double
GetYearForIndex(int index) const;
bool
SetVolatility(double);
bool
SetAlpha(double);
bool
SetLongVolatility(double);
private:
friend class
InterestRateModel;
class MuniCurveData *data;
};
template <class T> class AKAArray;
typedef AKAArray<Date> DateArray;
class CallPutOption;
typedef AKAArray<CallPutOption> OptionsArray;
class SinkSchedule;
typedef AKAArray<SinkSchedule> SinksArray;
class
Bond : public
Status {
private:
friend class
Value;
friend class
ValueAfterTax;
friend class
Compatibility;
class BondData *data;
long
CalculateFirstCouponDate();
public:
Bond(const char *name, const
Date &idate, const
Date &mdate, double coupon);
~
Bond();
Bond(const
Bond &);
Bond &
operator=(const
Bond &);
const
ConstantString ToXML() const;
explicit
Bond(const char *XML);
enum
DAYCOUNT {
DC_30_360,
DC_30E_360,
DC_ACT_360,
DC_ACT_365,
DC_ACT_ACT,
DC_CD_365,
DC_30_360_ISDA,
DC_30E_360_ISDA,
DC_NO_LEAP_365,
DC_BUS_252
};
bool
SetDaycount(
DAYCOUNT);
enum
FREQUENCY {
FREQ_INT_AT_MATURITY,
FREQ_ANNUAL,
FREQ_SEMIANNUAL,
FREQ_QUARTERLY,
FREQ_MONTHLY,
FREQ_SEMIANNUAL_COMPOUNDED,
FREQ_QUARTERLY_COMPOUNDED,
FREQ_ANNUAL_BY_WEEKS,
FREQ_SEMIANNUAL_BY_WEEKS,
FREQ_QUARTERLY_BY_WEEKS,
FREQ_MONTHLY_BY_WEEKS
};
bool
SetFrequency(
FREQUENCY);
bool
SetRedemptionPrice(double);
bool
SetIssuePrice(double);
bool
SetFaceAmount(unsigned long);
bool
SetFaceAmount(double);
bool
SetFirstCoupon(const
Date &);
bool
SetLastCoupon(const
Date &);
Date GetFirstCoupon() const;
Date GetLastCoupon() const;
bool
SetPayDayEndOfMonth(bool);
bool
SetPayDay(int);
enum
YIELD_METHOD {
YLD_BEY = 1,
YLD_SIMPLE_LAST_PERIOD,
YLD_SIMPLE_LAST_YEAR,
YLD_MUNI,
YLD_ANNUALIZED,
YLD_ANNUALIZED_SIMPLE_LAST_PERIOD,
YLD_ANNUALIZED_SIMPLE_LAST_YEAR
};
bool
SetYieldMethod(
YIELD_METHOD);
bool
SetCall(const
Date &, double price);
bool
SetPut(const
Date &, double price);
bool
SetSink(const
Date &, double amount, double price = 100);
bool
IsCallable() const;
bool
IsPutable() const;
bool
IsSinker() const;
bool
SetCoupon(const
Date &, double);
bool
SetXCouponDays(int);
bool
SetPIK(double pikrate, double percent_cash = 0);
bool
SetPIK(const
Date &, double pikrate, double percent_cash = 0);
bool
PIKToggleAllow(bool);
void
RemoveCall(const
Date &);
void
RemoveAllCalls();
void
RemovePut(const
Date &);
void
RemoveAllPuts();
void
RemoveSink(const
Date &);
void
RemoveAllSinks();
void
RemoveCoupon(const
Date &);
void
RemovePIK(const
Date &);
bool
SetNoticePeriod(int);
bool
SetOptionDelay(int d) { return
SetNoticePeriod(d); };
bool
SetCallAmerican(bool is_american);
bool
SetPutAmerican(bool is_american);
enum
ALLOCATION {
ALLOC_PRORATA,
ALLOC_FRONT,
ALLOC_BACK
};
bool
SetSinkOption(bool allow_delivery,
double acceleration,
ALLOCATION allocation);
bool
SetCouponSchedulePeriod(bool at_begin);
enum
NotifyBehavior {
BusinessDaysExtend,
BusinessDaysOnly
};
NotifyBehavior SetNotifyBehavior(
NotifyBehavior);
bool
SetBusinessDayWeekends(bool);
bool
SetHoliday(const
Date &);
bool
SetHolidays(const
Date *, int);
bool
ClearHolidays();
DateArray
GetHolidays() const;
enum
HOLIDAYS {
HOLIDAYS_US, HOLIDAYS_BRAZIL, HOLIDAYS_MEXICO
};
bool
SetHolidays(
HOLIDAYS);
static DateArray
GetHolidays(
HOLIDAYS);
enum
BusinessDayRollMethod {
BUSINESSDAY_ROLL_FORWARD, BUSINESSDAY_ROLL_BACKWARD
};
void
SetBusinessDayRollMethod(
Bond::
BusinessDayRollMethod);
bool
SetMortgage();
bool
SetAmortization(double years);
bool
SetMortgageRefinanceCost(double);
void
ClearMortgage();
const char *
GetName() const;
Date GetInitialDate() const;
Date GetMaturityDate() const;
double
GetCoupon() const;
DAYCOUNT GetDaycount() const;
FREQUENCY GetFrequency() const;
double
GetFaceAmount() const;
int
GetNoticePeriod() const;
bool
CallsAreAmerican() const;
bool
PutsAreAmerican() const;
OptionsArray
GetCalls() const;
OptionsArray
GetPuts() const;
SinksArray
GetSinks() const;
enum
PRESET {
US_CORPORATE,
US_MUNI,
US_TREASURYBOND,
BRAZIL_BOND,
US_CD,
MEXICAN_GOVERNMENT
};
bool
ApplyPreset(
PRESET);
};
class
Duration {
public:
Duration(double d, double c) :
duration(d),
convexity(c) {};
Duration() :
duration(0),
convexity(0) {};
double duration;
double convexity;
operator double() const { return duration; };
};
struct
YieldComplex {
double yield;
double modified_duration;
double modified_convexity;
int flow_index;
};
class
ScenarioAnalysis {
public:
enum
REDEEMED { NOTREDEEMED, CALL, PUT, SINK, MATURITY } redeemed;
int flowwhen;
double efficiency;
double reinvestment;
static const char *
redeemstring(
REDEEMED);
const char *
redeemstring() const { return
redeemstring(redeemed); };
};
class
ScenarioHorizon {
public:
double interestincome;
double principalincome;
double price;
double accrued;
double outstanding;
};
class SinkingFundStatus;
class InterestRateScenario;
class
Quote {
public:
double quote;
enum
QuoteType { OAS, PRICE, YTM, YTC, YTP } quotetype;
Quote(double q,
QuoteType qt) :
quote(q),
quotetype(qt) {};
};
typedef AKAArray<Duration> DurationArray;
typedef AKAArray<double> DoubleArray;
class
Value : public
Status {
protected:
Value(const
Value &) { };
Value &
operator=(const
Value &) { return *this; };
protected:
class ValueData *data;
public:
Value(const
Bond &, const
Date &pvdate);
Value(const
Bond &, const
Date &pvdate, const
Date &tradedate);
Value(const
Bond &, const
InterestRateModel &, const
Date &pvdate);
Value(const
Bond &, const
InterestRateModel &, const
Date &pvdate,
const
Date &tradedate);
Value(const
Bond &, const
InterestRateModel &, const
SinkingFundStatus &,
const
Date &pvdate);
Value(const
Bond &, const
InterestRateModel &, const
SinkingFundStatus &,
const
Date &pvdate, const
Date &tradedate);
~
Value();
int
Reset(const
Bond &, const
Date &pvdate);
int
Reset(const
Bond &, const
Date &pvdate, const
Date &tradedate);
int
Reset(const
Bond &, const
InterestRateModel &, const
Date &pvdate);
int
Reset(const
Bond &, const
InterestRateModel &, const
Date &pvdate,
const
Date &tradedate);
int
Reset(const
Bond &, const
InterestRateModel &,
const class
SinkingFundStatus &,
const
Date &pvdate);
int
Reset(const
Bond &, const
InterestRateModel &,
const class
SinkingFundStatus &,
const
Date &pvdate, const
Date &tradedate);
static const double BadValue;
static bool
IsBadValue(double v);
Date PVDate() const;
int
FlowCount() const;
enum
FLOWTYPE {
INTEREST = 1,
PRINCIPAL = 2,
CALLOPTION = 4,
PUTOPTION = 8,
PSEUDO_REGULAR = 16
};
int
FlowType(int) const;
bool
FlowType(int idx,
FLOWTYPE t) const { return (
FlowType(idx) & t) != 0; };
int
FirstFlow() const;
Date FlowDate(int) const;
double
YearsTo(int) const;
double
Interest(int) const;
double
Principal(int) const;
double
Accrued(int) const;
double
InitialOutstandingPercent() const;
double
OutstandingPercent(int) const;
double
PrincipalPercent(int) const;
double
PrincipalPrice(int) const;
double
CallPrice(int) const;
double
PutPrice(int) const;
const char *
BondName() const;
double
Accrued() const;
int
AccruedDays() const;
double
AccruedOn(const
Date &);
bool
SetYieldMethod(
Bond::
YIELD_METHOD);
Bond::
YIELD_METHOD GetYieldMethod() const;
double
YieldToCall(double price);
double
YieldToPut(double price);
double
YieldToMaturity(double price);
double
WeightedAverageMaturity(double price);
double
YieldToWAM(double price);
double
ModifiedDurationToWAM(double price);
double
ModifiedConvexityToWAM(double price);
struct YieldComplex
YieldToCallComplex(double price);
struct YieldComplex
YieldToPutComplex(double price);
struct YieldComplex
YieldToMaturityComplex(double price);
double
YieldToWorst(double price, bool also_to_sink = false);
double
YieldToWorst(double price, int &flowindex,
bool also_to_sink = false);
int
YieldToWorstFlow(double price, bool also_to_sinks = false);
struct YieldComplex
YieldToWorstComplex(double price,
bool also_to_sinks = false);
Duration ModifiedDuration(double price);
double
YieldToFlow(int, double price, bool as_cashflow_yield = false,
bool also_to_sinks = false);
Duration ModifiedDurationToFlow(int flowindex, double price, double yield);
double
ytm2price(double);
double
ytc2price(double);
double
ytp2price(double);
double
Price(double oas);
double
Price(
Quote);
double
PVInterest(
Quote);
double
PVPrincipal(
Quote);
double
OAS(double price);
double
OAS(
Quote);
double
ExpectedLife(
Quote);
double
OptionValue(double oas);
double
OptionValue(
Quote);
double
PriceToFlow(int flowindex, double yield,
bool as_cashflow_yield = false);
double
PriceToWorst(double yield, bool also_to_sinks = false);
double
PriceToWorst(double yield, int &flowindex,
bool also_to_sinks = false);
int
PriceToWorstFlow(double yield, bool also_to_sinks = false);
Duration EffectiveDuration(double oas, double durationbp = 30);
Duration EffectiveDuration(
Quote, double durationbp = 30);
double
UpDuration(double oas, double durationbp = 30);
double
DownDuration(double oas, double durationbp = 30);
double
UpDuration(
Quote, double durationbp = 30);
double
DownDuration(
Quote, double durationbp = 30);
Duration OASSpreadDuration(
Quote, double durationbp = 30);
double
UpOASSpreadDuration(
Quote, double durationbp = 30);
double
DownOASSpreadDuration(
Quote, double durationbp = 30);
DurationArray
KeyRatesDurations(
Quote, double durationbp,
const DoubleArray &terms,
bool scale = true);
Duration KeyRateDuration(double oas, double durationbp, double year);
Duration KeyRateDuration(
Quote, double durationbp, double year);
Duration KeyRateDuration(double oas, double durationbp, double year,
double width);
Duration KeyRateDuration(
Quote, double durationbp, double year,
double width);
Duration KeyRateDuration(double oas, double durationbp, double year,
double leftanchoryear, double rightanchoryear);
Duration KeyRateDuration(
Quote, double durationbp, double year,
double leftanchoryear, double rightanchoryear);
double
Discount(double value, double fromtime, double oas = 0) const;
double
GetRate(double year) const;
double
GetFactor(double year) const;
bool
AnalyzeScenario(const
InterestRateScenario &, double oas,
ScenarioAnalysis &);
bool
AnalyzeScenario(const
InterestRateScenario &,
Quote,
ScenarioAnalysis &);
bool
AnalyzeScenario(const
InterestRateScenario &,
Quote,
ScenarioAnalysis &,
ScenarioHorizon &);
double
AssetSwapSpread(double price);
double
ISpread(double price);
bool
PIKToggle(bool);
bool
PIKToggle(const
Date &, bool);
bool
PIKToggle(int flowindex, bool);
};
class
SinkingFundStatus {
public:
double outstanding;
double accumulation;
public:
SinkingFundStatus(unsigned long os, unsigned long ac) :
outstanding(os),
accumulation(ac) {};
SinkingFundStatus(double os, double ac) :
outstanding(os),
accumulation(ac) {};
SinkingFundStatus() :
outstanding(0),
accumulation(0) {};
};
class
InterestRateScenario {
protected:
InterestRateScenario(const
InterestRateScenario &) { };
InterestRateScenario &
operator=(const
InterestRateScenario &) {
return *this;
};
protected:
friend class
ValueData;
class InterestRateScenarioData *data;
public:
enum
SCENTYPE {
NOW,
GRADUAL,
THEN
};
InterestRateScenario(double years, const
InterestRateModel &horizonmodel,
SCENTYPE = NOW);
~
InterestRateScenario();
bool
AddTransition(double years, const
InterestRateModel &);
bool
SetEfficiencyThreshold(double);
void
SetReinvestStandard();
void
SetReinvestAtZeroOAS();
void
SetReinvestAtFixed(double);
};
class
Date {
private:
long _data;
public:
enum
ENTRY {
YMD,
MDY,
DMY
};
Date(int, int, int,
ENTRY = YMD );
Date(const char *,
ENTRY, char sep = '/');
Date(long = 0);
Date(const
Date &, double yrs,
Bond::
DAYCOUNT);
bool
Good() const;
long
Libdate() const { return _data; };
int
DayOf() const { return ((int) (_data) % 100); };
int
MonthOf() const { return (((int) (_data) / 100) % 100); };
int
YearOf() const { return ((int) (_data) / 10000); };
double
YearsTo(const
Date &other,
Bond::
DAYCOUNT) const;
int
DaysTo(const
Date &other) const;
Date &
operator +=(int);
Date &
operator -=(int days) { return *this += -days; };
bool
operator <(const
Date &other) const {
return
Libdate() < other.
Libdate();};
bool
operator <= (const
Date &other) const {
return
Libdate() <= other.
Libdate();};
bool
operator == (const
Date &other) const {
return
Libdate() == other.
Libdate();};
bool
operator >= (const
Date &other) const {
return
Libdate() >= other.
Libdate();};
bool
operator > (const
Date &other) const {
return
Libdate() > other.
Libdate();};
};
class
ConstantString {
private:
class ConstantStringData *data;
ConstantString(const char *, long);
friend class
InterestRateModel;
friend class
MuniCurve;
friend class
Bond;
public:
ConstantString(const
ConstantString &);
ConstantString &
operator=(
ConstantString &);
~
ConstantString();
const char *
String() const;
operator const char *() const { return
String(); };
long
Length() const;
};
template <class T> class AKAArray {
public:
explicit AKAArray(unsigned int sz = 0) : size(sz) { Alloc(); };
AKAArray(const AKAArray<T> &);
const AKAArray<T> & operator=(const AKAArray<T> &other);
~AKAArray() { DeAlloc(); };
unsigned int Size() const { return size; };
const T & operator[](unsigned int index) const { return array[index]; };
const T & Get(unsigned int index) const { return array[index]; };
T & Set(unsigned int index, const T &v) { return array[index] = v; };
T & operator[](unsigned int index) { return array[index]; };
void ReSize(unsigned int sz);
private:
unsigned int size;
T *array;
private:
void Alloc();
void DeAlloc();
};
class
CallPutOption {
public:
CallPutOption(
Date d, double p) :
date(d),
price(p) {};
Date date;
double price;
};
class
SinkSchedule {
public:
SinkSchedule(
Date d, double a, double p = 100) :
date(d),
amount(a),
price(p) {};
Date date;
double amount;
double price;
};
Index of Classes
Bond
CallPutOption
ConstantString
Date
Duration
Initialization
InterestRateModel
InterestRateScenario
MuniCurve
Quote
ScenarioAnalysis
ScenarioHorizon
SinkSchedule
SinkingFundStatus
Status
Value
C++/C Compatibility — akaapi_compatibility.hpp
#include "
akaapi.hpp"
#include "
akaapi.h"
Note: all objects are defined within the namespace 'AndrewKalotayAssociates'
class
Compatibility {
public:
static AKAHTREE
CApiTreeHandle(const InterestRateModel &);
static const AKABOND* const
CApiBond(const Bond &);
static const AKACURVE* const
CApiCurve(const InterestRateModel &);
static InterestRateModel
ModelFromCurve(const AKACURVE *);
static Bond
BondFromBOND(const AKABOND *);
};
Index of Classes
Compatibility
Java API
BondOAS™ provides a Java API. The API exactly follows the C++ API
except for operator method names (see below).
The class files and the bodoas.jar file are in the java directory of the
release. The akalib/java/bondoas.jar file is created by compiling the .java
files in the akalib/java directory and assembling the .jar file. The package
path used is com/kalotay/akalib. Both the compiled jar file and the java
sources are provided in akalib/java.
C++ operator methods such as +=
or <
do not translate.
All such operators have been consistently renamed as follows:
C++ Operator | Java Method |
operator+= | PlusEqual |
operator-= | MinusEqual |
operator< | IsLT |
operator<= | IsLE |
operator== | IsEq |
operator>= | IsGE |
operator> | IsGT |
A dynamic library bondoas_java_wrap is provided in the architecture
appropriate lib directory of the release. The bondoas.jar file can be used in
your java project. Before objects in the jar file can be used, you must
dynamically load the bondoas_java_wrap dynamic library. If your path is set
up approriately so that the Andrew Kalotay Associates library for the
appropriate architecture can be found, the load instruction looks like:
System.loadLibrary("bondoas_java_wrap");
C# API
BondOAS™ provides a C# API. The C# API exactly follows the C++ API.
The C# class files are in the csharp directory of the release. These need to
be compiled. The C# classes explicitly load the Andrew Kalotay Associates C#
API dynamic library bondoas_csharp_wrap. This dynamic library is provided in
the architecture appropriate lib directory of the release.
.Net
These instructions apply to using the Andrew Kalotay Associates C# API
under Windows for a .NET application.
The .cs files in the akalib/csharp directory need to be compiled.
They can either be imported directly into your project or they can be
separately compiled into a .NET dll. In the latter case, that
compiled dll can then be referenced in a project.
Note, It is not necessary (and does not work) to directly reference
the akalib library dlls in a .NET project. The code in
AkaApiPINVOKE.cs dynamically loads the appropriate Andrew Kalotay
Associates bondoas dlls. The path to the Andrew Kalotay Associates
bondoas dlls, (e.g., akalib/lib/win64) must be in your path at runtime.
C API — akaapi.h
typedef struct
AKAInitData AKAINITDATA;
long
AKA_initialize(long key, const char *uname);
long
AKA_initialize_configure(long key, const char *uname,
AKAINITDATA *config);
void
AKA_initialize_get_defaults(
AKAINITDATA *config);
void
AKA_authorize_expiration_date(int *year, int *month, int *day);
void
AKA_shutdown();
void
AKA_shutdown_configure(int unused);
extern int AKA_memory_diagnostics_enabled;
void
AKA_memory_diagnostics(unsigned long *allocations,
unsigned long *total_memory, unsigned long *trees);
typedef struct
AKABond AKABOND;
typedef struct
AKAScen AKASCEN;
typedef struct
AKAScenSetup AKASCENSETUP;
typedef struct
AKABondReport AKABONDREPORT;
typedef struct
AKABondYieldReport AKABONDYIELDREPORT;
typedef struct
AKAFlowReport AKAFLOWREPORT;
typedef struct
AKAFwdReport AKAFWDREPORT;
typedef struct
AKAKRDurReport AKAKRDURREPORT;
typedef struct
AKAkrdursetup AKAKRDURSETUP;
typedef struct
AKAScenReport AKASCENREPORT;
typedef struct
AKAVolReport AKAVOLREPORT;
typedef struct
AKAYldWorst AKAYLDWORST;
typedef struct
AKAPrcWorst AKAPRCWORST;
typedef struct
AKAAtaxYld AKAATAXYLD;
typedef struct
AKAAtaxBasis AKAATAXBASIS;
double
AKABondPrice(long pvdate,
AKAHTREE hTree, const
AKABOND *bond,
double oas);
double
AKABondOAS(long pvdate,
AKAHTREE hTree, const
AKABOND *bond,
double price);
double
AKABondAccrued(long pvdate, const
AKABOND *bond);
double
AKABondAccrued2(long pvdate, const
AKABOND *bond,
double *accrued, int *accrued_days);
double
AKABondPriceShifted(long pvdate,
AKAHTREE hTree, const
AKABOND *bond,
double oas, double treeshift);
double
AKABondPriceCnv(long pvdate, long cnvfrom, long cnvto, double quote,
const
AKABOND *bond);
double
AKAAssetSwapSpread(double clean_price, long pvdate,
AKAHTREE hTree,
const
AKABOND *bond);
double
AKAConvertAssetSwapSpread(double asset_swap_spread, long pvdate,
AKAHTREE hTree, const
AKABOND *bond);
double
AKAISpread(const
AKABOND *bond, long pvdate, double price,
const
AKACURVE *crv);
double
AKADiscount(
AKAHTREE hTree, double oas, double value, double fromtime);
long
AKABondVal(long pvDate, long quoteType, double quote,
AKAHTREE hTree, const
AKABOND *bond,
AKABONDREPORT *rpt);
long
AKABondVal2(long pvDate, long quoteType, double quote,
AKAHTREE hTree, const
AKABOND *bond,
AKABONDREPORT *rpt,
int value_option, int value_duration, int value_yield);
enum {
AKABONDVAL_DURATION = 1,
AKABONDVAL_OPTION = 2,
AKABONDVAL_YIELDS = 4
};
long
AKABondVal3(long pvDate, long quoteType, double quote,
AKAHTREE hTree, const
AKABOND *bond,
AKABONDREPORT *rpt, void *reserved,
int value_what_flag);
long
AKABondScenEx(long quoteType, double quote,
const
AKASCENSETUP *akascen, const
AKABOND *bond,
AKASCENREPORT *rpt, double *efficiency);
AKAKRDURREPORT *
AKABondKeyDur3(long pvdate, const
AKABOND *bond,
long quoteType, double quote,
AKAKRDURSETUP *setup);
AKAKRDURSETUP *
AKAKeyDurSetup(const
AKACURVE *curve, const
AKASPREAD *spread,
double durbp,
double *maturities, int maturities_count);
AKAKRDURSETUP *
AKAKeyDurSetupFree(
AKAKRDURSETUP *setup);
AKAKRDURREPORT *
AKABondKeyDur2(long pvdate, const
AKABOND *bond,
long quoteType, double quote,
const
AKACURVE *curve, const
AKASPREAD *spread,
int durbp,
AKAKRDURREPORT *rpt);
AKAKRDURREPORT *
AKABondKeyDur(long pvdate, const
AKABOND *bond,
long quoteType, double quote,
const
AKACURVE *curve, const
AKASPREAD *spread,
int durbp);
long
AKABondKRDur(long pvDate, long quoteType, double quote,
AKAHTREE hTree, const
AKABOND *bond,
AKAKRDURREPORT *rpt);
long
AKABondFlowOnly(long pvDate, const
AKABOND *bond,
AKAFLOWREPORT *rpt);
long
AKABondFlow(long pvDate, long quoteType, double quote,
AKAHTREE hTree, const
AKABOND *bond,
AKAFLOWREPORT *rpt);
long
AKAYieldToWorst(long pvDate, long quoteType, double quote,
const
AKABOND *bond,
AKAYLDWORST *rpt);
long
AKALowestYieldToSink(long pvDate, long quoteType, double quote,
const
AKABOND *bond,
AKAYLDWORST *rpt);
long
AKAYieldToWorstEx(long pvDate, long quoteType, double quote,
const
AKABOND *bond, int tosink, int ascfy,
AKAYLDWORST *rpt);
AKAYLDWORST *
AKAYieldToWorstEx2(long pvDate, long quoteType, double quote,
const
AKABOND *bond, int tosink, int ascfy);
long
AKAPriceToWorst(long pvDate, long quoteType, double quote,
const
AKABOND *bond,
AKAPRCWORST *rpt);
long
AKAAtaxYield(long pvDate, long quoteType, double quote,
const
AKABOND *bond,
AKAATAXYLD *rpt);
long
AKAAtaxBasis(long pvDate, long quoteType, double quote,
const
AKABOND *akabond,
AKAATAXBASIS *rpt);
long
AKABondValueYields(long pvdate, double price, const
AKABOND *bond,
AKABONDYIELDREPORT *rpt);
long
AKABondValueYieldsEx(long pvdate, double price, const
AKABOND *bond,
int tosink, int ascfy,
AKABONDYIELDREPORT *rpt);
void
AKADefaultTaxRate(double income, double capgain_short, double capgain_long,
double capgain_superlong);
void
AKABondTaxRate(
AKABOND *bond,
double income, double capgain_short, double capgain_long,
double capgain_superlong);
void
AKABondTaxRateGet(
AKABOND *bond,
double *income, double *capgain_short,
double *capgain_long, double *capgain_superlong);
enum
AKANotifyBehavior {
AKABusinessDaysExtend,
AKABusinessDaysOnly
};
i
nt
AKA_set_notifybehavior(AKABOND *, int behavior);
i
nt
AKA_set_notifyweekends(AKABOND *, int);
v
oid
AKA_set_notifyholiday(AKABOND *, long);
v
oid
AKA_clear_notifyholidays(AKABOND *);
int
AKABondMortgage(
AKABOND *bond, double amount, double amortization_years,
double reficost);
double
AKA_version();
const char *
AKA_version_string();
long
AKAFwdRates(
AKAHTREE hTree,
AKAFWDREPORT *report);
long
AKAFwdRatesFromCurve(
AKACURVE *curve,
AKAFWDREPORT *report);
long
AKAYieldVol(
AKAHTREE hTree,
AKAVOLREPORT *report);
void
AKA_set_duration_shift(long smode, double bp_no_options,
double bp_with_options);
double
AKAYears(long adate, long bdate, long daycount);
long
AKADateAdd(long adate, double time, long daycount);
long
AKADatePack(long settlement, long trade);
l
ong
AKAConvertMuniCurve(AKACURVE *, double *coupons, double noncallperiod);
struct
AKAInitData
{
char treePath[512];
long maxTrees;
long maxTreesPurge;
long msg_pop_order;
long enable_tls;
long treeCacheSize;
long _reserved3;
long durationShift;
double durBPNoOpts;
double durBPOpts;
double efficiency;
};
struct
AKACurve
{
long mode;
double vol;
double lvol;
double alpha;
long type;
long reseverd;
long n;
double *time;
double *yield;
};
struct
AKASpreads
{
long n;
double *time;
double *spread;
};
struct
AKABond
{
AKASECURITY *sec;
AKACOUPON *cpn;
AKAOPTION *call;
AKAOPTION *put;
AKASINK *sink;
};
struct
AKASecurity
{
char name[80];
long idate;
long ddate;
long fcdate;
long lcdate;
long mdate;
long daycount;
long frequency;
long ex_cpn_days;
long payday;
double redemption_value;
double coupon;
long yld_method;
double issue_price;
void *taxinfo;
void *_data;
};
struct
AKACoupon
{
long n;
long type;
long *date;
double *cpn;
};
struct
AKAOption
{
long n;
long type;
long delay;
long *date;
double *px;
};
struct
AKASink
{
long n;
long delivery;
long allocation;
double face;
double outstanding;
double acceleration;
double accumulation;
long *date;
double *amt;
double *px;
};
struct
AKAScenSetup
{
long type;
long n;
long *dates;
AKAHTREE *trees;
double eff_threshold;
int reinvestment_method;
double reinvestment_rate;
int is_aftertax;
};
enum
AKASCEN_REINVESTMENT {
AKASCEN_REINVEST_OAS,
AKASCEN_REINVEST_ZERO,
AKASCEN_REINVEST_FIXED
};
struct
AKABondReport
{
double price;
double accrued;
double optval;
double oas;
double effDur;
double effCon;
double effDV01;
double ytm;
double ytc;
double ytp;
double cfy;
double wam;
double modDur;
double modCon;
double modDV01;
};
struct
AKABondYieldReport
{
double ytm;
double ytc;
double ytp;
double cfy;
double wam;
double modDur;
double modCon;
double modDV01;
double modDurCall;
long worstdate;
double ytw;
double modDurWorst;
double modConWorst;
};
struct
AKAFlowReport
{
long nFlows;
double oas;
double value;
double accrued;
double optval;
double npv;
long *date;
double *iflow;
double *pflow;
double *tflow;
double *zero;
double *factor;
double *pv;
};
struct
AKAFwdReport
{
long nMats;
long nTimes;
double *mats;
double *times;
double **fwds;
};
struct
AKAKRDurReport
{
long n;
double oas;
double value;
double accrued;
double npv;
double effDur;
double effCon;
double *mats;
double *durs;
};
struct
AKAScenReport
{
double cap0;
double val0;
double acc0;
double interest;
double principal;
double intOnInt;
double cap1;
double val1;
double acc1;
double totalRet;
double dur0;
double dur1;
double con0;
double con1;
double oas;
double balance;
long redeemed;
long rDate;
};
struct
AKAVolReport
{
long n;
double alpha;
double *mats;
double *vols;
};
struct
AKAYldWorst
{
long *dates;
double *yields;
int n;
int worst;
};
struct
AKAPrcWorst
{
long *dates;
double *prices;
int n;
int worst;
};
struct
AKAAtaxYldResult {
double principal;
double tax;
double yield;
};
struct
AKAAtaxYld
{
double issue_price;
double taxrate_short;
double taxrate_long;
double taxrate_superlong;
double taxrate_income;
struct AKAAtaxYldResult ytm;
struct AKAAtaxYldResult ytc;
struct AKAAtaxYldResult ytp;
};
struct
AKAAtaxBasis
{
double issue_price;
double taxrate_short;
double taxrate_long;
double taxrate_superlong;
double taxrate_income;
long purchase_date;
double purchase_price;
double purchase_basis;
double holder_basis;
double sale_basis;
double atax_price;
};
#ifndef TRUE
#define TRUE (1==1)
#ifndef FALSE
#define FALSE (!TRUE)
enum
AKAQuoteType
{
AKA_QUOTE_OAS = 0,
AKA_QUOTE_PRICE = 1,
AKA_QUOTE_YTM = 2,
AKA_QUOTE_YTC = 3,
AKA_QUOTE_YTP = 4,
AKA_QUOTE_ATAX_PRICE = 5
};
enum
AKAShiftMode
{
AKA_SHIFT_SPOT = 0,
AKA_SHIFT_PAR = 1,
AKA_SHIFT_NONE = 2
};
enum
AKAVolatilityMode
{
AKA_VOLMODE_MEANREV = 0,
AKA_VOLMODE_LONGVOL = 1
};
enum
AKACurveType
{
AKA_CURVE_FACTOR = 0,
AKA_CURVE_PAR = 1,
AKA_CURVE_ZERO = 2,
AKA_CURVE_FORWARD = 3
};
enum
AKADaycount
{
AKA_DAYS_BUS_252 = 30,
AKA_DAYS_30_360 = 33,
AKA_DAYS_30E_360 = 34,
AKA_DAYS_30_360_ISDA = 35,
AKA_DAYS_30E_360_ISDA = 36,
AKA_DAYS_ACT_360 = 39,
AKA_DAYS_NO_LEAP_365 = 45,
AKA_DAYS_ACT_365 = 47,
AKA_DAYS_ACT_ACT = 63,
AKA_DAYS_CD_365 = 111
};
enum
AKAFrequency
{
AKA_FREQ_INT_AT_MATURITY = 0,
AKA_FREQ_ANNUAL = 1,
AKA_FREQ_SEMIANNUAL = 2,
AKA_FREQ_QUARTERLY = 4,
AKA_FREQ_MONTHLY = 12,
AKA_FREQ_SEMIANNUAL_COMPOUNDED = 18,
AKA_FREQ_QUARTERLY_COMPOUNDED = 20,
AKA_FREQ_ANNUAL_BY_WEEKS = 33,
AKA_FREQ_SEMIANNUAL_BY_WEEKS = 34,
AKA_FREQ_QUARTERLY_BY_WEEKS = 36,
AKA_FREQ_MONTHLY_BY_WEEKS = 44
};
enum
AKA_YIELD_METHOD {
AKA_YLD_GLOBAL,
AKA_YLD_BEY,
AKA_YLD_SIMPLE_LAST_PERIOD,
AKA_YLD_SIMPLE_LAST_YEAR,
AKA_YLD_MUNI,
AKA_YLD_ANNUALIZED,
AKA_YLD_ANNUALIZED_SIMPLE_LAST_PERIOD,
AKA_YLD_ANNUALIZED_SIMPLE_LAST_YEAR
};
enum
AKAOptionType
{
AKA_OPTION_EUROPEAN = 0,
AKA_OPTION_AMERICAN = 1,
AKA_OPTION_BERMUDAN = 2
};
enum
AKAAllocation
{
AKA_ALLOC_PRORATA = 0,
AKA_ALLOC_FRONT = 1,
AKA_ALLOC_BACK = 2
};
enum
AKAScenRedemption
{
AKA_REDEEM_NONE = 0,
AKA_REDEEM_CALL = 1,
AKA_REDEEM_PUT = 2,
AKA_REDEEM_SINK = 4,
AKA_REDEEM_MATURITY = 8
};
enum
AKAScenType
{
AKA_SCEN_NOW = 0,
AKA_SCEN_GRADUAL = 1,
AKA_SCEN_THEN = 2
};
enum
AKAPeriodType
{
AKA_PERIOD_BEGIN = 0,
AKA_PERIOD_END = 1
};
enum
AKA_SIMPLE_INTEREST_TYPE {
AKA_SI_OFF,
AKA_SI_LAST_PERIOD,
AKA_SI_LAST_YEAR
};
void
AKA_set_simple_interest_type(enum
AKA_SIMPLE_INTEREST_TYPE it);
#define AKA_set_simple_interest_yield(x) \
AKA_set_simple_interest_type((x) ? AKA_SI_LAST_PERIOD : AKA_SI_OFF)
#define AKA_set_global_simple_interest_yield(x) \
AKA_set_simple_interest_yield(x)
#define AKA_set_thread_simple_interest_yield(x) \
AKA_set_simple_interest_yield(x)
#define AKACouponSpread(pvdate, hTree, bond) AKAAssetSwapSpread(100.0, pvdate, hTree, bond)
#define AKAINIT_ERR_NONE AKA_ERROR_NONE
#define AKAINIT_ERR_AUTHORIZE AKA_ERROR_AUTHORIZATION
#define AKAINIT_ERR_ALLOC AKA_ERROR_MEMORY
#define AKATerm() AKA_shutdown_configure(0)
int
AKA_authorize_init(long key, const char *uname);
int
AKA_authorize_init2(long key, const char *uname);
long
AKAInit(
AKAINITDATA *config);
int
AKATreeFitShift2(
AKAHTREE tree, double *bpShift,
AKAHTREE *treeup,
AKAHTREE *treedown);
long
AKABondDuration(long pvdate,
AKAHTREE hTree_up,
AKAHTREE hTree_down,
double durbp, const
AKABOND *bond,
AKABONDREPORT *rpt);
long
AKABondScen(long quoteType, double quote,
const
AKASCEN *scen, const
AKABOND *bond,
AKASCENREPORT *rpt);
long
AKABondScen2(long quoteType, double quote,
const
AKASCEN *akascen, const
AKABOND *bond,
AKASCENREPORT *rpt,
double eff_threshold, double *efficiency);
long
AKABondScen3(long quoteType, double quote,
const
AKASCEN *akascen, const
AKABOND *bond,
AKASCENREPORT *rpt,
double eff_threshold, double *efficiency, double reinvest);
long
AKABondScen4(long quoteType, double quote,
const
AKASCEN *akascen, const
AKABOND *bond,
AKASCENREPORT *rpt,
double eff_threshold, double *efficiency, double reinvest,
AKAATAXYLD *ataxinfo);
struct
AKAScen
{
long type;
long n;
long *dates;
AKAHTREE *trees;
};
struct
AKARun
{
long mode;
double vol;
double lvol;
double alpha;
long pvdate;
long nBonds;
AKABOND **bonds;
double *bondPx;
long nRates;
long *rateDaycount;
long *rateMat;
double *rate;
};
typedef struct
AKARun AKARUN;
typedef enum {
AKA_MSG_NONE,
AKA_MSG_INFORMATION,
AKA_MSG_WARNING,
AKA_MSG_FATAL
} AKA_MSGTYPE;
#define AKA_MSG_MAXLEN 300
AKA_MSGTYPE AKA_msg_pop(char *text);
int
AKAFatalStatus();
void
AKAFatalReset();
AKA_MSGTYPE AKA_msg_status();
void
AKA_msg_push(char *text,
AKA_MSGTYPE mtype);
AKA_MSGTYPE AKA_msg_suppress(
AKA_MSGTYPE mtype);
struct
TREESAMPLE {
int nmats;
int npaths;
int ntimes;
double *mats;
double *times;
struct PATH_ITEM ***paths;
};
struct
PATH_ITEM {
double rate;
double center;
};
struct TREESAMPLE *
AKA_treesample_alloc(int nmats, int npaths, int ntimes);
void
AKA_treesample_free(
struct TREESAMPLE *sample);
int
AKA_treesample(
AKACURVE *curve,
struct TREESAMPLE *sample);
Index of Functions
AKAAssetSwapSpread
AKAAtaxBasis
AKAAtaxYield
AKABondAccrued
AKABondAccrued2
AKABondAlloc
AKABondCopy
AKABondDuration
AKABondFlow
AKABondFlowOnly
AKABondFree
AKABondKRDur
AKABondKeyDur
AKABondKeyDur2
AKABondKeyDur3
AKABondMortgage
AKABondOAS
AKABondPrice
AKABondPriceCnv
AKABondPriceShifted
AKABondScen
AKABondScen2
AKABondScen3
AKABondScen4
AKABondScenEx
AKABondTaxRate
AKABondTaxRateGet
AKABondVal
AKABondVal2
AKABondVal3
AKABondValueYields
AKABondValueYieldsEx
AKAConvertAssetSwapSpread
AKAConvertMuniCurve
AKACouponAlloc
AKACouponFree
AKACurveAlloc
AKACurveCopy
AKACurveFree
AKADateAdd
AKADatePack
AKADefaultTaxRate
AKADiscount
AKAError
AKAErrorString
AKAFatalReset
AKAFatalStatus
AKAFlowReportAlloc
AKAFlowReportFree
AKAFwdRates
AKAFwdRatesFromCurve
AKAFwdReportAlloc
AKAFwdReportFree
AKAISpread
AKAInit
AKAKRDurReportAlloc
AKAKRDurReportFree
AKAKeyDurSetup
AKAKeyDurSetupFree
AKALowestYieldToSink
AKAOptionAlloc
AKAOptionFree
AKAPrcWorstReportAlloc
AKAPrcWorstReportFree
AKAPriceToWorst
AKARunAlloc
AKARunFree
AKAScenAlloc
AKAScenFree
AKAScenSetupAlloc
AKAScenSetupFree
AKASinkAlloc
AKASinkFree
AKASpreadAlloc
AKASpreadFree
AKATreeFit
AKATreeFitRun
AKATreeFitShift
AKATreeFitShift2
AKATreeFitSpreads
AKATreeFitZero
AKATreeMinRate
AKATreeRelease
AKAVolReportAlloc
AKAVolReportFree
AKAWarnings
AKAYears
AKAYieldToWorst
AKAYieldToWorstEx
AKAYieldToWorstEx2
AKAYieldVol
AKAYldWorstReportAlloc
AKAYldWorstReportFree
AKA_authorize_expiration_date
AKA_authorize_init
AKA_authorize_init2
AKA_clear_notifyholidays
AKA_initialize
AKA_initialize_configure
AKA_initialize_get_defaults
AKA_memory_diagnostics
AKA_msg_pop
AKA_msg_push
AKA_msg_status
AKA_msg_suppress
AKA_set_duration_shift
AKA_set_notifybehavior
AKA_set_notifyholiday
AKA_set_notifyweekends
AKA_set_simple_interest_type
AKA_shutdown
AKA_shutdown_configure
AKA_treesample
AKA_treesample_alloc
AKA_treesample_free
AKA_version
AKA_version_string
Error Numbers and Definitions — akaerrno.h
#ifndef _AKAERRNO_H_
#define _AKAERRNO_H_
enum
AKA_ERROR_NUMBER {
AKA_ERROR_NONE,
AKA_ERROR_AUTHORIZATION,
AKA_ERROR_MEMORY,
AKA_ERROR_EXPIREDKEY,
AKA_ERROR_UNINITIALIZED,
AKA_ERROR_PERMISSION_LATTICE,
AKA_ERROR_PERMISSION_ADVANCED_LATTICE,
AKA_ERROR_PERMISSION_SCENARIOS,
AKA_ERROR_PERMISSION_ATAX,
AKA_ERROR_COMPUTE_COUPON,
AKA_ERROR_COMPUTE_KEYRATES,
AKA_ERROR_COMPUTE_OAS,
AKA_ERROR_COMPUTE_PRICE,
AKA_ERROR_COMPUTE_YIELD_ATAX,
AKA_ERROR_TREEFIT,
AKA_ERROR_INTERNAL,
AKA_ERROR_TREESAMPLE,
AKA_ERROR_HTREE,
AKA_ERROR_COUPON,
AKA_ERROR_QUOTETYPE,
AKA_ERROR_OAS,
AKA_ERROR_PRICE,
AKA_ERROR_YIELD,
AKA_ERROR_MATURED,
AKA_ERROR_RETIRED,
AKA_ERROR_CURVE,
AKA_ERROR_DATE,
AKA_ERROR_DURSHIFT,
AKA_ERROR_FACEAMOUNT,
AKA_ERROR_FCDATE,
AKA_ERROR_IDATE,
AKA_ERROR_LCDATE,
AKA_ERROR_MATURITY,
AKA_ERROR_OPTIONDATE,
AKA_ERROR_OPTIONPRICE,
AKA_ERROR_PURCHASEDATE,
AKA_ERROR_PVDATE,
AKA_ERROR_SALEDATE,
AKA_ERROR_SINKDATE,
AKA_ERROR_SINKPRICE,
AKA_WARN_SINK_ALLOCATION,
AKA_WARN_SINK_UNDESIGNATED,
AKA_WARN_FREQUENCY,
AKA_WARN_DAYCOUNT,
AKA_WARN_OPTIONDELAY,
AKA_WARN_OUTSTANDING_HIGH,
AKA_WARN_PAYDAY,
AKA_WARN_SINKSUM_HIGH,
AKA_WARN_SINKSUM_LOW,
AKA_WARN_TRADEDATE,
AKA_WARN_YIELDMETHOD,
AKA_WARN_IMPERFECT_COUPON,
AKA_WARN_IMPERFECT_OAS,
AKA_WARN_TOOMANY,
AKA_WARN_AMORTIZATION,
AKA_WARN_SINK_TOO_SOON,
AKA_WARN_OUTSTANDING_LOW,
AKA_WARN_LCDATE_NONCYCLICAL,
AKA_WARN_XML_PARSE_FAILURE,
AKA_WARN_CD_LONG_COUPON,
};
#define AKA_WARNINGS_MAX 12
* Copyright (c) 2014, Andrew Kalotay Associates, Inc.. All rights reserved. *