# stock-analysis **Repository Path**: the_machine/stock-analysis ## Basic Information - **Project Name**: stock-analysis - **Description**: No description available - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2019-11-27 - **Last Updated**: 2023-09-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # stock-analysis: 1.2.0 # Stock analysis ## Usage ```python from stock_analysis import stock stock_price = pd.read_csv('sample_data.csv', index_col=None, dtype={'trade_date': str}) stock = stock.Stock(data=stock_price) ``` ### Moving Average #### Simple Moving Average ```python # get result in dataframe ma_x, ma_y = stock.simple_moving_average(value='low', n=5, ret_list=True) # plot ma_line = Line(xdata=ma_x, ydata=ma_y, color='r', zorder=15) fig, ax = stock.plot(kind='line', value='low') ax.add_line(ma_line.get_line2d()) ``` #### Identify highs and lows (with visualization) ```python stock_price = pd.read_csv('sample_data.csv', index_col=None, dtype={'trade_date': str})\ .sort_values('trade_date')\ .reset_index(drop=True) s = Stock(data=stock_price) s2 = VisStock(stock_obj=s) h, l = s.get_local_high_and_low(value='low') x, y = s.dates_to_points(dates=h, value='low') x2, y2 = s.dates_to_points(dates=l, value='low') ``` ### Visualization Candlestick ```python stock.plot() ``` ![](docs/images/candlestick.png) Support line ```python # Create a canvas c = s.create_canvas(figsize=(30, 10)) # Add support line: price, start/end date c.add_support_line(92, 20201228, 20210416) # Plot stock price and the support line c.draw() ``` Line with reflection point ```python stock.plot(kind='line', show_reflection_point=True) ``` ![](docs/images/highs_and_lows.png) Moving average ```python from stock_vis.line import Line # get line x, y ma_x, ma_y = stock.simple_moving_average(value='low', n=5, ret_list=True) ma_line = Line(xdata=ma_x, ydata=ma_y, color='r', zorder=15) # add line to an axes fig, ax = stock.plot(kind='line', value='low') ax.add_line(ma_line.get_line2d()) ``` ![](docs/images/sma.png) # TSWrapper Tushare data dictionary ```python from tswrapper import tsmeta tsmeta.list_api()[:5] a = tsmeta.get_api_desc('monthly') print(a) ```