Avoid potential negative array index access to cached text.
[LibreOffice.git] / scaddins / source / pricing / black_scholes.hxx
blob9e82857e03649225fdb0db5caaaa5844aaaea372
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * Copyright (C) 2012 Tino Kluge <tino.kluge@hrz.tu-chemnitz.de>
14 #pragma once
16 // options prices and greeks in the Black-Scholes model
17 // also known as TV (theoretical value)
19 namespace sca {
20 namespace pricing {
22 namespace bs {
24 namespace types {
25 enum Greeks {
26 Value = 0,
27 Delta = 1, // d/dS
28 Gamma = 2, // d^2/dS^2
29 Theta = 3, // d/dt
30 Vega = 4, // d/dsigma
31 Volga = 5, // d^2/dsigma^2
32 Vanna = 6, // d^2/dsigma dS
33 Rho_d = 7, // d/dr_d
34 Rho_f = 8 // d/dr_f
37 enum PutCall {
38 Call = 1,
39 Put = -1
42 enum KOType {
43 Regular = 0,
44 Reverse = 1
47 enum BarrierKIO {
48 KnockIn = -1,
49 KnockOut = 1
52 // barrier observed continuously or just at maturity (truncated payoff)
53 enum BarrierActive {
54 Continuous = 0,
55 Maturity = 1
58 enum ForDom {
59 Domestic = 0,
60 Foreign = 1
63 } // namespace types
66 // binary option cash (domestic)
67 // call - pays 1 if S_T is above strike K
68 // put - pays 1 if S_T is below strike K
69 double bincash(double S, double vol, double rd, double rf,
70 double tau, double K,
71 types::PutCall pc, types::Greeks greeks);
73 // binary option asset (foreign)
74 // call - pays S_T if S_T is above strike K
75 // put - pays S_T if S_T is below strike K
76 double binasset(double S, double vol, double rd, double rf,
77 double tau, double K,
78 types::PutCall pc, types::Greeks greeks);
80 // vanilla put/call option
81 // call pays (S_T-K)^+
82 // put pays (K-S_T)^+
83 // this is the same as: +/- (binasset - K*bincash)
84 double putcall(double S, double vol, double rd, double rf,
85 double tau, double K,
86 types::PutCall putcall, types::Greeks greeks);
89 // truncated put/call option, single barrier
90 // need to specify whether it's down-and-out or up-and-out
91 // regular (keeps monotonicity): down-and-out for call, up-and-out for put
92 // reverse (destroys monoton): up-and-out for call, down-and-out for put
93 // call pays (S_T-K)^+
94 // put pays (K-S_T)^+
95 double putcalltrunc(double S, double vol, double rd, double rf,
96 double tau, double K, double B,
97 types::PutCall pc, types::KOType kotype,
98 types::Greeks greeks);
101 // wrapper function for put/call option which combines
102 // double/single/no truncation barrier
103 // B1<=0 - assume no lower barrier
104 // B2<=0 - assume no upper barrier
105 double putcalltrunc(double S, double vol, double rd, double rf,
106 double tau, double K, double B1, double B2,
107 types::PutCall pc, types::Greeks greek);
109 // barrier
110 // touch/no-touch options (cash/asset or nothing payoff profile)
111 double touch(double S, double vol, double rd, double rf,
112 double tau, double B1, double B2, types::ForDom fd,
113 types::BarrierKIO kio, types::BarrierActive bcont,
114 types::Greeks greek);
116 // barrier
117 // barrier option (put/call payoff profile)
118 double barrier(double S, double vol, double rd, double rf,
119 double tau, double K, double B1, double B2,
120 double rebate,
121 types::PutCall pc, types::BarrierKIO kio,
122 types::BarrierActive bcont,
123 types::Greeks greek);
126 // probability of hitting a barrier
127 double prob_hit(double S, double vol, double mu,
128 double tau, double B1, double B2);
131 // probability of being in-the-money, ie payoff is greater zero,
132 // assuming payoff(S_T) > 0 iff S_T in [B1, B2]
133 double prob_in_money(double S, double vol, double mu,
134 double tau, double B1, double B2);
135 double prob_in_money(double S, double vol, double mu,
136 double tau, double K, double B1, double B2,
137 types::PutCall pc);
140 } // namespace bs
142 } // namespace pricing
143 } // namespace sca
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */