Days to Third Friday.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:2k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Days to Third Friday
  4. //  Author/Uploader: Ed Cottrell 
  5. //  E-mail:          emc@edcottrell.com
  6. //  Date/Time Added: 2006-03-17 14:10:39
  7. //  Origin:          Self-written
  8. //  Keywords:        third friday options expiration 3rd fri
  9. //  Level:           medium
  10. //  Flags:           showemail,function
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=601
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=601
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  A function to determine the number of days left until the third Friday of
  17. //  the month, when U.S. options expire. By default, the function counts down
  18. //  to zero (on the third Friday), then starts counting down to the third
  19. //  Friday of the next month. Instructions on how to change this behavior
  20. //  (e.g., to make the counter stop at 0) are in the code.
  21. //
  22. //------------------------------------------------------------------------------
  23. function DaysInMonth(MonthNum,YearNum)
  24. {
  25. _Daysinmonth=IIf(MonthNum==1 OR MonthNum==3 OR MonthNum==5 OR MonthNum==7 OR MonthNum==8 OR MonthNum==10 OR MonthNum==12,31,30);
  26. Daysinmonthfeb=IIf(YearNum%4 == 0 AND YearNum%100!=0,29,28);
  27. _Daysinmonth=IIf(MonthNum==2,Daysinmonthfeb,_Daysinmonth);
  28. return _Daysinmonth;
  29. }
  30. function DaysToThirdFriday()
  31. {
  32. d = Day();
  33. wd = DayOfWeek();
  34. DaysToFriday = IIf(5-wd<0, (12-wd) % 7, (5 - wd) % 7);
  35. ThirdFriday = ((d + DaysToFriday) % 7)+14;
  36. _DaysToThirdFriday = ThirdFriday - d;
  37. /* To change behavior after the third friday, but before the end of the month, 
  38. to use zeroes, instead of counting down to next month, uncomment the second line, below */
  39. _DaysToThirdFriday = IIf(_DaysToThirdFriday >= 0, _DaysToThirdFriday, ThirdFriday+IIf(ThirdFriday+14>DaysInMonth(Month(),Year()),28,35)-d);
  40. //_DaysToThirdFriday = IIf(_DaysToThirdFriday >= 0, _DaysToThirdFriday, 0);
  41. return _DaysToThirdFriday;
  42. }
  43. Plot(DaysToThirdFriday(), "Days to 3rd Friday", colorBlack, styleLine);
  44. //
  45. //