![](https://private-user-images.githubusercontent.com/66322644/337323257-3f05d53a-7397-4235-90fe-0e5c75a2e932.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU3NDU2ODUsIm5iZiI6MTcyNTc0NTM4NSwicGF0aCI6Ii82NjMyMjY0NC8zMzczMjMyNTctM2YwNWQ1M2EtNzM5Ny00MjM1LTkwZmUtMGU1Yzc1YTJlOTMyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA3VDIxNDMwNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg4YjVhM2I1MTJlMmQzNTUyNTA1ZmI1ZjQ2MWVkOTE5MTRkY2IxNDExZjczNjhmODQ0ODY4MDkwZGEwNzNmM2QmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.C6bI4SCBMdyE8WoHadSX-uvrpZ8v49fPrBhT1_R93iM)
Convolutional Neural Networks (CNN's) are commonly used in image classifcation tasks because they are able to take into account the spatial structure of an image. This contrasts with a standard neural network, which would treat every pixel as an independent feature.
Just as a 2-D image has red, green and blue channels (which are best interpreted when analysed together) a price-data time-series can be assigned channels representing open/high/low/close prices, and traded volume.
By treating a price-data time-series as a 1-dimensional image, we hope to improve the model's ability to recognise temporal correlations, and therefore predict profitable trading opportunities.
Whilst attempting to predict price movements is a hard problem due to the highly stochastic nature of markets, even weak models can provide enough of a 'gambler's edge' to be profitable, assuming a large enough number of trades, and providing certain caveats are accounted for.
It may be true that markets behave differently at different times of the day or week. By expanding the index of the time series into a one-hot encoded categorical dataset, we can feed this into a separate branch of the CNN, in the hope of increasing its predictive power.
Converts 'open-high-low-close' (OHLC) price data into a format suitable for machine learning. It uses the variance, first-order filters, and significant levels to extract learnable features from the raw data.
Target labels are generated according to (potential) profitable trading conditions being met, whilst time and day labels are separated out and one-hot encoded.
The working dataframe is then transformed into a tensor of dimensions [batch_size, steps, channels] by using a rolling window. Appropriate target labels are selected to match the last timestep in each window, and transformed into a tensors of dimensions [batch_size, categories].
![](https://private-user-images.githubusercontent.com/66322644/337322947-beed5614-225a-498f-bfad-512acb10abf2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU3NDU2ODUsIm5iZiI6MTcyNTc0NTM4NSwicGF0aCI6Ii82NjMyMjY0NC8zMzczMjI5NDctYmVlZDU2MTQtMjI1YS00OThmLWJmYWQtNTEyYWNiMTBhYmYyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA3VDIxNDMwNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE2ZmM5MTRjYzE5ZjlhZWNiMjlkY2E1MjllYjEzNWZmNTc5Mjc1NDMzNzhlOTQwZGU3MzhmNjRiYzI5NjRmYTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.izKRuuRakvWnm8_c2ButojSdxQ2Znhad2aZ_7dBY98U)
![](https://private-user-images.githubusercontent.com/66322644/337322611-b44f5be6-5f52-4c82-bbfb-46c4d18aba32.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU3NDU2ODUsIm5iZiI6MTcyNTc0NTM4NSwicGF0aCI6Ii82NjMyMjY0NC8zMzczMjI2MTEtYjQ0ZjViZTYtNWY1Mi00YzgyLWJiZmItNDZjNGQxOGFiYTMyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA3VDIxNDMwNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ4MjBmNmZjZjhlOWZjMWY0ZTZjOTNlZDA2YzJiMzgzNDIzNjEwMDE1ODJlYmI5MDc1M2Q0MDFjM2Q3YmU1ZDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.6UdSHDfDhmvkWIOM0M7TuP6qxHxEzIkGKQm1uShUZnM)
We can see there are no prediction thresholds where the model is able to unambigously identify the positive class... This is unsurprising given the highly stocastic nature of market movements.
However, it also shows that the model does have a small edge over random guesswork, which may be exploitable given a number of suitably sized/risk-adjusted positions.
Many potential optimisations of the model and training data can also be explored, in particular the predictive lengths and time-series 'bucket' sizes.
Calculate profit factor and drawdown for chosen thresholds, and including commision costs.