
\documentclass[11pt]{article}
\usepackage[margin=0.5in]{geometry}

% Core packages
\usepackage{amsmath,amssymb,mathrsfs,bm,dsfont,bbold,euscript}
\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}
    I formalized how to get the best simulated trades at historical data with the use of mix lookback and lookahead. Although it sound dumb for the first time, the purpose of having a $time$ with rich information such as 
    $\mathcal{V}_{\mathfrak{t}} =
    (
        \mathfrak{E}_{\mathfrak{t}}, \Omega_{\mathfrak{t}}, \mathcal{T}_{\mathfrak{t}}, \mathcal{R}_{\mathfrak{t}}, \mathcal{L}_{\mathfrak{t}}, \mathcal{Q}_\mathfrak{t}, \mathcal{Y}_{\mathfrak{t}}
    )$ as another form of dataset, is benificial for field such as shaping the Reward function in Reinforcement Learning. The following contents will not discuss anything about RL, but a pure mathematital formalization of the said best trade at times $\mathfrak{t}$.
\end{abstract}

\begin{align}
    \mathfrak{E}_{\mathfrak{t}} &= \text{simulated entry at historical time } \mathfrak{t} \\
    O &= open \\
    C &= close \\
    H &= high \\
    L &= low \\
    P &\in \{O,C,H,L\}, \quad \text{raw prices} \\
    \mathfrak{O}_{\mathfrak{t}} &= (O_{\mathfrak{t}} - \mathfrak{E}_{\mathfrak{t}}), \quad \text{deviated open price at historical time } \mathfrak{t} \\
    \mathfrak{C}_{\mathfrak{t}} &= (C_{\mathfrak{t}} - \mathfrak{E}_{\mathfrak{t}}), \quad \text{deviated close price at historical time } \mathfrak{t} \\
    \mathfrak{H}_{\mathfrak{t}} &= (H_{\mathfrak{t}} - \mathfrak{E}_{\mathfrak{t}}), \quad \text{deviated high price at historical time } \mathfrak{t} \\
    \mathfrak{L}_{\mathfrak{t}} &= (L_{\mathfrak{t}} - \mathfrak{E}_{\mathfrak{t}}), \quad \text{deviated low price at historical time } \mathfrak{t} \\
    \mathfrak{P} &\in \{\mathfrak{O},\mathfrak{C},\mathfrak{H},\mathfrak{L}\}, \quad \text{deviated prices} \\
    mfe &= \text{max favorable excursion} \\
    mae &= \text{max adverse excursion} \\
    s_{\mathfrak{t}} &= \text{spread of that historical time, say we have 0.260}
\end{align}

\begin{align}
    t &= \text{current time}\\
    t-n &= \text{where } n \text{ refers to number of lookback} \\
    \dot{t} &= \text{is }  t \ge \dot{t} \ge (t-n) \\
    \mathfrak{t} &= \text{time where \textit{simulated entry} occured, where } \mathfrak{t} \in \{t-n\} \\
    \mathfrak{t} + \mathfrak{n} &= \text{where } \mathfrak{n} \text{ refers to the lookahead or holding period}\\
    \dot{\mathfrak{t}} &= \text{is } \mathfrak{t} \le \dot{\mathfrak{t}} \le (\mathfrak{t} + \mathfrak{n})\\
    \mathbb{t} &= \text{time before } \mathfrak{M} \ge -50\% \text{, where } \mathbb{t} \in \{\max((\mathfrak{t} + \mathfrak{n}) - 1)\} \\
    \mathbb{t} - \mathbb{n} &= \text{where } \mathbb{n} \text{ also refers to number of lookback}\\
    \dot{\mathbb{t}} &= \text{is } \mathbb{t} \ge \dot{\mathbb{t}} \ge (\mathbb{t}-\mathbb{n})\\
\end{align}

\begin{align}
    \mathfrak{X}_{\dot{\mathfrak{t}}} &=
    \begin{cases}
        \text{if buy}, \quad \underbrace{\max_{\mathfrak{t} \le \dot{\mathfrak{t}} \le (\mathfrak{t}+\mathfrak{n})} \mathfrak{H}_{\dot{\mathfrak{t}}}}_{mfe} \\
        \text{if buy}, \quad \underbrace{\min_{\mathfrak{t} \le \dot{\mathfrak{t}} \le (\mathfrak{t}+\mathfrak{n})} \mathfrak{L}_{\dot{\mathfrak{t}}}}_{mae} \\
        \text{if sell}, \quad \underbrace{\max_{\mathfrak{t} \le \dot{\mathfrak{t}} \le (\mathfrak{t}+\mathfrak{n})} \mathfrak{H}_{\dot{\mathfrak{t}}}}_{mae} \\
        \text{if sell}, \quad \underbrace{\min_{\mathfrak{t} \le \dot{\mathfrak{t}} \le (\mathfrak{t}+\mathfrak{n})} \mathfrak{L}_{\dot{\mathfrak{t}}}}_{mfe}
    \end{cases},
    \quad \text{\textcolor{red}{running extreme}}
