Skip to content

Instantly share code, notes, and snippets.

View alphazwest's full-sized avatar

Zack West alphazwest

View GitHub Profile
# Get pricing data
import yfinance as yf
# Get the previous 6 months pricing data for ETH and limit to High, Low
ETH = yf.Ticker('ETH-USD').history(period='6mo', interval="1d")[["High", "Low"]]
# View resulting dataframe
print(ETH)
High Low
# Create list for Daily Range values
daily_ranges = []
# Get High - Low (DR) for each period
for price in prices:
# Calculate DR
pct_daily_range = price["low"] / price["high"]
# Normalize
# Five prices as High and Low for the
# five day period K
prices = [
{"high": 5, "low": 3},
{"high": 7, "low": 4},
{"high": 9, "low": 6},
{"high": 7, "low": 3},
{"high": 8, "low": 4},
]
# Example access
Date Open Adj Close Predicted Close Trade Made Gain
2020-10-22 00:00:00 441.920013 425.790009 408.98989935265433 False 0
2020-10-23 00:00:00 421.839996 420.630005 404.07720184792413 False 0
2020-10-26 00:00:00 411.630005 420.279999 403.74397078786285 False 0
2020-10-27 00:00:00 423.76001 424.679993 407.93308373130776 False 0
2020-10-28 00:00:00 416.480011 406.019989 390.16740853240196 False 0
2020-10-29 00:00:00 409.959991 410.829987 394.7468749770709 False 0
2020-10-30 00:00:00 406.899994 388.040009 373.0491654300521 False 0
2020-11-02 00:00:00 394.0 400.51001 384.92150948185565 False 0
2020-11-03 00:00:00 409.730011 423.899994 407.19046819438336 False 0
@alphazwest
alphazwest / covariance-calculations.csv
Last active July 13, 2021 16:54
Resulting covariance calculations per sampled value of the X and Y series.
Observation Number Predictor (X) xi-x_bar Response (Y) yi - y_bar (yi - y_bar)(xi-x_bar)
1 10 4.5 3.15 -1.471 -6.6195
2 11 5.5 3.47 -1.151 -6.3305
3 12 6.5 3.86 -0.761 -4.9465
4 13 7.5 4.07 -0.551 -4.1325
5 14 8.5 4.57 -0.051 -0.4335
6 15 9.5 4.86 0.239 2.2705
@alphazwest
alphazwest / covariance-sample.csv
Created July 12, 2021 19:51
Sample data for covariance visualization and analysis
Observation Predictor (X) Response (Y)
1 10 3.15
2 11 3.47
3 12 3.86
4 13 4.07
5 14 4.57
6 15 4.86
7 16 5.0
8 17 5.43
9 18 5.64
@alphazwest
alphazwest / tsla.csv
Last active July 5, 2021 15:46
Historic pricing data for $TSLA from 2020-01-01 to 2021-06-30
Date Open High Low Close Adj Close Volume
2020-01-02 84.900002 86.139999 84.342003 86.052002 86.052002 47660500
2020-01-03 88.099998 90.800003 87.384003 88.601997 88.601997 88892500
2020-01-06 88.094002 90.311996 88.000000 90.307999 90.307999 50665000
2020-01-07 92.279999 94.325996 90.671997 93.811996 93.811996 89410500
2020-01-08 94.739998 99.697998 93.646004 98.428001 98.428001 155721500
2020-01-09 99.419998 99.760002 94.573997 96.267998 96.267998 142202000
2020-01-10 96.358002 96.987999 94.739998 95.629997 95.629997 64797500
2020-01-13 98.699997 105.125999 98.400002 104.972000 104.972000 132588000
2020-01-14 108.851997 109.482002 104.980003 107.584000 107.584000 144981000
@alphazwest
alphazwest / machine-learning-keywords.json
Created July 3, 2021 15:20
A JSON-format string containing the keywords, observed counts, and monthly volume reports, sorted in descending order of total monthly volume.
[["machine learning books", {
"count": 5,
"vol": "1300"
}
], ["best machine learning books", {
"count": 5,
"vol": "1000"
}
], ["artificial intelligence books", {
"count": 2,
@alphazwest
alphazwest / python_weekday_names_one.py
Created February 7, 2021 23:41
Getting a weekday integer representation using the datetime class
from datetime import datetime
# Create datetime object
date = datetime.now()
>>> 2021-02-07 15:30:46.665318
# Get the weekday value, as an integer
date.weekday()
>>> 6
# Create a new set object
set_one = {1, 2, 3}
>>> {1, 2, 3}
# Update with tuple value
set_one.update((4, 5, 6, 6))
>>> {1, 2, 3, 4, 5, 6}