<jupyter_start><jupyter_text>Determining Rebalance Day and Hour By: <NAME> 2020.04.05 DescriptionFart Set will rebalance once per week at the same day and hour.  Instead of picking an arbitrary time to rebalance on, let's find:* The day of week with the least price volatility* On that day, the hour with the least price volatility<jupyter_code>import pandas as pd

eth_1h = pd.read_csv('../data/ETH.csv')

print(f"Start date: {eth_1h['date'].iat[0]}")
print(f"End date: {eth_1h['date'].iat[-1]}")
eth_1h.head()
# Group ETH into 1d candles
# https://pypi.org/project/TAcharts
from TAcharts.utils import group_candles

eth_1d = group_candles(eth_1h, n=24)
eth_1d.head()<jupyter_output><empty_output><jupyter_text>Daily Volatility<jupyter_code>def calc_pct_change(high, low, _open):
    return (high - low) / _open
eth_1d['pct_change'] = calc_pct_change(eth_1d['high'], eth_1d['low'], eth_1d['open'])
eth_1d['weekday'] = pd.DatetimeIndex(eth_1d['date']).day_name()

daily_volatility = eth_1d.groupby('weekday')['pct_change'].mean().sort_values(ascending=False)
print(daily_volatility)<jupyter_output>weekday
Tuesday      0.070740
Wednesday    0.066079
Sunday       0.063304
Monday       0.062416
Friday       0.061621
Thursday     0.059621
Saturday     0.052946
Name: pct_change, dtype: float64<jupyter_text>Saturday has the lowest average daily volatility.  Hourly Volatility<jupyter_code>eth_1h['pct_change'] = calc_pct_change(eth_1h['high'], eth_1h['low'], eth_1h['open'])
eth_1h['hour'] = pd.DatetimeIndex(eth_1h['date']).hour

# Only take volatility from Saturday
eth_1h_saturday = eth_1h[pd.DatetimeIndex(eth_1h['date']).day_name() == 'Saturday']

hourly_volatility = eth_1h.groupby('hour')['pct_change'].mean().sort_values(ascending=False)
print(hourly_volatility)<jupyter_output>hour
11    0.015472
19    0.014008
10    0.013859
9     0.013478
18    0.013072
17    0.012644
8     0.012570
15    0.012349
7     0.012239
16    0.011714
5     0.011542
12    0.011506
4     0.011314
3     0.011192
6     0.011139
14    0.010986
20    0.010895
13    0.010425
23    0.010207
22    0.010100
21    0.010055
2     0.010032
0     0.009698
1     0.009190
Name: pct_change, dtype: float64
{'fraction_non_alphanumeric': 0.1223648029330889, 'fraction_numerical': 0.13565536205316223, 'mean_word_length': 4.498740554156171, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '529249', 'license': 'MIT', 'n_tokens_mistral': 1029, 'n_tokens_neox': 858, 'n_words': 188, 'path': 'FART/Determining Rebalance Day and Hour.ipynb', 'repo_name': 'carlfarterson/tokensets', 'size': '2190'}