Skip to content

Commit

Permalink
Black engine.py, models.py and support.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaveiga committed Jun 4, 2024
1 parent 1350b6d commit a02b9c7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
17 changes: 10 additions & 7 deletions optionlab/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def _init_inputs(inputs: Inputs) -> EngineData:
data._days_to_maturity.append(data.days_to_target)
data._use_bs.append(False)
elif isinstance(strategy.expiration, dt.date) and inputs.start_date:

if inputs.discard_nonbusiness_days:
n_discarded_days = get_nonbusiness_days(
inputs.start_date, strategy.expiration, inputs.country
Expand Down Expand Up @@ -141,7 +140,9 @@ def _run(data: EngineData) -> EngineData:
"""
inputs = data.inputs

time_to_target = (data.days_to_target + 1) / data._days_in_year # To consider the target date as a trading day
time_to_target = (
data.days_to_target + 1
) / data._days_in_year # To consider the target date as a trading day
data.cost = [0.0] * len(data.type)

data.profit = zeros((len(data.type), data.stock_price_array.shape[0]))
Expand Down Expand Up @@ -236,7 +237,9 @@ def _run_option_calcs(data: EngineData, i: int) -> EngineData:

return data

time_to_maturity = (data._days_to_maturity[i] + 1) / data._days_in_year # To consider the expiration date as a trading day
time_to_maturity = (
data._days_to_maturity[i] + 1
) / data._days_in_year # To consider the expiration date as a trading day
bs = get_bs_info(
inputs.stock_price,
data.strike[i],
Expand Down Expand Up @@ -280,7 +283,7 @@ def _run_option_calcs(data: EngineData, i: int) -> EngineData:
if data._use_bs[i]:
target_to_maturity = (
data._days_to_maturity[i] - data.days_to_target + 1
) / data._days_in_year # To consider the expiration date as a trading day
) / data._days_in_year # To consider the expiration date as a trading day

data.profit[i], data.cost[i] = get_pl_profile_bs(
type,
Expand Down Expand Up @@ -409,9 +412,9 @@ def _generate_outputs(data: EngineData) -> Outputs:
optional_outputs: dict[str, Any] = {}

if inputs.profit_target is not None:
optional_outputs["probability_of_profit_target"] = (
data.project_target_probability
)
optional_outputs[
"probability_of_profit_target"
] = data.project_target_probability
optional_outputs["project_target_ranges"] = data._profit_target_range

if inputs.loss_limit is not None:
Expand Down
6 changes: 4 additions & 2 deletions optionlab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class StockStrategy(BaseStrategy):
negative, it means that the position is closed and the
difference between this price and the current price is
considered in the payoff calculation.
"""

type: Literal["stock"] = "stock"
n: int = Field(gt=0)
premium: float | None = None
Expand Down Expand Up @@ -194,8 +195,9 @@ class Inputs(BaseModel):
mc_prices_number : int, optional
Number of random terminal prices to be generated when calculationg
the average profit and loss of a strategy. Default is 100,000.
"""

stock_price: float = Field(gt=0)
volatility: float
interest_rate: float = Field(gt=0, le=0.2)
Expand Down
1 change: 0 additions & 1 deletion optionlab/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ def get_pop(
return pop

if isinstance(inputs, ProbabilityOfProfitInputs):

stock_price = inputs.stock_price
volatility = inputs.volatility
years_to_maturity = inputs.years_to_maturity
Expand Down

0 comments on commit a02b9c7

Please sign in to comment.