Untitled

 avatar
unknown
plain_text
2 months ago
4.2 kB
5
Indexable
//@version=6
indicator("Option Greeks", overlay=false)

// chosen the 783 to represent all the business days in 3 years (leap options)
// if the script runs slow, you can assign `days_to_expiraiton` to a much lower number
// such as any of the following:
// 1 month: 22
// 3 months: 66
// 6 months: 132
// 1 year: 261
// 2 years: 522
// 3 years: 783
days_to_expiraiton = 783


// don't modify
var int[] dateValues = array.new_int(days_to_expiraiton)
var float[] deltaValues = array.new_float(days_to_expiraiton)
var float[] gammaValues = array.new_float(days_to_expiraiton)
var float[] thetaValues = array.new_float(days_to_expiraiton)
var float[] vegaValues = array.new_float(days_to_expiraiton)
var float[] rhoValues = array.new_float(days_to_expiraiton)
var float[] ivValues = array.new_float(days_to_expiraiton)

// don't modify
addRecord(index, date, delta, gamma, theta, vega, rho, iv) =>
    array.set(dateValues, index, date)
    array.set(deltaValues, index, delta)
    array.set(gammaValues, index, gamma)
    array.set(thetaValues, index, theta)
    array.set(vegaValues, index, vega)
    array.set(rhoValues, index, rho)
    array.set(ivValues, index, iv)


// For each new day of data, increment the index by 1
// addRecord(index, date, delta, gamma, theta, vega, rho, iv)
if (bar_index == 0)
    //                                          delta, gamma, theta, vega, rho,  iv
    addRecord(0, timestamp("2025-01-27 00:00"), 0.80, 0.10, -0.018, 0.20, 0.050, 0.30)
    addRecord(1, timestamp("2025-01-28 00:00"), 0.78, 0.11, -0.017, 0.22, 0.051, 0.31)
    addRecord(2, timestamp("2025-01-29 00:00"), 0.76, 0.12, -0.016, 0.21, 0.052, 0.32)
    addRecord(3, timestamp("2025-01-30 00:00"), 0.74, 0.13, -0.015, 0.23, 0.053, 0.33)
    addRecord(4, timestamp("2025-01-31 00:00"), 0.72, 0.14, -0.014, 0.24, 0.054, 0.34)
    addRecord(5, timestamp("2025-02-03 00:00"), 0.70, 0.15, -0.013, 0.25, 0.055, 0.35)
    addRecord(6, timestamp("2025-02-04 00:00"), 0.68, 0.16, -0.012, 0.26, 0.056, 0.36)
    addRecord(7, timestamp("2025-02-05 00:00"), 0.66, 0.17, -0.011, 0.27, 0.057, 0.37)
    addRecord(8, timestamp("2025-02-06 00:00"), 0.64, 0.18, -0.010, 0.28, 0.058, 0.38)
    addRecord(9, timestamp("2025-02-07 00:00"), 0.62, 0.19, -0.009, 0.29, 0.059, 0.39)
    addRecord(10, timestamp("2025-02-10 00:00"), 0.60, 0.20, -0.008, 0.30, 0.060, 0.40)
    addRecord(11, timestamp("2025-02-11 00:00"), 0.58, 0.21, -0.007, 0.31, 0.061, 0.41)
    addRecord(12, timestamp("2025-02-12 00:00"), 0.56, 0.22, -0.006, 0.32, 0.062, 0.42)
    addRecord(13, timestamp("2025-02-13 00:00"), 0.54, 0.23, -0.005, 0.33, 0.063, 0.43)
    addRecord(14, timestamp("2025-02-14 00:00"), 0.52, 0.24, -0.004, 0.34, 0.064, 0.44)
    addRecord(15, timestamp("2025-02-17 00:00"), 0.50, 0.25, -0.003, 0.35, 0.065, 0.45)
    addRecord(16, timestamp("2025-02-18 00:00"), 0.48, 0.26, -0.002, 0.36, 0.066, 0.46)
    addRecord(17, timestamp("2025-02-19 00:00"), 0.46, 0.27, -0.001, 0.37, 0.067, 0.47)
    addRecord(18, timestamp("2025-02-20 00:00"), 0.44, 0.28, 0.000, 0.38, 0.068, 0.48)
    addRecord(19, timestamp("2025-02-21 00:00"), 0.42, 0.29, 0.001, 0.39, 0.069, 0.49)

// don't modify
float deltaPlot = na
float gammaPlot = na
float thetaPlot = na
float vegaPlot = na
float rhoPlot = na
float ivPlot = na


// don't modify
// Loop through dates to find matching date and assign Greek values
for i = 0 to array.size(dateValues) - 1
    dataDate = array.get(dateValues, i)
    // Check if the current bar's time matches the dataDate
    if time == dataDate
        deltaPlot := array.get(deltaValues, i)
        gammaPlot := array.get(gammaValues, i)
        thetaPlot := array.get(thetaValues, i)
        vegaPlot := array.get(vegaValues, i)
        rhoPlot := array.get(rhoValues, i)
        ivPlot := array.get(ivValues, i)

// don't modify
plot(deltaPlot, color=color.blue, title="Delta")
plot(gammaPlot, color=color.orange, title="Gamma")
plot(thetaPlot, color=color.red, title="Theta")
plot(vegaPlot, color=color.green, title="Vega")
plot(rhoPlot, color=color.purple, title="Rho")
plot(ivPlot, color=color.yellow, title="IV")
Editor is loading...
Leave a Comment