<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Onno Kleen</title>
    <link>https://onnokleen.com/</link>
      <atom:link href="https://onnokleen.com/index.xml" rel="self" type="application/rss+xml" />
    <description>Onno Kleen</description>
    <generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><copyright>© Onno Kleen, 2026.</copyright><lastBuildDate>Sun, 09 Jul 2023 21:13:14 -0500</lastBuildDate>
    <image>
      <url>https://onnokleen.com/images/icon_hu17379476442904948675.png</url>
      <title>Onno Kleen</title>
      <link>https://onnokleen.com/</link>
    </image>
    
    <item>
      <title>Advice for seminar papers and theses</title>
      <link>https://onnokleen.com/post/how_to_write_thesis/</link>
      <pubDate>Sun, 09 Jul 2023 21:13:14 -0500</pubDate>
      <guid>https://onnokleen.com/post/how_to_write_thesis/</guid>
      <description>


&lt;p&gt;In this blog post, I gather general advice on how to write theses and seminar papers. References can be found below. The recommendations here are not necessarily well-structured but are more like a list of things that I observe(d) through time and want to share with future students of mine.&lt;/p&gt;
&lt;div id=&#34;general-advice&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;General advice&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A thesis is not a novel. Hence, state very early what you are doing. People want to know in which direction you are heading. This also helps to understand your priorities in the literature section. General statements like “Volatility investing is important to investors and market participants.” are kind of useless as your reader already knows this. My colleague Andreas Pick has a nice discussion about writing introductions: &lt;a href=&#34;https://apick.eu/teaching/2022/05/08/Academic_writing.html&#34;&gt;https://apick.eu/teaching/2022/05/08/Academic_writing.html&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don’t structure your results section w.r.t. models but w.r.t. evaluation criteria.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Hence, the section of your results should not be structured like Subsection 1: Model 1, Subsection 2: Model 2, and so on.&lt;/li&gt;
&lt;li&gt;Instead, structure your results by evaluation criteria; for example, Subsection 1: Forecast performance, Subsection 2: Economic significance, and so on. Discuss all models jointly w.r.t. these different criteria. For this it also helps to make a smaller number of possibly large tables. Jumping from one table to the other is tiring for the reader.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For a thesis, it is best if you have at least one own extension; be it theoretical or an alteration of a model that is out there but needs a twist to be applied in your setting. A horse race of methods that are already out there will not bring you an excellent grade, no matter how well-executed it is.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Econometricians like statistical tests. A lot of my supervised projects touch the current forecasting literature and quantitative finance. Hence, a small number of references.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Diebold-Mariano test: Diebold and Mariano (1995)&lt;/li&gt;
&lt;li&gt;Model confidence set: Hansen et al. (2011). If you use R for you computations, please use the implementation in the rugarch package instead of the implementation in the MCS package. The model confidence set can be though of being an extension of the Diebold-Mariano test for evaluating multiple models at once. In this sense, I would prefer it in most situations because you don’t need to choose a benchmark and you don’t run too deep into the multiple testing problem.&lt;/li&gt;
&lt;li&gt;Sharpe ratio test: Ledoit and Wolf (2008).&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Econometricians don’t like inconsistent notation. Triple-check everything in this regard including all formulas etc. This holds especially if you merge notation from different papers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are general guidelines about punctuation and equations; see, for example, &lt;a href=&#34;https://www.chicagomanualofstyle.org/book/ed17/part2/ch12/psec018.html&#34;&gt;https://www.chicagomanualofstyle.org/book/ed17/part2/ch12/psec018.htmls/&lt;/a&gt; and the following sections. You can only access this resource from the university network.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Minor details but still important:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In English, there are hyphens and two types of dashes for different use cases &lt;a href=&#34;https://www.merriam-webster.com/words-at-play/em-dash-en-dash-how-to-use&#34;&gt;https://www.merriam-webster.com/words-at-play/em-dash-en-dash-how-to-use&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Footnotes go after punctuation &lt;a href=&#34;https://proofed.com/writing-tips/should-footnote-markers-go-after-the-punctuation/&#34;&gt;https://proofed.com/writing-tips/should-footnote-markers-go-after-the-punctuation/&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Citations are written as Author (Year) or (Author, Year) but never (Author (Year)).&lt;/li&gt;
&lt;li&gt;In general, no abbreviations in title or abstract. If you need them in the abstract, always define them in the abstract.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&#34;how-to-make-nice-figures-and-tables&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;How to make nice figures and tables&lt;/h2&gt;
&lt;p&gt;Tables and figures should be self-containing. If you read this blog post, I am probably your main supervisor. Hence, I do a shameless selfplug and recommend Kleen and Tetereva (2023) as the best inspiration for your designs. In general, I think it is better to separate the caption from the more detailed notes below the figures and tables. The notes shouldn’t include any interpretation but enough info to understand what is presented.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;writing-process&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Writing process&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It is important to structure your day. One example could be to reserve 2 hours for writing in the morning and start coding after that.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Starting into the day with a plan makes it easier to get going in the morning. Hence, I recommend to use the last 15 minutes of your working day to plan your next working day. This can be done through making appointments with yourself in your calendar app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For joint seminar papers, it might be best to write in Overleaf. Some institutions like the EUR have a subscription for their students.&lt;/li&gt;
&lt;li&gt;Writing in Overleaf is nice but I think &lt;a href=&#34;https://www.texifier.com&#34;&gt;texifier&lt;/a&gt; is by far the best LaTeX editor when writing on your own. Depends on your budget of course as you need to pay for it.&lt;/li&gt;
&lt;li&gt;Think about using ToDo apps like Microsoft’s &lt;a href=&#34;https://todo.microsoft.com/tasks/&#34;&gt;To Do&lt;/a&gt; or &lt;a href=&#34;https://culturedcode.com/things/&#34;&gt;Things&lt;/a&gt;. The latter is paid but has a nicer user interface but your mileage may vary.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&#34;coding-and-computational-facilities&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;Coding and computational facilities&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A great reference for nice coding in financial econometrics is &lt;a href=&#34;https://www.tidy-finance.org&#34;&gt;tidyfinance&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is not so easy to write code that runs fast. However, often only a handful of sections in your code cause most of the delay; for example, due to copying large amounts of data back and forth. Hence, it is good to start using profiling early; for R, &lt;a href=&#34;https://rstudio.github.io/profvis/&#34;&gt;profvis&lt;/a&gt; is the best option in my opinion.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Students of mine had great experience with Google Colab when making use of computational resources beyond their own computers.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Especially, when working together for seminar papers, Google Colab makes it way easier to work on code together.&lt;/li&gt;
&lt;li&gt;There are two upsides to using something like Google Colab when writing code together: First, no sync issues and all teammates have the same computational backbone. Once, I had a seminar group with two students having very potent computers but the other two had not. As a consequence, one group was always wondering why two were complaining about performance issues. Sometimes the code wouldn’t even run due to different amounts of RAM.&lt;/li&gt;
&lt;li&gt;There is a reasonably potent free tier but also the paid plans are relatively cheap.&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&#34;references&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Diebold, F. X., &amp;amp; Mariano, R. S. (1995). Comparing predictive accuracy. Journal of Business and Economic Statistics, 13(3), 253–263. &lt;a href=&#34;https://doi.org/10.1198&#34; class=&#34;uri&#34;&gt;https://doi.org/10.1198&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Hansen, P. R., Lunde, A., &amp;amp; Nason, J. M. (2011). The model confidence set. Econometrica, 79(2), 453–497. &lt;a href=&#34;https://doi.org/10.3982/ECTA5771&#34; class=&#34;uri&#34;&gt;https://doi.org/10.3982/ECTA5771&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Kleen, O., &amp;amp; Tetereva, A. (2023). A Forest Full of Risk Forecasts for Managing Volatility. Available at SSRN: &lt;a href=&#34;http://doi.org/10.2139/ssrn.4161957&#34; class=&#34;uri&#34;&gt;http://doi.org/10.2139/ssrn.4161957&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Ledoit, O., &amp;amp; Wolf, M. (2008). Robust performance hypothesis testing with the Sharpe ratio. Journal of Empirical Finance, 15(5), 850–859. &lt;a href=&#34;https://doi.org/10.1016/j.jempfin.2008.03.002&#34; class=&#34;uri&#34;&gt;https://doi.org/10.1016/j.jempfin.2008.03.002&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Download TAQ data via WRDS inside R</title>
      <link>https://onnokleen.com/post/taq_via_wrds/</link>
      <pubDate>Mon, 21 Sep 2020 21:13:14 -0500</pubDate>
      <guid>https://onnokleen.com/post/taq_via_wrds/</guid>
      <description>


