I need to construct a loop (simulation) that will iterate a certain number of times and display a value of warrant once the new firm value is close to the guess firm value. Specifically, the idea is to start out with a guess for the firm value (for example the stock price multiplied by the number of shares). Then you value the warrant as a call option (the code below) on this value multiplied by dilution factor, using the same volatility as the vol of the share price. You recompute then the value of the firm (number of shares times share price plus number of warrants times warrant price). This value will be different from the value of the firm you started with. Then you redo the procedure and after a few iterations you will see that the difference in values of the firm tends to zero. For this, I have a following code, but what I get is the following:
Please, help me to figure out the error given the code below:
Error: warrant[i] = bsm_call_value(New_FirmValue[i]/N,100,1,0.1,0.2)*dilution
NameError: name 'New_FirmValue' is not defined
The problem is that 'New_FirmValue' is defined after the function. What I am missing is how to program dynamic dependencies (I tried in code below). For ex, "warrant" depends on "New_FirmValue" which is "Guess_FirmValue"(constant) + "warrant"(newly calculated). The output should be the value of "warrant" that brings this relation "Guess_FirmValue - New_FirmValue[i] == 0"Please, help me to figure out the error given the code below:
def bsm_call_value(S0, K, T, r, sigma): from math import log, sqrt, exp from scipy import stats S0 = float(S0) d1 = (log(S0 / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * sqrt(T)) d2 = (log(S0 / K) + (r - 0.5 * sigma ** 2) * T) / (sigma * sqrt(T)) value = (S0 * stats.norm.cdf(d1, 0.0, 1.0) - K * exp(-r * T) *stats.norm.cdf(d2, 0.0, 1.0)) return value Guess_FirmValue = S0*N def warrant_1unobservable(S0, K, T, r, sigma, k, N, M, Iteration): for i in range(1, Iteration): dilution = N/(N +k*M) warrant[i] = bsm_call_value(New_FirmValue[i]/N,100,1,0.1,0.2)*dilution New_FirmValue[i] = Guess_FirmValue + warrant[i] Guess_FirmValue - New_FirmValue[i] == 0 return warrant print(warrant_1unobservable(100,100,1,0.1,0.2,1,100,10, 1000))Please, advise me this issue.