楼主: fantuanxiaot
27186 140

[源码分享] [原创]基于MATLAB的通达信股价数据的复权处理(fantuanxiaot版本)   [推广有奖]

已卖:1597份资源

大师

9%

还不是VIP/贵宾

-

威望
7
论坛币
-234454 个
通用积分
225.8477
学术水平
3783 点
热心指数
3819 点
信用等级
3454 点
经验
150360 点
帖子
7597
精华
32
在线时间
1329 小时
注册时间
2013-2-4
最后登录
2025-3-23

初级学术勋章 初级热心勋章 中级热心勋章 中级学术勋章 初级信用勋章 中级信用勋章 高级热心勋章 高级学术勋章 特级学术勋章 特级热心勋章 高级信用勋章 特级信用勋章

楼主
fantuanxiaot 发表于 2015-2-8 22:10:18 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
改编自http://www.matlabsky.com/thread-38451-1-3.html

非常感谢blake_libo和faruto的源码,在他们的基础上启发改编完成

源码或者Wind的复权算法如有错误请提醒我

还有,这个例子显示除权的信息感觉有很大的缺失。

        量化板块支持分享重要代码、书籍资料(最好介绍详细) 、量化报告(最好介绍详细)、量化思想分享及提问(与量化或者编程软件、数理统计相关)、如果介绍详细或者有原创代码分享,有重大奖励!绝不手软!另外,发帖分享idea或者资料、转载代码,一般都会有奖励!但是不支持与量化无关的灌水帖!



FT_Plot_MACD.jpg


FT_Plot_Candle.jpg


FT_Plot_300100MACD.jpg


FT_Plot_300100CANDLE.jpg




源代码文件如下:




本帖隐藏的内容

股价向前复权.zip (669.35 KB) 本附件包括:
  • FT_Candle.m
  • FT_Dividend_Data.mat
  • FT_MACD.m
  • FT_Main.m
  • FT_Plot_300100CANDLE.jpg
  • FT_Plot_300100MACD.jpg
  • FT_Plot_Candle.jpg
  • FT_Plot_MACD.jpg
  • FT_SZ300100.day




