Skip to content

Commit

Permalink
Deployed d44b74f with MkDocs version: 1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
KarelZe committed Jan 4, 2024
1 parent 2b85409 commit 2338ca9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ <h2 id="advanced-example">Advanced Example<a class="headerlink" href="#advanced-
</span><span class="hll"><span class="n">features</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;trade_price&quot;</span><span class="p">,</span> <span class="s2">&quot;bid_ex&quot;</span><span class="p">,</span> <span class="s2">&quot;ask_ex&quot;</span><span class="p">,</span> <span class="s2">&quot;bid_best&quot;</span><span class="p">,</span> <span class="s2">&quot;ask_best&quot;</span><span class="p">]</span>
</span>
<span class="n">clf</span> <span class="o">=</span> <span class="n">ClassicalClassifier</span><span class="p">(</span>
<span class="hll"> <span class="n">layers</span><span class="o">=</span><span class="p">[(</span><span class="s2">&quot;quote&quot;</span><span class="p">,</span> <span class="s2">&quot;ex&quot;</span><span class="p">),</span> <span class="p">(</span><span class="s2">&quot;quote&quot;</span><span class="p">,</span> <span class="s2">&quot;best&quot;</span><span class="p">)],</span> <span class="n">strategy</span><span class="o">=</span><span class="s2">&quot;const&quot;</span><span class="p">,</span> <span class="n">features</span><span class="o">=</span><span class="n">features</span>
<span class="hll"> <span class="n">layers</span><span class="o">=</span><span class="p">[(</span><span class="s2">&quot;quote&quot;</span><span class="p">,</span> <span class="s2">&quot;ex&quot;</span><span class="p">),</span> <span class="p">(</span><span class="s2">&quot;quote&quot;</span><span class="p">,</span> <span class="s2">&quot;best&quot;</span><span class="p">)],</span> <span class="n">strategy</span><span class="o">=</span><span class="s2">&quot;random&quot;</span><span class="p">,</span> <span class="n">features</span><span class="o">=</span><span class="n">features</span>
</span><span class="p">)</span>
<span class="n">clf</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="n">acc</span> <span class="o">=</span> <span class="n">accuracy_score</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">clf</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
Expand All @@ -598,7 +598,7 @@ <h2 id="citation">Citation<a class="headerlink" href="#citation" title="Permanen
month = dec,
title = <span class="nb">{{</span>tclf<span class="nb">}</span> -- trade classification with python<span class="nb">}</span>,
url = <span class="nb">{</span>https://github.com/KarelZe/tclf<span class="nb">}</span>,
version = <span class="nb">{</span>0.0.1<span class="nb">}</span>,
version = <span class="nb">{</span>0.0.2<span class="nb">}</span>,
year = <span class="nb">{</span>2023<span class="nb">}</span>
<span class="nb">}</span>
</code></pre></div>
Expand Down
12 changes: 6 additions & 6 deletions option_trade_classification/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ <h2 id="setup-rules">Setup Rules<a class="headerlink" href="#setup-rules" title=
<p>[...] our new trade size rule together with quote rules successively applied to NBBO and quotes on the trading venue. Quotes at the midpoint on both the NBBO and the exchange should be classified first with the depth rule and any remaining trades with the reverse tick test.</p>
</blockquote>
<p>There's a lot going on.🥵</p>
<p>To match the author's description, we first set up <code>layers</code>. We use the <code>tclf</code> implementation of the <a href="https://github.com/KarelZe/tclf/blob/main/src/tclf/classical_classifier.py#L336">tradesize</a>, <a href="https://github.com/KarelZe/tclf/blob/main/src/tclf/classical_classifier.py#L154">quote</a>, and <a href="https://github.com/KarelZe/tclf/blob/main/src/tclf/classical_classifier.py#L362C1-L363C1">depth rule</a>, as well as <a href="https://github.com/KarelZe/tclf/blob/main/src/tclf/classical_classifier.py#L137">reverse tick test</a>. The subset named "ex" refers to exchange-specific data, "best" to the NBBO and "all" for inter-exchange level data. Identical to the paper, the reverse tick test is applied at the inter-exchange level, due to devastating results of tick-based algorithms at the exchange level. The authors perform random classification on unclassified trades, hence we choose <code>strategy="random"</code>.
<p>To match the author's description, we first set up <code>layers</code>. We use the <code>tclf</code> implementation of the <a href="https://github.com/KarelZe/tclf/blob/main/src/tclf/classical_classifier.py#L336">tradesize</a>, <a href="https://github.com/KarelZe/tclf/blob/main/src/tclf/classical_classifier.py#L154">quote</a>, and <a href="https://github.com/KarelZe/tclf/blob/main/src/tclf/classical_classifier.py#L362C1-L363C1">depth rule</a>, as well as <a href="https://github.com/KarelZe/tclf/blob/main/src/tclf/classical_classifier.py#L137">reverse tick test</a>. The subset named "ex" refers to exchange-specific data, "best" to the NBBO and "all" for inter-exchange level data. Identical to the paper, the reverse tick test is applied at the inter-exchange level, due to the devastating results of tick-based algorithms at the exchange level. The authors perform random classification on unclassified trades, hence we choose <code>strategy="random"</code>.
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">tclf.classical_classifier</span> <span class="kn">import</span> <span class="n">ClassicalClassifier</span>

