use super::{OptionContract, TypeFlag};
use crate::Payoff;
#[derive(Debug, Clone)]
pub struct PowerOption {
pub contract: OptionContract,
pub strike: f64,
pub power: f64,
}
#[derive(Debug, Clone)]
pub struct PoweredOption {
pub contract: OptionContract,
pub strike: f64,
pub power: f64,
}
#[derive(Debug, Clone)]
pub struct CappedPowerOption {
pub contract: OptionContract,
pub strike: f64,
pub power: f64,
pub cap: f64,
}
#[derive(Debug, Clone, Copy)]
pub struct PowerContract {
pub strike: f64,
pub power: f64,
}
impl Payoff for PowerContract {
type Underlying = f64;
fn payoff(&self, underlying: Self::Underlying) -> f64 {
(underlying / self.strike).powf(self.power)
}
}
impl Payoff for PowerOption {
type Underlying = f64;
fn payoff(&self, underlying: Self::Underlying) -> f64 {
match self.contract.type_flag {
TypeFlag::Call => (underlying.powf(self.power) - self.strike).max(0.0),
TypeFlag::Put => (self.strike - underlying.powf(self.power)).max(0.0),
}
}
}
impl Payoff for CappedPowerOption {
type Underlying = f64;
fn payoff(&self, underlying: Self::Underlying) -> f64 {
let payoff = match self.contract.type_flag {
TypeFlag::Call => (underlying.powf(self.power) - self.strike).max(0.0),
TypeFlag::Put => (self.strike - underlying.powf(self.power)).max(0.0),
};
payoff.min(self.cap)
}
}
impl Payoff for PoweredOption {
type Underlying = f64;
fn payoff(&self, underlying: Self::Underlying) -> f64 {
let payoff = match self.contract.type_flag {
TypeFlag::Call => (underlying - self.strike).max(0.0),
TypeFlag::Put => (self.strike - underlying).max(0.0),
};
payoff.powf(self.power)
}
}
impl PowerOption {
pub fn new(contract: OptionContract, strike: f64, power: f64) -> Self {
Self {
contract,
strike,
power,
}
}
}
impl PoweredOption {
pub fn new(contract: OptionContract, strike: f64, power: f64) -> Self {
Self {
contract,
strike,
power,
}
}
}
impl CappedPowerOption {
pub fn new(contract: OptionContract, strike: f64, power: f64, cap: f64) -> Self {
Self {
contract,
strike,
power,
cap,
}
}
}
impl PowerContract {
pub fn new(strike: f64, power: f64) -> Self {
Self { strike, power }
}
}