AmirTrader commited on
Commit
643be96
·
1 Parent(s): cf31902

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -15
app.py CHANGED
@@ -46,33 +46,23 @@ def get_hvplot(ticker , startdate , enddate , interval,window,window2):
46
  DF = getPolygonDF(ticker , startdate=startdate , enddate=enddate , intervalperiod=interval,window=window,window2=window2)
47
 
48
  import hvplot.pandas # Ensure hvplot is installed (pip install hvplot)
49
- from sklearn.linear_model import LinearRegression
50
  import holoviews as hv
51
  hv.extension('bokeh')
52
  # Assuming your dataframe is named 'df' with columns 'Date' and 'Close'
53
  # If not, replace 'Date' and 'Close' with your actual column names.
54
 
55
  # Step 1: Create a scatter plot using hvplot
56
- scatter_plot = DF.hvplot(x='Date', y='Close', kind='scatter',title=f'{ticker} Close vs. Date')
57
-
58
- # Step 2: Fit a linear regression model
59
- DF['Date2'] = pd.to_numeric(DF['Date'])
60
- X = DF[['Date2']]
61
- y = DF[['Close']] #.values
62
- model = LinearRegression().fit(X, y)
63
 
64
- # # Step 3: Predict using the linear regression model
65
- DF['Predicted_Close'] = model.predict(X)
66
 
67
- # # Step 4: Create a line plot for linear regression
68
- line_plot = DF.hvplot(x='Date', y='Predicted_Close', kind='line',line_dash='dashed', color='red')
69
- line_plot_SMA = DF.hvplot(x='Date', y='SMA', kind='line',line_dash='dashed', color='orange')
70
- line_plot_SMA2 = DF.hvplot(x='Date', y='SMA2', kind='line',line_dash='dashed', color='orange')
71
 
72
  # # Step 5: Overlay scatter plot and linear regression line
73
  # return (scatter_plot * line_plot).opts(width=800, height=600, show_grid=True, gridstyle={ 'grid_line_color': 'gray'})
74
  # grid_style = {'grid_line_color': 'black'}#, 'grid_line_width': 1.5, 'ygrid_bounds': (0.3, 0.7),'minor_xgrid_line_color': 'lightgray', 'xgrid_line_dash': [4, 4]}
75
- return (scatter_plot * line_plot *line_plot_SMA *line_plot_SMA2).opts(width=800, height=600, show_grid=True)
76
 
77
 
78
  tickers = ['AAPL', 'META', 'GOOG', 'IBM', 'MSFT','NKE','DLTR','DG']
 
46
  DF = getPolygonDF(ticker , startdate=startdate , enddate=enddate , intervalperiod=interval,window=window,window2=window2)
47
 
48
  import hvplot.pandas # Ensure hvplot is installed (pip install hvplot)
49
+
50
  import holoviews as hv
51
  hv.extension('bokeh')
52
  # Assuming your dataframe is named 'df' with columns 'Date' and 'Close'
53
  # If not, replace 'Date' and 'Close' with your actual column names.
54
 
55
  # Step 1: Create a scatter plot using hvplot
56
+ scatter_plot = DF.hvplot(x='UNIXTIME', y='c', kind='scatter',title=f'{ticker} Close vs. Date')
 
 
 
 
 
 
57
 
 
 
58
 
59
+ line_plot_SMA = DF.hvplot(x='UNIXTIME', y='SMA', kind='line',line_dash='dashed', color='orange')
60
+ line_plot_SMA2 = DF.hvplot(x='UNIXTIME', y='SMA2', kind='line',line_dash='dashed', color='orange')
 
 
61
 
62
  # # Step 5: Overlay scatter plot and linear regression line
63
  # return (scatter_plot * line_plot).opts(width=800, height=600, show_grid=True, gridstyle={ 'grid_line_color': 'gray'})
64
  # grid_style = {'grid_line_color': 'black'}#, 'grid_line_width': 1.5, 'ygrid_bounds': (0.3, 0.7),'minor_xgrid_line_color': 'lightgray', 'xgrid_line_dash': [4, 4]}
65
+ return (scatter_plot *line_plot_SMA *line_plot_SMA2).opts(width=800, height=600, show_grid=True)
66
 
67
 
68
  tickers = ['AAPL', 'META', 'GOOG', 'IBM', 'MSFT','NKE','DLTR','DG']