<span class="n">layers</span> <span class="o">=</span> <span class="p">[</span>
Expand All @@ -496,24 +496,24 @@ <h2 id="setup-rules">Setup Rules<a class="headerlink" href="#setup-rules" title=
<span class="n">clf</span> <span class="o">=</span> <span class="n">ClassicalClassifier</span><span class="p">(</span><span class="n">layers</span><span class="o">=</span><span class="n">layers</span><span class="p">,</span> <span class="n">strategy</span><span class="o">=</span><span class="s2">&quot;random&quot;</span><span class="p">)</span>
</code></pre></div></p>
<h2 id="prepare-dataset">Prepare Dataset<a class="headerlink" href="#prepare-dataset" title="Permanent link">&para;</a></h2>
<p>Next, we need to load a dataset of option trades. I choose one, which was recorded at the ISE and used in the paper to evaluate the trade classification rules. I access it from a google cloud bucket and load it into a pandas dataframe <code>X</code>.</p>
<p>Next, we need to load a dataset of option trades. I chose one, which was recorded at the ISE and used in the paper to evaluate the trade classification rules. I access it from a google cloud bucket and load it into a pandas dataframe <code>X</code>.</p>
<p><div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">gcsfs</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>

<span class="n">fs</span> <span class="o">=</span> <span class="n">gcsfs</span><span class="o">.</span><span class="n">GCSFileSystem</span><span class="p">()</span>

<span class="n">gcs_loc</span> <span class="o">=</span> <span class="n">fs</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span>
<span class="s2">&quot;gs://tclf/too_bad_cannot_share/*&quot;</span>
<span class="s2">&quot;gs://tclf/bucket_name/dir_name/*&quot;</span>
<span class="p">)</span>
<span class="n">X</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_parquet</span><span class="p">(</span><span class="n">gcs_loc</span><span class="p">,</span> <span class="n">engine</span><span class="o">=</span><span class="s2">&quot;pyarrow&quot;</span><span class="p">,</span> <span class="n">filesystem</span><span class="o">=</span><span class="n">fs</span><span class="p">)</span>
</code></pre></div>
Unfortunately, the dataset does not yet follow the <a href="https://karelze.github.io/tclf/naming_conventions/">naming conventions</a> and is missing columns required by <code>tclf</code>. We take care of this next.😅</p>
<div class="highlight"><pre><span></span><code><span class="n">clf</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="o">&gt;&gt;&gt;</span> <span class="ne">ValueError</span><span class="p">:</span> <span class="n">Expected</span> <span class="n">to</span> <span class="n">find</span> <span class="n">columns</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;ask_best&#39;</span><span class="p">,</span> <span class="s1">&#39;ask_size_best&#39;</span><span class="p">,</span> <span class="s1">&#39;bid_best&#39;</span><span class="p">,</span> <span class="s1">&#39;bid_size_best&#39;</span><span class="p">,</span> <span class="s1">&#39;trade_price&#39;</span><span class="p">,</span> <span class="s1">&#39;trade_size&#39;</span><span class="p">]</span><span class="o">.</span> <span class="n">Check</span> <span class="n">naming</span><span class="o">/</span><span class="n">presenence</span> <span class="n">of</span> <span class="n">columns</span><span class="o">.</span> <span class="n">See</span><span class="p">:</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">karelze</span><span class="o">.</span><span class="n">github</span><span class="o">.</span><span class="n">io</span><span class="o">/</span><span class="n">tclf</span><span class="o">/</span><span class="n">naming_conventions</span><span class="o">/</span>
<span class="o">&gt;&gt;&gt;</span> <span class="ne">ValueError</span><span class="p">:</span> <span class="n">Expected</span> <span class="n">to</span> <span class="n">find</span> <span class="n">columns</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;ask_best&#39;</span><span class="p">,</span> <span class="s1">&#39;ask_size_best&#39;</span><span class="p">,</span> <span class="s1">&#39;bid_best&#39;</span><span class="p">,</span> <span class="s1">&#39;bid_size_best&#39;</span><span class="p">,</span> <span class="s1">&#39;trade_price&#39;</span><span class="p">,</span> <span class="s1">&#39;trade_size&#39;</span><span class="p">]</span><span class="o">.</span> <span class="n">Check</span> <span class="n">the</span> <span class="n">naming</span><span class="o">/</span><span class="n">presence</span> <span class="n">of</span> <span class="n">columns</span><span class="o">.</span> <span class="n">See</span><span class="p">:</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">karelze</span><span class="o">.</span><span class="n">github</span><span class="o">.</span><span class="n">io</span><span class="o">/</span><span class="n">tclf</span><span class="o">/</span><span class="n">naming_conventions</span><span class="o">/</span>
</code></pre></div>
<p>The calculation of the <a href="https://github.com/KarelZe/tclf/blob/main/src/tclf/classical_classifier.py#L362C1-L363C1">depth rule</a> requires the columns <code>ask_{subset}</code>, <code>bid_{subset}</code>, and <code>trade_price</code>, as well as <code>ask_size_{subset}</code>, <code>bid_size_{subset}</code> and <code>trade_size</code>. The columns <code>BEST_ASK</code>, <code>BEST_BID</code>, <code>TRADE_PRICE</code>, and <code>TRADE_SIZE</code> are renamed to match our naming conventions of <code>ask_{subset}</code>, <code>bid_{subset}</code>, <code>trade_price</code>, and <code>trade_size</code>.</p>
<p>As there is no <code>{ask/bid}_size_best</code> at the NBBO level (<code>subset="best"</code>), I copy the columns from the trading venue. This allows us to mimic the author's decision to filter for mid-spread at the NBBO level, but classify by the trade size relative to the ask/bid size at the exchange.</p>
<p>We save the true label <code>y_true</code> and the timestamp of the trade <code>QUOTE_DATETIME</code> to a new dataframe, named <code>X_meta</code>, which we use for plotting and remove these columns from the original dataframe.</p>
<p>We save the true label <code>y_true</code> and the timestamp of the trade <code>QUOTE_DATETIME</code> to a new dataframe, named <code>X_meta</code>, which we use for plotting. We remove these columns from the original dataframe.</p>
<div class="highlight"><pre><span></span><code><span class="n">X</span> <span class="o">=</span> <span class="n">X</span><span class="o">.</span><span class="n">rename</span><span class="p">(</span>
<span class="p">{</span>
<span class="s2">&quot;TRADE_PRICE&quot;</span><span class="p">:</span> <span class="s2">&quot;trade_price&quot;</span><span class="p">,</span>
Expand Down Expand Up @@ -543,7 +543,7 @@ <h2 id="generate-results">Generate Results<a class="headerlink" href="#generate-
<span class="p">)</span>
</code></pre></div>
<h2 id="plot-results">Plot Results<a class="headerlink" href="#plot-results" title="Permanent link">&para;</a></h2>
<p>We use <a href="https://matplotlib.org/"><code>matplotlib</code></a> to match the plots from the paper as close as possible.</p>
<p>We use <a href="https://matplotlib.org/"><code>matplotlib</code></a> to match the plots from the paper as closely as possible.</p>
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">from</span> <span class="nn">matplotlib.dates</span> <span class="kn">import</span> <span class="n">DateFormatter</span>
<span class="kn">from</span> <span class="nn">matplotlib.ticker</span> <span class="kn">import</span> <span class="n">PercentFormatter</span>
Expand Down
2 changes: 1 addition & 1 deletion search/search_index.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://typer.tiangolo.com/</loc>
<lastmod>2023-12-28</lastmod>
<lastmod>2024-01-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://typer.tiangolo.com/naming_conventions/</loc>
<lastmod>2023-12-28</lastmod>
<lastmod>2024-01-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://typer.tiangolo.com/nan_handling/</loc>
<lastmod>2023-12-28</lastmod>
<lastmod>2024-01-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://typer.tiangolo.com/option_trade_classification/</loc>
<lastmod>2023-12-28</lastmod>
<lastmod>2024-01-04</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://typer.tiangolo.com/reference/</loc>
<lastmod>2023-12-28</lastmod>
<lastmod>2024-01-04</lastmod>
<changefreq>daily</changefreq>
</url>
</urlset>
Binary file modified sitemap.xml.gz
Binary file not shown.

0 comments on commit 2338ca9

Please sign in to comment.