本帖隐藏的内容



  1. %%  一个基于股价复盘价的改编
  2. %%  直接提取了blake_libo函数
  3. %%  数据和读取数据来自blake_libo的方法
  4. %%  Modified by fantuanxiaot
  5. clc
  6. clear all
  7. close all
  8. format compact
  9. %%  by  fantuanxiaot
  10. %  只读形式进行打开(read)
  11. %  这应该是通达信特有的数据处理格式
  12. file_fid=fopen('FT_SZ300100.day','r');
  13. %  指向开头
  14. frewind(file_fid)
  15. %  文件的属性
  16. dir_nature=dir('FT_SZ300100.day');
  17. %  读取8行751列的数据进去
  18. %  时间从20100806到20130923
  19. %  dir_nature.bytes/32=751
  20. %  数据总共有8*751个
  21. data=fread(file_fid,[8 dir_nature.bytes/32],'uint32');
  22. frewind(file_fid)
  23. %  将文件的指针指向第20个字节
  24. fseek(file_fid,20,'bof');
  25. %  成交量是float型数据,每隔28个数读取4个数
  26. data(6,:)=fread(file_fid,dir_nature.bytes/32,'float=>long',28);  
  27. %  开盘价,最高价,最低价,收盘价
  28. %  成交额  
  29. data(2:5,:)=data(2:5,:)/100;  
  30. data(6,:)=round(data(6,:)/10);  
  31. %  这里做了变动,结果一样
  32. %  对日期进行转换
  33. %  data(1,:)=datenum(fix(data(1,:)/10000),fix(mod(data(1,:)/100,100)),mod(data(1,:),100));  
  34. data(1,:)=datenum(num2str(data(1,:)'),'yyyymmdd')';  
  35. fclose(file_fid);
  36. stockdata=fints(data(1,:)',data([2:7],:)',{'OPEN','HIGH','LOW','CLOSE',...
  37.     'AMOUNT','VOLUME'},'D','SZ300100');
  38. %%  以上将数据进行了处理
  39. %  提取一段时间的数据就像这样fetch(myFts,'01-Jan-2001',[],'03-Jan-2001',[],1,'d')
  40. %  fetch(myFts,'01-Jan-2001','11:00','03-Jan-2001','12:00',1,'d')
  41. FromDate = '04-Jan-2011';
  42. ToDate = '20-Feb-2012';
  43. stock=fetch(stockdata,FromDate,[],ToDate,[],1,'d');
  44. %  载入除权数据
  45. load('FT_Dividend_Data.mat')
  46. %  一些数据处理
  47. txtRightout(2:end,3:8)=num2cell(numRightout);
  48. %  寻找除权的股价时间
  49. index=strcmp('300100',txtRightout(:,2));
  50. %  得到了除权的信息dividend_information
  51. dividend_information=txtRightout(index,:);
  52. dividend_information=[txtRightout(1,:);dividend_information];
  53. %%  下面进行向前的复权处理
  54. %%  方法是基于wind的涨跌幅法则
  55. Date=stockdata.dates;
  56. stock=fts2mat(stockdata);
  57. OPEN=stock(:,1);
  58. HIGH=stock(:,2);
  59. LOW=stock(:,3);
  60. CLOSE=stock(:,4);
  61. Date=datestr(Date,'yyyymmdd');
  62. %  数据的处理方法来自blake_libo的贡献
  63. %  再转化为数字
  64. Date=str2num(Date);
  65. %  除权日期
  66. chuquanriqi=cell2mat(dividend_information(2:end,3));
  67. %  派现金
  68. paixianjin=cell2mat(dividend_information(2:end,5));
  69. %  配股价  
  70. peigujia=cell2mat(dividend_information(2:end,6));
  71. %  送股权
  72. songzhuangu=cell2mat(dividend_information(2:end,7));
  73. %  配股数
  74. peigushu=cell2mat(dividend_information(2:end,8));
  75. %%  向前的复权处理
  76. %  除权位置
  77. location=ismember(Date,chuquanriqi);
  78. numlocation=1:length(Date);
  79. %  将数据分开多少部分
  80. split_num=sum(location)+1;
  81. %  得到了位置
  82. location_num=numlocation(location);
  83. %  计算位置
  84. caculate_num=location_num-1;
  85. %  得到计算复权分开的位置区间
  86. location_forward=[1 location_num;caculate_num length(Date)]';
  87. Close_yesterday=CLOSE(caculate_num);
  88. Close_T=Close_yesterday;
  89. %  昨日收盘价的运算
  90. for i=1:length(Close_yesterday)
  91.     %  红利
  92.     hongli=paixianjin(i)/10;
  93.     %  送股
  94.     songgu=songzhuangu(i)/10;
  95.     %  配股数
  96.     peigus=peigushu(i)/10;
  97.     %  配股价
  98.     peiguj=peigujia(i)/10;
  99.     %  流通股份比例
  100.     liutong=peigus+songgu;
  101.     Close_yesterday(i)=(Close_yesterday(i)-hongli+peiguj*liutong)/(1+liutong);
  102. end
  103. %  得到了比例
  104. close_ratio=Close_T./Close_yesterday;
  105. close_ratio_cum=cumprod(close_ratio);
  106. %  向前的复权价格处理
  107. Foward_CLOSE=[];
  108. Foward_OPEN=[];
  109. Foward_LOW=[];
  110. Foward_HIGH=[];
  111. for i=1:length(location_forward)
  112.     lo_num=location_forward(i,:);
  113.     CLOSE_Forward=CLOSE(lo_num(1):lo_num(2));
  114.     OPEN_Forward=OPEN(lo_num(1):lo_num(2));
  115.     LOW_Forward=LOW(lo_num(1):lo_num(2));
  116.     HIGH_Forward=HIGH(lo_num(1):lo_num(2));
  117.     if i<length(location_forward)
  118.         CLOSE_Forward=CLOSE_Forward/close_ratio_cum(end+1-i);
  119.         Foward_CLOSE=[Foward_CLOSE;CLOSE_Forward];
  120.         OPEN_Forward=OPEN_Forward/close_ratio_cum(end+1-i);
  121.         Foward_OPEN=[Foward_OPEN;OPEN_Forward];
  122.         LOW_Forward=LOW_Forward/close_ratio_cum(end+1-i);
  123.         Foward_LOW=[Foward_LOW;LOW_Forward];
  124.         HIGH_Forward=HIGH_Forward/close_ratio_cum(end+1-i);
  125.         Foward_HIGH=[Foward_HIGH;HIGH_Forward];
  126.     end
  127.     if i==length(location_forward)
  128.         Foward_CLOSE=[Foward_CLOSE;CLOSE_Forward];
  129.         Foward_OPEN=[Foward_OPEN;OPEN_Forward];
  130.         Foward_LOW=[Foward_LOW;LOW_Forward];
  131.         Foward_HIGH=[Foward_HIGH;HIGH_Forward];
  132.     end
  133. end
  134. %%  作图
  135. FT_Candle(Foward_HIGH(1:200),Foward_LOW(1:200),Foward_CLOSE(1:200),...
  136.     Foward_OPEN(1:200),'m',stockdata.dates(1:200),17)
  137. title('基于SZ300100的复权价格处理','fontname','华文楷体','fontsize',16)
  138. FT_MACD(Foward_CLOSE(1:200),9,26,12)
  139. title('基于SZ300100的MACD显示','fontname','华文楷体','fontsize',16)
  140. %%  以上作图显示貌似还有一些除权的信息统计不全
复制代码
  1. function FT_Candle(hi, lo, cl, op, color, dates, dateform)
  2. %%  Modified by fantuanxiaot
  3. %%  模仿faruto进行修改
  4. %%  以下是一些例子
  5. %   load disney
  6. %   FT_Candle(dis_HIGH(end-20:end),dis_LOW(end-20:end),dis_CLOSE(end-20:end),dis_OPEN(end-20:end))
  7. %   FT_Candle(dis_HIGH(end-200:end),dis_LOW(end-200:end),dis_CLOSE(end-200:end),dis_OPEN(end-200:end))
  8. %   FT_Candle(dis_HIGH(end-200:end),dis_LOW(end-200:end),dis_CLOSE(end-200:end),dis_OPEN(end-200:end),'m')
  9. %   FT_Candle(dis_HIGH(end-200:end),dis_LOW(end-200:end),dis_CLOSE(end-200:end),dis_OPEN(end-200:end),'m',dis_nv.dates(end-200:end))
  10. %   FT_Candle(dis_HIGH(end-200:end),dis_LOW(end-200:end),dis_CLOSE(end-200:end),dis_OPEN(end-200:end),'m',datestr(dis_nv.dates(end-200:end))
  11. %   FT_Candle(dis_HIGH(end-200:end),dis_LOW(end-200:end),dis_CLOSE(end-200:end),dis_OPEN(end-200:end),'m',dis_nv.dates(end-200:end),2)
  12. %   FT_Candle(dis_HIGH(end-200:end),dis_LOW(end-200:end),dis_CLOSE(end-200:end),dis_OPEN(end-200:end),'m',datestr(dis_nv.dates(end-200:end)),2)
  13. %   FT_Candle(dis_HIGH(end-200:end),dis_LOW(end-200:end),dis_CLOSE(end-200:end),dis_OPEN(end-200:end),'m',datestr(dis_nv.dates(end-200:end)),17)
  14. %   FT_Candle(dis_HIGH,dis_LOW,dis_CLOSE,dis_OPEN,'m',datestr(dis_nv.dates),17)
  15. %   FT_Candle(dis_HIGH(end-400:end),dis_LOW(end-400:end),dis_CLOSE(end-400:end),dis_OPEN(end-400:end),'m',datestr(dis_nv.dates(end-400:end)),17)
  16. %%  以上是一些例子
  17. %   CANDLE Candlestick chart.
  18. %   CANDLE(HI, LO, CL, OP)
  19. %   CANDLE(HI, LO, CL, OP, COLOR, DATES, DATEFORM)
  20. %   Optional Inputs: COLOR, DATES, DATEFORM
  21. %   Inputs:
  22. %         HI - Column vector of high prices of a security.
  23. %
  24. %         LO - Column vector of low prices of a security.
  25. %
  26. %         CL - Column vector of closing prices of a security.
  27. %
  28. %         OP - Column vector of opening prices of a security.
  29. %   Optional Inputs:
  30. %      COLOR - Three element color vector, [R G B], or a string specifying the
  31. %              color name. MATLAB supplies a default color if none is specified
  32. %              or if it is empty. The default color differs depending on the
  33. %              background color of the figure window. See COLORSPEC in the
  34. %              MATLAB Reference Guide for color names.
  35. %      DATES - Column vector of dates for user specified X-axis tick
  36. %              labels.
  37. %
  38. %   DATEFORM - A scalar dictating the format of the date string tick labels.
  39. %              See DATEAXIS for details on the date string formats.
  40. %
  41. %   See also BOLLING, HIGHLOW, MOVAVG, POINTFIG.
  42. %        Copyright 1995-2006 The MathWorks, Inc.
  43. %        $Revision: 1.9.2.4 [        DISCUZ_CODE_4        ]nbsp;  $Date: 2008/01/10 21:10:22 $
  44. if nargin < 5 || isempty(color)
  45.     color ='k';
  46. end
  47. if nargin < 4
  48.     error('finance:candle:missingInputs', ...
  49.         'Missing high, low, closing, or opening data.')
  50. end
  51. if size(hi, 2) > 1 || size(lo, 2) > 1 || size(cl, 2) > 1 || size(op, 2) > 1
  52.     error('finance:candle:invalidInputs', ...
  53.         'Please specify input data as column vectors.')
  54. elseif size(hi, 1) ~= size(lo, 1) || size(lo, 1) ~= size(cl, 1) || size(cl, 1) ~= size(op, 1),
  55.     error('finance:candle:mismatchInputData', ...
  56.         'Number of data must be consistent across inputs.');
  57. end
  58. if nargin == 6 || nargin == 7
  59.     %  补充了一下
  60.     dates=datenum(dates);
  61.     if size(dates, 2) ~= 1
  62.         error('finance:candle:invalidDateSize', ...
  63.             'DATES must be a column vector.');
  64.     elseif size(dates, 1) ~= size(hi, 1)
  65.         error('finance:candle:mismatchDatesData', ...
  66.             'Number of dates must correspond to number of data.');
  67.     end
  68. end
  69. %%  以下作图进行了修改
  70. backg='g';
  71. backr='r';
  72. % Determine if current plot is held or not
  73. if ishold
  74.     hldflag = 1;
  75. else
  76.     hldflag = 0;
  77. end
  78. m = length(hi(:));
  79. figure(1)
  80. scrsz=get(0,'ScreenSize');
  81. set(figure(1),'Position',[scrsz(3)*0.1 scrsz(4)*0.25 scrsz(3)*0.95 scrsz(4)]*0.7,...
  82.     'color','w')
  83. movegui(figure(1),'center')
  84. % Need to pad all inputs with NaN's to leave spaces between day data
  85. tmp = nan;
  86. nanpad = tmp(1, ones(1, m));
  87. hilo = [hi'; lo'; nanpad];
  88. index = 1:m;
  89. indhilo = index(ones(3, 1), :);
  90. plot(indhilo(:), hilo(:), 'color', color)
  91. clpad = [cl(:)';nanpad];
  92. clpad = clpad(:)';
  93. oppad = [op(:)'; nanpad];
  94. oppad = oppad(:)';
  95. % Create boundaries for filled regions
  96. xbottom = index - 0.25;
  97. xbotpad = [xbottom(:)'; nanpad];
  98. xbotpad = xbotpad(:)';
  99. xtop = index + 0.25;
  100. xtoppad = [xtop(:)'; nanpad];
  101. xtoppad = xtoppad(:)';
  102. ybottom = min(clpad, oppad);
  103. ytop = max(clpad, oppad);
  104. % Plot lines between high and low price for day
  105. hold on
  106. % z-data used to stagger layering. This prevents renderer layering issues.
  107. zdata = xtoppad;
  108. zdata(~isnan(zdata)) = .01;
  109. zdata2 = zdata + .01;
  110. % Plot box representing closing and opening price span
  111. % If the opening price is less than the close, box is empty
  112. i = find(oppad(:) <= clpad(:));
  113. boxes(i) = patch([xbotpad(i); xbotpad(i); xtoppad(i); xtoppad(i)],...
  114.     [ytop(i); ybottom(i); ybottom(i); ytop(i)], ...
  115.     [zdata(i); zdata(i); zdata(i); zdata(i)], ...
  116.     backr, 'edgecolor', 'r');
  117. % If the opening price is greater than the close, box is filled
  118. % If the opening price is greater than the close, box is filled
  119. i = find(oppad(:) > clpad(:));
  120. boxes(i) = patch([xbotpad(i); xbotpad(i); xtoppad(i); xtoppad(i)],...
  121.     [ytop(i); ybottom(i); ybottom(i); ytop(i)],...
  122.     [zdata2(i); zdata2(i); zdata2(i); zdata2(i)], ...
  123.     backg, 'edgecolor', 'g'); %#ok
  124. % set tag for use with timeser.m
  125. setappdata(gca, 'plottype', 'Candle ')        % set tag for use with timeser.m
  126. [Highest,hind] = max(hi);
  127. [Lowest,lind] = min(lo);
  128. % If original figure was not held, turn hold off
  129. if ~hldflag
  130.     hold off
  131. end
  132. %[EOF]
  133. hold on;
  134. if nargin < 6
  135.     text(hind,Highest*1.001,['\leftarrow',num2str(Highest)],'fontname','Times','fontsize',14);
  136.     text(lind,Lowest*0.999,['\leftarrow',num2str(Lowest)],'fontname','Times','fontsize',14);
  137. end
  138. if nargin >=6
  139.     dateset = dates;
  140.     text(dateset(hind),Highest*1.001,['\leftarrow',num2str(Highest)],'fontname','Times','fontsize',14);
  141.     text(dateset(lind),Lowest*0.999,['\leftarrow',num2str(Lowest)],'fontname','Times','fontsize',14);
  142. end
  143. % Add support for providing dates.
  144. % Add support for providing dates.
  145. if nargin == 6 || nargin == 7
  146.     dateset = dates;
  147.     hcdl_vl = findobj(gca, 'Type', 'line');
  148.     hcdl_bx = findobj(gca, 'Type', 'patch');
  149.     % The CANDLE plot is made up of patch(es) and a line.  hcdl_vl is the
  150.     % handle to the vertical lines; it's actually only 1 line object.
  151.     % hcdl_bx contains the handle(s) of the patch object(s) that make up the
  152.     % empty and filled boxes.  The XData of those objects need to be changed
  153.     % to dates so that ZOOM works correctly.
  154.     line_xdata = get(hcdl_vl, 'XData');
  155.     set(hcdl_vl, 'XData', dateset(line_xdata));
  156.     for pidx=1:length(hcdl_bx),   % Need to do loop since there can be 1 or 2 patches.
  157.         patch_xdata = get(hcdl_bx(pidx), 'XData');
  158.         offset = [-0.25*ones(2, size(patch_xdata, 2)); ...
  159.             +0.25*ones(2, size(patch_xdata, 2))] * min(abs(diff(dateset)));
  160.         set(hcdl_bx(pidx), 'XData', dateset(round(patch_xdata))+offset);
  161.     end
  162.     % Change XTickLabel to date string format.
  163.     if ~exist('dateform', 'var') || isempty(dateform)
  164.         datetick('x',20);
  165.     else
  166.         datetick('x', dateform);
  167.     end
  168. end
  169. set(gca,'fontname','Times','fontsize',10)
  170. hold off
  171. %[EOF]
复制代码
  1. function [DIFF, DEA, MACDbar] = FT_MACD(Close,short,long,Mlen)
  2. %  Last Modified by blake 2013/8/29
  3. %  Last Modified by fantuanxiaot 2015/2/8
  4. %  MACD指标计算
  5. %  几个具体的例子
  6. %  FT_MACD
  7. %  FT_MACD(10*rand(100,1),9,26,12)
  8. %  [DIFF, DEA, MACDbar] = FT_MACD
  9. %  [DIFF, DEA, MACDbar] = FT_MACD(10*rand(100,1),9,26,12)
  10. %  返回MACD值,如果无需返回则画图
  11. %  Email:blake_libo@163.com
  12. %  Input:
  13. %       Close: 输入的序列
  14. %       short: 短周期
  15. %       long: 长周期
  16. %       Mlen: 均线周期
  17. %       handle: axes句柄
  18. %  Output:
  19. %       MA_value: 计算的均线返回值
  20. %  程序实现测试所使用的MATLAB版本:MATLAB R2011b(7.13)
  21. %  如果程序在您本机运行不了,请首先检查您MATLAB的版本号,推荐使用较新版本的MATLAB。
  22. %%  输入输出参数设置
  23. if nargin==3
  24.     Mlen = 9;
  25. end
  26. if nargin==2
  27.     long = 26;
  28.     Mlen = 9;
  29. end
  30. if nargin==1
  31.     short = 12;
  32.     long = 26;
  33.     Mlen = 9;
  34. end
  35. if nargin==0
  36.     Close=10*rand(100,1);
  37.     short = 12;
  38.     long = 26;
  39.     Mlen = 9;
  40. end
  41. %%  计算
  42. DIFF = FT_EMA(Close, short)-FT_EMA(Close, long);
  43. DEA = FT_EMA(DIFF, Mlen);
  44. DIFF(1:29) = 0;
  45. DEA(1:29) = 0;
  46. MACDbar = 2*(DIFF-DEA);
  47. MACDbar(MACDbar==0) = nan;
  48. DIFF(DIFF==0) = nan;
  49. DEA(DEA==0) = nan;
  50. MACDbar = MACDbar';
  51. DEA = DEA';
  52. DIFF = DIFF';
  53. %%  Plot
  54. if nargout == 0
  55.     figure(2)
  56.     scrsz=get(0,'ScreenSize');
  57.     set(figure(2),'Position',[scrsz(3)*0.1 scrsz(4)*0.25 scrsz(3)*0.95 scrsz(4)]*0.7,...
  58.         'color','w')
  59.     movegui(figure(2),'center')
  60.     hold on;
  61.     pind = find(MACDbar >= 0);
  62.     nind = find(MACDbar < 0);
  63.     h1 = bar(pind,MACDbar(pind),'r','EdgeColor','r','LineWidth',0.1);
  64.     h2 = bar(nind,MACDbar(nind),'g','EdgeColor','g','LineWidth',0.1);
  65.     plot(DIFF,'k');
  66.     plot(DEA,'b');
  67.     legend('MACD','MACD','DIFF','DEA')
  68.     set(gca,'fontname','华文楷体','fontsize',12)
  69.     current_axes=gca;
  70.     strx=get(current_axes,'XTickLabel');
  71.     stry=get(current_axes,'YTickLabel');
  72.     x=get(current_axes,'XTick');
  73.     y=get(current_axes,'YTick');
  74.     yl=ylim(current_axes);
  75.     xl=xlim(current_axes);
  76.     %  句柄设置
  77.     set(current_axes,'XTickLabel',[]);
  78.     set(current_axes,'YTickLabel',[]);
  79.     %  使之倾斜
  80.     xtoy=zeros(1,length(x))+yl(1)-(max(yl)-min(yl))/30;
  81.     ytox=zeros(1,length(y))+xl(1)-(max(xl)-min(xl))/30;
  82.     text(x,xtoy,strx,'rotation',-20,'HorizontalAlignment'...
  83.         ,'center','FontName','times','FontSize',10,'backg','c');
  84.     text(ytox,y,stry,'rotation',-40,'HorizontalAlignment'...
  85.         ,'center','FontName','times','FontSize',12,'backg','c');
  86.     title('MACD/DEA/DIFF figure','fontname','华文楷体','fontsize',16)
  87. end
  88. end

  89. function EMAvalue = FT_EMA(Price, len, coef)
  90. %  指数移动平均线 函数
  91. %  Last Modified by LiYang 2011/12/27
  92. %  Email:faruto@163.com
  93. %  程序实现测试所使用的MATLAB版本:MATLAB R2011b(7.13)
  94. %  如果程序在您本机运行不了,请首先检查您MATLAB的版本号,推荐使用较新版本的MATLAB。
  95. %%  输入参数检查
  96. error(nargchk(1, 3, nargin))
  97. if nargin < 3
  98.     coef = [];
  99. end
  100. if nargin< 2
  101.     len = 2;
  102. end
  103. %%  指定EMA系数
  104. if isempty(coef)
  105.     k = 2/(len + 1);
  106. else
  107.     k = coef;
  108. end
  109. %%  计算EMAvalue
  110. EMAvalue = zeros(length(Price), 1);
  111. EMAvalue(1:len-1) = Price(1:len-1);
  112. for i = len:length(Price)   
  113.     EMAvalue(i) = k*( Price(i)-EMAvalue(i-1) ) + EMAvalue(i-1);   
  114. end
  115. end

  116. function MA_value = FT_MA(Price, MAlen)
  117. %  移动平均线
  118. %  by liyang 2011/12/13
  119. %  farutoliyang@gmail.com
  120. %  Input:
  121. %       Price: 输入的序列
  122. %       MAlen: 均线周期
  123. %  Output:
  124. %       MA_value: 计算的均线返回值
  125. %%  输入参数检查
  126. if nargin < 2
  127.     % 默认均线周期为5(5分钟线、5日线)
  128.     MAlen = 5;
  129. end
  130. error(nargchk(1, 2, nargin));
  131. if MAlen <= 0
  132.     error('The length of MA must >= 1');
  133. end
  134. %%  初始化
  135. len = numel(Price);
  136. MA_value = zeros(len, 1);
  137. Price = Price(:);
  138. %%  计算均线
  139. MA_value(1:MAlen-1) = Price(1:MAlen-1);
  140. for i = MAlen:len
  141.      MA_value(i) = sum( Price(i-MAlen+1:i) )/MAlen;
  142. end
  143. end
复制代码










二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:fantuanxiaot MATLAB matla atlab 股价数据 通达信

回帖推荐

yiweidon 发表于121楼  查看完整内容

继续定期。。。。

tomorrow89 发表于122楼  查看完整内容

对于财务数据的获取更加感兴趣一点,不知版本怎么实现?

lwzxy 发表于75楼  查看完整内容

作为练习可以,但从数据准确性上来说,我觉得通达信的应更靠谱。
已有 7 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
zxj246 + 5 + 1 + 1 + 1 奖励积极上传好的资料
yangyuzhou + 100 + 5 + 5 + 5 精彩帖子
oliyiyi + 100 精彩帖子
zbin7451f + 100 + 5 + 5 + 5 精彩帖子
chenyi112982 + 5 + 5 + 5 精彩帖子
2010slb + 3 + 3 + 3 精彩帖子
离歌レ笑 + 100 + 5 + 5 + 5 精彩帖子

总评分: 经验 + 300  论坛币 + 105  学术水平 + 24  热心指数 + 24  信用等级 + 24   查看全部评分

本帖被以下文库推荐

沙发
friedmann 发表于 2015-2-8 22:39:06

回帖奖励 +8

这个好,学习下
已有 1 人评分经验 收起 理由
fantuanxiaot + 5 精彩帖子

总评分: 经验 + 5   查看全部评分

藤椅
离歌レ笑 在职认证  发表于 2015-2-8 22:59:07

回帖奖励 +8

暂时没有时间看,先收藏,过几天再好好琢磨!
已有 1 人评分经验 论坛币 收起 理由
fantuanxiaot + 5 + 5 精彩帖子

总评分: 经验 + 5  论坛币 + 5   查看全部评分

板凳
fantuanxiaot 发表于 2015-2-8 23:11:29
离歌レ笑 发表于 2015-2-8 22:59
暂时没有时间看,先收藏,过几天再好好琢磨!

报纸
zhukeming 发表于 2015-2-8 23:41:50

回帖奖励 +8

先回复看明细
已有 1 人评分经验 论坛币 收起 理由
fantuanxiaot + 5 + 1 精彩帖子

总评分: 经验 + 5  论坛币 + 1   查看全部评分

地板
jerker 发表于 2015-2-8 23:44:37

回帖奖励 +8

跟各位学习来了
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
fantuanxiaot + 1 + 1 + 1 + 1 精彩帖子

总评分: 论坛币 + 1  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

7
tt_abc 发表于 2015-2-9 00:02:26
已有 1 人评分论坛币 收起 理由
fantuanxiaot + 5 精彩帖子

总评分: 论坛币 + 5   查看全部评分

8
nndbc 发表于 2015-2-9 00:02:57
学习一下。
已有 1 人评分经验 论坛币 收起 理由
fantuanxiaot + 10 + 3 精彩帖子

总评分: 经验 + 10  论坛币 + 3   查看全部评分

9
tt_abc 发表于 2015-2-9 00:04:39
需要仔细看看。
已有 1 人评分经验 论坛币 收起 理由
fantuanxiaot + 7 + 3 精彩帖子

总评分: 经验 + 7  论坛币 + 3   查看全部评分

10
2010slb 在职认证  发表于 2015-2-9 00:06:50

回帖奖励 +8

好东西,回头学习下~

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jr
拉您进交流群
GMT+8, 2025-12-30 04:59