\end{align}


And we formalize our imaginary stoploss as:
\begin{align}
    \omega &= \frac{1}{\mathfrak{T}}\sum_{\mathfrak{t}=0}^{\mathfrak{T}-1} 
    \begin{cases}
        \text{if buy}, \quad \max\left({\mathfrak{O}}_{-\mathfrak{t}} - {\mathfrak{L}}_{-\mathfrak{t}},|{\mathfrak{O}}_{-\mathfrak{t}}-{\mathfrak{C}}_{{-\mathfrak{t}}-1}|,|{\mathfrak{L}}_{-\mathfrak{t}}-{\mathfrak{C}}_{{-\mathfrak{t}}-1}|\right)\\
        \text{if sell}, \quad \max\left(|{\mathfrak{O}}_{-\mathfrak{t}} - {\mathfrak{H}}_{-\mathfrak{t}}|,|{\mathfrak{O}}_{-\mathfrak{t}}-{\mathfrak{C}}_{{-\mathfrak{t}}-1}|,|{\mathfrak{H}}_{-\mathfrak{t}}-{\mathfrak{C}}_{{-\mathfrak{t}}-1}|\right)
    \end{cases},  \quad \text{\textcolor{red}{avg. imaginary $mae$}}
    \\
    \Omega_{\mathfrak{t}} &= 
    \begin{cases} 
        \text{if buy}, \quad \mathfrak{E}_{\mathfrak{t}} -(\omega_{{\mathfrak{t}}-1} \cdot s_{\mathfrak{t}} \cdot m) \\ 
        \text{if sell}, \quad \mathfrak{E}_{\mathfrak{t}} +(\omega_{{\mathfrak{t}}-1} \cdot s_{\mathfrak{t}} \cdot m) 
    \end{cases},\quad \text{\textcolor{red}{projected deviated stoploss} and $m$ (10x) as multiplier (the entry is $\mathfrak{E}_{\mathfrak{t}}$)}
\end{align}
That ensures that the stoploss is always greater than the spread multiplier, $\Omega_{\mathfrak{t}} > (s_{\mathfrak{t}} \cdot m)$

Therefore, our run stop creterion is defined as
\begin{align}
    \mathfrak{R}_{\dot{\mathfrak{t}}} &=
    \begin{cases}
        \text{if buy}, \quad \left(\left(\underbrace{\max_{\mathfrak{t} \le \dot{\mathfrak{t}} \le (\mathfrak{t}+\mathfrak{n})} \mathfrak{H}_{\dot{\mathfrak{t}}}}_{mfe} + \Omega_{\mathfrak{t}} \right) \cdot d \right)+ \Omega_{\mathfrak{t}} \\
        \text{if sell}, \quad \left(\left(\underbrace{\min_{\mathfrak{t} \le \dot{\mathfrak{t}} \le (\mathfrak{t}+\mathfrak{n})} \mathfrak{L}_{\dot{\mathfrak{t}}}}_{mfe} - \Omega_{\mathfrak{t}} \right) \cdot d \right)+ \Omega_{\mathfrak{t}}
    \end{cases}, \quad 
    \text{\textcolor{red}{run stop creterion}, where $d$ is divider (say 0.50)}
\end{align}

And the time where price crosses the opposite bound of run stop creterion is defined as:
\begin{align}
    \mathfrak{C}_{\mathbb{t}} &= 
    \begin{cases}
        \text{if buy}, \quad \mathfrak{L}_{\max(\dot{\mathfrak{t}})} \ge \mathfrak{R}_{\dot{\mathfrak{t}}} \\
        \text{if sell}, \quad \mathfrak{H}_{\max(\dot{\mathfrak{t}})} \le \mathfrak{R}_{\dot{\mathfrak{t}}}
    \end{cases}, \quad \text{\textcolor{red}{crossover price}, where $\mathfrak{C}$ is the deviated close price of time $\mathbb{t}$}
