{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Sydney Stock Exchange – calendar view\n", "\n", "This notebook helps you see the number of stock and share sheets in the [bound volumes from the Sydney Stock Exchange](https://archivescollection.anu.edu.au/index.php/or59j) for each day from 1901 to 1950. You can pick out major changes such as when the number of sheets per day changed, and when Saturday trading finished. For example, if you look at July 1934 you'll see the number of sheets produced per day changed from 5 to 6, and in April 1937 that increased again to 9. You'll also pick out official holidays and other days on which trading was suspended. Look for the ends of the wars! Hover over each day for more information.\n", "\n", "However, the bound volumes are not always complete. You'll notice some days have fewer sheets than expected or none at all. In 1947, for example, there are no pages from September. Where there are no pages, I've searched Trove for evidence that trading was suspended and added a note when I've found something. In using these records it's important to be aware of the gaps." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from math import ceil\n", "\n", "import altair as alt\n", "import pandas as pd\n", "from IPython.display import HTML, display" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def week_of_month(dt):\n", " \"\"\"\n", " Returns the week of the month for the specified date.\n", " From: https://stackoverflow.com/a/16804556\n", " \"\"\"\n", " first_day = dt.replace(day=1)\n", " dom = dt.day\n", " adjusted_dom = dom + first_day.weekday()\n", " return int(ceil(adjusted_dom / 7.0))\n", "\n", "\n", "# Get the list of dates\n", "df = pd.read_csv(\"complete_date_list.csv\", parse_dates=[\"date\"])\n", "df.loc[:, \"week\"] = df.loc[:, \"date\"].apply(week_of_month)\n", "# Make empty reasons an empty string so they look better in tooltips\n", "df[\"reason\"].fillna(value=\"\", inplace=True)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def make_year_chart(df, year):\n", " # Filter df to specified year\n", " df_year = df.loc[(df[\"date\"] >= f\"{year}-01-01\") & (df[\"date\"] <= f\"{year}-12-31\")]\n", " chart = (\n", " alt.Chart(df_year)\n", " .mark_rect(stroke=\"white\")\n", " .encode(\n", " # Days of the week. Have to set order specifically to put Sunday at the end of the week\n", " x=alt.X(\n", " \"date:O\",\n", " timeUnit=\"day\",\n", " title=None,\n", " sort=[\n", " \"Monday\",\n", " \"Tuesday\",\n", " \"Wednesday\",\n", " \"Thursday\",\n", " \"Friday\",\n", " \"Saturday\",\n", " \"Sunday\",\n", " ],\n", " ),\n", " # The rows are weeks\n", " y=alt.Y(\"week:O\", title=None, axis=alt.Axis(ticks=False, labels=False)),\n", " # Facet by month\n", " facet=alt.Facet(\n", " \"month(date):T\",\n", " title=\"\",\n", " columns=4,\n", " header=alt.Header(format=\"%B\", labelFontWeight=alt.FontWeight(\"bold\")),\n", " ),\n", " # Colours indicate the number of pages\n", " color=alt.Color(\n", " \"pages:Q\",\n", " scale=alt.Scale(scheme=\"yelloworangebrown\", domain=[0, 10]),\n", " legend=alt.Legend(title=\"Number of pages\"),\n", " ),\n", " tooltip=[\n", " alt.Tooltip(\"date:T\", format=\"%a, %e %b %Y\"),\n", " \"pages:Q\",\n", " \"expected:Q\",\n", " \"reason\",\n", " ],\n", " )\n", " .resolve_scale(x=\"independent\")\n", " )\n", " return chart" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "