ラベル

AI Forecast 8306MUFG (214) Social (75) life (70) Financial (62) IT (57) Proposal (56) idea (50) Fund Management (48) Trading (43) economics (42) Covid-19 (40) AI (38) Hedge Fund (36) Risk (36) Culture (31) BOJ (29) Science (26) hobby (24) accounting (17) Apps (16) career (11) job (7) Travel (6) Hiking (5) emotion (5) music (3) Statarb (2) piano (2)

2020年1月23日木曜日

Javascript 格闘記 .. 配列編 Javascript Tackling .. Chapter Array

Javascript 格闘記 .. 配列編

Javascript Tackling .. Chapter Array




現在、Javascriptで株価の新値三本からAIで株価予測するプログラムを作成中だNow building up program to AI-forecast stock price behavior based on three line break profile.

まず、新値3本の生成をプログラム。場合分けですんなりいくはずが難航した。1st, needed to create three line break time series. It should be no-brainier using case by case process but it took longer in reality.

チェックWriteを入れまくってデバッグしていると、配列処理中、マカ不思議な現象に出会った。プログラムで、二つの配列の値を比較したところ、大小の比較ができないのだ! I inserted lots of check-writes to debug, then found pretty funny phenomena in array process. I compared two numbers in array but could not compare which one is bigger than the other!

下のように、pd[i]=1,010とtlb[j-1]=992を比較すると、pd[i]はtlb[j-1]より大きくない!と出てしまう。As below, when I compared pd[i]=1,010 and tlb[j-1]=992, program said pd[i] is not bigger than tlb[j-1]!

プログラムProgram
                            console.log("pd[i]",pd[i])
                            console.log("tlb[j-1]",tlb[j-1])
                            console.log("pd[i] - tlb[j-1]",(pd[i] - tlb[j-1]))
                            console.log("pd[i] > tlb[j-1]",(pd[i] > tlb[j-1]))
                            console.log("pd[i] - tlb[j-1] > 0",(pd[i] - tlb[j-1] > 0))
結果Result













仕方がないので、pd[i]-tlb[j-1]はゼロより大きいか?と聞くと、これは大きいと出て、ホッとした。回避策としてpd[i] > tlb[j-1]の代わりに、pd[i]-tlb[j-1]>0を使った。I asked if pd[i]-tlb[j-1] is positive, the now the answer was yes, so I was relieved.  As a workaround, I used pd[i]-tlb[j-1]>0instead of pd[i] > tlb[j-1].

Javascriptの配列=は値コピーではなく、ポインタコピーで、メモリ上は同じ位置にマップされるだけという場合もあると知り、配列定義にConstだったのをVarにしたが、結果は一緒で、まだ私が理解できていないJavascriptの仕組みから来るものだと思う。I also learned that Javascript copy by = is not value cpy but pointer copy, hence actual number is mapped in same memory location. So I changed array definition from const to Var but there was no difference to this problem.  I believe this phenomena comes from some Javascript feature I still do not aware of.


結果が正しいことが検証しながら利用するので当面問題ないが、エラーが出ない範囲で文法的に何か変なことをやっているのだろう。Since I am moving on verifying the result each time, this will not be a problem for now however I may be doing something that is not really compliant to Javascript grammar.

このようなことで苦しんでも、プログラムを学習するうえでも、自分の解決したい課題をプログラミングする過程で学習を進めていきたい。Even if I suffer like this, I wish to keep building up program by solving own problem, to learn programming.

やはり、手を動かして何かを作っていくのが上達への近道だと思う。The best way to learn programming is to keep having hands on experience by keep building up something.