a question about MatLab function--"highlow()" and relative functions.

Discussion in 'App Development' started by cf0532, Mar 21, 2013.

  1. cf0532

    cf0532

    Now I have the data resource as below:

    Date--------OpenPrice------HighPrie-----LowPrice----ClosePrice

    2012/3/8----6.18-------------6.28-----------5.68-----------6.09

    2012/3/9----6.01-------------6.21-----------5.95-----------6.03

    2012/3/12--6.03-------------6.09-----------5.87-----------6.89

    2012/3/13--5.9--------------6.16------------5.9------------6.04

    then I use "figure" and "highlow()" to get a chart. if I use "dateaxis('x',2,'8-Mar-2012');", 12/03/08, 12/03/09,12/03/10, 12/03/11 and so on will be listed on the x axis.

    Now I request that 12/03/08, 12/03/09, 12/03/12, 12/03/13 and so on are listed on the x axis according to above data's dates exactly. Shall I and How?

    in addition,I request that 12/03/08, 12/03/09,12/03/10, 12/03/11, 12/03/12, 12/03/13 and so on are listed on the x axis, but the "K lines" generated by "highlow()" only exist on 12/03/08, 12/03/09, 12/03/12 and 12/03/13 rather than 12/03/10 and 12/03/11 according to above data's dates exactly. Shall I and How?

    Thanks a lot!
     
  2. I don't have the financial toolpack so I can't experiment with this but looking at the MATLAB help stuff, I think you should put the date vector in your initial call to highlow:

    highlow(High, Low, Close, Open, Color, Dates, Dateform)
     
  3. cf0532

    cf0532

    Thank you for your advice.
    According to your idea, I have make the code in M file as below:
    "
    clear;clc;
    load 'ctgs2.txt';
    r=size(ctgs2,1);
    figure;
    highlow(ctgs2(1:r,3),ctgs2(1:r,4),ctgs2(1:r,5),ctgs2(1:r,2),'r',ctgs2(1:r,1),2);
    xlabel('Date);
    ylabel('This Stock's Price');
    title('This Stock's Current Chart');
    "
    Note: "ctgs2.txt" includes all the data about this stock which was listed on the post before partially.

    But I get terrible result after I execute the M file.

    In addition, if these code was changed to the one as below in M flie, it runs well, but just can't get the requested date list on x axis.
    "
    clear;clc;
    load 'ctgs2.txt';
    r=size(ctgs2,1);
    figure;
    highlow(ctgs2(1:r,3),ctgs2(1:r,4),ctgs2(1:r,5),ctgs2(1:r,2),'r');
    xlabel('Date);
    ylabel('Price');
    title('This Stock's Current Chart');
    axis([0,r+1,2.4,inf]);
    dateaxis('x',2,'2012-1-1');
    "

    So can you help me to modify the code?
     
  4. cf0532

    cf0532

    In the fact, I am not very clear about "dates" in the function--"highlow()". shall I get more instruction?
     
  5. cf0532

    cf0532

    I use the below code:

    highlow(ctgs2(1:r,3),ctgs2(1:r,4),ctgs2(1:r,5),ctgs2(1:r,2),'r',ctgs2:),1),2);

    and get the chart as attachment.
    I don't know why?
    "Dates" in the highlow() seems not x axis's dates.
     
    • ctgs.jpg
      File size:
      28.9 KB
      Views:
      123
  6. Mysteron

    Mysteron

    You sent me an email recently which I lost. I have all the matlab (2008b) toolboxes including financial however I don't use them, prefering instead to create my own code. So I'm not familiar with the functions you are trying to use. The online help for matlab is usually very good and will give you all the answers you need.

    At the matlab prompt enter:

    help highlow

    it shows the function has the form:

    HIGHLOW(HI,LO,CL,OP,COLOR,DATES,DATEFORM)

    so it looks like you haven't specified the DATEFORM parameter.

    However if you enter at the matlab prompt:

    doc highlow

    then I get this in the browser help screen:

    Syntax

    highlow(High, Low, Close, Open, Color)
    Handles = highlow(High, Low, Close, Open, Color)

    So it looks like an oddity in the browser form of online help in that it doesn't give the complete functional form and omits the DATEFORM parameter.

    Also when trying to understand a matlab function sometimes just using google will give answers.

    DATEFORM Format Description

    0 01-Mar-1995 15:45:17 (day-month-year, hour:minute)
    1 01-Mar-1995 (day-month-year)
    2 03/01/95 (month/day/year)
    3 Mar (month, three letter)
    4 M (month, single letter)
    5 3 (month)
    6 03/01 (month/day)
    7 1 (day of month)
    8 Wed (day of week, three letter)
    9 W (day of week, single letter)
    10 1995 (year, four digit)
    11 95 (year, two digit)
    12 Mar95 (month year)
    13 15:45:17 (hour:minute:second)
    14 03:45:17 (hour:minute:second AM or PM)
    15 15:45 (hour:minute)
    16 03:45 PM (hour:minute AM or PM)
    17 95/03/01 (year/month/day)