RustQuant_instruments/options/
log.rs

1// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2// RustQuant: A Rust library for quantitative finance tools.
3// Copyright (C) 2023 https://github.com/avhz
4// Dual licensed under Apache 2.0 and MIT.
5// See:
6//      - LICENSE-APACHE.md
7//      - LICENSE-MIT.md
8// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9
10use super::OptionContract;
11use crate::Payoff;
12
13/// Log Moneyness Contract.
14#[derive(Debug, Clone)]
15pub struct LogMoneynessContract {
16    /// The option contract.
17    pub contract: OptionContract,
18
19    /// Strike price of the option.
20    pub strike: f64,
21}
22
23/// Log Underlying Contract.
24#[derive(Debug, Clone)]
25pub struct LogUnderlyingContract {
26    /// The option contract.
27    pub contract: OptionContract,
28
29    /// Strike price of the option.
30    pub strike: f64,
31}
32
33/// Log Option.
34#[derive(Debug, Clone)]
35pub struct LogOption {
36    /// The option contract.
37    pub contract: OptionContract,
38
39    /// Strike price of the option.
40    pub strike: f64,
41}
42
43impl Payoff for LogMoneynessContract {
44    type Underlying = f64;
45
46    fn payoff(&self, underlying: Self::Underlying) -> f64 {
47        (underlying / self.strike).ln()
48    }
49}
50
51impl Payoff for LogUnderlyingContract {
52    type Underlying = f64;
53
54    fn payoff(&self, underlying: Self::Underlying) -> f64 {
55        underlying.ln()
56    }
57}
58
59impl Payoff for LogOption {
60    type Underlying = f64;
61
62    fn payoff(&self, underlying: Self::Underlying) -> f64 {
63        (underlying / self.strike).ln().max(0.0)
64    }
65}