Last active
March 5, 2024 11:59
-
-
Save quantra-go-algo/2057ee9eace3a0ab41e951bddf784ed9 to your computer and use it in GitHub Desktop.
Sharpe Ratio - Sharpe Ratio in Python
This file contains 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
# Load the required modules and packages | |
import numpy as np | |
import pandas as pd | |
import yfinance as yf | |
# Pull NIFTY data from Yahoo finance | |
NIFTY = yf.download('^NSEI','2012-01-01', '2016-01-01') | |
# Compute the logarithmic returns using the closing price | |
returns = np.log(NIFTY['Close'] / NIFTY['Close'].shift(1)) | |
volatility = returns.std() * np.sqrt(252) | |
sharpe_ratio = ((returns.mean()*252) - 0.05) / volatility | |
sharpe_ratio |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment