Created
November 29, 2021 23:21
-
-
Save alphazwest/d405895ffe3d53aace21eff1974fc9c3 to your computer and use it in GitHub Desktop.
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 | |
ETH["mod_adr"] = ETH['dr_pct'].rolling(window=20).mean() | |
# View Result | |
print(ETH) | |
High Low dr_pct mod_adr | |
Date | |
2021-05-18 3562.465088 3246.404053 9.735727 NaN | |
2021-05-19 3437.935791 1952.460205 76.082246 NaN | |
2021-05-20 2993.145264 2170.229004 37.918407 NaN | |
2021-05-21 2938.205078 2113.347168 39.030876 NaN | |
2021-05-22 2483.983154 2168.124268 14.568302 NaN | |
... ... ... ... ... | |
2021-11-14 4689.842773 4516.935547 3.827976 5.057539 | |
2021-11-15 4764.636230 4546.599121 4.795609 5.075362 | |
2021-11-16 4891.704590 4144.334961 18.033524 5.507737 | |
2021-11-17 4300.306641 4107.125977 4.703549 5.246916 | |
2021-11-18 4343.557129 3985.766113 8.976719 5.480348 | |
[185 rows x 4 columns] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment