Skip to main content

hypercall/
valuation_utils.rs

1use anyhow::{anyhow, Result};
2
3use crate::types::OptionType;
4
5pub(crate) fn now_unix_timestamp_secs() -> Result<i64> {
6    Ok(std::time::SystemTime::now()
7        .duration_since(std::time::UNIX_EPOCH)
8        .map_err(|error| anyhow!("failed to read system clock: {}", error))?
9        .as_secs() as i64)
10}
11
12pub(crate) fn intrinsic_option_price(
13    settlement_price: f64,
14    strike: f64,
15    option_type: &OptionType,
16) -> f64 {
17    match option_type {
18        OptionType::Call => (settlement_price - strike).max(0.0),
19        OptionType::Put => (strike - settlement_price).max(0.0),
20    }
21}