Probability Calculator.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:6k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Probability Calculator
  4. //  Author/Uploader: Anthony Faragasso 
  5. //  E-mail:          ajf1111@epix.net
  6. //  Date/Time Added: 2001-09-08 15:45:03
  7. //  Origin:          
  8. //  Keywords:        
  9. //  Level:           semi-advanced
  10. //  Flags:           commentary
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=114
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=114
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  To be used in the Guru Commentary Window. Provides Support for
  17. //
  18. //  Options and Derivatives. By using Probability theory, you are letting
  19. //
  20. //  the market find the trades for you that are likely to be
  21. //
  22. //  consistent winners.
  23. //
  24. //------------------------------------------------------------------------------
  25. /* Probability Calculator  */
  26. /* coded by Anthony Faragasso */
  27. /*c1 = 625;*/         /* remove comments if manually entering price*/
  28. c1 = c;                    /* current closing price , Install comments if manually entering price */
  29.                      
  30.     
  31. dt =10;          /* days in trade , insert days till option expiration,  */                                
  32.                      /* or days to test a range */
  33. x =1;        /* Standard Deviation ,*/
  34.                       /* 67 to 68 % of all outcomes */
  35.                      /* happen between +1 and -1 standard deviation */
  36.                      /* 90% probability = 1.2815 standard deviation, */
  37.                     /* and 95% = 1.645  */   
  38.           
  39. /*vl =.25;*/               /*Remove comments and Enter */
  40.                           /*Implied Volatitliy (ex.36.41% = .3641) which */
  41.                            /*is a better predictor of future volatility, use decimal */
  42.                            /*in front of percentage.*/
  43.                                       
  44. hv1=20;             /*Install Comments if using Implied Volatiltiy */
  45. vl= Stdev(log(C/ref(C,-1)),hv1)*Sqrt(365);            /*Comment this line out if using Implied Volatility,*/
  46.                                                                             /* remove comments  if   using  daily  Historical */
  47.                                                                           /* volatility (ex.  10,20,30,60,90, day etc.  in ( hv ) line , */                                                                                       /* must be 2 days or more. */                                                                  
  48.                                                                       
  49. t = sqrt(dt/365);              /* Time Conversion*/
  50.                                                 
  51. b1= exp(vl*t*x)*c1;         /* 1st Target is ...  Future Price Above Close */
  52. b2= exp(vl*t*-x)*c1;        /* 2nd Target is...  Future Price Below Close */
  53.                                                         
  54. b1a = 0.31938153;
  55. b2a = -0.3565638;
  56. b3a = 1.78147794;
  57. b4a = -1.821256;
  58. b5a = 1.33027443;
  59. p = 0.2316419;
  60. t1= 1/(1+(p*x));
  61. e1=exp(-x*x/2);
  62. e2=(b1a*t1)+(b2a*(t1^2))+(b3a*(t1^3))+(b4a*(t1^4))+(b5a*(t1^5));
  63. pr = (1-(1-0.398942*e1*e2))*100;   /* 1st Percentage is  Probability of finishing above upper target*/
  64.                                                       /* and Probability of finishing  below lower target in days selected*/
  65.                                                       /* and current volatility selected remaining*/
  66.                          
  67. pr2 = (1-0.398942*e1*e2)*100;      /*  2nd Percentage is Probability of finishing below upper target*/
  68.                                                       /*  and Probability of finishing  above lower target in days selected*/
  69.                                                       /* and current volatility selected remaining   */
  70. TU = b1 ;                                       /* Target up */
  71. TD = b2;                                        /* Target Down */
  72. /* Guru Commentary */
  73. "PROBABILITY CALCULATOR : ";
  74. "";   
  75. "Market being Evaluated =    " +""+name() +"   Date:   " +Date();
  76. "";
  77. "Asset Price : (Closing Price ) .............................. "  +writeval(c1,format=1.2);
  78. "";
  79. "Market Volatility :................................................  " +writeval(vl*100,format=1.2)+"%";
  80. "";
  81. "Number of Days :..............................................   "+writeval (dt,fromat=1);
  82. "";
  83. "Upper Target :..................................................   "+ writeval( TU,format=1.2) ;
  84. "";
  85. "Lower Target :..................................................   "+writeval(TD,format=1.2);
  86. "";
  87. "Probability of Finishing Above Upper Target :....  " +writeval(pr,format = 1.2)+" %"  ;  
  88. "or Below the Lower Target. ( If one Target Selected ) ";   
  89. "";
  90. "Probability of Finishing Below Upper Target :.....  "+writeval(pr2,format = 1.2)+" % ";
  91. "or  Above the Lower Target. ( If one Target Selected ) ";  
  92. "";
  93. "--------------------IF TWO TARGETS  ARE SELECTED---------------------";
  94. "";
  95. "Probability of Finishing Above Upper Target :....  " +writeval(pr,format = 1.2)+" %"  ;  
  96.  ""; 
  97. "Probability of Finishing Below Lower Target :.....  " +writeval(pr,format = 1.2)+" %"  ;  
  98. "";
  99. "Probability of Finishing between an Uppernand Lower Target : . ............................................" +writeval(pr2-pr,format = 1.2)+" % ";
  100. "(Trading Range , If you Bracket the Market ) ";
  101. "";
  102. "Standard Deviation :............................................."+writeval(x,format=1.4);
  103. "( Default is +1 , -1 Standard Deviation , 68% of allnMarket Outcome happens between +1, -1)";
  104. "";
  105. "Probability Percentages  to use in Standard Deviation ( X ) Value . ";
  106. "";
  107. " 1.645 = 95% ... 1.2815 = 90% ...  1 = 84.13%  ,  .8417 = 80%";
  108. "";
  109. "  .6745 = 75%  ,   .5245 = 70%  ,  .3854 = 65%  ,   .2534 = 60% ";
  110. "";
  111. "  .1256 = 55%  ,   .0251 = 51%  ,  .0001 = 50% ";
  112.