I wrote the following code, the goal is to
find the target call price where the probability of reaching the price is less than 0.3, or prob otm is > 0.7.
The problem is at the
# Use
# Use
def otm_strike_call = fold index = atm_strike to atm_strike + 10 do
if 1 - PopTargetPrice(index, timeToExpirationHours, iv) > prob_otm_threshold then index else index;
it complains "no such variable: index"
I feel like the root cause has something to do with the subscript, but I need the subscript to perform complex math computation.
Any ideas to fix it?
Thanks!
find the target call price where the probability of reaching the price is less than 0.3, or prob otm is > 0.7.
The problem is at the
# Use
fold
to simulate finding the strike price# Use
fold
to simulate finding the strike pricedef otm_strike_call = fold index = atm_strike to atm_strike + 10 do
if 1 - PopTargetPrice(index, timeToExpirationHours, iv) > prob_otm_threshold then index else index;
it complains "no such variable: index"
I feel like the root cause has something to do with the subscript, but I need the subscript to perform complex math computation.
Ruby:
input daysToExpiration = 0;
input closeTime = 1100;
def iv = if(IsNaN(imp_volatility()), iv[1], imp_volatility());
def westTime = closeTime + 300;
def timeToExpirationHours = SecondsTillTime(westTime) / 3600 + 24 * daysToExpiration;
script PopTargetPrice {
# Input parameters
input targetPrice = 0;
input timeToExpirationHours = 0;
input impliedVolatility = 0.2;
# Calculate the current price and standard deviation
def currentPrice = close;
def timeToExpiration = timeToExpirationHours / 24 / 365; # Convert hours to years
def stdDev = currentPrice * impliedVolatility * Sqrt(timeToExpiration); # Standard deviation of price movement
# Z-Score Calculation
def zScore = AbsValue(targetPrice - currentPrice) / stdDev;
# Approximation of the cumulative distribution using a simplified approach (no Erf)
def CDF = 1 / (1 + Exp(-1.65451 * zScore));
# Return the probability
plot result = 1 - CDF;
}
def prob_otm_threshold = 0.7;
def atm_strike = round(close(), 0);
# Use `fold` to simulate finding the strike price
def otm_strike_call = fold index = atm_strike to atm_strike + 10 do
if 1 - PopTargetPrice(index, timeToExpirationHours, iv) > prob_otm_threshold then index else index;
Any ideas to fix it?
Thanks!