LibreOffice Module scaddins (master) 1
black_scholes.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * Copyright (C) 2012 Tino Kluge <tino.kluge@hrz.tu-chemnitz.de>
10 *
11 */
12
13
14#pragma once
15
16// options prices and greeks in the Black-Scholes model
17// also known as TV (theoretical value)
18
19namespace sca {
20namespace pricing {
21
22namespace bs {
23
24namespace types {
25enum 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
35};
36
37enum PutCall {
38 Call = 1,
39 Put = -1
40};
41
42enum KOType {
44 Reverse = 1
45};
46
48 KnockIn = -1,
49 KnockOut = 1
50};
51
52// barrier observed continuously or just at maturity (truncated payoff)
55 Maturity = 1
56};
57
58enum ForDom {
60 Foreign = 1
61};
62
63} // namespace types
64
65
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
69double bincash(double S, double vol, double rd, double rf,
70 double tau, double K,
71 types::PutCall pc, types::Greeks greeks);
72
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
76double binasset(double S, double vol, double rd, double rf,
77 double tau, double K,
78 types::PutCall pc, types::Greeks greeks);
79
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)
84double putcall(double S, double vol, double rd, double rf,
85 double tau, double K,
87
88
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)^+
95double putcalltrunc(double S, double vol, double rd, double rf,
96 double tau, double K, double B,
98 types::Greeks greeks);
99
100
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
105double 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);
108
109// barrier
110// touch/no-touch options (cash/asset or nothing payoff profile)
111double touch(double S, double vol, double rd, double rf,
112 double tau, double B1, double B2, types::ForDom fd,
114 types::Greeks greek);
115
116// barrier
117// barrier option (put/call payoff profile)
118double barrier(double S, double vol, double rd, double rf,
119 double tau, double K, double B1, double B2,
120 double rebate,
123 types::Greeks greek);
124
125
126// probability of hitting a barrier
127double prob_hit(double S, double vol, double mu,
128 double tau, double B1, double B2);
129
130
131// probability of being in-the-money, ie payoff is greater zero,
132// assuming payoff(S_T) > 0 iff S_T in [B1, B2]
133double prob_in_money(double S, double vol, double mu,
134 double tau, double B1, double B2);
135double prob_in_money(double S, double vol, double mu,
136 double tau, double K, double B1, double B2,
137 types::PutCall pc);
138
139
140} // namespace bs
141
142} // namespace pricing
143} // namespace sca
144
145
146/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double touch(double S, double vol, double rd, double rf, double tau, double B1, double B2, types::ForDom fd, types::BarrierKIO kio, types::BarrierActive bcont, types::Greeks greek)
double putcalltrunc(double S, double vol, double rd, double rf, double tau, double K, double B, types::PutCall pc, types::KOType kotype, types::Greeks greeks)
double prob_in_money(double S, double vol, double mu, double tau, double B1, double B2)
double binasset(double S, double vol, double rd, double rf, double tau, double K, types::PutCall pc, types::Greeks greeks)
double barrier(double S, double vol, double rd, double rf, double tau, double K, double B1, double B2, double rebate, types::PutCall pc, types::BarrierKIO kio, types::BarrierActive bcont, types::Greeks greek)
double putcall(double S, double vol, double rd, double rf, double tau, double K, types::PutCall putcall, types::Greeks greeks)
double prob_hit(double S, double vol, double mu, double tau, double B1, double B2)
double bincash(double S, double vol, double rd, double rf, double tau, double K, types::PutCall pc, types::Greeks greeks)