1 Sigma

Discussion in 'Options' started by wxytrader, Dec 22, 2023.

  1. Yeah changed that...don't know why I keep typing 352...anyway if I messed up then so did tos and I think they know how to calculate SD. :)

    I have dabbled in php but not anything else. Are you api the data for the script or have to manually add it in?

    the DBL_EPSILON stuff means just to make it slightly > 0, ie. to avoid <= 0 (b/c otherwise NaN or DivByZero can happen)

    on google sheets you just need iferror( :)
     
    #21     Dec 23, 2023
  2. Quanto

    Quanto

    Can you just tell which input parameters they use to calc it?

    Ah, I finally figured out what you are attempting to do: Converting IV down for DTE and then calc SD of stock for DTE...
    Here's the solution using the Linux "bc" calculator:
    s=201.48 ; iv=20.99 ; dte=5 ; z=1 ; pp = iv * z * sqrt(dte / 365) ; sd = s * pp / 100 ; sd
    4.9497
    Ie. just set s, iv, dte, and keep the rest

    Here's a slightly extended version by also varying z: for z it prints the SD and the Sx:
    Code:
    s=201.48 ; iv=20.99 ; dte=5 ; z=-1 ; pp = iv * z * sqrt(dte / 365) ; sd = s * pp / 100 ; sd ; s + sd
    -4.94974642575233342445
    196.53025357424766657555
    
    s=201.48 ; iv=20.99 ; dte=5 ; z=1 ; pp = iv * z * sqrt(dte / 365) ; sd = s * pp / 100 ; sd ; s + sd
    4.94974642575233342445
    206.42974642575233342445
    

    You can do whatever you like :)
     
    Last edited: Dec 23, 2023
    #22     Dec 23, 2023
    wxytrader likes this.
  3. Adam777

    Adam777

    I’ll give you a shortcut, but you need to google how to find EM (expected move) for 30 days:

    SD=EM/0.8 (approx)
     
    #23     Dec 23, 2023
  4. Quanto

    Quanto

    Oh boy, I'm afraid this C/C++ code is too complicated for you, since you never ever have compiled a program before (FYI: a C/C++ program must be "compiled" to an executable binary (exe), this is much different from interpreted (scripting) languages where no such compilation is necessary).
    The code was intended that you just read it and convert it to your own language of choice.

    But that's a very bad programming practice and slows down the program. Better is to avoid the error case in the first place, as done in my code.
     
    Last edited: Dec 23, 2023
    #24     Dec 23, 2023
  5. Quanto

    Quanto

    That's BS, man! :)
     
    #25     Dec 23, 2023
  6. Quanto

    Quanto

    C++ code for ExpectedMove (EM): this is practically the same as the above "bc"-code
    z means xSD, ie. -1 or +1 for -1SD or +1SD; one can of course use also other values for z.
    What's missing in this solution is rPct and qPct (this is left for you as an exercise :)) --> see the above calc_Sx for their meaning.
    And: this version uses NormalDistribution around S, but it rather should use LognormalDistribution (ie. that would make it an Advanced Solution, a more exact solution).
    Code:
    double ExpectedMove(const double S, const double AnnVolaPct, const double nDays, const double z, double& PeriodPct, double& Sx)
      {
        PeriodPct = AnnVolaPct * z * sqrt(nDays / 365.0);
        const double SD = S * PeriodPct / 100.0;
        Sx = S + SD;
        return SD;
      }
    
    Example output when called from a wrapper program:
    Code:
    ExpectedMove for S=201.4800 Vola=20.9900 nDays=5.00 z=-1.00: -4.949746(-2.4567% --> Sx=196.530254)
    ExpectedMove for S=201.4800 Vola=20.9900 nDays=5.00 z=+1.00: +4.949746(+2.4567% --> Sx=206.429746)
    
     
    Last edited: Dec 23, 2023
    #26     Dec 23, 2023
  7. What the rule of 16? Already have it.


    if(A3=0,""
     
    #27     Dec 23, 2023
  8. So all that to come to the same result as my spreadsheet, but without P/L ladder and color coded SD levels, or the cool P/L graph. :)

    rp.jpg
     
    #28     Dec 23, 2023
  9. Quanto

    Quanto

    Yeah, cool! Enjoy! :)
    Mine is low-level library code (it can be put into an own DLL etc. and then used from other programs).
    It's no problem to build GUI wrapper programs that use the library.
     
    #29     Dec 23, 2023
  10. Anyway BS is all skewed wrong imo...the trend weighted sigma is more likely the actual statistical range, which comes to a 1SD range for IWM DEC29 of:
    $198.39/$206.34
     
    Last edited: Dec 23, 2023
    #30     Dec 23, 2023