File size: 22,753 Bytes
d09db33 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
\documentclass[11pt]{article}
\usepackage[margin=0.5in]{geometry}
% Core packages
\usepackage{amsmath,amssymb,enumitem}
\usepackage{tikz-cd}
\usepackage{multicol}
% Paragraphs
\setlength{\parindent}{0pt}
\setlength{\parskip}{1\baselineskip}
\title{Simulated Trades}
\author{algorembrant}
\date{\today}
\begin{document}
\maketitle
\begin{abstract}
This paper presents a comprehensive framework for generating simulated trade signals through lookahead analysis. We introduce a systematic methodology with mathematical formalization for calculating entry prices, stoploss levels, takeprofit targets, recovery prices, and adverse loss levels, along with their associated ratios. The framework employs a scoring system to determine valid trades and organizes the resulting data for use in reinforcement learning applications. Our approach provides a novel dataset structure that captures optimal price levels and timing information for each time index.
\end{abstract}
\section{Notations}
Let:
\begin{align*}
t &= \text{be the \textcolor{red}{time-index}}\\
\overrightarrow{t} &= \text{be the \textcolor{red}{time-index from lookahead}, where } \overrightarrow{t} \in \{t+n\}, \text{ with } n \in \{0,1,2,\ldots,\infty\},\\
\overline{t} &= \text{be any time-index in between } t \text{ and } \overrightarrow{t} \text{, where } t \le \overline{t} \le \overrightarrow{t} \\
E_t &= \text{be the \textcolor{red}{Entry Price} at } t \\
\Omega_{\overrightarrow{t}} &= \text{be the \textcolor{red}{Stoploss Price} at } \overrightarrow{t} \\
T_{\overrightarrow{t}} &= \text{be the \textcolor{red}{Takeprofit Price} at } \overrightarrow{t} \\
R_{\overrightarrow{t}} &= \text{be the \textcolor{red}{Recovery Price} at } \overrightarrow{t} \\
A_{\overrightarrow{t}} &= \text{be the \textcolor{red}{Adverseloss Price} at } \overrightarrow{t} \\
Q_{\overrightarrow{t}} &= \text{be the \textcolor{red}{$A_{\overrightarrow{t}}:\Omega_{\overrightarrow{t}}$ Ratio} or Q-Ratio at } \overrightarrow{t} \\
W_{\overrightarrow{t}} &= \text{be the \textcolor{red}{$R_{\overrightarrow{t}}:T_{\overrightarrow{t}}$ Ratio} or W-Ratio at } \overrightarrow{t} \\
Y_{\overrightarrow{t}} &= \text{be the \textcolor{red}{$\Omega_{\overrightarrow{t}}:T_{\overrightarrow{t}}$ Ratio} or Y-Ratio at } \overrightarrow{t} \\
V_t &= \{E_t, \Omega_{\overrightarrow{t}}, T_{\overrightarrow{t}}, R_{\overrightarrow{t}}, A_{\overrightarrow{t}}, Q_{\overrightarrow{t}}, W_{\overrightarrow{t}}, Y_{\overrightarrow{t}}\} \text{, be the \textcolor{red}{Set of all Values}, where values at } \overrightarrow{t} \text{ are carried by } t \\
P &\in \{H,O,C,L\} = \text{be the \textcolor{red}{Price} with } \{ \text{High, Open, Close, Low} \} \text{ respectively} \\
\Omega_t &= \text{be } \Omega_{\overrightarrow{t}} \text{ brought back to time-index } t \\
T_t &= \text{be } T_{\overrightarrow{t}} \text{ brought back to time-index } t \\
R_t &= \text{be } R_{\overrightarrow{t}} \text{ brought back to time-index } t \\
A_t &= \text{be } A_{\overrightarrow{t}} \text{ brought back to time-index } t \\
Q_t &= \text{be } Q_{\overrightarrow{t}} \text{ brought back to time-index } t \\
W_t &= \text{be } W_{\overrightarrow{t}} \text{ brought back to time-index } t \\
Y_t &= \text{be } Y_{\overrightarrow{t}} \text{ brought back to time-index } t \\
V_t &= \{E_t, \Omega_t, T_t, R_t, A_t, Q_t, W_t, Y_t\} = \{E_t, \Omega_{\overrightarrow{t}}, T_{\overrightarrow{t}}, R_{\overrightarrow{t}}, A_{\overrightarrow{t}}, Q_{\overrightarrow{t}}, W_{\overrightarrow{t}}, Y_{\overrightarrow{t}}\} \\
\mathcal{T}_t^{\text{null}} &= \text{be the null or invalid trade, representing no trade at time-index } t \\
\mathcal{T}_t^{\text{valid}} &= \text{be the valid trade, representing an eligible trade (either buyside or sellside) at time-index } t \\
J^T_{\overrightarrow{t}} &= \text{be the timeout time for Takeprofit target, from lookahead } \overrightarrow{t} \\
J^R_{\overrightarrow{t}} &= \text{be the timeout time for Recovery target, from lookahead } \overrightarrow{t} \\
F^T_{\overrightarrow{t}} &= \text{be the Close Price at timeout for Takeprofit target, from lookahead } \overrightarrow{t} \\
F^R_{\overrightarrow{t}} &= \text{be the Close Price at timeout for Recovery target, from lookahead } \overrightarrow{t} \\
J^T_t &= \text{be } J^T_{\overrightarrow{t}} \text{ brought back to time-index } t \\
J^R_t &= \text{be } J^R_{\overrightarrow{t}} \text{ brought back to time-index } t \\
F^T_t &= \text{be } F^T_{\overrightarrow{t}} \text{ brought back to time-index } t \\
F^R_t &= \text{be } F^R_{\overrightarrow{t}} \text{ brought back to time-index } t
\end{align*}
\newpage
\section{Values at Time-Index $t$}
\subsection{Entry Price}
By default, we use a 3-minute timeframe. We always buy and sell at $E_t$ (we enter at the Open Price based on the previous bar's Close price, therefore $E_t = O_t$) at the same time-index.
\subsection{Stoploss Price}
We begin by calculating our \textcolor{red}{average of maximum imaginary adverse excursion}, formalized as:
\begin{align}
\omega &= \frac{1}{K}\sum_{t=0}^{K-1}
\begin{cases}
\max\left(O_{-t} - L_{-t},\; |O_{-t}-C_{-t-1}|,\; |L_{-t}-C_{-t-1}|\right), & \text{if } O_{-t} < C_{-t} \\[6pt]
\max\left(|O_{-t} - H_{-t}|,\; |O_{-t}-C_{-t-1}|,\; |H_{-t}-C_{-t-1}|\right), & \text{if } O_{-t} > C_{-t}
\end{cases}
\end{align}
This captures the average of wicks and gaps within the total lookback $\textcolor{blue}{K}$. The default value is $K=20$ with a step of $1$, which does not include high-low ranges.
Therefore, the stoploss placement is:
\begin{align}
\Omega_t &=
\begin{cases}
O_t -(\omega_{t-1} \cdot s_t\cdot m), & \text{for } E_t^{\text{buyside}} \\[4pt]
O_t +(\omega_{t-1} \cdot s_t \cdot m), & \text{for } E_t^{\text{sellside}}
\end{cases}
\quad \text{\textcolor{red}{Stoploss Price}}
\end{align}
Where $s_t$ is the live spread at the time-index provided by the broker in real time, and $\textcolor{blue}{m}$ is a multiplier. The default value is $m=10$ with a step of $5$. The index $-1$ from $\omega_{t-1}$ ensures our projected stoploss is valid and not exposed to lookahead bias.
\section{Values at Time-Index Lookahead $\overrightarrow{t}$}
\subsection{Recovery Price}
We calculate $P^{\text{extreme}}_{\overline{t}}$ as time moves forward:
\begin{align}
P^{\text{extreme}}_{\overline{t}} =
\begin{cases}
\displaystyle\max_{t \le \overline{t} \le \overrightarrow{t}} [\max P_{\overline{t}}], & \text{for } E_t^{\text{buyside}} \\[10pt]
\displaystyle\min_{t \le \overline{t} \le \overrightarrow{t}} [\min P_{\overline{t}}], & \text{for } E_t^{\text{sellside}}
\end{cases}
\quad \text{where } P_{\overline{t}} \in \{H_{\overrightarrow{t}}, O_{\overrightarrow{t}}, C_{\overrightarrow{t}}, L_{\overrightarrow{t}}\}
\end{align}
\begin{align}
S_{\overrightarrow{t}} =
\begin{cases}
\left| \Omega_t - \displaystyle\max_{t \le \overline{t} \le \overrightarrow{t}} [\max P_{\overline{t}}] \right| \times d + \Omega_t, & \text{for } E_t^{\text{buyside}} \\[12pt]
\left| \Omega_t - \displaystyle\min_{t \le \overline{t} \le \overrightarrow{t}} [\min P_{\overline{t}}] \right| \times d - \Omega_t, & \text{for } E_t^{\text{sellside}}
\end{cases}
\quad \text{Stop Criterion}
\end{align}
Where $\textcolor{blue}{d}$ is the divisor, with default value $d = 0.50$ and step $0.10$. The $S_{\overrightarrow{t}}$ serves as a criterion: if the price breaches the boundary, we register that time as:
\begin{align}
R_{\overrightarrow{t}} =
\begin{cases}
[\min P_{\overline{t}}] < S_{\overrightarrow{t}}^{\text{buyside}} \implies C_{\overrightarrow{t}}, & \text{for } E_t^{\text{buyside}} \\[6pt]
[\max P_{\overline{t}}] > S_{\overrightarrow{t}}^{\text{sellside}} \implies C_{\overrightarrow{t}}, & \text{for } E_t^{\text{sellside}}
\end{cases}
\quad \text{\textcolor{red}{Recovery Price}}
\end{align}
\subsection{Takeprofit Price}
With $R_{\overrightarrow{t}}$ established, we calculate the optimal takeprofit levels:
\begin{align}
T_{\overrightarrow{t}} =
\begin{cases}
\displaystyle\left(\max_{t_{E_t} \le \overline{t} \le \overrightarrow{t}_{R_{\overrightarrow{t}}}} [\max P_{\overline{t}}] \right) - (s_t \times l), & \text{for } E_t^{\text{buyside}} \\[12pt]
\displaystyle\left(\min_{t_{E_t} \le \overline{t} \le \overrightarrow{t}_{R_{\overrightarrow{t}}}} [\min P_{\overline{t}}] \right) + (s_t \times l), & \text{for } E_t^{\text{sellside}}
\end{cases}
\quad \text{\textcolor{red}{Takeprofit Price}}
\end{align}
Where $l$ is a multiplier with default value $l = 2$ and step $1$.
\subsection{Adverse Price}
With $T_{\overrightarrow{t}}$ established, we calculate the optimal adverseloss levels:
\begin{align}
A_{\overrightarrow{t}} =
\begin{cases}
\displaystyle\min_{t_{E_t} \le \overline{t} \le \overrightarrow{t}_{T_{\overrightarrow{t}}}} [\min P_{\overline{t}}], & \text{for } E_t^{\text{buyside}} \\[12pt]
\displaystyle\max_{t_{E_t} \le \overline{t} \le \overrightarrow{t}_{T_{\overrightarrow{t}}}} [\max P_{\overline{t}}], & \text{for } E_t^{\text{sellside}}
\end{cases}
\quad \text{\textcolor{red}{Adverseloss Price}}
\end{align}
\subsection{Q-Ratio or $A_{\overrightarrow{t}}:\Omega_{\overrightarrow{t}}$ Ratio}
The ratio of Adverse Price to Stoploss Price is:
\begin{align}
Q_{\overrightarrow{t}} =
\begin{cases}
\left|\displaystyle\frac{E_t - A_{\overrightarrow{t}}^{\text{buyside}}}{E_t - \Omega_t^{\text{buyside}}} \right|, & \text{for } E_t^{\text{buyside}} \\[12pt]
\left| \displaystyle\frac{E_t - A_{\overrightarrow{t}}^{\text{sellside}}}{E_t - \Omega_t^{\text{sellside}}} \right|, & \text{for } E_t^{\text{sellside}}
\end{cases}
\quad \text{\textcolor{red}{$A_{\overrightarrow{t}}:\Omega_{\overrightarrow{t}}$ Ratio}}
\end{align}
\subsection{W-Ratio or $R_{\overrightarrow{t}}:T_{\overrightarrow{t}}$ Ratio}
The ratio of Recovery Price to Takeprofit Price is:
\begin{align}
W_{\overrightarrow{t}} =
\begin{cases}
\left| \displaystyle\frac{E_t - R_{\overrightarrow{t}}^{\text{buyside}}}{E_t - T_{\overrightarrow{t}}^{\text{buyside}}} \right|, & \text{for } E_t^{\text{buyside}} \\[12pt]
\left| \displaystyle\frac{E_t - R_{\overrightarrow{t}}^{\text{sellside}}}{E_t - T_{\overrightarrow{t}}^{\text{sellside}}} \right|, & \text{for } E_t^{\text{sellside}}
\end{cases}
\quad \text{\textcolor{red}{$R_{\overrightarrow{t}}:T_{\overrightarrow{t}}$ Ratio}}
\end{align}
\subsection{Y-Ratio or $\Omega_{\overrightarrow{t}}:T_{\overrightarrow{t}}$ Ratio}
The ratio of Stoploss Price to Takeprofit Price is:
\begin{align}
Y_{\overrightarrow{t}} =
\begin{cases}
\left| \displaystyle\frac{E_t - \Omega_t^{\text{buyside}}}{E_t - T_{\overrightarrow{t}}^{\text{buyside}}} \right|, & \text{for } E_t^{\text{buyside}} \\[12pt]
\left| \displaystyle\frac{E_t - \Omega_t^{\text{sellside}}}{E_t - T_{\overrightarrow{t}}^{\text{sellside}}} \right|, & \text{for } E_t^{\text{sellside}}
\end{cases}
\quad \text{\textcolor{red}{$\Omega_{\overrightarrow{t}}:T_{\overrightarrow{t}}$ Ratio}}
\end{align}
\section{Set of Values at Time-Index $t$}
We construct $V_t$, the set of all values from time-index $t$ and time-index lookahead $\overrightarrow{t}$:
\begin{align}
V_t = \{E_t, \Omega_{\overrightarrow{t}}, T_{\overrightarrow{t}}, R_{\overrightarrow{t}}, A_{\overrightarrow{t}}, Q_{\overrightarrow{t}}, W_{\overrightarrow{t}}, Y_{\overrightarrow{t}}\}, \quad \text{\textcolor{red}{Set of all Values}}
\end{align}
Note that $V$ has a time-index of $t$, carrying all values from both $t$ and $\overrightarrow{t}$. In dataframe terms, $V_t$ represents all values written in the same row as \{datetime, open, high, low, close, tick volume\} CSV variables.
This methodology lags more than conventional indicators; therefore, it is best used as a new form of dataset rather than a trading signal. For example, a dataset consisting of optimal price levels for ordering at a given time can be used to engineer the reward function of a Reinforcement Learning model.
\section{The Valid $V_t$ at Time-Index $t$}
\subsection{Deviating from $E_t$}
We find the deviation of price-based elements $\{\Omega_{\overrightarrow{t}}, T_{\overrightarrow{t}}, R_{\overrightarrow{t}}, A_{\overrightarrow{t}}\}$ from $E_t$. For an element $v$ of $V_t$:
\begin{align}
\text{Dev}(v) =
\begin{cases}
\left| E_t - \Omega_{\overrightarrow{t}} \right|, & \text{Stoploss Deviation} \\
\left| E_t - T_{\overrightarrow{t}} \right|, & \text{Takeprofit Deviation} \\
\left| E_t - R_{\overrightarrow{t}} \right|, & \text{Recovery Deviation} \\
\left| E_t - A_{\overrightarrow{t}} \right|, & \text{Adverse Deviation}
\end{cases}
\end{align}
\subsection{Simplifying the Elements of $V_t$}
Since all elements with index $\overrightarrow{t}$ are carried back to the same time-index as $E_t$ (which is $t$), we simplify:
\begin{align}
V_t = \{E_t, \Omega_{\overrightarrow{t}}, T_{\overrightarrow{t}}, R_{\overrightarrow{t}}, A_{\overrightarrow{t}}, Q_{\overrightarrow{t}}, W_{\overrightarrow{t}}, Y_{\overrightarrow{t}}\}
\implies
V_t = \{E_t, \Omega_t, T_t, R_t, A_t, Q_t, W_t, Y_t\}
\end{align}
\subsection{Assigning Points}
At time-index $t$, there will be both buy and sell entries, each with corresponding elements to obtain their own $V_t$. We care only about one side (buyside $bs$ or sellside $ss$) that will have the Valid $V_t$.
\begin{align}
\text{Point }(v^{bs},v^{ss}) =
\begin{cases}
(E_t^{bs} = E_t^{ss}) &\implies (1,1) \\
(\Omega_t^{bs,\text{Dev}} > \Omega_t^{ss,\text{Dev}}) &\implies (0,1) \\
(\Omega_t^{bs,\text{Dev}} < \Omega_t^{ss,\text{Dev}}) &\implies (1,0) \\
(T_t^{bs,\text{Dev}} > T_t^{ss,\text{Dev}}) &\implies (1,0) \\
(T_t^{bs,\text{Dev}} < T_t^{ss,\text{Dev}}) &\implies (0,1) \\
(R_t^{bs,\text{Dev}} > R_t^{ss,\text{Dev}}) &\implies (1,0) \\
(R_t^{bs,\text{Dev}} < R_t^{ss,\text{Dev}}) &\implies (0,1) \\
(A_t^{bs,\text{Dev}} > A_t^{ss,\text{Dev}}) &\implies (0,1) \\
(A_t^{bs,\text{Dev}} < A_t^{ss,\text{Dev}}) &\implies (1,0) \\
(Q_t^{bs} > Q_t^{ss}) &\implies (0,1) \\
(Q_t^{bs} < Q_t^{ss}) &\implies (1,0) \\
(W_t^{bs} > W_t^{ss}) &\implies (1,0) \\
(W_t^{bs} < W_t^{ss}) &\implies (0,1) \\
(Y_t^{bs} > Y_t^{ss}) &\implies (1,0) \\
(Y_t^{bs} < Y_t^{ss}) &\implies (0,1)
\end{cases}
\end{align}
Where $v$ is an element of $V_t$. The rules are:
\begin{itemize}[label=$\rightarrow$]
\item For Entry Price, both sides get 1 point (same open price)
\item For Stoploss, the side with lesser deviation gets 1 point
\item For Takeprofit, the side with greater deviation gets 1 point
\item For Recovery, the side with greater deviation gets 1 point
\item For Adverseloss, the side with lesser deviation gets 1 point
\item For Q-Ratio, the side with lesser value gets 1 point
\item For W-Ratio, the side with greater value gets 1 point
\item For Y-Ratio, the side with greater value gets 1 point
\end{itemize}
\subsection{Score Calculator}
\subsubsection{Normal Scoring}
With points assigned, we calculate the score:
\begin{align}
\text{Score}(V_t^{bs},V_t^{ss}) = \left( \sum_{\text{all Point}(v^{bs})} \text{Point}(v^{bs}),\; \sum_{\text{all Point}(v^{ss})} \text{Point}(v^{ss}) \right)
\end{align}
This sums all points of elements for each side. Normally, one side will have a greater or lesser total.
\subsubsection{Special Scoring}
If a trade has an invalid element (e.g., Takeprofit Deviation smaller than Stoploss Deviation), we invalidate it:
\begin{align}
\text{Score}(V_t^{bs},V_t^{ss}) = (Y_t^{bs} < 1) \oplus (Y_t^{ss} < 1) \implies (0,0)
\end{align}
If $Y_t < 1$ for either side, that side is automatically invalid.
\subsection{Valid $V_t$}
With total scores determined, we decide which side remains at time-index $t$:
\begin{align}
\text{Valid}(V_t^{bs},V_t^{ss}) =
\begin{cases}
(1,0), & \text{if } \text{Score}(V_t^{bs}) > \text{Score}(V_t^{ss}), \quad \text{favor the buyside} \\
(0,1), & \text{otherwise}, \quad \text{favor the sellside}
\end{cases}
\end{align}
\subsection{Null $V_t$}
\begin{align}
\text{Null}(V_t^{bs},V_t^{ss}) =
\begin{cases}
(1,0), & \text{if } \text{Score}(V_t^{bs}) = 0 \\
(0,1), & \text{if } \text{Score}(V_t^{ss}) = 0
\end{cases}
\end{align}
\section{Organizing The Valid $V_t$'s}
\subsection{Valid and Null Trades $\mathcal{T}$}
The process includes both buy and sell entries at the same time-index $t$. Corresponding elements are calculated (lookahead calculations are performed and brought back to time-index $t$), then points are assigned to determine scores for validation. Only one side remains:
\begin{align}
\mathcal{T}_t^{\text{valid}} = (\text{Valid }(V_t^{bs}) = 1) \oplus (\text{Valid }(V_t^{ss}) = 1)
\end{align}
And
\begin{align}
\mathcal{T}_t^{\text{null}} = (\text{Null }(V_t^{bs}) = 1) \land (\text{Null }(V_t^{ss}) = 1)
\end{align}
\subsection{Scaling the Number of Trades}
Simulated trades are conducted for each time-index $t$ (parallel calculations are recommended due to computational intensity) and filtered by assigning whether $\mathcal{T}_t^{\text{valid}}$ (either buyside or sellside) or $\mathcal{T}_t^{\text{null}}$ (no side, no trade) is appropriate. The resulting time-series data appears as:
\begin{align}
\{\mathcal{T}_t^{\text{valid}}, \mathcal{T}_t^{\text{null}}, \mathcal{T}_t^{\text{valid}}, \mathcal{T}_t^{\text{valid}}, \mathcal{T}_t^{\text{valid}}, \mathcal{T}_t^{\text{null}},\ldots,\mathcal{T}_t^{\text{?}}\}
\end{align}
Where $\mathcal{T}_t^{\text{valid}}$ corresponds to values and elements from either the buyside or sellside.
\section{Recommendations for Implementation}
\subsection{Representing the Elements of $V_t$ on Chart}
Representing these elements on a chart is complex. It is recommended to represent $\{E_t, \Omega_{\overrightarrow{t}}, T_{\overrightarrow{t}}, R_{\overrightarrow{t}}, A_{\overrightarrow{t}} \}$ as single dots in an overlayed line plot at time-index $t$, and $\{Q_{\overrightarrow{t}}, W_{\overrightarrow{t}}, Y_{\overrightarrow{t}}\}$ as bars in a separate barchart pane (as they cannot be represented as prices). The deviations $\{\Omega_t^{\text{Dev}}, T_t^{\text{Dev}}, R_t^{\text{Dev}}, A_t^{\text{Dev}} \}$ can also be plotted as bars in another separate pane.
\subsection{Dataset for Reinforcement Learning}
Individual rows of a dataframe from a CSV file may have a row of \{datetime, open, high, low, close, tick volume\} as raw data. The new dataset is organized in the same row as the raw data:
\[
\{\mathcal{T}_t^{\text{valid}}, \mathcal{T}_t^{\text{null}}, V_t^{bs}, V_t^{ss}, E_t, \Omega_t, T_t, R_t, A_t, Q_t, W_t, Y_t, \Omega_t^{\text{Dev}}, T_t^{\text{Dev}}, R_t^{\text{Dev}}, A_t^{\text{Dev}}\}
\]
We introduce timeout times as time indicators for the agent to force exit if targets are not reached in real environments:
\begin{align}
J^T_{\overrightarrow{t}} &=
\begin{cases}
\text{Count}(t_{0,E_t^{bs}}, t_1, \ldots, t_{j,T_{\overrightarrow{t}}^{bs}}), & \text{for buyside} \\
\text{Count}(t_{0,E_t^{ss}}, t_1, \ldots, t_{j,T_{\overrightarrow{t}}^{ss}}), & \text{for sellside}
\end{cases} \\[10pt]
J^R_{\overrightarrow{t}} &=
\begin{cases}
\text{Count}(t_{0,E_t^{bs}}, t_1, \ldots, t_{j,R_{\overrightarrow{t}}^{bs}}), & \text{for buyside} \\
\text{Count}(t_{0,E_t^{ss}}, t_1, \ldots, t_{j,R_{\overrightarrow{t}}^{ss}}), & \text{for sellside}
\end{cases}
\end{align}
Both $J^T$ and $J^R$ enable the agent to force exit if pending targets are not reached during real-time environments.
Once the timeout is reached, use the close price at that time to force-exit:
\begin{align}
F^T_{\overrightarrow{t}} &=
\begin{cases}
C_{\overrightarrow{t}}^{J^T,bs}, & \text{for buyside} \\
C_{\overrightarrow{t}}^{J^T,ss}, & \text{for sellside}
\end{cases} \\[10pt]
F^R_{\overrightarrow{t}} &=
\begin{cases}
C_{\overrightarrow{t}}^{J^R,bs}, & \text{for buyside} \\
C_{\overrightarrow{t}}^{J^R,ss}, & \text{for sellside}
\end{cases}
\end{align}
\subsubsection{Simplifying the Notation}
Bringing lookahead values $\overrightarrow{t}$ back to time-index $t$:
\begin{align}
J^T_{\overrightarrow{t}} &\implies J^T_t \\
J^R_{\overrightarrow{t}} &\implies J^R_t \\
F^T_{\overrightarrow{t}} &\implies F^T_t \\
F^R_{\overrightarrow{t}} &\implies F^R_t
\end{align}
\subsubsection{Final Form of the New Dataset}
The final dataset structure is:
\begin{center}
\{$\mathcal{T}_t^{\text{valid}}$, $\mathcal{T}_t^{\text{null}}$, $V_t^{bs}$, $V_t^{ss}$, $E_t$, $\Omega_t$, $T_t$, $R_t$, $A_t$, $Q_t$, $W_t$, $Y_t$, $\Omega_t^{\text{Dev}}$, $T_t^{\text{Dev}}$, $R_t^{\text{Dev}}$, $A_t^{\text{Dev}}$, $J^T_t$, $J^R_t$, $F^T_t$, $F^R_t$\}
\end{center}
This is placed in the same row as the raw dataset for each time-index $t$:
\begin{center}
\{datetime, open, high, low, close, tick volume, $\mathcal{T}_t^{\text{valid}}$, $\mathcal{T}_t^{\text{null}}$, $V_t^{bs}$, $V_t^{ss}$, $E_t$, $\Omega_t$, $T_t$, $R_t$, $A_t$, $Q_t$, $W_t$, $Y_t$, $\Omega_t^{\text{Dev}}$, $T_t^{\text{Dev}}$, $R_t^{\text{Dev}}$, $A_t^{\text{Dev}}$, $J^T_t$, $J^R_t$, $F^T_t$, $F^R_t$\}
\end{center}
\section{Conclusion}
This paper has presented a comprehensive framework for generating simulated trade signals through lookahead analysis. The methodology systematically calculates entry prices, stoploss levels, takeprofit targets, recovery prices, and adverse loss levels, along with their associated ratios. The scoring system effectively determines valid trades, and the resulting data structure is well-suited for reinforcement learning applications.
The framework provides several key contributions:
\begin{enumerate}
\item A rigorous mathematical foundation for trade signal generation
\item A novel dataset structure capturing optimal price levels and timing information
\item A validation mechanism to ensure trade quality
\item Practical implementation recommendations for charting and machine learning applications
\end{enumerate}
Future work may explore optimizing the parameter values ($K$, $m$, $d$, $l$) through systematic backtesting and incorporating additional market microstructure features to enhance signal quality.
\end{document}
|