+ 3

Python Finance Analyzing Bitcoin

Hello, i'm struggling with the last Code Repo task for the Python Finance Course: Tasks 1. Calculate the volatility of Bitcoin and output the risk %. 2. Calculate and output the Sharpe ratio. My code is a mess with lot of trial and error: import numpy as np import numpy_financial as npf import matplotlib.pyplot as plt import yfinance as yf #Task1: Calculate the Volatility of Bitcoin and output the Risk % #Task2: Calculate tand output the Sharpe Ratio #Need to calculate the returns data = yf.Ticker('BTC-USD') #Daily return d = yf.download('BTC-USD', start='2020-01-01') #Calculate percentage change pc = d['Close'].pct_change() x = data.history('1y')['Close'] start = 1000 / x[0] #Volatility #To do this use the std.dv of my returns vol = (np.std(d)) print(vol) annual_std = np.std(vol) * np.sqrt(252) print(annual_std) y = np.multiply(start, x) plt.plot(y) plt.savefig('plot.png')

29th Nov 2021, 1:18 AM
Thomas Dent
Thomas Dent - avatar
3 Answers
+ 6
Please put the code in Code Playground and then pass the link. I know a person who has already passed the course and knows a lot about the subject: Lobo Solitario
12th Dec 2021, 4:51 PM
Caleb Guerra Ortega
Caleb Guerra Ortega - avatar
8th Jan 2022, 7:22 PM
Pranav Hirani
Pranav Hirani - avatar
- 1
Bitcoin Price Time to get some values! Task 1. Get and output Close prices of Tesla stock for the last 5 days. Hint Use history() function on your data object and pass the period parameter with the appropriate value for the specified period. Don't forget to add the ['Close'] filter at the end.
12th Oct 2022, 5:02 AM
Moe Sanda Htun