\end{align} 
That will get the price at max timestamp indexing before the price touches the lowerbound (if buyside) or upperbound (if sellside) of $\mathfrak{R}_{\dot{\mathfrak{t}}}$

And to get the max imaginary takeprofit, we formalize it as:

\begin{align}
    \mathcal{T}_{\dot{\mathbb{t}}} &= 
    \begin{cases}
        \text{if buy}, \quad \displaystyle \max_{\mathbb{t} \ge \dot{\mathbb{t}} \ge \mathfrak{t}}(\mathfrak{H}_{\dot{\mathbb{t}}}) - (s_{\mathfrak{t}} \cdot \mathfrak{m})\\
        \text{if sell}, \quad \displaystyle \min_{\mathbb{t} \ge \dot{\mathbb{t}} \ge \mathfrak{t}}(\mathfrak{L}_{\dot{\mathbb{t}}}) + (s_{\mathfrak{t}} \cdot \mathfrak{m})
    \end{cases}, \quad \text{where $\mathfrak{m} (2x)$ as multiplier, and $\mathfrak{t} \in \{\mathbb{t}-\mathbb{n}\}$}, \quad \text{\textcolor{red}{max simulated takeprofit}} \\
    \mathcal{R}_{\dot{\mathbb{t}}} &=
        \begin{cases}
        \text{if buy,} \quad \mathfrak{C}_{\mathbb{t}}^{buy} \\
        \text{if sell,} \quad \mathfrak{C}_{\mathbb{t}}^{sell}
        \end{cases}, \quad \text{\textcolor{red}{emergency return}} \\
    \mathcal{L}_{\dot{\mathbb{t}}} &= 
    \begin{cases}
        \text{if buy}, \quad \displaystyle \min_{\mathbb{t} \ge \dot{\mathbb{t}} \ge \mathfrak{t}}(\mathfrak{L}_{\dot{\mathbb{t}}}) \\
        \text{if sell}, \quad \displaystyle \max_{\mathbb{t} \ge \dot{\mathbb{t}} \ge \mathfrak{t}}(\mathfrak{H}_{\dot{\mathbb{t}}})
    \end{cases}, \quad \text{where $\mathfrak{t} \in \{\mathbb{t}-\mathbb{n}\}$}, \quad \text{\textcolor{red}{max simulated adverse-loss }}
\end{align}
That finds the max high (if buyside) or min low (if sell side) in between from $\mathfrak{P}_{\mathbb{t}}$ to $\mathfrak{E}_{\mathfrak{t}}$

And quality is defined as;

\begin{align}
    \mathcal{Q}_{\mathfrak{t}} &=
    \begin{cases}
        \text{if buy}, \quad \displaystyle \underbrace{\min_{\mathbb{t} \ge \dot{\mathbb{t}} \ge \mathfrak{t}}(\mathfrak{L}_{\dot{\mathbb{t}}})}_{\mathcal{L}_{\dot{\mathfrak{t}}}} \cdot \frac{1}{\underbrace{\mathfrak{E}_{\mathfrak{t}} -(\omega_{{\mathfrak{t}}-1} \cdot s_{\mathfrak{t}} \cdot m)}_{\Omega_{\mathfrak{t}}}} \\
        \text{if sell}, \quad \displaystyle \underbrace{\max_{\mathbb{t} \ge \dot{\mathbb{t}} \ge \mathfrak{t}}(\mathfrak{H}_{\dot{\mathbb{t}}})}_{\mathcal{L}_{\dot{\mathfrak{t}}}} \cdot \frac{1}{\underbrace{\mathfrak{E}_{\mathfrak{t}} +(\omega_{{\mathfrak{t}}-1} \cdot s_{\mathfrak{t}} \cdot m)}_{\Omega_\mathfrak{t}}}
    \end{cases}, \quad
    \text{\textcolor{red}{quality of adverse}}
\end{align}
where if $\mathcal{Q}_{\mathfrak{t}}$ is closer or equal to zero, then the better, $\mathcal{Q}_{\mathfrak{t}} \succeq 0$.

And we formalize our simulated risk-reward ratio as:

\begin{align}
    \mathcal{Y}_{\mathfrak{t}} &=
    \begin{cases}
        \text{if buy,} \quad \displaystyle \left|\frac{\mathcal{R}_{\mathfrak{t}}^{buy}}{\Omega_{\mathfrak{t}}^{buy}} \right| \\
        \text{if sell,} \quad \displaystyle \left|\frac{\mathcal{R}_{\mathfrak{t}}^{sell}}{\Omega_{\mathfrak{t}}^{sell}} \right|
    \end{cases}, \quad \text{\textcolor{red}{simulated risk-reward ratio}}
