Skip to content
All library documents

Correcting the Double-Barrier Asymmetric Binary Option Series

Article Quant Q&A · Author: OptionsN00b

Summary

The document describes an implementation attempt for Haug’s double-barrier binary option formulas and explains why the asymmetric case produced incorrect results. The key correction is to treat the final term involving the asset’s position between the lower and upper barriers as a single additive contribution after summing the series, rather than adding it during every iteration. This changes how the asymmetric payoff is assembled.

The post also contrasts that correction with the symmetric formula and supplies revised Clojure code intended to reproduce the published formula. It reports that the earlier code matched a table for the symmetric case, while the corrected asymmetric version still lacked a convergence check. No revised numerical results are presented, so the implementation should be viewed as an explanation of a formula-reading error rather than a validated pricing routine.

Key ideas

  • The asymmetric formula’s terminal barrier-position term is added once after the series is accumulated.
  • The original implementation added that term on every iteration, causing the discrepancy.
  • The post provides revised code for both asymmetric and symmetric cases.
  • The revised implementation does not yet include a convergence check.

Tags

Full text
# Trying to code Haug's 4.19.7 Double-Barrier Binary Asymmetrical


# Trying to code Haug's 4.19.7 Double-Barrier Binary Asymmetrical












The following Clojure code correctly outputs the table in section 4.19.6 of "The Complete Guide to Option Pricing Formulas", but I'm wildly out on the asymmetrical in 4.19.7.

```
(defn double-barrier-binary
  [S L U T r b v asymmetric?]
  (let [R 1
        Z (Math/log (/ U L))
        v-sq (Math/pow v 2)
        term (- (/ (* 2 b) v-sq) 1)
        alpha (* -0.5 term)
        beta (- (* -0.25 (Math/pow term 2)) (* 2 (/ r v-sq)))
        N 100]
    (loop [i 1 result 0]
      (let [i-pi (* i Math/PI)
            i-pi-Z (/ i-pi Z)
            i-pi-Z-sq (Math/pow i-pi-Z 2)
            log-s-l (Math/log (/ S L))
            sin-pi-log (Math/sin (* i-pi-Z log-s-l))
            exp-term (Math/exp (* -0.5 (* (- i-pi-Z-sq beta) (* v-sq T))))]
        (case asymmetric?
          true (if (= N i)
                  (float (* R (Math/pow (/ S L) alpha) result))
                  (let [i-pi-2 (/ 2 i-pi)
                        t-top (- beta (* i-pi-Z-sq exp-term))
                        t-btm (- i-pi-Z-sq beta)
                        log-Z (- 1 (/ log-s-l Z))]
                    (recur (inc i) (+ result (* i-pi-2 (/ t-top t-btm) sin-pi-log) log-Z))))
          false (if (= N i)
                  (float result)
                  (let [K 10
                        i-pi-K-Z (/ (* 2 i-pi K) (Math/pow Z 2))
                        sla (Math/pow (/ S L) alpha)
                        sua (Math/pow (/ S U) alpha)
                        neg-1-i (Math/pow -1 i)
                        t-top (- sla (* neg-1-i sua))
                        t-btm (+ (Math/pow alpha 2) i-pi-Z-sq)]
                    (recur (inc i) (+ result (* i-pi-K-Z (/ t-top t-btm) sin-pi-log exp-term))))))))))

(letfn [(nk [L H v] (double-barrier-binary 100 L H 0.25 0.05 0.03 v false))]
  (println (map (fn [v] (str "\n" (mapv #(nk (first v) (second v) %) [0.1 0.2 0.3 0.5]))) [[80 120] [85 115] [90 110] [95 105]])))
```

To try the above, paste into the left panel of https://repl.it/languages/clojure and hit 'run'. Grateful if anyone has working code (any language will do) as I just can't see how I've interpreted the asymmetric formula incorrectly.

## Answer by OptionsN00b (score 2, accepted)

https://quant.stackexchange.com/a/54276

Answering my own question - it appears that I can't read formulas correctly. The final $$ \left( 1 - \dfrac{ln(S/L)}{Z} \right) $$ term at the bottom of page 181 of Haug is only added once at the end of the iteration, not on each loop. Hui's original work also brackets similarly. I assumed the square brackets included it each time. So back to maths classes for me. Revised code (Clojure again for those (few?) using it in this domain, convergence checking not yet done):

```
(defn double-barrier-binary
  [S L U T r b v asymmetric?]
  (let [R 10
        Z (Math/log (/ U L))
        v-sq (Math/pow v 2)
        term (- (/ (* 2 b) v-sq) 1)
        alpha (* -0.5 term)
        beta (- (* -0.25 (Math/pow term 2)) (* 2 (/ r v-sq)))
        log-s-l (Math/log (/ S L))
        log-Z (- 1 (/ log-s-l Z))
        N 100]
    (loop [i 1 result 0]
      (let [i-pi (* i Math/PI)
            i-pi-Z (/ i-pi Z)
            i-pi-Z-sq (Math/pow i-pi-Z 2)
            sin-pi-log (Math/sin (* i-pi-Z log-s-l))
            exp-term (Math/exp (* -0.5 (* (- i-pi-Z-sq beta) (* v-sq T))))]
        (case asymmetric?
          true (if (= N i)
                  (float (* R (Math/pow (/ S L) alpha) (+ result log-Z)))
                  (let [i-pi-2 (/ 2 i-pi)
                        t-top (- beta (* i-pi-Z-sq exp-term))
                        t-btm (- i-pi-Z-sq beta)]
                    (recur (inc i) (+ result (* i-pi-2 (/ t-top t-btm) sin-pi-log)))))
          false (if (= N i)
                  (float result)
                  (let [K 10
                        i-pi-K-Z (/ (* 2 i-pi K) (Math/pow Z 2))
                        sla (Math/pow (/ S L) alpha)
                        sua (Math/pow (/ S U) alpha)
                        neg-1-i (Math/pow -1 i)
                        t-top (- sla (* neg-1-i sua))
                        t-btm (+ (Math/pow alpha 2) i-pi-Z-sq)]
                    (recur (inc i) (+ result (* i-pi-K-Z (/ t-top t-btm) sin-pi-log exp-term))))))))))
```

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.