# Timeseries from Finance

**URL:** <https://scilab.discourse.group/t/timeseries-from-finance/221>\
**Category:** General usage\
**Created:** [October 30, 2023, 2:18pm UTC](https://scilab.discourse.group/t/timeseries-from-finance/221 "2023-10-30T14:18:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [October 30, 2023, 2:18pm UTC](https://scilab.discourse.group/t/timeseries-from-finance/221/1 "2023-10-30T14:18:44Z")

</div>

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

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [October 31, 2023, 2:27pm UTC](https://scilab.discourse.group/t/timeseries-from-finance/221/2 "2023-10-31T14:27:32Z")

</div>

i tried this

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

```

but it stoped in the middle?

 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/2b94bbb191792310acccd456027eedde350caa4f.png)

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [October 31, 2023, 2:48pm UTC](https://scilab.discourse.group/t/timeseries-from-finance/221/3 "2023-10-31T14:48:04Z")

</div>

> [@pascal](#):
>
> `sleep(30,"s");`

Why did you insert this ???

S.

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [October 31, 2023, 3:12pm UTC](https://scilab.discourse.group/t/timeseries-from-finance/221/4 "2023-10-31T15:12:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [October 31, 2023, 3:28pm UTC](https://scilab.discourse.group/t/timeseries-from-finance/221/5 "2023-10-31T15:28:16Z")

</div>

When I pasted your code I noticed the following error:

```scilab
timeseries: Row times vector is missing.

```

So please read carefully [timeseries - Create a timeseries - table with time as index](https://help.scilab.org/timeseries)

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [October 31, 2023, 3:45pm UTC](https://scilab.discourse.group/t/timeseries-from-finance/221/6 "2023-10-31T15:45:38Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![adeline.carnis](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@adeline.carnis](https://scilab.discourse.group/u/adeline.carnis)\
**Post date:** [October 31, 2023, 4:30pm UTC](https://scilab.discourse.group/t/timeseries-from-finance/221/7 "2023-10-31T16:30:43Z")

</div>

Hello Pascal,

I suggest to use the readtimeseries function as follows:

```scilab
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

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [November 1, 2023, 6:12am UTC](https://scilab.discourse.group/t/timeseries-from-finance/221/8 "2023-11-01T06:12:58Z")

</div>

Thanks, im looking for that

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [November 1, 2023, 6:14am UTC](https://scilab.discourse.group/t/timeseries-from-finance/221/9 "2023-11-01T06:14:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [November 3, 2023, 2:32pm UTC](https://scilab.discourse.group/t/timeseries-from-finance/221/10 "2023-11-03T14:32:35Z")

</div>

![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/dd0d24a6abed36ce340f042629675d5539c6f9c6.png)  
i made this stackedplot and watch the number 7 at CNY ?