\end{align}


Therefore we can now project the value of that entry at spcific time $\mathfrak{E}_{\mathfrak{t}}$, formalized as:

\begin{align}
    \mathcal{V}_{\mathfrak{t}} &=
    (
        \mathfrak{E}_{\mathfrak{t}}, \Omega_{\mathfrak{t}}, \mathcal{T}_{\mathfrak{t}}, \mathcal{R}_{\mathfrak{t}}, \mathcal{L}_{\mathfrak{t}}, \mathcal{Q}_\mathfrak{t}, \mathcal{Y}_{\mathfrak{t}}
    ), \text{\textcolor{red}{values of simulated trade at $\mathfrak{t}$} where $\mathcal{T}_{\mathfrak{t}}=\mathcal{T}_{\dot{\mathbb{t}}}, \mathcal{R}_{\mathfrak{t}}=\mathcal{R}_{\dot{\mathbb{t}}}, \mathcal{L}_{\mathfrak{t}}=\mathcal{L}_{\dot{\mathbb{t}}} $}
\end{align}

That equation above defines a perfect trade (when enter  at that time $\mathfrak{E}_{\mathfrak{t}}$) because all values are already showed at the time of entry. Before you argue that this is a product of mix loockback and lookahead, there is no problem since we are trying to make a another form of data here (the perfect trade). 

the catch is that if $\mathcal{Y}_{\mathfrak{t}} \ge 1$ then $\mathcal{V}_{\mathfrak{t}}$ is valid, otherwise it's invalid and must not be included in the dataset

Now lets proceed to polishing.

Since $\mathfrak{E}_{\mathfrak{t}}$ is also equavalent to 0 as deviated price. Therefore our two possible trades at time $\mathfrak{t}$ is defined as:

\begin{align}
    \mathcal{V}_{\mathfrak{t}}^{buy} &=
    \left(
        \mathfrak{E}_{\mathfrak{t}}^{buy}, \Omega_{\mathfrak{t}}^{buy}, \mathcal{T}_\mathfrak{t}^{buy}, \mathcal{R}_{\mathfrak{t}}^{buy}, \mathcal{L}_{\mathfrak{t}}^{buy}, \mathcal{Q}_\mathfrak{t}^{buy}, \mathcal{Y}_\mathfrak{t}^{buy}
    \right) \\
    \mathcal{V}_{\mathfrak{t}}^{sell} &=
    \left(
        \mathfrak{E}_{\mathfrak{t}}^{sell}, \Omega_{\mathfrak{t}}^{sell}, \mathcal{T}_\mathfrak{t}^{sell}, \mathcal{R}_{\mathfrak{t}}^{sell}, \mathcal{L}_{\mathfrak{t}}^{sell}, \mathcal{Q}_\mathfrak{t}^{sell}, \mathcal{Y}_\mathfrak{t}^{sell}
    \right)
\end{align}

First, we need to make all variables of $\mathcal{V}_{\mathfrak{t}}^{sell}$ into into reverse becuase the favorable side is the opposite if its value (i.e. the loss is located at positive and the return is located at the negative, if we follow the formula discussed from the very beginning), therefore we formalize that as
\begin{align}
    \mathcal{V}_{\mathfrak{t}}^{{sell},{r}} &=
    \text{Rev}
    (
        \mathfrak{E}_{\mathfrak{t}}, \Omega_{\mathfrak{t}}, \mathcal{T}_{\mathfrak{t}}, \mathcal{R}_{\mathfrak{t}}, \mathcal{L}_{\mathfrak{t}}, \mathcal{Q}_\mathfrak{t}, \mathcal{Y}_{\mathfrak{t}}
    ) =
    (
        -\mathfrak{E}_{\mathfrak{t}}, -\Omega_{\mathfrak{t}}, -\mathcal{T}_{\mathfrak{t}}, -\mathcal{R}_{\mathfrak{t}}, -\mathcal{L}_{\mathfrak{t}}, -\mathcal{Q}_\mathfrak{t}, -\mathcal{Y}_{\mathfrak{t}}
    ), \quad \text{where $r$ is notation for $reverse$}
\end{align}

then let $v$ be the invididual variables of $\mathcal{V}$, and we formalize our points calculator as:

