Created
September 1, 2021 01:04
-
-
Save SajidLhessani/f83c554ecda0068ac225169c2ee0563c 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
| # Data manipulation libraries | |
| import pandas as pd | |
| import numpy as np | |
| # Machine learning libraries | |
| from sklearn.svm import SVC | |
| from sklearn.preprocessing import StandardScaler | |
| from sklearn.model_selection import RandomizedSearchCV | |
| from sklearn.model_selection import TimeSeriesSplit | |
| from sklearn.pipeline import Pipeline | |
| from sklearn.metrics import confusion_matrix | |
| from sklearn.metrics import classification_report | |
| # Technical indicator library | |
| import talib as ta | |
| # Data import library | |
| import yfinance as yf | |
| # Plotting libraries | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| from matplotlib.dates import DateFormatter | |
| import matplotlib.dates as mdates | |
| import plotly.graph_objs as go | |
| #Download live data | |
| df = yf.download('TSLA',period = '1d', interval = '1m') | |
| df | |
| #declare figure | |
| fig = go.Figure() | |
| #Set up traces | |
| fig.add_trace(go.Candlestick(x=df.index, | |
| open=df['Open'], | |
| high=df['High'], | |
| low=df['Low'], | |
| close=df['Close'], name = 'market data')) | |
| # Add titles | |
| fig.update_layout( | |
| title='Tesla price', | |
| yaxis_title='Stock Price (USD per Shares)') | |
| # X-Axes | |
| fig.update_xaxes( | |
| rangeslider_visible=True, | |
| rangeselector=dict( | |
| buttons=list([ | |
| dict(count=1, label="30m", step="minute", stepmode="backward"), | |
| dict(count=6, label="90m", step="minute", stepmode="backward"), | |
| dict(count=1, label="HTD", step="hour", stepmode="todate"), | |
| dict(step="all") | |
| ]) | |
| ) | |
| ) | |
| #Show | |
| fig.show() | |
| # Drop the rows with zero volume traded | |
| df = df.drop(df[df['Volume'] == 0].index) | |
| # Create a variable n with a value of 10 | |
| n = 10 | |
| # Create a column by name, RSI and assign the calculation of RSI to it | |
| df['RSI'] = ta.RSI(np.array(df['Close'].shift(1)), timeperiod=n) | |
| df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment