zcakhaa / DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books

This jupyter notebook is used to demonstrate our recent work, "DeepLOB: Deep Convolutional Neural Networks for Limit Order Books", published in IEEE Transactions on Singal Processing. We use FI-2010 dataset and present how model architecture is constructed here. The FI-2010 is publicly avilable and interested readers can check out their paper.
374 stars 205 forks source link

Another question for help #5

Open willinglion opened 3 years ago

willinglion commented 3 years ago

'The labels are then decided based on a threshold (a) for the percentage change (lt).' What is the method which can be used to set the value of the threshold?

zcakhaa commented 3 years ago

l_t is defined in Equation 4 in the paper. You can set a \alpha and then use l_t to decide labels. [cid:202bbf1f-7993-4b2a-82fb-267ee335cd64]


From: willinglion notifications@github.com Sent: Friday, January 15, 2021 1:20 PM To: zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books] Another question for help (#5)

'The labels are then decided based on a threshold (a) for the percentage change (lt).' What is the method which can be used to set the value of the threshold?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books/issues/5, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFN66TFP4IGTULS4OO4SSWTS2A6IVANCNFSM4WEBNS7Q.

willinglion commented 3 years ago

l_t has its method in the paper. but a \alpha I do not know how to set it. I set several a \alpha by man-made. the results of accuracy is far away from them in your paper. How can I set a \alpha? Must I loop through all possible values of a \alpha to see which one has the best results?

zcakhaa commented 3 years ago

The choice of \alpha depends on your application. For academic purposes, we set \alpha for each stock to have a balanced training set. In practice, you can set it to a higher threshold to trade only if the movement is great. I don't think you should loop through all \alpha to just get good results.


From: willinglion notifications@github.com Sent: Saturday, January 16, 2021 1:44 PM To: zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books@noreply.github.com Cc: Zihao Zhang zhangzihao@hotmail.co.uk; Comment comment@noreply.github.com Subject: Re: [zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books] Another question for help (#5)

l_t has its method in the paper. but a \alpha I do not know how to set it. I set several a \alpha by man-made. the results of accuracy is far away from them in your paper. How can I set a \alpha? Must I loop through all possible values of a \alpha to see which one has the best results?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books/issues/5#issuecomment-761565671, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFN66TE2YP5C2JXQU4WCU4TS2GJ4TANCNFSM4WEBNS7Q.

willinglion commented 3 years ago

what you mean 'have a balanced training set' is let the proportion(1,0,-1) to be 1:1:1?

zcakhaa commented 3 years ago

Yes, each class accounts for about 33% in the training data


From: willinglion notifications@github.com Sent: Saturday, January 16, 2021 2:35 PM To: zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books@noreply.github.com Cc: Zihao Zhang zhangzihao@hotmail.co.uk; Comment comment@noreply.github.com Subject: Re: [zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books] Another question for help (#5)

what you mean 'have a balanced training set' is let the proportion(1,0,-1) to be 1:1:1?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books/issues/5#issuecomment-761573408, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFN66TC57FWJ2W2NA5VO523S2GPZZANCNFSM4WEBNS7Q.

willinglion commented 3 years ago

Great, thank you. higher thresholds can help Trading Strategy get more profit. I have try some higher thresholds, and it will make the class aacount(0) higher, such as 20%:60%:20%. The model can learn the accuracy more than 60%. but the accuracy is mainly for the class aacount(0). it is very low for the class aacounts(-1,1). it is get a bad profit for Trading Strategy, only class aacounts(-1,1) making trade. So i think the imbalance of class aacounts will let the model always select 0 for classification and get worse result comparing with mean proportion 33%. it is confuse me how to make the model get a better result by higher thresholds. Can you give me some suggestion?

zcakhaa commented 3 years ago

You can check our paper on discussing trading rules: https://arxiv.org/abs/1811.10041. Not necessarily related to label parameter \alpha, but it would be helpful. A higher threshold is needed when you take transaction costs into account and you can set \alpha to your cost, so you know at least the movement is greater than your cost.


From: willinglion notifications@github.com Sent: Saturday, January 16, 2021 3:16 PM To: zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books@noreply.github.com Cc: Zihao Zhang zhangzihao@hotmail.co.uk; Comment comment@noreply.github.com Subject: Re: [zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books] Another question for help (#5)

Great, thank you. higher thresholds can help Trading Strategy get more profit. I have try some higher thresholds, and it will make the class aacount(0) higher, such as 20%:60%:20%. The model can learn the accuracy more than 60%. but the accuracy is mainly for the class aacount(0). it is very low for the class aacounts(-1,1). it is get a bad profit for Trading Strategy, only class aacounts(-1,1) making trade. So i think the imbalance of class aacounts will let the model always select 0 for classification and get worse result comparing with mean proportion 33%. it is confuse me how to make the model get a better result by higher thresholds. Can you give me some suggestion?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books/issues/5#issuecomment-761579969, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFN66TFQSGGCBU2J7RUE77LS2GUVZANCNFSM4WEBNS7Q.

willinglion commented 3 years ago

Thanks for you help. I really need a higher threshold, as the transaction cost is not free.

willinglion commented 3 years ago

I have read your paper 'BDLOB: Bayesian Deep Convolutional Neural Networks for Limit Order Books'. The solution with Bayesian networks is so wonderful. I do not find code for Bayesian network in your project. 'we add a we apply a dropout layer with rate 0.2 after the Inception Module, decided using grid-search methods'. Is it the code as following?

use the MC dropout here

conv_reshape = Reshape((int(convsecond_output.shape[1]), int(convsecond_output.shape[3])))(convsecond_output)
zcakhaa commented 3 years ago

Code is not published, but it is very simple to implement. You just need to use dropout and enable it during the testing period.


From: willinglion notifications@github.com Sent: Wednesday, January 20, 2021 1:18 PM To: zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books@noreply.github.com Cc: Zihao Zhang zhangzihao@hotmail.co.uk; Comment comment@noreply.github.com Subject: Re: [zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books] Another question for help (#5)

I have read your paper 'BDLOB: Bayesian Deep Convolutional Neural Networks for Limit Order Books'. The solution with Bayesian networks is so wonderful. I do not find code for Bayesian network in your project. 'we add a we apply a dropout layer with rate 0.2 after the Inception Module, decided using grid-search methods'. Is it the code as following?

use the MC dropout here

conv_reshape = Reshape((int(convsecond_output.shape[1]), int(convsecond_output.shape[3])))(convsecond_output)

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books/issues/5#issuecomment-763600263, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFN66TGUNFDZGXTICZK5DZTS23J25ANCNFSM4WEBNS7Q.

willinglion commented 3 years ago

I add a dropout layer with rate 0.2 after the Inception Module and applied Concrete Dropout to convolutional layers in the Inception Module, by import the class ConcreteDropout(Wrapper) in the paper Concrete Dropout, as the paper introduce. The code is as following, but it ovefit after several epochs. Can you give me some suggestion about my implement code of your paper?

build the inception module

convsecond_1 = ConcreteDropout(Conv2D(64, (1, 1), padding='same'))(conv_first1)
convsecond_1 = keras.layers.LeakyReLU(alpha=0.01)(convsecond_1)
convsecond_1 = ConcreteDropout(Conv2D(64, (3, 1), padding='same'))(convsecond_1)
convsecond_1 = keras.layers.LeakyReLU(alpha=0.01)(convsecond_1)

convsecond_2 = ConcreteDropout(Conv2D(64, (1, 1), padding='same'))(conv_first1)
convsecond_2 = keras.layers.LeakyReLU(alpha=0.01)(convsecond_2)
convsecond_2 = ConcreteDropout(Conv2D(64, (5, 1), padding='same'))(convsecond_2)
convsecond_2 = keras.layers.LeakyReLU(alpha=0.01)(convsecond_2)

convsecond_3 = MaxPooling2D((3, 1), strides=(1, 1), padding='same')(conv_first1)
convsecond_3 = ConcreteDropout(Conv2D(64, (1, 1), padding='same'))(convsecond_3)
convsecond_3 = keras.layers.LeakyReLU(alpha=0.01)(convsecond_3)

convsecond_output = keras.layers.concatenate([convsecond_1, convsecond_2, convsecond_3], axis=3)

# use the MC dropout here
convsecond_output_drop = Dropout(0.2)(convsecond_output)
conv_reshape = Reshape((int(convsecond_output.shape[1]), int(convsecond_output.shape[3])))(convsecond_output_drop)

# build the last LSTM layer
conv_lstm = CuDNNLSTM(number_of_lstm)(conv_reshape)
zcakhaa commented 3 years ago

You need to enable the dropout during testing, otherwise the dropout is switched off. Also, you need to use mask to drop the entire sequence of a feature map from the Inception module.


From: willinglion notifications@github.com Sent: Thursday, January 21, 2021 12:05 PM To: zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books@noreply.github.com Cc: Zihao Zhang zhangzihao@hotmail.co.uk; Comment comment@noreply.github.com Subject: Re: [zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books] Another question for help (#5)

I add a dropout layer with rate 0.2 after the Inception Module and applied Concrete Dropout to convolutional layers in the Inception Module, by import the class ConcreteDropout(Wrapper) in the paper Concrete Dropout, as the paper introduce. The code is as following, but it ovefit after several epochs. Can you give me some suggestion about my implement code of your paper?

build the inception module

convsecond_1 = ConcreteDropout(Conv2D(64, (1, 1), padding='same'))(conv_first1) convsecond_1 = keras.layers.LeakyReLU(alpha=0.01)(convsecond_1) convsecond_1 = ConcreteDropout(Conv2D(64, (3, 1), padding='same'))(convsecond_1) convsecond_1 = keras.layers.LeakyReLU(alpha=0.01)(convsecond_1)

convsecond_2 = ConcreteDropout(Conv2D(64, (1, 1), padding='same'))(conv_first1) convsecond_2 = keras.layers.LeakyReLU(alpha=0.01)(convsecond_2) convsecond_2 = ConcreteDropout(Conv2D(64, (5, 1), padding='same'))(convsecond_2) convsecond_2 = keras.layers.LeakyReLU(alpha=0.01)(convsecond_2)

convsecond_3 = MaxPooling2D((3, 1), strides=(1, 1), padding='same')(conv_first1) convsecond_3 = ConcreteDropout(Conv2D(64, (1, 1), padding='same'))(convsecond_3) convsecond_3 = keras.layers.LeakyReLU(alpha=0.01)(convsecond_3)

convsecond_output = keras.layers.concatenate([convsecond_1, convsecond_2, convsecond_3], axis=3)

use the MC dropout here

convsecond_output_drop = Dropout(0.2)(convsecond_output) conv_reshape = Reshape((int(convsecond_output.shape[1]), int(convsecond_output.shape[3])))(convsecond_output_drop)

build the last LSTM layer

conv_lstm = CuDNNLSTM(number_of_lstm)(conv_reshape)

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books/issues/5#issuecomment-764597953, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFN66TBQQOALPM6FV25VXYTS3AJ67ANCNFSM4WEBNS7Q.

HaishuoFang commented 3 years ago

Great, thank you. higher thresholds can help Trading Strategy get more profit. I have try some higher thresholds, and it will make the class aacount(0) higher, such as 20%:60%:20%. The model can learn the accuracy more than 60%. but the accuracy is mainly for the class aacount(0). it is very low for the class aacounts(-1,1). it is get a bad profit for Trading Strategy, only class aacounts(-1,1) making trade. So i think the imbalance of class aacounts will let the model always select 0 for classification and get worse result comparing with mean proportion 33%. it is confuse me how to make the model get a better result by higher thresholds. Can you give me some suggestion?

I have the same problem, do you try to downsample class 0 to make balanced data?

zcakhaa commented 3 years ago

Hi, in general, I don't downsample the data to make it balance, but I guess you can always try and compare the results. Otherwise, you can use some weighted loss function to correct this.


From: Haishuo @.> Sent: Friday, April 23, 2021 5:20 PM To: zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books @.> Cc: Zihao Zhang @.>; Comment @.> Subject: Re: [zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books] Another question for help (#5)

Great, thank you. higher thresholds can help Trading Strategy get more profit. I have try some higher thresholds, and it will make the class aacount(0) higher, such as 20%:60%:20%. The model can learn the accuracy more than 60%. but the accuracy is mainly for the class aacount(0). it is very low for the class aacounts(-1,1). it is get a bad profit for Trading Strategy, only class aacounts(-1,1) making trade. So i think the imbalance of class aacounts will let the model always select 0 for classification and get worse result comparing with mean proportion 33%. it is confuse me how to make the model get a better result by higher thresholds. Can you give me some suggestion?

I have the same problem, do you try to downsample class 0 to make balanced data?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/zcakhaa/DeepLOB-Deep-Convolutional-Neural-Networks-for-Limit-Order-Books/issues/5#issuecomment-825802144, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFN66TFMELG3WELNATDQ6E3TKGT53ANCNFSM4WEBNS7Q.