&lt;p&gt;Welcome to my first blog post! I wanted to set up a blog for a while now and I am very excited that I finally found the time to do so. In the future, I plan to share some of my approaches for wrangling data and implementing real-time forecasting.&lt;/p&gt;
&lt;p&gt;Todays blog post is about using the NYSE Trade and Quote (TAQ) database which holds intraday transactions data (trades and quotes) for the entire cross-section of stocks listed on the New York Stock Exchange (NYSE), the American Stock Exchange (AMEX), and the Nasdaq National Market System (NMS).
For research in financial econometrics, it may be described as the de-facto reference data set if a paper is about intraday price movements on financial markets.&lt;/p&gt;
&lt;div id=&#34;wrds-and-taq-via-postgres&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;WRDS and TAQ via Postgres&lt;/h2&gt;
&lt;p&gt;For research purposes, TAQ files are typically accessed via a WRDS subscription (&lt;a href=&#34;https://wrds-www.wharton.upenn.edu/&#34; class=&#34;uri&#34;&gt;https://wrds-www.wharton.upenn.edu/&lt;/a&gt;).
After signing up to WRDS via your institution and logging in, TAQ data can be accessed via a web query.
However, due to large files sizes even for one single day of transaction data the web query only allows very restricted access per web query.
Hence, if you want to look at a large cross-section of stocks over a longer period of time it is best to access the TAQ data via &lt;a href=&#34;https://de.wikipedia.org/wiki/PostgreSQL&#34;&gt;PostgreSQL&lt;/a&gt;-queries that can be automated; for example, in my preferred statistical language &lt;a href=&#34;https://www.r-project.org/&#34;&gt;R&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As a prerequisite, please follow the &lt;a href=&#34;https://wrds-www.wharton.upenn.edu/pages/support/programming-wrds/programming-r/r-from-your-computer/&#34;&gt;WRDS documentation&lt;/a&gt; for setting up your local R session such that it can access TAQ data on WRDS via Postgres.&lt;/p&gt;
&lt;p&gt;The following code snippet&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;establishes the connection to WRDS,&lt;/li&gt;
&lt;li&gt;searches for available trading days in TAQ (&lt;code&gt;df_dates&lt;/code&gt;),&lt;/li&gt;
&lt;li&gt;selects one trading day of interest (&lt;code&gt;dd&lt;/code&gt;), and&lt;/li&gt;
&lt;li&gt;checks the column names of that day (&lt;code&gt;colnames_tay_daily_file&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Technical note: In this blog post, I only consider the “Millisecond Trade and Quote” data set in which the first observations are recorded in 2003.&lt;/em&gt;&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(dplyr)
## 
## Attaching package: &amp;#39;dplyr&amp;#39;
## The following objects are masked from &amp;#39;package:stats&amp;#39;:
## 
##     filter, lag
## The following objects are masked from &amp;#39;package:base&amp;#39;:
## 
##     intersect, setdiff, setequal, union
library(RPostgres)
library(highfrequency)
library(lubridate)
## 
## Attaching package: &amp;#39;lubridate&amp;#39;
## The following objects are masked from &amp;#39;package:base&amp;#39;:
## 
##     date, intersect, setdiff, union
library(ggplot2)
## Warning: package &amp;#39;ggplot2&amp;#39; was built under R version 4.3.2
wrds &amp;lt;- dbConnect(Postgres(),
                  host = &amp;#39;wrds-pgdata.wharton.upenn.edu&amp;#39;,
                  port = 9737,
                  dbname = &amp;#39;wrds&amp;#39;,
                  sslmode = &amp;#39;require&amp;#39;,
                  user = your_username)

res &amp;lt;- dbSendQuery(wrds, &amp;quot;select distinct table_name
                   from information_schema.columns
                   where table_schema=&amp;#39;taqmsec&amp;#39;
                   order by table_name&amp;quot;)
df_dates &amp;lt;- dbFetch(res, n = -1)
dbClearResult(res)

# df_dates contains also quotes table names and indices. However, we are only 
# interested in the trades tables for now which are called ctm_DATE. 
dates_trades &amp;lt;-
  df_dates %&amp;gt;%
  filter(grepl(&amp;quot;ctm&amp;quot;,table_name), !grepl(&amp;quot;ix_ctm&amp;quot;,table_name)) %&amp;gt;%
  mutate(table_name = substr(table_name, 5, 12)) %&amp;gt;%
  unlist()

# First and last day that are available in TAQ
min(dates_trades)
## [1] &amp;quot;_ctm_201&amp;quot;
max(dates_trades)
## [1] &amp;quot;20240418&amp;quot;

# Choose one exemplary trading day for our example
dd &amp;lt;- dates_trades[4000]
dd
## table_name4000 
##     &amp;quot;20190708&amp;quot;

# What are the names of the columns accessible via Postgres?
res &amp;lt;-
  dbSendQuery(wrds, 
              paste0(&amp;quot;select column_name&amp;quot;,
                     &amp;quot; from information_schema.columns&amp;quot;,
                     &amp;quot; where table_schema=&amp;#39;taqmsec&amp;#39;&amp;quot;,
                     &amp;quot; and table_name = &amp;#39;ctm_&amp;quot;, dd, &amp;quot;&amp;#39;&amp;quot;,
                     &amp;quot; order by column_name&amp;quot;)) 
colnames_tay_daily_file &amp;lt;- dbFetch(res, n = -1)$column_name
dbClearResult(res) 
colnames_tay_daily_file
##  [1] &amp;quot;date&amp;quot;           &amp;quot;ex&amp;quot;             &amp;quot;part_time&amp;quot;      &amp;quot;part_time_nano&amp;quot;
##  [5] &amp;quot;price&amp;quot;          &amp;quot;size&amp;quot;           &amp;quot;sym_root&amp;quot;       &amp;quot;sym_suffix&amp;quot;    
##  [9] &amp;quot;time_m&amp;quot;         &amp;quot;time_m_nano&amp;quot;    &amp;quot;tr_corr&amp;quot;        &amp;quot;tr_id&amp;quot;         
## [13] &amp;quot;tr_rf&amp;quot;          &amp;quot;tr_scond&amp;quot;       &amp;quot;tr_seqnum&amp;quot;      &amp;quot;tr_source&amp;quot;     
## [17] &amp;quot;tr_stop_ind&amp;quot;    &amp;quot;trf_time&amp;quot;       &amp;quot;trf_time_nano&amp;quot;  &amp;quot;tte_ind&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With this knowledge in mind, we now download the transaction data for one exemplary stock, in this case Apple Inc. which has the ticker symbol &lt;em&gt;AAPL&lt;/em&gt;.
In the following, we do not need all columns so we select the ones relevant for us in the SQL-statement.
We restrict ourselves to observations on the NYSE, AMEX, and Nasdaq (&lt;code&gt;where (ex = &#39;N&#39; or ex = &#39;T&#39; or ex = &#39;Q&#39; or ex = &#39;A&#39;)&lt;/code&gt;) which will become important in a possible future blog post about merging TAQ data with &lt;a href=&#34;http://www.crsp.org/&#34;&gt;CRSP&lt;/a&gt; data.
In this part, we only consider uncorrected trades as a first cleaning step (&lt;code&gt;tr_corr = &#39;00&#39;&lt;/code&gt;).&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;stock &amp;lt;- &amp;quot;AAPL&amp;quot;
# Fetch the data, create a DT column which pastes date and time together.
# In a future blog post we will merge our data with CRSP data, so we will 
# restrict ourselves to NYSE, AMEX, and NASDAQ. Prices should be nonzero 
# and we only consider non-corrected trades.
res &amp;lt;- 
  dbSendQuery(wrds,
              paste0(&amp;quot;select concat(date, &amp;#39; &amp;#39;,time_m) as DT,&amp;quot;, 
                     &amp;quot; ex, sym_root, sym_suffix, price, size, tr_scond&amp;quot;,
                     &amp;quot; from taqmsec.ctm_&amp;quot;, dd,
                     &amp;quot; where (ex = &amp;#39;N&amp;#39; or ex = &amp;#39;T&amp;#39; or ex = &amp;#39;Q&amp;#39; or ex = &amp;#39;A&amp;#39;)&amp;quot;,
                     &amp;quot; and sym_root = &amp;#39;&amp;quot;, stock, &amp;quot;&amp;#39;&amp;quot;,
                     &amp;quot; and price != 0 and tr_corr = &amp;#39;00&amp;#39;&amp;quot;))
df_aapl &amp;lt;- dbFetch(res, n = -1)
dbClearResult(res)

df_aapl %&amp;gt;%
  head()
##                           dt ex sym_root sym_suffix  price size tr_scond
## 1 2019-07-08 04:00:47.678376  Q     AAPL       &amp;lt;NA&amp;gt; 203.15    3     @ TI
## 2 2019-07-08 04:01:11.592717  Q     AAPL       &amp;lt;NA&amp;gt; 203.10    3     @ TI
## 3 2019-07-08 04:01:16.476405  Q     AAPL       &amp;lt;NA&amp;gt; 203.05    3     @ TI
## 4 2019-07-08 04:02:06.346591  Q     AAPL       &amp;lt;NA&amp;gt; 203.00    3     @ TI
## 5 2019-07-08 04:02:19.347772  Q     AAPL       &amp;lt;NA&amp;gt; 202.95    3     @ TI
## 6 2019-07-08 04:03:11.572726  Q     AAPL       &amp;lt;NA&amp;gt; 202.90    3     @FTI&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We follow the cleaning procedure in Barndorff-Nielsen et al. (2009) and rely on the R package &lt;a href=&#34;https://cran.r-project.org/package=highfrequency&#34;&gt;highfrequency&lt;/a&gt; for which I am a co-author. Non-zero trades were already filtered in the Postgres-query. Next, we filter for valid sales conditions (see the documentation of &lt;code&gt;highfrequency::salesCondition&lt;/code&gt;) and select a single exchange; in the case of Apple Inc. we choose NASDAQ.
Thereafter, trades on the same time stamp are merged via &lt;code&gt;highfrequency::mergeTradesSameTimestamp&lt;/code&gt;.
Because TAQ data is huge, the highfrequency package assumes input to be &lt;a href=&#34;https://cran.r-project.org/package=data.table&#34;&gt;data.tables&lt;/a&gt; for memory management purposes.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# Rename data for use in highfrequency package and clean the data
dt_aapl &amp;lt;- 
  df_aapl %&amp;gt;%
  rename(DT = dt, PRICE = price, SYM_ROOT = sym_root, SYM_SUFFIX = sym_suffix, 
         SIZE = size, EX = ex, COND = tr_scond) %&amp;gt;%
  mutate(DT = lubridate::ymd_hms(DT, tz = &amp;quot;UTC&amp;quot;)) %&amp;gt;%
  data.table::as.data.table() %&amp;gt;%
  exchangeHoursOnly() %&amp;gt;% # only observations from 9:30 to 16:00
  tradesCondition() %&amp;gt;% # from highfrequency package
  selectExchange(c(&amp;quot;T&amp;quot;, &amp;quot;Q&amp;quot;)) %&amp;gt;% # select NASDAQ
  mergeTradesSameTimestamp() %&amp;gt;% # merge trades from same time stamp
  rmOutliersTrades() # remove outliers
# The last step can also be implemented using additional quote data.
# However, merging additional quote data is beyond the scope of this blog post.

# First 6 observations of cleaned high-frequency data
head(dt_aapl)
##                     DT SYMBOL  PRICE NUMTRADES  SIZE     EX SYM_SUFFIX   COND
##                 &amp;lt;POSc&amp;gt; &amp;lt;char&amp;gt;  &amp;lt;num&amp;gt;     &amp;lt;int&amp;gt; &amp;lt;int&amp;gt; &amp;lt;char&amp;gt;     &amp;lt;char&amp;gt; &amp;lt;char&amp;gt;
## 1: 2019-07-08 09:30:00   AAPL 200.79         1    71      Q       &amp;lt;NA&amp;gt;   @  I
## 2: 2019-07-08 09:30:00   AAPL 200.78         1    34      Q       &amp;lt;NA&amp;gt;   @F I
## 3: 2019-07-08 09:30:00   AAPL 200.78         1    26      Q       &amp;lt;NA&amp;gt;   @F I
## 4: 2019-07-08 09:30:00   AAPL 200.78         1    36      Q       &amp;lt;NA&amp;gt;   @F I
## 5: 2019-07-08 09:30:00   AAPL 200.78         1     2      Q       &amp;lt;NA&amp;gt;   @F I
## 6: 2019-07-08 09:30:00   AAPL 200.78         1     2      Q       &amp;lt;NA&amp;gt;   @F I
##          DATE
##        &amp;lt;Date&amp;gt;
## 1: 2019-07-08
## 2: 2019-07-08
## 3: 2019-07-08
## 4: 2019-07-08
## 5: 2019-07-08
## 6: 2019-07-08

# Create a data.table with aggregated price information
dt_aapl_five_minutes &amp;lt;-
  dt_aapl %&amp;gt;%
  aggregatePrice(alignPeriod = 5)

# First 6 observations of aggregated five-minute data
head(dt_aapl_five_minutes)
##                     DT SYMBOL   PRICE NUMTRADES  SIZE     EX SYM_SUFFIX   COND
##                 &amp;lt;POSc&amp;gt; &amp;lt;char&amp;gt;   &amp;lt;num&amp;gt;     &amp;lt;int&amp;gt; &amp;lt;int&amp;gt; &amp;lt;char&amp;gt;     &amp;lt;char&amp;gt; &amp;lt;char&amp;gt;
## 1: 2019-07-08 09:30:00   AAPL 200.790         1    71      Q       &amp;lt;NA&amp;gt;   @  I
## 2: 2019-07-08 09:35:00   AAPL 201.180         1     9      Q       &amp;lt;NA&amp;gt;   @  I
## 3: 2019-07-08 09:40:00   AAPL 199.730         1    10      Q       &amp;lt;NA&amp;gt;   @  I
## 4: 2019-07-08 09:45:00   AAPL 199.585         1   100      Q       &amp;lt;NA&amp;gt;      @
## 5: 2019-07-08 09:50:00   AAPL 198.990         1   170      Q       &amp;lt;NA&amp;gt;      @
## 6: 2019-07-08 09:55:00   AAPL 198.870         1   100      Q       &amp;lt;NA&amp;gt;      @
##          DATE
##        &amp;lt;Date&amp;gt;
## 1: 2019-07-08
## 2: 2019-07-08
## 3: 2019-07-08
## 4: 2019-07-08
## 5: 2019-07-08
## 6: 2019-07-08&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We now are able to plot the cleaned and aggregated time series.
The aggregated time series is marked by blue dots.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# Plot the aggregated price series
dt_aapl %&amp;gt;%
  ggplot() +
  geom_line(aes(x = DT, y = PRICE)) +
  geom_point(aes(x = DT, y = PRICE), 
             data = dt_aapl_five_minutes, 
             colour = &amp;quot;blue&amp;quot;, size = 2, na.rm = TRUE) +
  scale_x_datetime(date_breaks = &amp;quot;30 mins&amp;quot;, # nicer breaks
                   date_labels = &amp;quot;%H:%M&amp;quot;) +
  scale_y_continuous(limits = c(198,202)) +
  theme_minimal() + 
  xlab(&amp;quot;&amp;quot;) +
  ylab(&amp;quot;Intraday price in USD&amp;quot;) +
  ggtitle(paste0(&amp;quot;AAPL on &amp;quot;, ymd(dd))) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;https://onnokleen.com/post/taq_via_wrds/index_files/figure-html/plot-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;My main application of high-frequency data is to calculate realized measures on a daily frequency.
Given our five-minute data set, we can construct a small tibble that holds open and close prices, the
number of intraday observations, the realized variance, the realized skewness, and the realized kurtosis.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# Calculate some realized measures
dt_aapl_five_minutes %&amp;gt;%
  mutate(ret = 100 * (log(PRICE) - log(lag(PRICE, order_by = DT)))) %&amp;gt;%
  filter(is.na(ret) == FALSE) %&amp;gt;%
  {tibble(open_taq = first(dt_aapl_five_minutes$PRICE),
           close_taq = last(dt_aapl_five_minutes$PRICE),
           n_intraday = dim(dt_aapl)[1],
           rv = sum(.$ret^2),
           rskew = rSkew(.$ret),
           rkurt = rKurt(.$ret))}
## # A tibble: 1 × 6
##   open_taq close_taq n_intraday    rv rskew rkurt
##      &amp;lt;dbl&amp;gt;     &amp;lt;dbl&amp;gt;      &amp;lt;int&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt; &amp;lt;dbl&amp;gt;
## 1     201.      200.      60188  1.22 -2.21  16.2&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In a future blog post, I will extend this approach to multiple stocks and days via the foreach package which
enables us to parallelize the computation of realized measures.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;references&#34; class=&#34;section level2&#34;&gt;
&lt;h2&gt;References&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Barndorff-Nielsen, O. E., P. R. Hansen, A. Lunde, and N. Shephard (2009). Realized kernels in practice: Trades and quotes. Econometrics Journal 12, C1-C32.&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Slides</title>
      <link>https://onnokleen.com/slides/example/</link>
      <pubDate>Tue, 05 Feb 2019 00:00:00 +0000</pubDate>
      <guid>https://onnokleen.com/slides/example/</guid>
      <description>&lt;h1 id=&#34;create-slides-in-markdown-with-academic&#34;&gt;Create slides in Markdown with Academic&lt;/h1&gt;
&lt;p&gt;
&lt;a href=&#34;https://sourcethemes.com/academic/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Academic&lt;/a&gt; | 
&lt;a href=&#34;https://sourcethemes.com/academic/docs/managing-content/#create-slides&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Documentation&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;features&#34;&gt;Features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Efficiently write slides in Markdown&lt;/li&gt;
&lt;li&gt;3-in-1: Create, Present, and Publish your slides&lt;/li&gt;
&lt;li&gt;Supports speaker notes&lt;/li&gt;
&lt;li&gt;Mobile friendly slides&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;controls&#34;&gt;Controls&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Next: &lt;code&gt;Right Arrow&lt;/code&gt; or &lt;code&gt;Space&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Previous: &lt;code&gt;Left Arrow&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Start: &lt;code&gt;Home&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Finish: &lt;code&gt;End&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Overview: &lt;code&gt;Esc&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Speaker notes: &lt;code&gt;S&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Fullscreen: &lt;code&gt;F&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Zoom: &lt;code&gt;Alt + Click&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;https://github.com/hakimel/reveal.js#pdf-export&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;PDF Export&lt;/a&gt;: &lt;code&gt;E&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;code-highlighting&#34;&gt;Code Highlighting&lt;/h2&gt;
&lt;p&gt;Inline code: &lt;code&gt;variable&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Code block:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;porridge = &amp;quot;blueberry&amp;quot;
if porridge == &amp;quot;blueberry&amp;quot;:
    print(&amp;quot;Eating...&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h2 id=&#34;math&#34;&gt;Math&lt;/h2&gt;
&lt;p&gt;In-line math: $x + y = z$&lt;/p&gt;
&lt;p&gt;Block math:&lt;/p&gt;
&lt;p&gt;$$
f\left( x \right) = ;\frac{{2\left( {x + 4} \right)\left( {x - 4} \right)}}{{\left( {x + 4} \right)\left( {x + 1} \right)}}
$$&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;fragments&#34;&gt;Fragments&lt;/h2&gt;
&lt;p&gt;Make content appear incrementally&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{{% fragment %}} One {{% /fragment %}}
{{% fragment %}} **Two** {{% /fragment %}}
{{% fragment %}} Three {{% /fragment %}}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Press &lt;code&gt;Space&lt;/code&gt; to play!&lt;/p&gt;
&lt;span class=&#34;fragment &#34; &gt;
   One 
&lt;/span&gt;
&lt;span class=&#34;fragment &#34; &gt;
   **Two** 
&lt;/span&gt;
&lt;span class=&#34;fragment &#34; &gt;
   Three 
&lt;/span&gt;
&lt;hr&gt;
&lt;p&gt;A fragment can accept two optional parameters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;class&lt;/code&gt;: use a custom style (requires definition in custom CSS)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;weight&lt;/code&gt;: sets the order in which a fragment appears&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;speaker-notes&#34;&gt;Speaker Notes&lt;/h2&gt;
&lt;p&gt;Add speaker notes to your presentation&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-markdown&#34;&gt;{{% speaker_note %}}
- Only the speaker can read these notes
- Press `S` key to view
{{% /speaker_note %}}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Press the &lt;code&gt;S&lt;/code&gt; key to view the speaker notes!&lt;/p&gt;
&lt;aside class=&#34;notes&#34;&gt;
  &lt;ul&gt;
&lt;li&gt;Only the speaker can read these notes&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;S&lt;/code&gt; key to view&lt;/li&gt;
&lt;/ul&gt;

&lt;/aside&gt;
&lt;hr&gt;
&lt;h2 id=&#34;themes&#34;&gt;Themes&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;black: Black background, white text, blue links (default)&lt;/li&gt;
&lt;li&gt;white: White background, black text, blue links&lt;/li&gt;
&lt;li&gt;league: Gray background, white text, blue links&lt;/li&gt;
&lt;li&gt;beige: Beige background, dark text, brown links&lt;/li&gt;
&lt;li&gt;sky: Blue background, thin dark text, blue links&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;ul&gt;
&lt;li&gt;night: Black background, thick white text, orange links&lt;/li&gt;
&lt;li&gt;serif: Cappuccino background, gray text, brown links&lt;/li&gt;
&lt;li&gt;simple: White background, black text, blue links&lt;/li&gt;
&lt;li&gt;solarized: Cream-colored background, dark green text, blue links&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;

&lt;section data-noprocess data-shortcode-slide
  
      
      data-background-image=&#34;/img/boards.jpg&#34;
  &gt;

&lt;h2 id=&#34;custom-slide&#34;&gt;Custom Slide&lt;/h2&gt;
&lt;p&gt;Customize the slide style and background&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-markdown&#34;&gt;{{&amp;lt; slide background-image=&amp;quot;/img/boards.jpg&amp;quot; &amp;gt;}}
{{&amp;lt; slide background-color=&amp;quot;#0000FF&amp;quot; &amp;gt;}}
{{&amp;lt; slide class=&amp;quot;my-style&amp;quot; &amp;gt;}}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h2 id=&#34;custom-css-example&#34;&gt;Custom CSS Example&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s make headers navy colored.&lt;/p&gt;
&lt;p&gt;Create &lt;code&gt;assets/css/reveal_custom.css&lt;/code&gt; with:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-css&#34;&gt;.reveal section h1,
.reveal section h2,
.reveal section h3 {
  color: navy;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h1 id=&#34;questions&#34;&gt;Questions?&lt;/h1&gt;
&lt;p&gt;
&lt;a href=&#34;https://spectrum.chat/academic&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Ask&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
&lt;a href=&#34;https://sourcethemes.com/academic/docs/managing-content/#create-slides&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Documentation&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
