Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SHARE PYTHON FILE
#1
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()
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Timestamp of file changes if a share mapped to a server…. tester_V 34 3,629 Jul-04-2023, 05:19 AM
Last Post: tester_V
  access share attributed among several class methods drSlump 0 1,038 Nov-18-2021, 03:02 PM
Last Post: drSlump
  How to share a numpy array between 2 processes on Windows? qstdy 0 2,134 Jan-29-2021, 04:24 AM
Last Post: qstdy
  Access Network SMB Share on a NAS deltapy 2 8,874 Oct-31-2020, 09:14 AM
Last Post: deltapy
  Multiprocessing share variable catosp 0 2,130 Jul-15-2020, 10:45 AM
Last Post: catosp
  Copy info of 2 files with share information AngelRuizM 1 2,627 Aug-14-2017, 07:31 PM
Last Post: buran
  Properly share logger objects CardBoy 2 3,125 Jun-27-2017, 08:33 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020