Code covered by the BSD License  

Highlights from
Metastockread

4.5

4.5 | 4 ratings Rate this file 18 Downloads (last 30 days) File Size: 1.38 MB File ID: #28664
image thumbnail

Metastockread

by

 

08 Sep 2010 (Updated )

Read metastock files (master, emaster, xmaster and .dat/.mwd)

| Watch this File

File Information
Description

Read metastock files (symbols index files: master, emaster, xmaster; data files: .dat and .mwd; no .dop support)

SYNTAXES:
(1) METASTOCKREAD Read the symbols index file selected with uigetfile and import the data
(2) METASTOCKREAD(FULLPATH) Read the file specified by FULLPATH

OUT = metastockread(...)
OUT is a "m by 1" NON-scalar structure, where "m" is the # of .dat/.mwd files in the same directory of the symbol index files.

The (sub)scalar structure has the following fields:
- datNum : # of the .dat/.mwd file with the data
- symbol : security symbol
- name : security name
- inDate : initial date as 'yyyy-mm-dd'
- fiDate : final date as 'yyyy-mm-dd'
- freq : time freq. of the data I (intraday), D (daily), W, M, Q or Y
- idFreq : intraday time frequency in minutes
- data : time series data with variable number of fields (columns)

The data field columns follow the schema:

| Date/Time | Open | High | Low | Close | Volume | OpenInterest |

For details see help
For examples see the attached image.

WARNING: This function has not been tested extensively therefore I ask to report any unexpected behaviour and to attach the metastock files which you tried to import.

p12v5

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
06 Jan 2014 Goryn

Very useful, thank you! I've found an error on line 156 and 158. Variable 'm' should be changed for 'mn' (minutes) or it overwrites variable 'm'(months) and causes error with intraday data.

06 Jan 2014 Goryn  
04 Mar 2012 James Kunce

Thank you!! Exactly what I was looking for and works great.

09 Dec 2010 cheng

just i want;so thanks

03 Nov 2010 Oleg Komarov

I will look into the problem after the 12th of nov.
I hope I'll be able to write a metastockwrite function, in the meantime you can use the solution suggested by Tony.

03 Nov 2010 Tony Tran

For whose who need to export to Metastock format
Step 1: output to text format, see the example

% format AAM,20100913,24.40,24.90,23.70,24.00,13600,0
fid = fopen('scindex.txt','w');
for i=1:size(SCIndex)
sdate=datestr(TDate(i),'yyyymmdd');
fprintf(fid, 'SCINDEX,%s,%.2f,%.2f,%.2f,%.2f,0\n',sdate,SCIndex(i),SCIndex(i),SCIndex(i),SCIndex(i));
end
fclose(fid);

Then call external program to convert the text file to MS. asc2ms can be found easily by google.

% execute
dos('asc2ms -r recordReplace -f "scindex.txt" -o "D:\MetaStock Data\VNINDEX"');

29 Oct 2010 Han Oostdijk

nice well structured example of reading binary data.

27 Oct 2010 Shailesh Joshi

I will be happy to have program which will write data in metastock format. Mostly I convert it after downloading manually.

09 Oct 2010 Oleg Komarov

I may if there's request.

07 Oct 2010 Shailesh Joshi

By any chance do you have program to write to metastock format?

Updates
09 Sep 2010

Added link to FEX page, edited example and edited description.

03 Aug 2011

Added fix for buggy *.dat files as pointed out by Davide Dalmasso

03 Aug 2011

Added fix for buggy *.dat files as pointed out by Davide Dalmasso

19 Feb 2012

Fixed erroneous date conversion for intraday series. As pointed out by Luca LPr the month had the same value as minutes due to same name of the variable.

19 Feb 2012

Uploaded wrong file.

17 Oct 2013

 - Cross platform compatible filepath handling (thanks to Thiago Tavares for reporting)
- got rid of dataread for forward compatibility

Contact us