Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Piecewise function for black-scholes

5 visualizaciones (últimos 30 días)
N/A
N/A el 30 de Ag. de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
hello, I am trying to get a piecewise function, f(x) = blsprice for Put if exercise price < S_0; blsprice for Call if exercise price >= S_0.
I have all the inputs in my code as well, didn't include it here.
my code:
syms y
y = piecewise(E < S_0, [Put] = blsprice(S_0,E,r,T,sigma), E >= S_0, [Call] = blsprice(S_0,E,r,T,sigma))
I am getting an error: the expression to the left of the equal sign is a valid target for an assignment.

Respuestas (1)

Neil Guertin
Neil Guertin el 7 de Sept. de 2017
piecewise expects a value in the second and fourth arguments, and what you have entered is not valid syntax there.
What you need to do is calculate the values first, then pass the results to the piecewise function.
[Put, Call] = blsprice(S_0,E,r,T,sigma);
y = piecewise(E < S_0, Put, E >= S_0, Call)

La pregunta está cerrada.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by