![]() Similar to my previous post, I use the 5-day moving average of the rate of return of the close price as the target variable in order to smoothen the flucuation. Then, stack over of 2-GRU, and the final Dense layer to get the predicted rate of return of the next day. I use the OsRSI Matrix of the current day and the previous ( seqlen) days to form a sequence of Matrix as the input of the CNN layers. That Matrix can be feed into the Convolution Neural Network (CNN) for pattern recognition. rsi_ma, Symbol("ORSI-",i,"-",j) ) result_orsi = merge(result_orsi,orsi,method=:inner) end endĪll these OsRMI(i,j) will form a Matrix. for i in day0:day1 rsi_ts = toRSI(price_ts,i) result_rsi = merge(result_rsi,rsi_ts,method=:inner) for j in day0:day1 rsi_ma = TimeSeries.rename(moving(mean,rsi_ts,j),Symbol("RSIMA-",i,"-",j)) orsi = TimeSeries.rename(rsi_ts. With the leverage of the computer automation, we can loop over the value of i and j over a range instead of just base on a single value of the loopback in the analysis. For each MA we need to specify the loopback period, let it be i and j, and defined as below: rsi_ts = toRSI(price_ts,i) rsi_ma = moving(mean,rsi_ts,j) orsi = rsi_ts. For each OsRSI calculation, there are 2 moving averages: (1) the MA in the calcation of up_roll and down_roll, and (2) the MA of the RSI. ![]() The Oscillator of the Moving average of RSI (OsRSI) can be used as the model feature. rsi_ma = TimeSeries.rename(moving(mean,rsi_ts,j),Symbol("RSIMA-",i,"-",j)) Feature Engineering Moving Average of the RSI can be easily be computed by the function “moving(mean, …)”. (timestamp, if values (timestamp, if values (timestamp, f_rsi(values)), updown),Symbol("RSI-",loopback)) return rsi_ts end Using TimeSeries function toRSI(price_ts,loopback) pct = percentchange(price_ts) upidx = findall(pct. It is common to use map function instead of loop for time series operations. ![]() TimeSeries.map is used to apply the function f_rsi on each element of the time series.f_rsi is the function to apply on each element of the time series to calculate the RSI = 100–(100/1+up_roll/down_roll).up_roll and down_roll is the moving average of the positive difference and negative difference for the period “loopback”. ![]() Time Series “up” and “down” are the positive price difference (%) and negative price difference (%) generated by setting the opposite sign value 0.percentchange(price_ts) is the function to compute the price difference in % from the lag-1 price.Here is the code of Julia of the computation. RS = (MA of positive difference) / (MA of negative difference) Relative Strength (RS) and Relative Strength Indicator (RSI) can be computed from the Moving Average (MA) of the historical positive price difference (%) divided by that of negative price difference (%). Inspired by that, I want to try to use that as the machine learning feature to predict the future stock return. RSI is an useful indicator of trend and momentum. Just learned the Oscillator of Moving average (OsMA) and RSI from the post. Use Oscillator of RSI to predict Stock Return (accuracy over 70%!)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |