-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
simaki
authored
Jun 30, 2021
1 parent
097524c
commit 8471dd2
Showing
23 changed files
with
716 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from .american_binary import AmericanBinaryOption | ||
from .base import Derivative | ||
from .base import Primary | ||
from .european import EuropeanOption | ||
from .european_binary import EuropeanBinaryOption | ||
from .lookback import LookbackOption | ||
from .underlier import BrownianStock | ||
from .derivative.american_binary import AmericanBinaryOption | ||
from .derivative.base import Derivative | ||
from .derivative.european import EuropeanOption | ||
from .derivative.european_binary import EuropeanBinaryOption | ||
from .derivative.lookback import LookbackOption | ||
from .primary.base import Primary | ||
from .primary.brownian import BrownianStock | ||
from .primary.heston import HestonStock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
2 changes: 1 addition & 1 deletion
2
pfhedge/instruments/american_binary.py → ...instruments/derivative/american_binary.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from abc import ABC | ||
from abc import abstractmethod | ||
from typing import Optional | ||
from typing import TypeVar | ||
|
||
import torch | ||
from torch import Tensor | ||
|
||
from ..base import Instrument | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
class Derivative(Instrument): | ||
"""Base class for all derivatives. | ||
A derivative is a financial instrument whose payoff is contingent on | ||
a primary instrument (or a set of primary instruments). | ||
A (over-the-counter) derivative is not traded on the market and therefore the price | ||
is not directly accessible. | ||
Examples include options and swaps. | ||
A derivative relies on primary assets (See :class:`Primary` for details), such as | ||
stocks, bonds, commodities, and currencies. | ||
Attributes: | ||
underlier (:class:`Primary`): The underlying asset on which the derivative's | ||
payoff relies. | ||
dtype (torch.dtype): The dtype with which the simulated time-series are | ||
represented. | ||
device (torch.device): The device where the simulated time-series are. | ||
""" | ||
|
||
underlier: "Primary" | ||
maturity: float | ||
|
||
@property | ||
def dtype(self) -> torch.dtype: | ||
return self.underlier.dtype | ||
|
||
@property | ||
def device(self) -> torch.device: | ||
return self.underlier.device | ||
|
||
def simulate( | ||
self, n_paths: int = 1, init_state: Optional[tuple] = None, **kwargs | ||
) -> None: | ||
"""Simulate time series associated with the underlier. | ||
Args: | ||
n_paths (int): The number of paths to simulate. | ||
init_state (tuple, optional): The initial state of the underlying | ||
instrument. If `None` (default), sensible default values are used. | ||
**kwargs: Other parameters passed to `self.underlier.simulate()`. | ||
""" | ||
self.underlier.simulate( | ||
n_paths=n_paths, time_horizon=self.maturity, init_state=init_state, **kwargs | ||
) | ||
|
||
def to(self: T, *args, **kwargs) -> T: | ||
self.underlier.to(*args, **kwargs) | ||
return self | ||
|
||
@abstractmethod | ||
def payoff(self) -> Tensor: | ||
"""Returns the payoffs of the derivative. | ||
Shape: | ||
- Output: :math:`(N)` where :math:`N` stands for the number of simulated | ||
paths. | ||
Returns: | ||
torch.Tensor | ||
""" | ||
|
||
|
||
Derivative.to.__doc__ = Instrument.to.__doc__ |
2 changes: 1 addition & 1 deletion
2
pfhedge/instruments/european.py → pfhedge/instruments/derivative/european.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
pfhedge/instruments/european_binary.py → ...instruments/derivative/european_binary.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
pfhedge/instruments/lookback.py → pfhedge/instruments/derivative/lookback.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.