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
import sys | |
import os | |
def print_dir_tree(dirname: str, indent: int=0): | |
# Prints the indendations | |
for i in range(indent): | |
print(" ", end="") | |
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
import time | |
import requests | |
# use a context manager to make an HTTP request and file | |
with requests.get("https://www.example.com/file.txt", stream=True) as r: | |
with open('download.txt', 'wb') as file: | |
# Get the total size, in bytes, from the response header | |
total_size = int(r.headers.get('Content-Length')) |
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
import requests | |
with requests.get('https://www.example.com/file.txt')as r: | |
with open('download.txt', 'wb')as file: | |
file.write(r.raw) |
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
import requests | |
import shutil | |
from tqdm.auto import tqdm | |
# make an HTTP request within a context manager | |
with requests.get("https://www.example.com/file.txt", stream=True) as r: | |
# check header to get content length, in bytes | |
total_length = int(r.headers.get("Content-Length")) | |
# implement progress bar via tqdm |
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
""" | |
Sources like OpenSea will pull metadata from a contract URI | |
specified in a e.g. tokenURI function within a contract. | |
Sample Reference: https://docs.opensea.io/docs/metadata-standards | |
OpenSea particularly will use values stored within the "attributes" | |
key, found within a JSON-formatted, to display verifiably-rare | |
characteristics of an NFT. | |
Notes: | |
This illustrates poor attempts at randomness |
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
# Get pricing data | |
import yfinance as yf | |
# Get the previous 6 months pricing data for ETH | |
ETH = yf.Ticker('ETH-USD').history(period='6mo', interval="1d")[["High", "Low"]] | |
# Calculate Daily Range for each period and normalize as pct change | |
ETH['dr_pct'] = ETH.apply(lambda x: 100 * (x["High"] / x["Low"] - 1), axis=1) | |
# Calculate the average daily range over a 20-period interval |
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
# Get High/Low for each period | |
daily_ranges = [d[1] / d[0] for d in data] | |
# Get SMA of daily Ranges | |
sma = mean(daily_ranges) | |
# Calculate | |
modified_adr = 100 * (sma - 1) | |
>>> 85.0 |
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 rows # 18-21 | |
print(ETH.iloc[17:21]) | |
High Low dr adr | |
Date | |
2021-06-04 2857.165527 2562.637451 294.528076 NaN | |
2021-06-05 2817.484863 2558.233643 259.251221 NaN | |
2021-06-06 2743.441162 2616.162354 127.278809 435.919141 | |
2021-06-07 2845.185059 2583.995117 261.189941 433.175586 |
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
# Add a simple moving average | |
ETH["adr"] = ETH['dr'].rolling(window=20).mean() | |
# View result | |
High Low dr adr | |
Date | |
2021-05-18 3562.465088 3246.404053 316.061035 NaN | |
2021-05-19 3437.935791 1952.460205 1485.475586 NaN | |
2021-05-20 2993.145264 2170.229004 822.916260 NaN | |
2021-05-21 2938.205078 2113.347168 824.857910 NaN |
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
# Calculate Daily Range for each period | |
ETH['dr'] = ETH.apply(lambda x: x["High"] - x["Low"], axis=1) | |
# Result | |
High Low dr | |
Date | |
2021-05-18 3562.465088 3246.404053 316.061035 | |
2021-05-19 3437.935791 1952.460205 1485.475586 | |
2021-05-20 2993.145264 2170.229004 822.916260 |
NewerOlder