import pandas as pd
import numpy as np
import datetime as dt
import yfinance as yf
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import plotly.graph_objects as go # Import plotly.graph_objects for using go.Figure
com_tckr=input(“State the Ticker of the company you want to analyse:”)
st_dt=input(“Enter the starting date:”)
end_dt=input(“Enter the end date:”)
com_df=yf.download(com_tckr, start=st_dt, end=end_dt, actions=True)
#checking for null or NaN values
num_null=com_df.isnull().sum()
print(“The number of null or missing values in the downloaded data:”,num_null)
#Calculate % daily returns
com_df[‘DailyReturns’]=(com_df[‘Close’].pct_change(1)*100).round(2)
com_df[‘DailyReturns’].replace(np.nan,0,inplace=True)
print(com_df)
print()
#Calculate and print the maximum %daily return for the company
print(com_df.describe().round(2))
def plot_financial_data(df, title):
fig=go.Figure() # Create a Figure object using go.Figure
financial_columns = ['Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume']
financial_columns = [col for col in financial_columns if col in df.columns]
for col in financial_columns:
fig.add_trace(go.Scatter(x=df.index, y=df[col], mode='lines', name=col))
fig.update_traces(line_width=2)
fig.update_layout(title=title, xaxis_title="Date", yaxis_title="Value", plot_bgcolor="white" )
fig.show()
option=input("Do you want graphical representation(y/n)?")
if(option=='y'):
plot_financial_data(com_df, 'Financial Data')
Hey @Rituparna_Duttagupta welcome to the forums.
Must be related to your data. Working example:
import pandas as pd
import plotly.graph_objects as go
from plotly import data
# dummy data
df = data.stocks()
def plot_financial_data(df, title):
fig=go.Figure() # Create a Figure object using go.Figure
financial_columns = ['GOOG', 'High', 'FB', 'Close', 'Adj Close', 'Volume']
financial_columns = [col for col in financial_columns if col in df.columns]
for col in financial_columns:
fig.add_trace(go.Scatter(x=df.index, y=df[col], mode='lines', name=col))
fig.update_traces(line_width=2)
fig.update_layout(title=title, xaxis_title="Date", yaxis_title="Value", plot_bgcolor="white" )
fig.show()
# usage
plot_financial_data(df, 'Financial Data')
Okay. But I tried with AAPL, TSLA and JPM. Can it be that the problem is in the downloaded data?
Not sure what you are referring to. But it is definitely not related to plotly or the function you use.
I recommend inspecting the downloaded data.