how do i create this loop in matlab?

1 Ansicht (letzte 30 Tage)
L Mllr
L Mllr am 23 Apr. 2021
Kommentiert: L Mllr am 23 Apr. 2021
i want to create this loop in matlab, this is a python code :
mvols = np.zeros((len(df['NASDAQ']),len(risks)))
for j in range(len(risks)):
mvols[0:windowsize,j] = np.std(np.array(df[risks[j]])[0:windowsize],ddof=1)
for i in range(windowsize-1,len(df['NASDAQ'])-1):
mvols[i+1,j] = np.sqrt(l*mvols[i,j]**2+(1-l)*df.iloc[i][risks[j]]**2)
for j in range(len(risks)):
the variable risks is a matrix of indices which are all the same length :
risks = ['NASDAQ','AEXUSD','DAXUSD','Nikkei','EURIBOR']
matlab gives me an error because i want to calculate the varaible mvols(i+1,j) which is one time period ahead and its past, mvols(i,j) is in the formula , i have no idea how to code this in matlab, does anyone have any idea?
thanks in advance
  6 Kommentare
Rik
Rik am 23 Apr. 2021
From my limited knowledge of Python I suspect that line of code becomes this in Matlab:
mvols(i+1,j) = sqrt(l*mvols(i,j)^2+(1-l)*risks{j}(i)^2);
I had to guess df.iloc[i][risks[j]].
Using the previous element of a vector is easy as that, but depending on what data you have stored in each variable, converting the rest to Matlab might be a bit more tricky.
L Mllr
L Mllr am 23 Apr. 2021
thank you

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by