Freemat print out array12/16/2023 % calculate profit on trading SPY long/short when above/below x-length smaĭata = csvread('spy_2000_2011.csv',1,7) % column with adj. csv, but how can they used for the x-axis? The dates are available in the first column of the. (: a period during which the "buy-and-hold" investor ended with about the same capital (actually a bit less) he started with at the left hand side of the chart (ex dividends)) Is "report" the culprit and how should I handle the storing of the daily "delta's"?Īnother issue bugging me is a correct x-axis: the data window is from until. I suspect the error is caused by some improper use of the "report" array, not sure though? Great! (see attachments).īut as soon as I alter the starting value for the loop from 200 to i.e. Works OK for one specific sma length, like 200: the code yields a graphical equity curve and a report with: sma-length, profit% and number of trades. (NB! Not completely sure about the arithmetical validity of the calculations and summing, but for now that is the least of my problems). The rules are quite simple: when and during (close >= sma) we go/stay "long" otherwise "short".Įvery day the daily difference (in %) is calculated and stored.Īt the end of the price array, all differences are summed. So, could anyone help me get going with the simple moving average?Īfter plotting the difference between the daily closing price of SPY and the 200-day sma in points and next in %, eventually the script below evolved to calculate total performance over 11 years. I would however very much appreciate some guidance and hints during the process. generate/print an ordered (max to low) table with profits for every z value Īs I can imagine the coding of such a "scriptorium" would involve a lot of time and effort, I have no intention as to ask for anyone to write the code for me. calculate profits for each value of z between 10 and 300 with increments of 5) code an optimization script to find max profit for long/short when above/below z day sma (i.e. plot a separate chart for profit's histogram (time, dollars) calculate overall profit for long when price >= 200sma and short when price < 200sma (so the crossover of the 200sma triggers both exit and entry For instance, we want to number each array element in the output. We can also use map() and join() methods to manipulate first and then print the array’s elements. plot a 200 day simple moving average on the price chart We can print all array elements by passing the array’s name to the console.log() function. and the second the resulting variables and this array must already be dimensioned. plot the price data on semi-log y-axis lpsolve is callable from FreeMat via an external interface or Import. let Freemat read and order the data (adj. ) I wanted to learn a platform to create scripts for analysing and optimizing stock data, or at least to it a serious try.įlabbergasted by the pricing of MatLab ("commercial user"), I found Freemat and this group too. On my blog ( I publish free "thinkscript" studies: indicators and strategies for the TDA thinkorswim platform ( After reading some posts on Seeking Alpha (see i.e. There are following ways to print an array in Java: Java for loop. So, we can store a fixed set of elements in an array. Just starting to get a little bit acquainted with Freemat. The elements of an array are stored in a contiguous memory location. So, why not hack the Object.First post from a new "user". Now, all classes have Object as the parent-type. Printing an array directly gives the internal representation and the hashCode. Just a hack that can make debugging simpler. Please note, this is not a permanent fix by any means. It's not very convenient writing Arrays.toString(arr), then importing all the time. I came across this post in Vanilla #Java recently. Now the point to observe is that the method Arrays.stream(T), which in case of int returns us Stream and then method flatMapToInt() maps each element of stream with the contents of a mapped stream produced by applying the provided mapping function to each element. (epToString(str2DArray)) Īrrays.stream(int2DArray).flatMapToInt(x -> Arrays.stream(x)).forEach(System.out::println) Īrrays.stream(str2DArray).flatMap(x -> Arrays.stream(x)).forEach(System.out::println) Simple Array: String array = new String.The output is even decorated in the exact way you're asking. Since Java 5 you can use Arrays.toString(arr) or epToString(arr) for arrays within arrays.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |