Timeseries from Finance

hi, i have a code, were i can take free currencies datas, i wanted to implement the new timeseries, but
i stuck with creating the timeseries with csv and with the datetime.

Is there not a more elegant way and should the date function not give yyyymmdd like the iso standard?

M.gf.G. Pascal

clear ();
//ALPHA_VANTAGE_API_KEY
Key="W7CY990V4EBY8SPU";
//Currencies CHF to...
A=["AUD","BRL","CAD","CNY","EUR","GBP","INR","JPY","MXN","USD","ZAR"];
for i=1:size(A)(2);
sleep(30,"s");
[B(A(i)),status(i)] =http_get("https://www.alphavantage.co/query?function=FX_DAILY&from_symbol=CHF&to_symbol="+A(i)+"&outputsize=full&apikey="+"Key"+"&datatype=csv",cert="none");
C(A(i))=strsplit(B(A(i)),ascii(10));
a(i,:)=size(C(A(i)));
for j=1:a(i);
    D(A(i))(j,:)=strsplit(C(A(i))(j),",");
    E(A(i))(j,:)=strtod(D(A(i))(j,5));
    time=D(A(i))(2:$-1,1)
    open=D(A(i))(2:$-1,2)
    high=D(A(i))(2:$-1,3)
    low=D(A(i))(2:$-1,4)
    close=D(A(i))(2:$-1,5)
    TS(A(i))(j,:)=timeseries(time,open,high,low,close);
end;
b(i,:)=[min(strtod(D(A(i)))),max(strtod(D(A(i))))];
end;
c=(min(a(:,1))-1);

i tried this

C(A(i))=csvRead(B(A(i)),",",".","string",[],[],[],1)

but it stoped in the middle?

Why did you insert this ???

S.

when i do several Currencies, Advantech allows only 5 times during a short of period, so by stretching the time i don’t have to do this twice.

But with on example, it can be outlined.

M.f.g. Pascal

When I pasted your code I noticed the following error:

timeseries: Row times vector is missing.

So please read carefully timeseries - Create a timeseries - table with time as index

BTW, each line of your data ends wirh CR+LF, hence you should split the input with

C(A(i))=strsplit(B(A(i)),ascii(13)+ascii(10));

Hello Pascal,

I suggest to use the readtimeseries function as follows:

Key="W7CY990V4EBY8SPU";
A = ["AUD","BRL","CAD","CNY","EUR","GBP","INR","JPY","MXN","USD","ZAR"];
for i = 1:size(A, "c")
    http_get("https://www.alphavantage.co/query?function=FX_DAILY&from_symbol=CHF&to_symbol="+A(i)+"&outputsize=full&apikey="+"Key"+"&datatype=csv",cert="none", "TMPDIR/data.csv");
    TS(A(i)) = readtimeseries("TMPDIR/data.csv");
    mat = TS(A(i))(["open", "high", "low", "close"]);
    b(i,:) = [min(mat),max(mat)];
end

Adeline

2 Likes

Thanks, im looking for that

Thanks, and im looking also for this split method, i didn’t remember, that this was possible in this way.


i made this stackedplot and watch the number 7 at CNY ?