\begin{align}
    \text{Point}\left(v_{\mathfrak{t}}^{buy}, v_{\mathfrak{t}}^{sell}\right) &=
    \begin{cases}
        (1,1) & \text{if } \mathfrak{E}_{\mathfrak{t}}^{buy} \gtreqless \mathfrak{E}_{\mathfrak{t}}^{{sell},r} \\
        (1,1) & \text{if } \Omega_{\mathfrak{t}}^{buy} \gtreqless \Omega_{\mathfrak{t}}^{{sell},r} \\
        (1,0) & \text{if }  \mathcal{T}_{\mathfrak{t}}^{buy}  >  \mathcal{T}_{\mathfrak{t}}^{{sell},r}  \\
        (0,1) & \text{if }  \mathcal{T}_{\mathfrak{t}}^{buy}  <  \mathcal{T}_{\mathfrak{t}}^{{sell},r}  \\
        (1,0) & \text{if }  \mathcal{R}_{\mathfrak{t}}^{buy}  >  \mathcal{R}_{\mathfrak{t}}^{{sell},r}  \\
        (0,1) & \text{if }  \mathcal{R}_{\mathfrak{t}}^{buy}  <  \mathcal{R}_{\mathfrak{t}}^{{sell},r}  \\
        (0,1) & \text{if }  \mathcal{L}_{\mathfrak{t}}^{buy}  >  \mathcal{L}_{\mathfrak{t}}^{{sell},r}  \\
        (1,0) & \text{if }  \mathcal{L}_{\mathfrak{t}}^{buy}  <  \mathcal{L}_{\mathfrak{t}}^{{sell},r}  \\
        (0,1) & \text{if }  \mathcal{Q}_\mathfrak{t}^{buy}  >  \mathcal{Q}_\mathfrak{t}^{{sell},r}  \\
        (1,0) & \text{if }  \mathcal{Q}_\mathfrak{t}^{buy}  <  \mathcal{Q}_\mathfrak{t}^{{sell},r}  \\
        (1,0) & \text{if }  \mathcal{Y}_\mathfrak{t}^{buy}  >  \mathcal{Y}_\mathfrak{t}^{{sell},r}  \\
        (0,1) & \text{if }  \mathcal{Y}_\mathfrak{t}^{buy}  <  \mathcal{Y}_\mathfrak{t}^{{sell},r}  \\
    \end{cases}
\end{align}

Therefore our scoring is formalized as:

\begin{align}
    \text{Favor} \left(\mathcal{V}_{\mathfrak{t}}^{buy},\mathcal{V}_{\mathfrak{t}}^{sell}\right) &=
    \begin{cases}
    (1,0) & \text{if } \displaystyle\sum_{\text{all } v} \text{Point}\left(v_{\mathfrak{t}}^{buy}\right) > \sum_{\text{all } v} \text{Point}\left(v_{\mathfrak{t}}^{sell}\right) \\
    (0,1) & \text{if } \displaystyle\sum_{\text{all } v} \text{Point}\left(v_{\mathfrak{t}}^{buy}\right) < \sum_{\text{all } v} \text{Point}\left(v_{\mathfrak{t}}^{sell}\right)
    \end{cases}
\end{align}
That equation above will tell us whether if it is best to buy or sell at that time $\mathfrak{t}$

\newpage
Say we want to know wheter it is best to buy or sell at times $\mathfrak{t}_1, \mathfrak{t}_2, \mathfrak{t}_3, \mathfrak{t}_4, \mathfrak{t}_5$, and we calculate each $\text{Favor} \left(\mathcal{V}_{\mathfrak{t}}^{buy},\mathcal{V}_{\mathfrak{t}}^{sell}\right)$ at that time, then we get something like; as example:
\begin{align}
\mathcal{V}_{\mathfrak{t}_1}^{sell}, \mathcal{V}_{\mathfrak{t}_2}^{sell}, \mathcal{V}_{\mathfrak{t}_3}^{buy}, \mathcal{V}_{\mathfrak{t}_4}^{sell}, \mathcal{V}_{\mathfrak{t}_5}^{buy}
\end{align}
where each time contains rich information of
\begin{align}
\mathcal{V}_{\mathfrak{t}} &=
    (
        \mathfrak{E}_{\mathfrak{t}}, \Omega_{\mathfrak{t}}, \mathcal{T}_{\mathfrak{t}}, \mathcal{R}_{\mathfrak{t}}, \mathcal{L}_{\mathfrak{t}}, \mathcal{Q}_\mathfrak{t}, \mathcal{Y}_{\mathfrak{t}}
    ),
\end{align}

\end{document}
