xquantipy.stocks package¶
Submodules¶
xquantipy.stocks.analysis module¶
- class xquantipy.stocks.analysis.Analysis(tickers)[source]¶
Bases:
objectA 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
xquantipy.stocks.ticker module¶
- class xquantipy.stocks.ticker.Ticker(ticker, period='10Y')[source]¶
Bases:
objectA 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
- 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_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
- 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_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