Python launcher functioning but not displaying any output

Multi tool use
Python launcher functioning but not displaying any output
I am using Pandas to read a CSV file that consists of names of stocks. After that, I am creating a new list where stocks that fit certain algorithms are appended; however, it only works with 8 - 9 stocks at a time. Is there somewhere I am making the code very inefficient and that can be optimized?
Here is my code:
import datetime as dt
from dateutil.relativedelta import relativedelta
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader.data as web
import numpy as np
import csv
from mpl_finance import candlestick_ohlc
import matplotlib.dates as mdates
from matplotlib.dates import DateFormatter, MonthLocator, YearLocator, DayLocator, WeekdayLocator
end = dt.date.today()
start_48 = end - relativedelta( years=4 )
ticker_names = [ 'GGP', 'XLU', 'AAPL', 'AMZN', 'NVDA', 'XLI', 'XLP', 'ROL', 'MU', 'CAKE', 'CHUBA', 'HCA', 'ADI', 'EA', 'WYNN' ]
new_list =
for each in ticker_names:
df_w = web.DataReader( each, 'morningstar', start_48, end )
file_name_w = each + 'weekly.csv'
df_w.to_csv( file_name_w )
df_w = pd.read_csv( file_name_w, parse_dates=True, index_col=0 )
df_w[ 'Date2' ] = df_w[ 'Date' ]
df_w['Date'] = pd.to_datetime(df_w['Date'])
df_w.set_index('Date', inplace=True)
df_w.sort_index(inplace=True)
def take_first(array_like):
return array_like[0]
def take_last(array_like):
return array_like[-1]
output_w = df_w.resample('W', # Weekly resample
how={'Date2': take_first,
'Open': take_first,
'High': 'max',
'Low': 'min',
'Close': take_last,
'Volume': 'sum'},
loffset=pd.offsets.timedelta(days=-6)) # to put the labels to Monday
df_w = output_w[['Date2','Open', 'High', 'Low', 'Close', 'Volume']]
alldays = DayLocator()# minor ticks on the days
allweeks = WeekdayLocator()
allmonths = MonthLocator()
yearFormatter = DateFormatter( '%b %Y' )
monthFormatter = DateFormatter( '%m' )
weekFormatter = DateFormatter('%b %d %Y') # e.g., Jan 12 2018
dayFormatter = DateFormatter('%d') # e.g., 12
df_w[ 'EMA_40' ] = df_w[ 'Close' ].ewm( span = 40, adjust=False ).mean()
df_w[ 'EMA_150' ] = df_w[ 'Close' ].ewm( span = 150, adjust=False ).mean()
df_w[ 'EMA_200' ] = df_w[ 'Close' ].ewm( span = 200, adjust=False ).mean()
df_w[ 'H_40' ] = ( df_w[ 'High' ] - df_w[ 'EMA_40' ] ) / df_w[ 'EMA_40' ]
df_w[ 'H_150' ] = ( df_w[ 'High' ] - df_w[ 'EMA_150' ] ) / df_w[ 'EMA_150' ]
df_w[ 'H_200' ] = ( df_w[ 'High' ] - df_w[ 'EMA_200' ] ) / df_w[ 'EMA_200' ]
df_w[ 'L_40' ] = ( df_w[ 'Low' ] - df_w[ 'EMA_40' ] ) / df_w[ 'EMA_40' ]
df_w[ 'L_150' ] = ( df_w[ 'Low' ] - df_w[ 'EMA_150' ] ) / df_w[ 'EMA_150' ]
df_w[ 'L_200' ] = ( df_w[ 'Low' ] - df_w[ 'EMA_200' ] ) / df_w[ 'EMA_200' ]
df_w[ 'C_40' ] = ( df_w[ 'Close' ] - df_w[ 'EMA_40' ] ) / df_w[ 'EMA_40' ]
df_w[ 'C_150' ] = ( df_w[ 'Close' ] - df_w[ 'EMA_150' ] ) / df_w[ 'EMA_150' ]
df_w[ 'C_200' ] = ( df_w[ 'Close' ] - df_w[ 'EMA_200' ] ) / df_w[ 'EMA_200' ]
df_w[ 'OP_40' ] = ( df_w[ 'Open' ] - df_w[ 'EMA_40' ] ) / df_w[ 'EMA_40' ]
df_w[ 'OP_150' ] = ( df_w[ 'Open' ] - df_w[ 'EMA_150' ] ) / df_w[ 'EMA_150' ]
df_w[ 'OP_200' ] = ( df_w[ 'Open' ] - df_w[ 'EMA_200' ] ) / df_w[ 'EMA_200' ]
df_w.dropna( inplace=True )
df_ohlc_w = df_w
final_file_name_w = each + 'weekly.csv'
df_ohlc_w.to_csv( final_file_name_w, index=False )
latest_ema_40 = df_w[ 'EMA_40' ].tail( 1 )
latest_ema_40 = max( latest_ema_40 )
latest_ema_150 = df_w[ 'EMA_150' ].tail( 1 )
latest_ema_150 = max( latest_ema_150 )
latest_ema_200 = df_w[ 'EMA_200' ].tail( 1 )
latest_ema_200 = max( latest_ema_200 )
max_h_40 = df_tail[ 'H_40' ].max()
max_h_150 = df_tail[ 'H_150' ].max()
max_h_200 = df_tail[ 'H_200' ].max()
min_h_40 = df_tail[ 'H_40' ].min()
min_h_150 = df_tail[ 'H_150' ].min()
min_h_200 = df_tail[ 'H_200' ].min()
last_close_40 = df_w[ 'C_40' ].tail( 1 )
last_close_40 = max( last_close_40 )
last_close_150 = df_w[ 'C_150' ].tail( 1 )
last_close_150 = max( last_close_150 )
last_close_200 = df_w[ 'C_200' ].tail( 1 )
last_close_200 = max( last_close_200 )
if ( ( max_h_40 - min_h_40 <= 0.15 ) or ( max_h_150 - min_h_150 <= 0.15 ) or ( max_h_200 - min_h_200 <= 0.15 ) ):
new_list.append( each )
elif ( abs( last_close_40 ) <= 0.08 or abs( last_close_150 ) <= 0.08 or abs( last_close_200 ) <= 0.08 ):
new_list.append( each )
print( new_list )
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.