Black Scholes Option Pricing.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:3k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Black Scholes Option Pricing
  4. //  Author/Uploader: Anthony Faragasso 
  5. //  E-mail:          ajf1111@epix.net
  6. //  Date/Time Added: 2005-03-20 13:19:39
  7. //  Origin:          
  8. //  Keywords:        Options, Black Scholes
  9. //  Level:           advanced
  10. //  Flags:           exploration
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=447
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=447
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  Black Scholes Option Pricing returns the Fair Value of call and put
  17. //  options.
  18. //
  19. //------------------------------------------------------------------------------
  20. //BLACK SHCOLES OPTION PRICING FORMULA
  21. //coded by Anthony Faragasso
  22. //1-01-03
  23. // User Variables
  24.  
  25. StockPrice  = Param("stockPrice",81,1,200,1); //Stock Price 
  26. Timedays    = Param("DaysToExpire",30,1,300,1); //Time to expiry ( days to exp/365 )
  27. StrikePrice = Param("StrikePrice",75,1,300,1); //strike Price of Option to evaluate
  28. InterestRate= Param("InterestRate",0.06,0.01,0.11,0.001); //prevailing interest rate 
  29. VKnown =Param("Volatility",0.30,0.10,0.50,0.001);//You can insert Known volatility here , Implied Volatility. 
  30. //////////////////////////////////////////////////////
  31. time=timedays/365;// days to expire conversion formula
  32. //Formula variables below
  33. /*************************************************/
  34. // Solves for ( X )
  35. x = (ln(stockPrice/strikePrice) + (interestrate + Vknown*Vknown/2)*time)/(Vknown*sqrt(time)); 
  36. /*************************************************/
  37. P =  0.2316419;   
  38. bb1 = 0.31938153; 
  39. bb2 = -0.3565638; 
  40. bb3 = 1.78147794; 
  41. bb4 = -1.821256;
  42. bb5 = 1.33027443;
  43. pi = 3.141592654; // PI
  44. A2 = 1/sqrt(2*pi);
  45. A3 = exp(-(x^2)/2);
  46. y= a2*a3;
  47. A4 = exp(-interestrate*time);
  48. t1 = 1/(1+ P*x);
  49. A5=(bb1*t1)+(bb2*t1^2) +( bb3*t1^3)+(bb4*t1^4)+(bb5*t1^5);
  50. /************************************************************/
  51. //Standard Normal Distribution Function of ( x )
  52. N = 1- y *A5 ;
  53. /************************************************************/
  54.   // Solves for ( X1 )
  55. X1=x-Vknown*sqrt(TIME);
  56. y1=1/sqrt(2*pi);
  57. N0=exp(-(x1^2)/2);
  58. T2=1/(1+ P*X1);
  59. A6=(bb1*t2)+(bb2*t2^2) +( bb3*t2^3)+(bb4*t2^4)+(bb5*t2^5);
  60. A7=exp(-interestrate*time);
  61. y2=y1*n0;
  62. /************************************************************/
  63. /* Standard Normal Distribution Function OF ( x1 )*/
  64. /***********************************************************/
  65. N2= 1-y2 * A6;
  66. /************ CALL OPTION FAIR VALUE************/
  67. Call = stockPrice  * N - strikePrice *  A4  * N2;
  68. /************ PUT OPTION FAIR VALUE*************/
  69. Put =  Call - stockprice  + strikeprice*A7;
  70.  
  71. Filter = 1;
  72. SetOption("nodefaultcolumns",1);
  73. AddColumn(stockPrice,"AssetP",2.2);
  74. AddColumn(strikeprice,"StrikeP",1.2);
  75. AddColumn(InterestRate*100,"InterestRate%",1.2);
  76. AddColumn(VKnown*100,"Volatility%",1.2);
  77. AddColumn(timedays,"DaysToExpire ",1);
  78. AddColumn(Call,"Call FV",1.2);
  79. AddColumn(put,"Put FV",1.2);
  80. //Notes
  81. /* AA window
  82. 1. Select current symbol ( could be any stock, output is not associated
  83. with the current stock).
  84. 2. n last quotations
  85. 3. n = 1
  86. 4. Use the Parameters button to make user selections
  87. 5. Click explore */