xquantipy.stocks package

Submodules

xquantipy.stocks.analysis module

class xquantipy.stocks.analysis.Analysis(tickers)[source]

Bases: object

A class to perform the analysis on tickers … Attributes: tickers : list/ticker object

Input can be a list of stock ticker objects or one stock ticker object

Methods: show_alpha_vs_beta(self)

plots a graph between alpha values and beta values of the stocks listed

get_merged_adj_close(self)

get merge all the data with adj close values in the tickers list

show_merged_adj_close_chart(self)

plot the adj close comparison of the stocks

get_merged_adj_close()[source]

Summary: A method to merge all the data with adj close values in the tickers list

Return: merged_dfs : DataFrame

returns the dataframe with adj close value of the tickers

show_alpha_vs_beta(index='^GSPC', risk_free_rate=0.05)[source]

Summary: A method to plot the alpha vs beta comparison of the stocks

Parameters: index : str

a string for the bench mark index default: ^GSPC

risk_free_ratefloat

value of the risk free return value default: 0.05 i.e. 5%

Return: fig : matplotlib

a figure object represents alpha vs beta

show_merged_adj_close_chart()[source]

Summary: A method to plot the adj close comparison of the stocks

Return: fig : matplotlib

a figure object represents merged adj close chart

xquantipy.stocks.ticker module

class xquantipy.stocks.ticker.Ticker(ticker, period='10Y')[source]

Bases: object

A class to represent a stock object … Attributes: stock : str

stock ticker name

periodstr

period selected for the data default: “10Y”

dataDataframe

timeseries daily data of the stock

fundamentalsdict -> DISCONTINUED DUE TO YAHOO FINANCE

fundamental data of the stock

Methods: get_adj_close(self)

returns a adj close dataframe for the ticker

show_adj_close(self)

plot adj close for the ticker

get_beta(self)

gets the beta value of the ticker object

get_alpha(Self, index = constants.BENCHMARK_INDEX, risk_free_rate=constants.RISK_FREE_RATE)

gets the alpha value of the ticker object

show_moving_average(self, period = [constants.MOVING_AVERAGE_PERIOD])

get the moving average of the particular stock analysis objects

show_moving_average_convergence_divergence(self, fastperiod=12, slowperiod=26, signalperiod=9)

plot the moving average convergence divergence (MACD) of the particular stock analysis objects

show_parabolic_sar(self, af=0.02, max_af=0.2)

plot the Parabolic SAR of the particular stock analysis objects

show_bollinger_bands(self, period=constants.MOVING_AVERAGE_PERIOD)

plot the bollinger band of the particular stock analysis objects

show_profit_loss(self, investment=5000)

plot profit loss of a particular stock based on the investment

show_roi(self)

plot roi of a particular stock

get_kelly_criterion(self) show_mass_index(self, periods=25, ema_periods=9) show_vortex_indicator(self, period=14) show_stochastic_oscillator(self, period=14, k=3)

get_adj_close()[source]

Summary: A method to get only the adj close column which is renamed to the self.stock name

Return: adj_close : dataframe

return value which represents the dataframe with adj close column

get_alpha(index='^GSPC', risk_free_rate=0.05)[source]

Summary: A method to calculate the alpha value of the stock which is a measure to find how a stock is beating a benchmark

Parameters: index : str

a string for the bench mark index default: ^GSPC

risk_free_ratefloat

value of the risk free return value default: 0.05 i.e. 5%

Return: alpha : float

return value which represents the alpha of the stock

get_beta(index='^GSPC')[source]

Summary: A method to calculate the beta value of the stock this value measures the expected move in a stock relative to movements in the overall market

Return: beta : float

return value which represents the beta of the stock

get_kelly_criterion()[source]

Summary: A method to get the kelly criterion for the whole period of the dataframe

Return: kelly_criterion : int

an integer represents kelly criterion

get_moving_average(type='simple', period=[20])[source]

Summary: A method to get the moving average of the particular stock analysis objects

Parameters: type : str

can be simple or exponential moving average

periodlist

a list of period to which moving average is calculated

Returns: df : Dataframe

a Dataframe of the stock with moving average

get_rsi(window=14, upper_band=70, lower_band=30)[source]
show_adj_close()[source]

Summary: A method to plot adj close column which is renamed to the self.stock name

Return: fig : module

return value which represents the matplotlib figure with adj close column

show_bollinger_bands(period=20)[source]

Summary: A method to plot the bollinger band of the particular stock analysis objects

Parameters: period : int

period for the calculation

Return: fig : matplotlib

a figure object represents bollinger band

show_candle_stick()[source]

Summary: A method to plot candle strick for self.stock name

Return: fig : module

return value which represents the matplotlib figure with candle stick

show_line()[source]

Summary: A method to plot line chart for self.stock data

Return: fig : module

return value which represents the plotly figure with line chart

show_mass_index(periods=25, ema_periods=9)[source]

Summary: A method to plot the mass index of the particular stock objects

Parameters: periods : int (optional default=25)

period of the plot

ema_periodsint (optional default=9)

exponential moving average period of the plot

Return: fig : matplotlib

a figure object represents mass index

show_moving_average(type='simple', period=[20])[source]

Summary: A method to plot the moving comparison of the particular stock analysis objects

Parameters: type : str

can be simple or exponential moving average

periodlist

a list of period to which moving average is calculated

Return: fig : matplotlib

a figure object represents moving average

show_moving_average_convergence_divergence(fastperiod=12, slowperiod=26, signalperiod=9)[source]

Summary: A method to plot the moving average convergence divergence (MACD) of the particular stock analysis objects

Parameters: fastperiod : int

fast period for the calculation

slowperiodint

slow period for the calculation

signalperiodint

signal period for the calculation

Return: fig : matplotlib

a figure object represents moving average convergence divergence

show_parabolic_sar(af=0.02, max_af=0.2)[source]

Summary: A method to plot the Parabolic SAR of the particular stock analysis objects

Parameters: af : int

acceleration factor for the calculation

max_afint

max acceleration factor for the calculation

Return: fig : matplotlib

a figure object represents parabolic SAR

show_profit_loss(investment=5000)[source]

Summary: A method to plot the profit or loss based on investments of the particular stock objects

Parameters: investment : int

investment value to invest in the stock

Return: fig : matplotlib

a figure object represents profit loss

resultsdict

a dictionary with profit loss results

show_roi()[source]

Summary: A method to get the plot for roi

Return: fig : matplotlib

a figure object represents roi

show_stochastic_oscillator(period=14, k=3)[source]

Summary: A method to plot the stochastic oscillator of the particular stock objects

Parameters: periods : int (optional default=14)

period of the plot

kint (optional default=3)

k value

Return: fig : matplotlib

a figure object represents mass index

show_volume()[source]

Summary: A method to plot volume chart for self.stock data

Return: fig : module

return value which represents the plotly figure with volume chart

show_vortex_indicator(period=14)[source]

Summary: A method to plot the vortex indicator of the particular stock objects

Parameters: periods : int (optional default=14)

period of the plot

Return: fig : matplotlib

a figure object represents mass index

Module contents