Skip to content

Commit

Permalink
feat: merton's martingale for drift (#625)
Browse files Browse the repository at this point in the history
* feat: martingale of merton jump prices

* test correction for stock prices

* test std change based on mean distribution

* lint fix

* feat: martingale of merton jump prices

* test correction for stock prices

* test std change based on mean distribution

* lint fix

* kou's jump model

* Revert "Merge pull request #4 from rhandal-pfn/merton_jump_martingale"

This reverts commit b41e745, reversing
changes made to 303e03a.

remove kou's model from this PR

* lint fix

* lint fix-2
  • Loading branch information
rhandal-pfn authored Aug 27, 2024
1 parent 9912f0a commit a2f756a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion pfhedge/stochastic/merton_jump.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ def generate_merton_jump(
randn = engine(*(n_paths, n_steps), dtype=dtype, device=device)
randn[:, 0] = 0.0
drift = (
(mu - (sigma ** 2) / 2 - jump_per_year * (jump_mean + jump_std ** 2 / 2))
(
mu
- (sigma ** 2) / 2
- jump_per_year * (math.exp(jump_mean + jump_std ** 2 / 2) - 1)
)
* dt
* torch.arange(n_steps).to(randn)
)
Expand Down
12 changes: 6 additions & 6 deletions tests/stochastic/test_merton_jump.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ def test_generate_brownian_mean_no_jump_std(device: str = "cpu"):
output = generate_merton_jump(
n_paths,
n_steps,
jump_per_year=1000,
jump_per_year=68.2, # default value
jump_std=0.0,
jump_mean=0.1,
device=torch.device(device),
)
assert output.size() == torch.Size((n_paths, n_steps))
result = output[:, -1].log().mean()
expect = torch.zeros_like(result)
std = 0.2 * sqrt(1 / n_paths)
result = output[:, -1].mean()
expect = torch.ones_like(result)
std = 0.4 * sqrt(1 / n_paths)
assert_close(result, expect, atol=3 * std, rtol=0)


Expand Down Expand Up @@ -272,8 +272,8 @@ def test_generate_merton_jump_sobol_mean(device: str = "cpu"):
n_paths, n_steps, engine=engine, jump_per_year=0, device=torch.device(device)
)
assert output.size() == torch.Size((n_paths, n_steps))
result = output[:, -1].log().mean()
expect = torch.zeros_like(result).to(device)
result = output[:, -1].mean()
expect = torch.ones_like(result).to(device)
std = 0.2 * sqrt(1 / n_paths)
assert_close(result, expect, atol=10 * std, rtol=0)

Expand Down

0 comments on commit a2f756a

Please sign in to comment.