{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "55a0c72f-3c76-740f-03de-f62a0616d5c8"
      },
      "source": [
        "Do u have a time for time?"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "ea3962f3-6162-31d0-f85e-3d17c52b260e"
      },
      "outputs": [],
      "source": [
        "import numpy as np \n",
        "import seaborn as sns\n",
        "import pandas as pd\n",
        "\t\n",
        "import matplotlib.pyplot as plt\n",
        "import matplotlib.ticker as ticker"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a4d9023c-83f8-8239-ac6a-093357def498"
      },
      "outputs": [],
      "source": [
        "data = pd.read_hdf('../input/train.h5')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "dde50810-8ecc-338e-e12a-2cd596b04b35"
      },
      "outputs": [],
      "source": [
        "pd.set_option('display.max_columns', 150)\n",
        "pd.set_option('display.max_rows', 100)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "d97318b7-dad6-44fd-5f69-9cf454ab1cc9"
      },
      "outputs": [],
      "source": [
        "def myticks(x,pos):\n",
        "\n",
        "    exponent = abs(int(np.log10(np.abs(x))))  \n",
        "    return exponent"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "01c346bb-09a4-c77e-cf73-694ab54cc384"
      },
      "outputs": [],
      "source": [
        "def plot_exp(data, title):\n",
        "    fig, ax =plt.subplots(figsize = (12, 8))\n",
        "    ax.plot(data.t16_exp, data.timestamp)\n",
        "    \n",
        "    ax.set_title(title)\n",
        "    ax.set_xlabel('Negative Power of Technical_16')\n",
        "    ax.set_ylabel('Timestamp')\n",
        "    plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "a8fdf1f4-8f5b-6559-9126-8763c46398e0"
      },
      "source": [
        "I want to introduce you most weird(in my opinion) feature in this competition - technical_16, a friend of time. Take a look on graps below.  Technical_16 is going closure to zero like sand clock, when time is going further. And technical_16 first number is making round. Just like simple clock )"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "95715378-960f-54ee-8d65-a42f1868b0ef"
      },
      "outputs": [],
      "source": [
        "data.technical_16.fillna(0, inplace = True)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "b61cece0-7ae5-3a22-06ec-8159c4edfc83"
      },
      "source": [
        "Let's take an exponent of technical_16's value"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a8ba767b-ea46-5599-f0ee-d0e36ef99d0a"
      },
      "outputs": [],
      "source": [
        "data['t16_exp'] = data.technical_16.map(lambda z: int(np.log10(np.abs(z))) - 1 if z!=0  else 0)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "2d831307-3b04-b80b-5707-acb973803446"
      },
      "outputs": [],
      "source": [
        "plot_exp(data.loc[(data.id == 288) & (data.t16_exp != 0)  & (~data.t16_exp.isnull()) ,['timestamp', 't16_exp']], 'id = 288')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "653941f9-2efe-374f-8ebc-6b6150eac6dc"
      },
      "source": [
        "Sometimes it's bigger than zero, in case bellow it is less. But it is always going to zero and making round."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "1c1d0d1a-01d1-0184-ae60-4d67a8124a84"
      },
      "outputs": [],
      "source": [
        "plot_exp(data.loc[(data.id == 1201) & (data.t16_exp != 0.0)  & (~data.t16_exp.isnull()) ,['timestamp', 't16_exp']], 'id = 1201')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "ba475887-9652-f3a8-d335-89ec06ce85b5"
      },
      "source": [
        "So after each 10-14 timestamps technical_16 decrease a power"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "ba66a2a2-b807-dccd-9e97-1abf1f49ac8a"
      },
      "source": [
        "Let's get a first number. It's not a good way to multiply so huge numbers, but it is easiest way i found"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "13f7e967-1a10-ad73-f88d-2c87c868ebdc"
      },
      "outputs": [],
      "source": [
        "data['t16_first_number'] = (data.technical_16 * (10**(data.t16_exp.abs())).astype('int'))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "9a52ccb7-58dc-911c-afd3-3b4c8cb89fd5"
      },
      "outputs": [],
      "source": [
        "def plot_first_numb(data, title):\n",
        "    fig, ax =plt.subplots(figsize = (12, 8))\n",
        "    ax.plot(data.timestamp, data.t16_first_number,marker = 'v',  mfc = 'g')\n",
        "    \n",
        "    ax.set_title(title)\n",
        "    ax.set_yticks(range(-10,10))\n",
        "    ax.set_xlabel('Timestamp')\n",
        "    ax.set_ylabel('First_number')\n",
        "    plt.show()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "cf672a79-68e7-53a3-e539-e043b682044f"
      },
      "outputs": [],
      "source": [
        "plot_first_numb(data.loc[(data.id == 300) & (data.t16_exp != 0) ,['timestamp', 't16_first_number']], 'id = 300')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "ff84c2ca-5023-bb01-eb53-30fa7fc55a75"
      },
      "source": [
        "Tail in right is not true number. It occurs because we multiplied on a really big number, i suppose."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "436a2b6d-efb3-11c9-cd9c-0dd178fbe2d0"
      },
      "outputs": [],
      "source": [
        "plot_first_numb(data.loc[(data.id == 1201) & (data.t16_exp != 0) ,['timestamp', 't16_first_number']], 'id = 1201')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "9d175b69-234d-2342-a681-2cba70831126"
      },
      "source": [
        "First number is making a round in every power - decreasing step. It seem's like we see cycle and step of cycle is defined by power. I suppose that power of technical_16 is day of trading and first number is time of this day."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "c1505c1b-415b-2f45-f79b-d659d346390c"
      },
      "outputs": [],
      "source": ""
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.6.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}