DMI.C
上传用户:bjghjy
上传日期:2007-01-07
资源大小:379k
文件大小:5k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <malloc.h>
  4. #include <string.h>
  5. #include <math.h>
  6. #include "resource.h"
  7. #include "global.h"
  8. #include "fx.h"
  9. extern LPFX Fx;
  10. int CreateDmiData(K_DATA *lpKData,int RNum,DATA *Data,PARA *Para)
  11.  
  12.  int i,j;
  13.  long m;
  14.  double jia1,jia2,jia3;
  15.  double Ttr,Tpdm,Tndm,Tadx;
  16.  DMI_DATA *DmiData;
  17.                    
  18.  DmiData=(DMI_DATA*)_fmalloc(sizeof(DMI_DATA)*RNum);
  19.  memset(DmiData,0,sizeof(DMI_DATA)*RNum);
  20.  for(j=0;j<RNum;j++)
  21.  {
  22.             if(j==0)
  23.             {       
  24.                 Ttr=Tpdm=Tndm=Tadx=0;
  25.               jia1=fabs(lpKData[j].zg-lpKData[j].zd);
  26.               if(j>0)
  27.               {
  28.               jia2=fabs(lpKData[j].zd-lpKData[j-1].ss);
  29.               jia3=fabs(lpKData[j].zg-lpKData[j-1].ss);
  30.               Tpdm=DmiData[j].pdm=lpKData[j].zg - lpKData[j-1].zg;
  31.               if(DmiData[j].pdm<fabs(lpKData[j].zd - lpKData[j-1].zd))
  32.               Tpdm=DmiData[j].pdm=0;
  33.               Tndm=DmiData[j].ndm=lpKData[j].zd - lpKData[j-1].zd;
  34.               if(DmiData[j].ndm<fabs(lpKData[j].zg - lpKData[j-1].zg))
  35.               Tndm=DmiData[j].ndm=0;             
  36.               }
  37.               else
  38.               {
  39.                 jia2=jia3=0;
  40.                 DmiData[j].pdm=DmiData[j].ndm=0;
  41.               }
  42.               Ttr=DmiData[j].tr=max(jia1,max(jia2,jia3));             
  43.               DmiData[j].pdi=DmiData[j].ndi=0;
  44.               DmiData[j].dx=DmiData[j].adx=0;
  45.               Tadx=0;
  46.             }
  47.             else
  48.             {
  49.              jia1=fabs(lpKData[j].zg-lpKData[j].zd);
  50.               jia2=fabs(lpKData[j].zd-lpKData[j-1].ss);
  51.               jia3=fabs(lpKData[j].zg-lpKData[j-1].ss);
  52.              DmiData[j].tr=max(jia1,max(jia2,jia3));
  53.                 
  54.               DmiData[j].pdm=lpKData[j].zg - lpKData[j-1].zg;
  55.               if(DmiData[j].pdm<0)
  56.                   DmiData[j].pdm=0;
  57.               if(DmiData[j].pdm<fabs(lpKData[j].zd - lpKData[j-1].zd))
  58.               DmiData[j].pdm=0;
  59.               DmiData[j].ndm=lpKData[j-1].zd - lpKData[j].zd;
  60.               if(DmiData[j].ndm<0)
  61.                  DmiData[j].ndm=0;
  62.               if(DmiData[j].ndm<fabs(lpKData[j].zg - lpKData[j-1].zg))             
  63.               DmiData[j].ndm=0;             
  64.                 
  65.              if(j<=Para->periods[0]-1)
  66.              {                   
  67.                  Ttr+=DmiData[j].tr;
  68.                  Tpdm+=DmiData[j].pdm;
  69.                  Tndm+=DmiData[j].ndm;
  70.                  if(Tndm<0)
  71.                      Tndm=0;     
  72.                   
  73.               DmiData[j].pdi=DmiData[j].ndi=0;
  74.               DmiData[j].dx=DmiData[j].adx=0;            
  75.              }
  76.              if(j>Para->periods[0]-1)
  77.              {   
  78.                  
  79.                  m=j-Para->periods[0];             
  80.                Ttr+=DmiData[j].tr-DmiData[m].tr;
  81.                Tpdm+=DmiData[j].pdm-DmiData[m].pdm;                
  82.                     Tndm+=DmiData[j].ndm-DmiData[m].ndm;        
  83.                  if(Tndm<0)
  84.                      Tndm=0;
  85.              }
  86.              if(j>=Para->periods[0]-1)
  87.              {   
  88.              if(Ttr!=0)
  89.              {
  90.                   DmiData[j].pdi=Tpdm/Ttr;
  91.                   DmiData[j].ndi=Tndm/Ttr;
  92.                   if(DmiData[j].pdi>1.00)
  93.                      DmiData[j].pdi=1.00;
  94.                   if(DmiData[j].ndi>1.00)   
  95.                   DmiData[j].ndi=1.00;   
  96.                  }
  97.                  else
  98.                   DmiData[j].pdi=DmiData[j].ndi=0;
  99.                  if(Tpdm+Tndm!=0) 
  100.                   DmiData[j].dx=fabs((Tpdm-Tndm)/(Tpdm+Tndm));
  101.                  else
  102.                      DmiData[j].dx=0;
  103.              }
  104.              if(j<Para->periods[0]*2-1) 
  105.              {
  106.              Tadx+=DmiData[j].dx;
  107.              DmiData[j].adx=0;
  108.              } 
  109.              if(j==Para->periods[0]*2-1)   
  110.              {
  111.                  Tadx+=DmiData[j].dx;
  112.              DmiData[j].adx=0;            
  113.              }
  114.              if(j>Para->periods[0]*2-1)
  115.              {
  116.                  m=Para->periods[0];
  117.                  DmiData[j].adx=
  118.                   (DmiData[j-1].adx*(m-1)+DmiData[j].dx)/m;
  119.              }                                    
  120.             }
  121.     }         
  122.     for(j=0;j<10;j++)
  123.     {
  124.         if(Data->v==NULL) 
  125.          break;
  126.      if(Data->v[j]!=NULL)
  127.      {
  128.      _ffree(Data->v[j]);
  129.      Data->v[j]=NULL;
  130.      }
  131.     }
  132.     Data->v==NULL;     
  133.     Data->num =Para->dnum; 
  134.     Data->no =Para->no;
  135.     strcpy(Data->gpdm,Fx->gpdm);
  136.     Data->type =Fx->type;
  137.     Data->range =Fx->range;
  138.     Data->size =RNum;
  139.     for(j=0;j<Data->num;j++)
  140.      Data->v[j]=(double *)_fmalloc(sizeof(double)*RNum);
  141.     for(i=0;i<Data->num;i++)
  142.     {
  143.      for(j=0;j<RNum&&i==0;j++) 
  144.      Data->v[i][j]=DmiData[j].pdi;
  145.      for(j=0;j<RNum&&i==1;j++) 
  146.      Data->v[i][j]=DmiData[j].ndi;
  147.      for(j=0;j<RNum&&i==2;j++) 
  148.      Data->v[i][j]=DmiData[j].adx;
  149.      Data->method[i]=CURVE_METHOD;
  150.     }
  151.     //Para->price[2] =20;
  152.     //Para->price[3] =50;
  153.     //Para->price[4] =80;
  154.     Para->feature |=DW_ALL;
  155.     //Para->feature &=~DW_MAX;
  156.     //Para->feature &=~DW_MIN;
  157.     _ffree(DmiData);
  158. return TRUE;
  159. }