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

"w" in def CVaR() #8

Open
NikolausKCL opened this issue Aug 1, 2022 · 0 comments
Open

"w" in def CVaR() #8

NikolausKCL opened this issue Aug 1, 2022 · 0 comments

Comments

@NikolausKCL
Copy link

What is the input "w" in the CVaR loss function.

def CVaR(wealth = None, w = None, loss_param = None):
    alpha = loss_param
    # Expected shortfall risk measure
    return K.mean(w + (K.maximum(-wealth-w,0)/(1.0-alpha)))

How do I have to initialize it in order to avoid the following error:

optimizer = Adam(learning_rate=lr)

# Setup and compile the model
model_simple = Deep_Hedging_Model(N=N, d=d+2, m=m, risk_free=risk_free, \
          dt = dt, strategy_type="simple", epsilon = epsilon, \
          use_batch_norm = use_batch_norm, kernel_initializer = kernel_initializer, \
          activation_dense = activation_dense, activation_output = activation_output, \
          final_period_cost = final_period_cost, delta_constraint = delta_constraint, \
          share_stretegy_across_time = share_stretegy_across_time, \
          cost_structure = cost_structure)
loss = CVaR(model_simple.output,None,loss_param)
model_simple.add_loss(loss)

model_simple.compile(optimizer=optimizer)

early_stopping = EarlyStopping(monitor="loss", \
          patience=10, min_delta=1e-4, restore_best_weights=True)
reduce_lr = ReduceLROnPlateau(monitor="loss", \
          factor=0.5, patience=2, min_delta=1e-3, verbose=0)

callbacks = [early_stopping, reduce_lr]

# Fit the model.
model_simple.fit(x=xtrain, batch_size=batch_size, epochs=epochs, \
          validation_split=0.1, verbose=1)

#clear_output()

print("Finished running deep hedging algorithm! (Simple Network)")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-68-f4e901423d20>](https://localhost:8080/#) in <module>()
      3 # Setup and compile the model
      4 model_simple = Deep_Hedging_Model(N=N, d=d+2, m=m, risk_free=risk_free,           dt = dt, strategy_type="simple", epsilon = epsilon,           use_batch_norm = use_batch_norm, kernel_initializer = kernel_initializer,           activation_dense = activation_dense, activation_output = activation_output,           final_period_cost = final_period_cost, delta_constraint = delta_constraint,           share_stretegy_across_time = share_stretegy_across_time,           cost_structure = cost_structure)
----> 5 loss = CVaR(model_simple.output,None,loss_param)
      6 model_simple.add_loss(loss)
      7 

3 frames
[/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py](https://localhost:8080/#) in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

ValueError: Exception encountered when calling layer "tf.math.subtract_2" (type TFOpLambda).

Tried to convert 'y' to a tensor and failed. Error: None values not supported.

Call arguments received:
  • x=tf.Tensor(shape=(None, 1), dtype=float32)
  • y=Nonenam
3 frames
[/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py](https://localhost:8080/#) in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

ValueError: Exception encountered when calling layer "tf.math.subtract_2" (type TFOpLambda).

Tried to convert 'y' to a tensor and failed. Error: None values not supported.

Call arguments received:
  • x=tf.Tensor(shape=(None, 1), dtype=float32)
  • y=Nonename=None
```e=None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant