summaryrefslogtreecommitdiffstats
path: root/scaddins/source/pricing/black_scholes.hxx
blob: 9e82857e03649225fdb0db5caaaa5844aaaea372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Copyright (C) 2012 Tino Kluge <tino.kluge@hrz.tu-chemnitz.de>
 *
 */


#pragma once

// options prices and greeks in the Black-Scholes model
// also known as TV (theoretical value)

namespace sca {
namespace pricing {

namespace bs {

namespace types {
enum Greeks {
    Value    = 0,
    Delta    = 1,        // d/dS
    Gamma    = 2,        // d^2/dS^2
    Theta    = 3,        // d/dt
    Vega     = 4,        // d/dsigma
    Volga    = 5,        // d^2/dsigma^2
    Vanna    = 6,        // d^2/dsigma dS
    Rho_d    = 7,        // d/dr_d
    Rho_f    = 8         // d/dr_f
};

enum PutCall {
    Call     = 1,
    Put      = -1
};

enum KOType {
    Regular = 0,
    Reverse = 1
};

enum BarrierKIO {
    KnockIn = -1,
    KnockOut = 1
};

// barrier observed continuously or just at maturity (truncated payoff)
enum BarrierActive {
    Continuous = 0,
    Maturity   = 1
};

enum ForDom {
    Domestic = 0,
    Foreign  = 1
};

} // namespace types


// binary option cash (domestic)
//   call - pays 1 if S_T is above strike K
//   put  - pays 1 if S_T is below strike K
double bincash(double S, double vol, double rd, double rf,
               double tau, double K,
               types::PutCall pc, types::Greeks greeks);

// binary option asset (foreign)
//   call - pays S_T if S_T is above strike K
//   put  - pays S_T if S_T is below strike K
double binasset(double S, double vol, double rd, double rf,
                double tau, double K,
                types::PutCall pc, types::Greeks greeks);

// vanilla put/call option
//   call pays (S_T-K)^+
//   put  pays (K-S_T)^+
// this is the same as: +/- (binasset - K*bincash)
double putcall(double S, double vol, double rd, double rf,
               double tau, double K,
               types::PutCall putcall, types::Greeks greeks);


// truncated put/call option, single barrier
// need to specify whether it's down-and-out or up-and-out
// regular (keeps monotonicity): down-and-out for call, up-and-out for put
// reverse (destroys monoton):   up-and-out for call, down-and-out for put
//   call pays (S_T-K)^+
//   put  pays (K-S_T)^+
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);


// wrapper function for put/call option which combines
// double/single/no truncation barrier
// B1<=0 - assume no lower barrier
// B2<=0 - assume no upper barrier
double putcalltrunc(double S, double vol, double rd, double rf,
                    double tau, double K, double B1, double B2,
                    types::PutCall pc, types::Greeks greek);

// barrier
// touch/no-touch options (cash/asset or nothing payoff profile)
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);

// barrier
// barrier option  (put/call payoff profile)
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);


// probability of hitting a barrier
double prob_hit(double S, double vol, double mu,
                double tau, double B1, double B2);


// probability of being in-the-money, ie payoff is greater zero,
// assuming payoff(S_T) > 0 iff S_T in [B1, B2]
double prob_in_money(double S, double vol, double mu,
                     double tau, double B1, double B2);
double prob_in_money(double S, double vol, double mu,
                     double tau, double K, double B1, double B2,
                     types::PutCall pc);


} // namespace bs

} // namespace pricing
} // namespace sca


/* vim:set shiftwidth=4 softtabstop=4 expandtab: */