Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: implicit args in blackscholes #485

Closed
masanorihirano opened this issue Feb 8, 2022 · 6 comments
Closed

ENH: implicit args in blackscholes #485

masanorihirano opened this issue Feb 8, 2022 · 6 comments
Labels
black-scholes Related to Black-Scholes model enhancement New feature or request

Comments

@masanorihirano
Copy link
Collaborator

Currently, BlackScholes modules work like:

from pfhedge.instruments import BrownianStock
from pfhedge.instruments import EuropeanOption
from pfhedge.nn import BlackScholes

derivative = EuropeanOption(BrownianStock())
pricer = lambda derivative: BlackScholes(derivative).price(
             log_moneyness=derivative.log_moneyness(),
             time_to_maturity=derivative.time_to_maturity(),
             volatility=derivative.ul().volatility)
derivative = EuropeanOption(BrownianStock(), maturity=5/250)
derivative.list(pricer, cost=1e-4)
derivative.simulate(n_paths=2)
derivative.spot

However, the part,

pricer = lambda derivative: BlackScholes(derivative).price(
             log_moneyness=derivative.log_moneyness(),
             time_to_maturity=derivative.time_to_maturity(),
             volatility=derivative.ul().volatility)

seems a little bit redundant and not universal.
I think it comes from the following reasons:

  1. it is obvious that each args are generated from derivatives.
  2. required args (and the number of required args) depend on underliers

Thus, I suggest that all args are not required, and if the args are missing, these required args are calculated automatically based on registered derivatives.

Of course, in the case of derivative using autogreeks, these implicit args cannot be applied, but, I think my suggestion is worth being considere.

This suggestion is not limited to BlackScholes.price, but also to all other methods in greeks methods.

@masanorihirano
Copy link
Collaborator Author

Note that the current best workaround for the universality problem is

pricer = lambda derivative: BlackScholes(derivative).price(
             *[get_feature(f).of(derivative=derivative) for f in BlackScholes(derivative).inputs()])

@ghost
Copy link

ghost commented Feb 8, 2022

Sounds great 👍
Maybe I will make that enhancement when I find the time, while it is more than welcome if you kindly send a patch.
If you want to implement this let me know to prevent duplicate work.

One way is to register default arguments as attributes of a module in init and pass them in function calls as:

    def __init__(self, ..., log_moneyness=None):
        self.log_moneyness = log_moneyness

    def price(self, log_moneyness=None, ...):
        log_moneyness = self.log_moneyness or log_moneyness
        ...

@masanorihirano
Copy link
Collaborator Author

I know it is not high priority problem for you and me. So, I wrote this as just a note.
I'll let you know here before I do this implementation.

@masanorihirano
Copy link
Collaborator Author

I'll make a prototype

@masanorihirano
Copy link
Collaborator Author

I made a prototype for this: #516
Currently, this is only implemented for European option.
If it looks good for you (@simaki ), I'll implement to the others.

@ghost ghost added enhancement New feature or request black-scholes Related to Black-Scholes model labels Mar 3, 2022
@ghost
Copy link

ghost commented Mar 9, 2022

Resolved by #516

@ghost ghost closed this as completed Mar 9, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
black-scholes Related to Black-Scholes model enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant