-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
any plan to add SMA, RSI, ATR indices? #7
Comments
All these additional indicators are essentially functions of timeseries of Bitcoin prices and that too specifically closing prices. A convolutional network is able to compute these functions and thus providing them explicitly is redundant. |
However, I have an earlier commit in the master branch which contains calculation of these indicators and passes them as state representation to the Q network. |
I disagree. There is a contextual LSTM model which I think would fair better results if the context of price were included in training. https://arxiv.org/pdf/1602.06291.pdf a successful agent needs to decouple from training data and level up in risk / reward plays. the agent should generalize on other data. If you take an Elliot wave trader on any stock - they can make/ predict the counts / predict a couple of scenarios and place the bet accordingly. these bot agents need to grasp these contexts. If RSI is bearish - then in that context - we're anticipating price swings downwards. If the training is over fit here - sure - then the bot - if given the same prices - it will get the bet right. but it would be better to anticipate if there's a high risk reward scenario to put the farm on bet (like George Soros did by borrowing billions of dollars to bet against the pound) becoming one of the richest men in the world. how did he do this? he took a bet that had very little risk / he only had to pay interest on loan. |
we could branch off into competing forks? the idea being the best code wins to get merged into master. this preprocessing code expands out features to a very wide selection of indicators. eg. cci is useful indicator for bearish / bullish channels. if you fast forward to a finished training sample / given any time + price - you going to get a hodgepodge of signals on different time frames. 5 min / 1 hr / 2 hr etc. https://github.com/bfmill253/ForexDL/blob/3fcbd8cc92ff98363c478b5cdae5c0a2959ef3fc/ForexDL/Data.py def expandData(startTime="0", instrument="EUR_USD", endTime="0"):
close, high, low, volume, openMid, time = getData(startTime=startTime, instrument=instrument, endTime=endTime)
inputs = {
'open': openMid,
'high': high,
'low': low,
'close': close,
'volume': volume
}
#print (type(inputs.get('open')))
#Overlap Studies
sma = SMA(inputs)
bbuper, bbmiddle, bblower = BBANDS(inputs)
dema = DEMA(inputs)
ema = EMA(inputs)
htTrend = HT_TRENDLINE(inputs)
kama = KAMA(inputs)
ma = MA(inputs)
mama, fama = MAMA(inputs)
midpoint = MIDPOINT(inputs)
midprice = MIDPRICE(inputs)
sar = SAR(inputs)
sarext = SAREXT(inputs)
t3 = T3(inputs)
trima = TRIMA(inputs)
wma = WMA(inputs)
#Momentum Indicators
adx = ADX(inputs)
adxr = ADXR(inputs)
apo =APO(inputs)
aroonDown, aroonUp = AROON(inputs)
aroon = AROONOSC(inputs)
bop = BOP(inputs)
cci = CCI(inputs)
cmo = CMO(inputs)
dx = DX(inputs)
macd, macds, macdh = MACD(inputs)
macdext, macdexts, macdexth = MACDEXT(inputs)
macdfix, macdfixs, macdfixh = MACDFIX(inputs)
mfi = MFI(inputs)
minusdi = MINUS_DI(inputs)
minusdm = MINUS_DM(inputs)
mom = MOM(inputs)
plusdi = PLUS_DI(inputs)
plusdm = PLUS_DM(inputs)
ppo = PPO(inputs)
roc = ROC(inputs)
rocp = ROCP(inputs)
rocr = ROCR(inputs)
rocr100 = ROCR100(inputs)
rsi = RSI(inputs)
slowk, slowd = STOCH(inputs)
fastk, fastd = STOCHF(inputs)
rsifastk, rsifastd = STOCHRSI(inputs)
trix = TRIX(inputs)
ultosc = ULTOSC(inputs)
willr = WILLR(inputs)
#volume indicators
ad = AD(inputs)
adosc = ADOSC(inputs)
obv = OBV(inputs)
#cycle indicators
ht_dcperiod = HT_DCPERIOD(inputs)
ht_dcphase = HT_DCPHASE(inputs)
ht_phasor_inphase, ht_phasor_quadrature = HT_PHASOR(inputs)
ht_sine, ht_leadsine = HT_SINE(inputs)
ht_trendmode = HT_TRENDMODE(inputs)
#price transform
avgprice = AVGPRICE(inputs)
medprice = MEDPRICE(inputs)
typrice = TYPPRICE(inputs)
wclprice = WCLPRICE(inputs)
#volatility ind
atr = ATR(inputs)
natr = NATR(inputs)
trange = TRANGE(inputs)
#pattern rec
twocrows = CDL2CROWS(inputs)
threeblackcrows = CDL3BLACKCROWS(inputs)
threeinside = CDL3INSIDE(inputs)
threelinestrike = CDL3LINESTRIKE(inputs)
threeoutside = CDL3OUTSIDE(inputs)
threestarsinsouth = CDL3STARSINSOUTH(inputs)
threeWhiteSoldiers = CDL3WHITESOLDIERS(inputs)
abandonBaby = CDLABANDONEDBABY(inputs)
advanceBlock = CDLADVANCEBLOCK(inputs)
beltHold = CDLBELTHOLD(inputs)
breakAway = CDLBREAKAWAY(inputs)
closingM = CDLCLOSINGMARUBOZU(inputs)
consealBabySwall = CDLCONCEALBABYSWALL(inputs)
counterAttack = CDLCOUNTERATTACK(inputs)
darkCloudCover = CDLDARKCLOUDCOVER(inputs)
doji = CDLDOJI(inputs)
dojiStar = CDLDOJISTAR(inputs)
dragonFlyDoji = CDLDRAGONFLYDOJI(inputs)
engulfing = CDLENGULFING(inputs)
eveningDojiStar = CDLEVENINGDOJISTAR(inputs)
eveningStar = CDLEVENINGSTAR(inputs)
gapSideSideWhite = CDLGAPSIDESIDEWHITE(inputs)
graveStoneDoji = CDLGRAVESTONEDOJI(inputs)
hammer = CDLHAMMER(inputs)
hangingMan = CDLHANGINGMAN(inputs)
harami = CDLHARAMI(inputs)
haramiCross = CDLHARAMICROSS(inputs)
highWave = CDLHIGHWAVE(inputs)
hikkake = CDLHIKKAKE(inputs)
hikkakeMod = CDLHIKKAKEMOD(inputs)
homingPigeon = CDLHOMINGPIGEON(inputs)
identical3Crows = CDLIDENTICAL3CROWS(inputs)
inNeck = CDLINNECK(inputs)
invertedHammer = CDLINVERTEDHAMMER(inputs)
kicking = CDLKICKING(inputs)
kickingByLength = CDLKICKINGBYLENGTH(inputs)
ladderBottom = CDLLADDERBOTTOM(inputs)
longLeggedDoji = CDLLONGLEGGEDDOJI(inputs)
longLine = CDLLONGLINE(inputs)
maruBozu = CDLMARUBOZU(inputs)
matchingLow = CDLMATCHINGLOW(inputs)
matHold = CDLMATHOLD(inputs)
morningDojiStar = CDLMORNINGDOJISTAR(inputs)
morningStar = CDLMORNINGSTAR(inputs)
onNeck = CDLONNECK(inputs)
piercing = CDLPIERCING(inputs)
rickShawman = CDLRICKSHAWMAN(inputs)
riseFall3Methods = CDLRISEFALL3METHODS(inputs)
seperatingLines = CDLSEPARATINGLINES(inputs)
shootingStar = CDLSHOOTINGSTAR(inputs)
shortline = CDLSHORTLINE(inputs)
spinningTop = CDLSPINNINGTOP(inputs)
stalledPattern = CDLSTALLEDPATTERN(inputs)
stickSandwhich = CDLSTICKSANDWICH(inputs)
takuri = CDLTAKURI(inputs)
tasukiGap = CDLTASUKIGAP(inputs)
thrusting = CDLTHRUSTING(inputs)
triStar = CDLTRISTAR(inputs)
unique3River = CDLUNIQUE3RIVER(inputs)
upsideGap2Crows = CDLUPSIDEGAP2CROWS(inputs)
xSdieGap3Methods = CDLXSIDEGAP3METHODS(inputs)
data = np.array([close, high, low, volume, openMid, time, sma, bbuper, bbmiddle, bblower, dema, ema, htTrend, kama, ma, mama, fama, midpoint, midprice, sar, sarext, t3, trima, wma, adx, adxr, ppo, apo, aroonDown, aroonUp, aroon, bop, cci, cmo, dx, macd, macds, macdh, macdext, macdexts, macdexth, macdfix, macdfixs, macdfixh, mfi, minusdi, minusdm, mom, plusdi, plusdm, roc, rocr, rocp, rocr100, rsi, slowk, slowd, fastk, fastd, rsifastk, rsifastd, trix, ultosc, willr, ad, adosc, obv, ht_dcperiod, ht_dcphase, ht_phasor_inphase, ht_phasor_quadrature, ht_sine, ht_leadsine, ht_trendmode, avgprice, medprice, typrice, wclprice, atr, natr, trange, twocrows, threeblackcrows, threeinside, threelinestrike, threeoutside, threestarsinsouth, threeWhiteSoldiers, abandonBaby, advanceBlock, beltHold, breakAway, closingM, consealBabySwall, counterAttack, darkCloudCover, doji, dojiStar, dragonFlyDoji, engulfing, eveningDojiStar, eveningStar, gapSideSideWhite, graveStoneDoji, hammer, hangingMan, harami, haramiCross, highWave, hikkake, hikkakeMod, homingPigeon, identical3Crows, inNeck, invertedHammer, kicking, kickingByLength, ladderBottom, longLeggedDoji, longLine, maruBozu, matchingLow, matHold, morningDojiStar, morningStar, onNeck, piercing, rickShawman, riseFall3Methods, seperatingLines, shootingStar, shortline, spinningTop, stalledPattern, stickSandwhich, takuri, tasukiGap, thrusting, triStar, unique3River, upsideGap2Crows, xSdieGap3Methods])
return data N.B. all these functions are out of the box with TALib. |
Competing forks seems to nice idea but currently I don't have much ideas remaining to improve the performance of the agent. In that scenario may be collaboration and sharing ideas seems as a better alternative. |
stepping back - rather than adding these as features into data set
the action would need to observe the corresponding value of result & feedback into system. I skimmed through this code by @dandxy89 - but not sure how one could cherry pick this code. https://github.com/dandxy89/rf_helicopter/blob/master/Model/Q_Learning_Agent.py alternative could be then step 2- somehow cross bread / concatenate other signals into a super strategy. |
Seems like a nice idea, need to do a bit more research on this topic. I was also considering using Google Trends per minute statistics as an input to the model as they serve as a proxy to the market sentiments. But currently I am having issue acquiring per minute trends due to rate limits of the API. |
from @antkve, https://github.com/antkve/neuralnet/blob/master/neuralnetcrypto.py |
the reinforcement paper use these components in vector. we can use backtrader to test strategies for profitability. from my understanding of the paper - and reading this graph predictions of 1 day ahead - really sucked |
seems like the more indicators = the better - here author is using 18. |
there's a config file that's appending these features eg. here acceleration in price if conf['ac96/96'] is True:
ac96_per_asset = []
for asset in range(num_assets):
p = closes[asset, :].astype(np.float64)
pavgs = talib.MA(p, timeperiod=96) #avg(p, 12)
pavgsavgs = talib.MA(p / pavgs, timeperiod=96) # avg[p/avg(p, 12), 12]
item = (p / pavgs) / pavgsavgs
avgs = talib.MA(item, timeperiod=96)
stddevs = talib.STDDEV(item, timeperiod=96)
zScores = np.nan_to_num((item - avgs) / stddevs)
ac96_per_asset.append(zScores)
ac96_per_asset = np.array(ac96_per_asset).astype(np.float32)
features.append(ac96_per_asset) |
So I think the state representation should include
|
https://launchpad.ai/blog/trading-bitcoin are using 18 indicators but they are not providing |
recommend https://github.com/tensorflow/models/pull/1509/files |
This is the direct link to the file extracting all the features from the historical price dataset as mentioned by @yunhaizhu . |
to throw a spanner in the works - consider we need an RNN to discriminate how long the time periods to use. |
@johndpope this complicates the already difficult task, I guess. |
I am currently working in |
Another thing to consider is to how to normalise the input technical indicators. As @johndpope mentioned in an earlier comment, we can normalise them based on predefined maximum and minimum values of the indicators. We need to decide upon these values as well since they will largely affect the training process. |
Working with predefined maximums and minimums raises an issue in the sense that the price of Bitcoin varies in extremes in the time period under consideration. Using fixed values for the entire time frame will render certain values very low in certain cases and very high in certain cases sending the network in shocks. |
Regarding normalisation of the input to the network, I have found this which describes a general method to normalise the input in a reinforcement learning problem using online algorithms to calculate mean and variance. |
I did a lot of validation on technical indicators on a FCN net, and here are the main insights:
Just adding the difference (delta) between the previous n-days close prices is key to increase model accuracy. Also, change in momentum and change of change (second derivative) is key.
Specifically, the distance between the closing price and key indicators such as
To some extent, these insights are almost too obvious to be true, but here you codify domain knowledge by making implicit observations explicit. Taking the infamous Bollinger bands as an example, when the closing price approaches the upper-band, usually a trend reversal is due. The distance between close and upper band captures exactly this and allows the net/agent to find a matching rule.
Calculating most commonly used indicators isn't terribly fun, so instead, I pull them together with the data from AlphaVantage and merge them over index. You may wonder what's the point of downloading indicator data, but as AlphaVantage offer tick resolution data for free, loading and caching them speeds things up noticeably. I have stuffed all the above in a bunch of utils and released them here: Finally, in terms of RL, it seems that neuro evolution combined with Bayesian optimization seems to work quite well: |
Do you have any plan to add SMI, RSI, ATR indices to the input state?
The text was updated successfully, but these errors were encountered: