As a Political Scientist, it could not be more gauche to talk about the Presidential debate in terms of a winner and a loser, but the occasion provides the opportunity to show how to do (at least) three really useful things:
- Directly load price and volume data for InTrade contracts. All you need to know is the InTrade contractId, which can be found in the URL of a page like this one, for Barack Obama to win the third Presidential debate.
- Convert the character-class time and date from the InTrade .CSV to a POSIXt-class time and date, which many R functions recognize and use in a special way. This is done with parse_date_time from lubridate, which really is as amazing as people say it is. (More on lubridate here.)
- Superimpose the price trend over indicators of trade volume, using ggplot2. There is some odd (to me) behavior in the plotting code, meaning that in one place we have to specify the time as.numeric, but it gets the job done.