Data Visualization
FinLab provides a suite of charting tools to help you gain deeper insight into market data.
Technical Indicator Charts
Use plot_tw_stock_candles to draw candlestick charts, with support for overlaying multiple EMA lines and technical indicator subplots such as STOCH and RSI.
from finlab.plot import plot_tw_stock_candles
from talib import abstract
from finlab.data import indicator
stock_id = '2330'
recent_days = 1000
adjust_price = False
resample = "D"
overlay_func = {
'ema_5': indicator('EMA', timeperiod=5),
'ema_10': indicator('EMA', timeperiod=10),
'ema_20': indicator('EMA', timeperiod=20),
'ema_60': indicator('EMA', timeperiod=60),
}
k, d = indicator('STOCH')
rsi = indicator('RSI')
technical_func = [{'K': k, 'D': d}, {'RSI': rsi}]
plot_tw_stock_candles(
stock_id,
recent_days,
adjust_price,
resample,
overlay_func=overlay_func,
technical_func=technical_func,
)
Return and Turnover Treemap
The nested treemap displays multi-dimensional data with interactive features, showing Taiwan stock data organized by industry classification.
from finlab.plot import plot_tw_stock_treemap
plot_tw_stock_treemap(
start='2021-07-01', end='2021-07-02', area_ind="turnover", item="return_ratio"
)
P/E Ratio and Market Cap Treemap
You can also use market capitalization as the area indicator and P/E ratio as the color indicator, with clip and color_continuous_scale parameters to customize the visual effect.
from finlab.plot import plot_tw_stock_treemap
plot_tw_stock_treemap(
start='2021-07-01',
end='2021-07-02',
area_ind="market_value",
item="price_earning_ratio:本益比",
clip=(0, 50),
color_continuous_scale='RdBu_r',
)
Financial Indicator Radar Chart
Compare the indicator rankings of a portfolio's holdings. Supports bar_polar, line_polar, and scatter_polar modes.
bar_polar Mode
from finlab.plot import plot_tw_stock_radar
portfolio = ['1101', '2330', '8942', '6263']
plot_tw_stock_radar(portfolio=portfolio, mode="bar_polar")
line_polar Mode (Custom Financial Indicators)
You can specify particular financial indicators for comparison and adjust the number of bins.
from finlab.plot import plot_tw_stock_radar
feats = [
'fundamental_features:營業毛利率',
'fundamental_features:營業利益率',
'fundamental_features:稅後淨利率',
'fundamental_features:現金流量比率',
'fundamental_features:負債比率',
]
plot_tw_stock_radar(portfolio=["9939"], feats=feats, mode="line_polar", cut_bins=8)
P/E River Chart
Uses the highest and lowest P/E or P/B values to draw a river chart, helping determine where the current indicator stands relative to its historical range.
from finlab.plot import plot_tw_stock_river
plot_tw_stock_river(
stock_id='2330', start='2015-1-1', end='2022-7-1', mode='pe', split_range=10
)
Strategy Position Sunburst Chart
Monitor multi-strategy position allocations with a sunburst chart visualization.