This code harnesses the AlphaVantage API to download and analyze equity data on any constituent of the following groups:
This code also downloads and analyzes data from the United States SEC's Financial Statements datasets, which supplies additional feature data from a fundamental analysis standpoint.
load_single
downloads and processes a single symbol from AlphaVantage API into a fileload_single_drive
downloads and processes a single symbol from local drive into a variableload_separate
downloads and processes many symbols from AlphaVantage API into many filesload_combined_drive
downloads and processes many symbols from local drive into one variable-tickerUniverse
: collection of tickers to download (can also be a CSV of ticker symbols) -folderPath
: location of folder to store file-apiKey
: AlphaVantage API key (user-specific)-function
: distinguishes between intraday, daily, weekly, etc. downloads-interval
specifies what kind of intraday (1min, 15min, etc.)update_in_folder
updates all equity files in a folder, using the latest data from AlphaVantage-folderPath
: location of folder to look for files-apiKey
: AlphaVantage API key (user-specific)download_unzip
downloads and unzips data directly from the SEC websiteproc_in_directory
walks through download directory and parses each filepost_proc
performs post-processing on files, which makes them smallerjson_build
builds one JSON file for each company chosen-folderPath
: location of folder to download data-stockFolderPath
: location of folder to look for stock data-financialFolderPath
: location of folder to load financial data-suppressDownload
: order to suppress downloading data (i.e. already downloaded)-suppressProcess
: order to suppress processing data (i.e. already processed)json_parse
provides backup parsing code to clean up the JSON files in edgar_load.pyget_sic_names
scrapes SEC.gov for data on industry codes (SICs)submission_parse
parses submission filesnumber_parse
parses number filespresentation_parse
parses presentation filestag_parse
parses tag filesget_unique_tags
returns list of unique tags in a single company's JSON fileget_data_this_tag
writes data on one chosen tag to an output fileget_rolling_returns
calculates a list of rolling returns on an asset or portfoliooverall_returns
calculates the overall return from start to finishaccum_swing
computes the accumulation (running total) of the swing index, which depends on asset dataad_line
returns the accumulation-distribution line of asset dataadx
returns the average directional (movement) index of asset dataadxr
returns the average directional (movement) index rating of asset dataaroon
returns the Aroon indicator of asset dataaroon_oscillator
returns the Aroon oscillator of asset dataaverage_price
returns the average price of asset dataaverage_true_range
returns the average true range of asset databollinger
returns the Bollinger bands and width thereof, for asset datachaikin
returns the Chaikin money flow of price datachaikin_ad_osc
returns the Chaikin accumulation-distribution oscillator of asset datachaikin_volatility
returns the Chaikin volatility of asset datachande_momentum_oscillator
returns the Chande momentum oscillator of a price inputdema
returns the "double" exponential moving average of inputdetrended_price_osc
returns the de-trended price oscillator of a price inputdirectional_index
returns the directional indices (+DI and -DI) of asset datadirectional_movt_index
returns the directional movement index (based directly on +DI and -DI) of asset datadynamic_momentum_index
returns the DSI of price dataease_of_movt
returns the ease of movement of asset dataexponential_moving_average
returns the exponential moving average of inputgeneral_stochastic
returns the general Stochastic indicator of a price inputklinger_osc
returns the Klinger oscillator of asset datamacd
returns the MACD of a price input (same as price oscillator with 26-period slow EMA and 12-period fast EMA)market_fac_index
returns the market facilitation index of asset datamass_index
returns the mass index of asset datamedian_price
returns the median price of asset datamomentum
returns the momentum of a price inputmoney_flow_index
returns the money flow index of asset datanegative_volume_index
returns the negative volume index of asset datanormalized_price
returns the baseline-normalized price (a.k.a. performance indicator) of a price inputon_balance_volume
returns the on balance volume of asset dataparabolic_sar
returns the parabolic SAR of asset datapercent_volume_oscillator
returns the percent volume oscillator of volume datapolarized_fractal_efficiency
returns the polarized fractal efficiency of asset datapositive_volume_index
returns the positive volume index of asset dataprice_channel
returns the high and low price channels of a price inputprice_oscillator
returns the price oscillator of a price input, which depends on a choice of moving average functionprice_rate_of_change
returns the price rate of change of a price inputprice_volume_rank
returns the price-volume rank of asset data (with user choice for which price)price_volume_trend
returns the price-volume trend of asset dataqstick
returns the Q-stick indicator of asset data, which depends on a choice of moving average functionrandom_walk_index
returns the random walk index of asset datarange_indicator
returns the range indicator of asset datarel_momentum_index
returns the relative momentum index of a price input (typically closing price)rel_strength_index
returns the 14-day relative momentum index of a price inputrel_vol_index
returns the relative volatility index of a price inputsimple_moving_average
returns the simple moving average of inputstochastic_momentum_index
returns the stochastic momentum index of asset datastochastic_oscillator
returns the stochastic oscillator of asset data, which depends on a choice of moving average functionstochastic_rsi
returns the general stochastic of the RSI (dependent on a price input)swing_index
returns the swing index of asset datatee_three
and tee_four
return T3 and T4, generalizations of DEMA, of input, respectivelytrend_score
returns the trend score of a price inputtriangular_moving_average
returns the triangular moving average of inputtriple_ema
returns the triple exponential moving average of inputtrix
returns the TRIX indicator of a price inputtrue_range
returns the true range of asset datatrue_strength_index
returns the true strength index of a price inputtypical_price
returns the typical price of asset dataultimate_oscillator
returns the ultimate oscillator of asset datavariable_moving_average
returns the variable moving average of a price inputvertical_horizontal_filter
returns the vertical-horizontal filter (VHF) of asset datavol_adj_moving_average
returns the volume-adjusted moving average of asset dataweighted_close
returns the weighted close of asset dataweighted_moving_average
returns the weighted moving average of a price inputwilliams_ad
returns the Williams accumulation-distribution indicator of asset datawilliams_percent
returns the Williams %R indicator of asset datazero_lag_ema
returns the "zero-lag" exponential moving average of a price inputadf
computes the augmented Dickey-Fuller test for mean reversion propertiesget_features
returns a dataframe of features, with one column for each indicator listed above-tickerUniverse
: collection of tickers to download (can also be a comma-delimited list of ticker symbols) -baseline
: selection of symbol to use as baseline asset/index-startDate
: start date of data to process into features-endDate
: end date of aforementioned-function
: distinguishes between intraday, daily, weekly, etc. downloads-interval
specifies what kind of intraday (1min, 15min, etc.)-folderPath
: location of folder to write the files-plotOnly
: if indicated, plot the heatmaps; otherwise, build from scratch without plotshold_clear
builds a simple strategy for buying/selling, holding one's position, and clearingcrossover
builds a strategy for buying when trend crosses below baseline and selling when trend crosses above (or vice versa)zscore_distance
builds a strategy for for buying when trend crosses far below baseline and selling when trend crosses far above (or vice versa), as measured by z-scoresasset_ranker
ranks a group of assets based on a certain criterion, choosing which ones should be bought long or sold shortapply_trades
applies any series of trades to any set of symbols, yielding a portfolio simulationbeta
calculates asset/portfolio betasharpe_ratio
calculates the Sharpe ratio for a given portfoliotreynor_ratio
calculates the Treynor ratio for given portfolioreturns_valuation
values the portfolio (initial value, final value, and return) against a benchmark (such as an index)get_generic_from_prompts
gets any non-tickerverse prompt from a list of command promptsget_tickerverse_from prompts
returns a tickerverse and its name, from a list of command promptsget_current_symbols
looks for stock ticker symbols in the files within directorymemory_check
verifies if file occupies too much space in RAMmerge_chunked
inner-joins a small dataframe (left) with a large one (right), the latter being read in chunkswrite_as_append
writes dataframe to file path in append modeperiodic_compound
calculates the bond discounting factor under periodic compoundingcontinuous_compound
calculates the bond discounting factor under continuous compoundingfixed_rate_bond
calculates the initial bond price for zero- and non-zero-coupon fixed-rate bondsobtain_parse_nasdaq
gets the Nasdaq 100 stocks from stockmonitor.com. obtain_parse_wiki
gets either the S&P 500 or the Dow 30 stocks from Wikipedia. obtain_parse_mutual_funds
gets the top 25 mutual funds from marketwatch.com.obtain_parse_etfs
gets the top 100 ETFs from etfdb.com.feature_plot
plots a file of features as a correlation heatmapcandle_plot
plots a single asset in candlestick formprice_plot
plots a single asset against any number of prices, trends, indicators, etc.-symbol
: symbol of the asset to plot-folderPath
: location of folder to look for files-function
: distinguishes between intraday, daily, weekly, etc. downloads-interval
specifies what kind of intraday (1min, 15min, etc.)-startDate
: start date of data to plot-endDate
: end date of aforementioned-column
: choice of price or volume to plot-candlestick
: choice to use candlestick plot instead of typical plot