SHARE PYTHON FILE - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: SHARE PYTHON FILE (/thread-15695.html) |
SHARE PYTHON FILE - ambush - Jan-27-2019 I have a python file and it consists of modules such as pandas,numpy,matplotlib and quandl. However, I need to share the file so the user can directly see the results after running the file # -*- coding: utf-8 -*- """ Created on Mon Jan 28 03:30:19 2019 @author: sai """ import quandl import pandas as pd import matplotlib.pyplot as plt import numpy as np equitydata = quandl.get("HKEX/02382",authtoken='Jjz7SvMpapFPhoZPAzga',pagination = True) print(equitydata) #plotting nominal prices equitydata['Nominal Price'].plot(grid=True) plt.title("Sunny optical closing price") plt.show() #making short and long windows short_window = 40 long_window = 100 signals = pd.DataFrame(index=equitydata.index) signals['signal'] = 0.0 #SMA of Short window signals['short_mavg'] = equitydata['Nominal Price'].rolling(window=short_window,min_periods=1,center=False).mean() #SMA of Long WIndow signals['long_mavg'] = equitydata['Nominal Price'].rolling(window=long_window,min_periods=1,center=False).mean() # Create signals signals['signal'][short_window:] = np.where(signals['short_mavg'][short_window:] > signals['long_mavg'][short_window:],1.0,0.0) #Generate trading orders signals['positions'] = signals['signal'].diff() print(signals) import matplotlib.pyplot as plt # Initialize the plot figure fig = plt.figure(figsize=(20,15)) # Add a subplot and label for y—axis ax1 = fig.add_subplot(111, ylabel='Price in $') # Plot the closing price equitydata['Nominal Price'].plot(ax=ax1, color='black', lw=2.) # Plot the short and long moving averages signals[['short_mavg', 'long_mavg']].plot(ax=ax1, lw=2.) # Plot the buy signals ax1.plot(signals.loc[signals.positions == 1.0].index,signals.short_mavg[signals.positions == 1.0],'^', markersize=20, color='g') # Plot the sell signals ax1.plot(signals.loc[signals.positions == -1.0].index,signals.short_mavg[signals.positions == -1.0],'v', markersize=20, color='r') # Show the plot plt.show() RE: SHARE PYTHON FILE - snippsat - Jan-28-2019 If users need to run your code the easiest way is eg Google CoLab, Azure Notebooks, Binder(yet a new way). So then there is no installation for users as all run in cloud,and you can just share your code. There are other way that can vary in difficulty. I have build all this stuff to a single .exe file with pyinstaller, then have to understand error that's gone come in build process and fix them. nbviewer is an other way,but the view is static and show the render output of NoteBook. |