This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| OpenTime | Open | High | Low | Close | CloseTime | |
|---|---|---|---|---|---|---|
| Wed 01 Jan, 2020 01:00:00 | 7195.24 | 7255.0 | 7175.15 | 7200.85 | Thu 02 Jan, 2020 00:59:59 | |
| Thu 02 Jan, 2020 01:00:00 | 7200.77 | 7212.5 | 6924.74 | 6965.71 | Fri 03 Jan, 2020 00:59:59 | |
| Fri 03 Jan, 2020 01:00:00 | 6965.49 | 7405.0 | 6871.04 | 7344.96 | Sat 04 Jan, 2020 00:59:59 | |
| Sat 04 Jan, 2020 01:00:00 | 7345.0 | 7404.0 | 7272.21 | 7354.11 | Sun 05 Jan, 2020 00:59:59 | |
| Sun 05 Jan, 2020 01:00:00 | 7354.19 | 7495.0 | 7318.0 | 7358.75 | Mon 06 Jan, 2020 00:59:59 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| print(freq) | |
| print(sum(freq['Frequency (f)']) == len(series)) | |
| # Outputs: | |
| # {'Zones': ['$6965.7 - $7390.3', '$7390.3 - $7814.9', '$7814.9 - $8239.5', '$8239.5 - $8664.1', '$8664.1 - $9088.7', '$9088.7 - $9513.3'], 'Frequency (f)': [5, 1, 7, 5, 9, 4]} | |
| # True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| series = df['Close'].to_list() | |
| freq = grouped_frequency(series) | |
| keys = list(freq.keys()) | |
| # Create the table with column names from the returned dictionary | |
| table = PrettyTable([keys[0], keys[1]], title="BTCUSDT Zones (1 Jan. - 31 Jan. 2020)") | |
| # append nested lists to the table | |
| for i, j in zip(freq['Zones'], freq['Frequency (f)']): | |
| table.add_row([i, j]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def prec(num: int): | |
| """Returns the number of decimal places""" | |
| # check if there is a decimal in the stringed numnber | |
| if '.' in str(num): | |
| # looks for the decimal point index | |
| ind = str(num).index('.') | |
| # returns the number of characters from the decimal... | |
| # point to the end of the number | |
| return len(str(num)[ind:]) - 1 | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def mode(data: pd.Series): | |
| return data.mode() | |
| series = df['Close'] | |
| print(mode(series)) | |
| # Outputs: | |
| # Output exceeds the size limit.... | |
| # 0 6965.71 | |
| # 1 7200.85 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def mode(data: pd.Series): | |
| return data.mode() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def mode(data: list): | |
| return max(set(data), key=data.count) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def median(data: list, days: int = 14) -> list: | |
| data = sorted(data[-days:]) | |
| length = len(data) | |
| if length % 2 == 0: | |
| half = int(length/2) | |
| new = data[half-1:half+1] | |
| return round(sum(new) / len(new), 2) | |
| else: | |
| half = int(length/2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def median(data: pd.Series, days: int = 14) -> int: | |
| return round(series.iloc[-days:].median(),2) | |
| series = df['Close'] | |
| mid_price = median(series,14) | |
| print(f"${mid_price}") | |
| # Outputs: $8718.87 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def median(data: pd.Series, days: int = 14) -> int: | |
| """Returns the median of a Pandas series: | |
| Args: | |
| data (pd.Series): Set of observations | |
| days (int): Number of days. Defaults to 14. | |
| Returns: | |
| int | |
| """ | |
| return round(series.iloc[-days:].median(),2) |