麻煩指點 是否有更簡單之寫法
大家好:不好意思 請教一個有點笨的問題小弟最近 想把 兩類數據(分別為 x,y )求算其迴歸線之斜率 第一個資料x是先將價格 進行運算是以函數求算出之資料 如同 x1=rsi(close,len1) ,x2=rsi(close,len2)第二個資料y 是先將區間 進行運算也是以函數求算出之資料如同 y1=le1*len1, y2=len2*len2然後 一共會有 x1 x2 x3 ...x100,y1 y2y3...y100這時我就將這x與y 進行 迴歸線之斜率求算我現在做法有點笨 (因為太笨了所以只寫到10原本是要寫到1000) Inputs: Base(close); variables: var0( 0 ), var1( 0 ), var2( 0 ), var3( 0 ), var4( 0), var5( 0 ), var6( 0 ), var7( 0 ), var8( 0 ), var9( 0 ), var10( 0),tar1(0 ), tar2( 0 ), tar3( 0 ), tar4( 0), tar5( 0 ), tar6( 0 ), tar7( 0 ), tar8( 0 ), tar9( 0 ), tar10( 0); value1 = t2;value2 = t2+1;value3 = t2+2;value4 = t2+3;value5 = t2+4;value6 = t2+5;value7 = t2+6;value8 = t2+7;value9 = t2+8; var1 = rsi(Base,value1);var2 = rsi(Base,value2);var3 = rsi(Base,value3);var4 = rsi(Base,value4);var5 = rsi(Base,value5);var6 = rsi(Base,value6);var7 = rsi(Base,value7);var8 = rsi(Base,value8);var9 = rsi(Base,value9); tar1 = (value1*value1);tar2 = (value1*value2);tar3 = (value1*value3);tar4 = (value1*value4);tar5 = (value1*value5);tar6 = (value1*value6);tar7 = (value1*value7);tar8 = (value1*value8);tar9 = (value1*value9); 然後再將xi=var(i) yi=tar(i)依據迴歸公式去推算slope 因為 var tar 都各為兩個函數 然後進行迴歸時 又需重新帶入另一個函數 試過些不同方法但似乎都很笨因為想問大家有無更簡單做法? 謝謝大家 Max拜上除了用陣列與迴圈搭配去做之外,我想不出更方便的作法了。
頁:
[1]