"XOM", "BAC", "MCD", "WMT", "HD", "CMG", "GM", "F", "TGT", "KO", "GIS", "MRO", "PSX", "AXP", "GS", "NDAQ", "ABC", "CELG", "CVS", "AAL", "BA", "GE", "LUV", "CTXS", "SHW", "AMT", "REG", "AEE", "EXC", "PCG", "UNP", "WM" ] #StocksTicker=['BTC',"ETH","LTC","BCH","EOS",'LINK','TRX'] Prices = [] CurrentPrices = [] DayBefore = [] Mean = [] Correlation = [] Order = [] df = pd.DataFrame(columns=StocksTicker) for x in StocksTicker: y = prices(assets=symbols(x), start='2019-04-24', end='2019-09-24', frequency='minute') df[x] = pd.Series( np.gradient( np.gradient( scipy.signal.savgol_filter(y, 31, 2, 0, 1.0, -1, 'interp', 0.0)))) corr = df.corr() #corr.describe() useless for us rn #can make it more legible if needed, #it will be much more easier from this to see the correlation ax = sns.heatmap(corr, vmin=-1, vmax=1, center=0, square=True) #less number of negative correlation. bit shocking though.
# In[1]: ############INTRODUCTION######################## # Research environment functions from quantopian.research import prices, symbols # Pandas library: https://pandas.pydata.org/ import pandas as pd # Query historical pricing data for AAPL aapl_close = prices( assets=symbols('AAPL'), start='2013-01-01', end='2016-01-01', ) # Compute 50 and 200 day moving averages on # AAPL's pricing data aapl_sma50 = aapl_close.rolling(50).mean() aapl_sma200 = aapl_close.rolling(200).mean() # Combine results into a pandas DataFrame and plot pd.DataFrame({ 'AAPL': aapl_close, 'SMA50': aapl_sma50, 'SMA200': aapl_sma200 }).plot( title='AAPL Close Price / SMA Crossover'
# Computing library imports import matplotlib.pyplot as plt import numpy as np import pandas as pd from scipy import stats # ## Pricing & Returns # Historic pricing & returns data is imported and visualized based on the long-term period defined above. DataFrames are defined for cross referencing to other auxillary data. # In[3]: # Query historical pricing data for TDG tdg_close = prices(assets = asset, start = analysis_start,end = analysis_end,) # Compute 20 and 50 day moving averages on pricing data tdg_sma20 = tdg_close.rolling(20).mean() tdg_sma50 = tdg_close.rolling(50).mean() # Combine results into a pandas DataFrame and plot tdg_pricing_dataframe = pd.DataFrame({ stock_symbol: tdg_close, 'SMA20': tdg_sma20, 'SMA50': tdg_sma50}) # Query returns data for TDG tdg_returns = returns(assets = symbols(stock_symbol),start = analysis_start,end = analysis_end,) # Plot pricing data
# Research environment functions from quantopian.research import prices, symbols # Pandas library: https://pandas.pydata.org/ import pandas as pd # Query historical pricing data for AAPL aapl_close = prices( assets=symbols('AAPL'), start='2013-01-01', end='2015-01-01', ) # Compute 20 and 50 day moving averages on # AAPL's pricing data aapl_sma20 = aapl_close.rolling(20).mean() aapl_sma50 = aapl_close.rolling(50).mean() # Combine results into a pandas DataFrame and plot pd.DataFrame({ 'AAPL': aapl_close, 'SMA20': aapl_sma20, 'SMA50': aapl_sma50 }).plot(title='AAPL Close Price / SMA Crossover')
import pandas as pd import datetime # Research environment # Select a time range to inspect period_start = pd.Timestamp('2014-01-01') period_end = pd.Timestamp('2015-12-31') # Select a security ticker to inspect # Top choices: GOOG and GLD both perform well stock_symbol = 'QQQ' stock_close = prices(assets=symbols(stock_symbol), start=period_start, end=period_end) extremadataframe = pd.DataFrame({ 'price': [], 'type': [], 'trend': [], }, index=[]) orders = pd.DataFrame({ 'type': [], 'prev_exitgain': [], 'marker': [] }, index=[]) increasing = False
# Importar libreria de analisis de datos import pandas as pd # Importar componentes de la libreria de Quantopian from quantopian.research import prices, symbols # Obtener precios de cierre diario de una organización serie = prices( assets=symbols(acronimo), # Acronimo de la organización start='fecha_inicio', # 'AAAA-MM-DD' end='fecha_fin', # 'AAAA-MM-DD' ) # Obtener retornos diarios de una organización serie = returns( assets=symbols(acronimo), # Acronimo de la organización start='fecha_inicio', # 'AAAA-MM-DD' end='fecha_fin', # 'AAAA-MM-DD' ) # Obtener el numero de acciones negociadas serie = volumes( assets=symbols(acronimo), # Acronimo de la organización start='fecha_inicio', # 'AAAA-MM-DD' end='fecha_fin', # 'AAAA-MM-DD' ) # Obtener precios logatirmicos de cierre diario de una organización serie = log_prices( assets=symbols(acronimo), # Acronimo de la organización
@author: Hp """ ######################THIS PROJECT WILL WORK ONLY ON QUANTOPIAN##################### #SIMPLE MOVING AVERAGE CROSSOVER #Import the Libraries from quantopian.research import prices, symbols, returns import numpy as np import pandas as pd import matplotlib.pyplot as plt #CLOSING PRICES FOR PEPSI AND COKE FROM 2018 to MAY 2020 pep_close = prices(assets=symbols('PEP'), start='2018-01-01', end='2020-05-27') coke_close = prices(assets=symbols('KO'), start='2018-01-01', end='2020-05-27') #ROLLING WINDOW FOR 15 and 75 DAY MOVING AVERAGE FOR BOTH STOCKS pep_sma_15 = pep_close.rolling(window=15, min_periods=1, center=False).mean() coke_sma_15 = coke_close.rolling(window=15, min_periods=1, center=False).mean() pep_sma_75 = pep_close.rolling(window=75, min_periods=1, center=False).mean() coke_sma_75 = coke_close.rolling(window=75, min_periods=1, center=False).mean() #DATA FRAME TO CALCULATE THE SIGNALS (TRADING POINTS) trade_points = pd.DataFrame() #INITIALIZING THE DATA FRAME WITH THE 15- & 75-DAY MOVING AVERAGES trade_points['Pepsi_15_Day_SMA'] = pep_sma_15 trade_points['Pepsi_75_Day_SMA'] = pep_sma_75
# In addition to sentiment data, we will need pricing data for all assets present in this period. We can easily get a list of these assets from our pipeline output's index, and pass that list to `prices` to get the pricing data we need: # In[4]: # Import prices function from quantopian.research import prices # Get list of unique assets from the pipeline output asset_list = pipeline_output.index.levels[1].unique() # Query pricing data for all assets present during # evaluation period asset_prices = prices( asset_list, start=period_start, end=period_end ) # Now we can use Quantopian's open source factor analysis tool, [Alphalens](https://www.quantopian.com/lectures/factor-analysis-with-alphalens), to test the quality of our selection strategy. First, let's combine our factor and pricing data using get_clean_factor_and_forward_returns. This function classifies our factor data into quantiles and computes forward returns for each security for multiple holding periods. We will separate our factor data into 2 quantiles (the top and bottom half), and use 1, 5 and 10 day holding periods: # In[5]: # Import Alphalens import alphalens as al # Get asset forward returns and quantile classification # based on sentiment scores factor_data = al.utils.get_clean_factor_and_forward_returns(