Yuhei-Handa / STDC_Classification_pycaret

classify DC events have OS ebvent using STDC(single threshold directional change) with pycaret classification model
1 stars 2 forks source link

threshold optimization #1

Closed ericleonardo closed 5 months ago

ericleonardo commented 5 months ago

Hi Yuhei! Why did you use 0.0025 threshold? For better classification result, the threshold must be optimized and tailored for each currency data. Not randomly chosen. The author got average 81% accuracy in the classification phase. Please, check this other paper version on page 19: https://repository.essex.ac.uk/29573/1/Class-Regr-Trading.pdf

image

Thank you so much for sharing your code!

Yuhei-Handa commented 5 months ago

Thank you for your reply.

I certainly wrote some code that could be misleading. I apologize for that.

The threshold=0.0025 doesn't have any special significance. It's simply code to track changes in the DC dataset, and there's no suggestion that this threshold is optimal. I'll add a new comment to clarify.

Upon reviewing the original paper, it seems that DC datasets are generated from real-time data based on various thresholds, and then the top 5 thresholds with the lowest RMSE are selected as the optimal thresholds using GP. However, in this case, there's still a possibility that the labels indicating whether the generated dataset contains OS events could become imbalanced for each threshold. In fact, I extracted several thresholds and plotted the proportion of OS events for the entire dataset as a bar graph.

Thus, the dynamic threshold selection in the original paper may disrupt the balance of labels, potentially leading to inappropriate evaluation during the classification phase.

As one solution, during the generation of the DC dataset, I dynamically adjust the thresholds to ensure that the proportion of labels is closest to 50%, creating a balanced dataset.

image

In the provided code, we use the provisional balanced data generated by the code for classification and evaluation.

While it's true that there's no guarantee of generating balanced data in the GP-based optimal threshold selection, the code prioritizes real-time performance and undergoes frequent data updates, so there's no guarantee that balanced data will always be generated. It's certain that the generation method lacks reliability for evaluation.

ericleonardo commented 5 months ago

Suggestion: you can check if different threshold will have better/worse Classification accuracy. Instead of selecting threshold to force 50% balanced classes, you could select the best threshold for higher classification accuracy (in the training data only, to avoid bias in the test). After the best threshold is found, use Random Under Sampling (ignore some majority class samples), or other tool to balance the data.

Also I will try the TabPFN classifier to see if its accuracy is better. https://arxiv.org/pdf/2207.01848.pdf https://github.com/automl/TabPFN EnsembleTabPFN: https://github.com/ersilia-os/chempfn

I will try to adapt your code to predict Binary Options (if price will go Up or Down for next X time - X can vary, not fixed for all samples, according to OS duration or any other criteria). In BO, you earn 80% to 90% profit if predict the Direction Up/Down of the price for next X time. If prediction is incorrect, all the money in the trade is lost. Tell me if you are interested in Binary Option, we can work in the project. No one ever applied DC framework to binary options.

Please, can you share part of the tick dataset you used? USDJPY_10 Mins_Ask_2003.05.04_2024.03.29.csv Just a little part of it is enough to see the expected data format. Did you download it from Dukascopy?

Thank you, Yuhei!

Yuhei-Handa commented 5 months ago

Thank you for your reply.

Yes. I downloaded it from Dukascopy.

Also, I am interested in applying classification models to DC events as binary options. In time-series deep learning, there's a drawback to the approach of predicting future prices using past prices, as it tends to make predictions that follow the actual values. Therefore, an approach that doesn't predict prices seems appealing, as it incorporates the thought process of actual traders into the theory.

However, there is a concern. Should we be predicting future movements in exchange rates from DCC points? When traders make profits, they assess whether the current point could be a turning point by examining various factors such as price movements, changes in indicators, trendlines, and horizontal lines, by tracing back from the current point to past points. In other words, shouldn't our task be to predict the length of time until each past point that appears to be the OS_End point has passed, rather than predicting the future length and movement from the DC_End point to the OS_End point?

DC

At the conceptual stage, I'm developing a model that predicts turning points without predicting prices using this approach.

I believe it's also possible to output reliability scores simultaneously with labels indicating whether OS has passed, which can be utilized in trading if necessary.

If you don't mind, I'd love to hear your opinion as well!

Yuhei-Handa commented 5 months ago

The structure of the data used is as follows:

Time (UTC),Open,High,Low,Close,Volume 2003.05.04 21:00:00,118.99,118.99,118.944,118.946,1472.9 2003.05.04 21:10:00,118.949,119.032,118.948,118.963,2258.4 2003.05.04 21:20:00,118.964,118.992,118.948,118.969,2092.6 2003.05.04 21:30:00,118.968,118.989,118.968,118.97,1798.3 2003.05.04 21:40:00,118.975,119.003,118.913,119.003,2096.9 2003.05.04 21:50:00,119.006,119.008,118.941,119.006,1966.3 2003.05.04 22:00:00,119.007,119.013,118.981,119.004,1688.8 2003.05.04 22:10:00,119.006,119.02,118.972,119.02,2081.6 2003.05.04 22:20:00,119.012,119.015,118.991,118.998,2095.2 2003.05.04 22:30:00,118.997,119.02,118.991,119.001,2241 2003.05.04 22:40:00,119,119.041,118.989,119.003,2160 2003.05.04 22:50:00,119.002,119.016,118.994,119.005,1461.3 2003.05.04 23:00:00,119.017,119.056,119.016,119.041,2014.5 2003.05.04 23:10:00,119.035,119.038,119.008,119.025,1805.2 2003.05.04 23:20:00,119.026,119.05,118.993,119.018,1622.6 2003.05.04 23:30:00,119.029,119.056,119.009,119.056,1912.2 2003.05.04 23:40:00,119.058,119.07,119.008,119.024,1732.5 2003.05.04 23:50:00,119.025,119.059,119.01,119.059,1990.1 2003.05.05 00:00:00,119.054,119.054,118.991,119.01,2182 2003.05.05 00:10:00,119.014,119.026,118.962,118.973,2027.2

ericleonardo commented 5 months ago

Really! I also realized that predicting financial time series tends to follow last known value like a shadow. That's why DC framework is different, because it ignores most of noise and focus only important movements.

Very interesting your strategy for binary options. I was also thinking about predicting Duration. I thought about predicting OS duration when DCC is confirmed. So, trade in the continuation of trend for X minutes/hours. The scaling law of OS duration being 2x the DC duration was interesting, but doesn't seem to be always true. Many strategies can be explored... Also would like to compare results on Forex currency pairs to Synthetic market. If the synthetic market (generated by Geometric Brownian Motion) follows the same behavior, we can expand opportunities.

I'm happy you are interested in applying DC to binary options. We hope DC will bring more positive results than traditional time series.

Soon I will share more information. Thank you!

Yuhei-Handa commented 5 months ago

Mr. ericleonardo,

Your suggestion is also wonderful. I look forward to your new information.

Thank you!

Yuhei-Handa commented 5 months ago

Hi, Leonardo!

Thank you for your email! I just sent you a message to your email for future communication. I would appreciate it if you could use that from now on. Should I delete the post that contains the email address you previously submitted?

ericleonardo commented 5 months ago

Hi Yuhei! No problem... I'm deleting my email from the message and closing this issue. Talk to you soon by email... Thank you!