So, moving to my laptop worked. I got a bit faster environment than old good Raspberry Pi. Unfortunately (or, rather fortunately) I discovered a bug in my previous codes – this beautiful picture “predicting” next 300 transactions.. Was bullshit 🙂 After carefully reading code I realized it predicts/forecasts just 1 next value and retrains the model.
Following link greatly help me understand how Arima works and how to use it.
Well – that gave me a lot of thinking and my next approach is to work on slightly less granular data than transactions but also not on a daily open/low/high/close data. Idea for today is to calculat an average out of every, let’s say 5 or 50 transactions or every 5 minutes and ask Arima model to forecast next average price for next batch of transactions. Seems totally doable within my primitive Python skills.
Let’s code it.
First, we need some data and following SQL query can do the job:
SELECT FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(time)/300)*300) x, AVG( price ) FROM gdax_matches WHERE product_id = 'BTC-USD' AND time between '2018-07-30' and '2018-08-01' GROUP BY x
Alright. Let’s store it as a CSV file by adding this to the sql query:
into outfile 'btc-usd-matches-5-minute.csv' fields terminated by ',' enclosed by '' lines terminated by '\n';
followed by feeding data into arima script.
Results are presented on the screenshot (red-predicted, by always 1 move ahead, blue – original data):
and a Visual Studio Code screenshot with some of the console data:
Looks good and quite promising. There is quite a good prediction what happens next over 5 minutes.
Final screenshot show that 5 minute interval was 173 transactions between selected datetime range:
With that idea I could try to have a little bit more automation in prepping data and forecasting next price in the timespan of 5 minutes. Assuming there could be hundrends of transactions I could place buy/sell order with the predicted amount and just wait 5 minutes in order to find out. In the meantime script will be forecasting next interval fed with new real data. Interesting! Need to try that!
Thanks for reading,