Bottom Page

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()







Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  python file output to log file Rsh 4 180 Aug-13-2019, 09:00 PM
Last Post: DeaD_EyE
  Help me with python read file and save file wereak 9 689 Apr-02-2019, 04:17 PM
Last Post: wereak
  Execute a file within another Python file in Spyder Antonio 1 710 Jun-11-2018, 08:10 PM
Last Post: snippsat
  Executing external Python file in background and get output in python nakiscia 0 2,554 Feb-15-2018, 02:07 PM
Last Post: nakiscia
  Help with python code to search string in one file & replace with line in other file mforthman 26 3,111 Dec-19-2017, 07:11 PM
Last Post: Larz60+
  Copy info of 2 files with share information AngelRuizM 1 907 Aug-14-2017, 07:31 PM
Last Post: buran
  Properly share logger objects CardBoy 2 1,049 Jun-27-2017, 08:33 PM
Last Post: Ofnuts

Forum Jump:


Users browsing this thread: 1 Guest(s)