<jupyter_start><jupyter_text>Tic rule example<NAME> proposes in his book "Advances in Financial Machine Learning" one way to give the sign label to ticks transactions as first step to infer how information arrives to the markets.  $b_{t} = \frac{\left | \Delta p_{t} \right |}{\Delta p_{t}}\$,if $p_{t} \neq 0$.  Otherwise $b_{t} = b_{t-1}$By construction, the first bt is bt+1.The data used in this note book was get from:https://quotes.hegnar.no/quotes/paperdump.php?paper=JPM.N.  Handler 04/03-2019 *Downloaded data on March 5, 2019.   The data was used here is only for teaching purposes, note only is showing data fragments, and the csv file is not posted to the public, in order to protect copyrights owner.**COPYRIGHT DISCLAIMER UNDER SECTION 107 OF THE COPYRIGHT ACT 1976 Copyright Dislcaimer Under Section 107 of the Copyright Act 1976, allowance is made for “fair use” for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statue that might otherwise be infringing. Non-profit, educational, or personal use tips the balance in favor of fair use.**<jupyter_code>import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import microfinkitv_0_2 as mf
import seaborn as sns
%matplotlib inline
pd.set_option('display.float_format', lambda x: '%.2f' % x)
df = pd.read_csv('20190304JPMT.csv')
# Transform time stamp
df['time']=df.time.str.replace("T", "")
df["time"] = pd.to_datetime(df["time"])
df.head()
# Copy the data frame time , price  and quantity columns
dfp = df[['time','price','quantity']].copy()
dfp.head()<jupyter_output><empty_output><jupyter_text>Tick ruleTick ule it's a rule designed to give a sign to a transaction tick, according to the difference of the same with the previous tick. Basically, calculate the difference in absolute value between the price of the tick at time t and the price at time t-1, divided by the same difference, but this time taking into account its sign. The result is a value of -1, 0 or 1. When the value obtained is 0, it is assumed that the sign is the same as time t -1<jupyter_code>dfp['b_t'] = mf.tick_rule(dfp,'price')
dfp.head()<jupyter_output><empty_output><jupyter_text>As you can see, the first two values have the same sign, that is, because of the ease in formulating the function to apply at the beginning of the series, the sign in t takes the later value in the series (t + 1) , and not the previous value that in this case does not exist.<jupyter_code>dfp['b_t'].head(10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.087984496124031, 'fraction_numerical': 0.01937984496124031, 'mean_word_length': 5.002325581395349, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '440376', 'license': 'MIT', 'n_tokens_mistral': 806, 'n_tokens_neox': 751, 'n_words': 359, 'path': 'docs/Tick_rule_example.ipynb', 'repo_name': 'microfinkit/microfinkitv0', 'size': '2588'}