<jupyter_start><jupyter_text>Bollinger Bands ExampleThis example shows up how to use `stock-pandas` and mplfinance to draw a candlestick chart - with bollinger bands- And if the stock price of a certain day crosses up the upper bollinger band or crosses down the lower band, we want to draw a marker to emphasize the price.In the [example](https://github.com/kaelzhang/stock-pandas/tree/master/example) directory, there is a csv file which contains klines of `HK.00700` (TENCENT HOLDINGS LTD) from Oct 15, 2019 to March 9, 2020.<jupyter_code>import pandas as pd
from stock_pandas import StockDataFrame<jupyter_output><empty_output><jupyter_text>StockDataFrame(data, date_column=None, *args, **kwargs)`StockDataFrame` accepts all arguments available for `pandas.DataFrame`.Besides, we could specify the optional argument `date_column`, and `StockDataFrame` will convert the `dtype` of the column named `date_column` to `datetime`, then set the column as index.Setting the index of a data frame as `DatetimeIndex` is required by many plotting libraries.<jupyter_code>stock = StockDataFrame(
    # Use pandas IO tools to read the csv
    pd.read_csv('tencent.csv'), 
    date_col='time_key'
)

stock
import mplfinance as mpf
import numpy as np<jupyter_output><empty_output><jupyter_text>`mplfinance` requires some columns with capitalized names. We could use `stock.alias()` to create an alias name for column `"open"` without duplicating it.<jupyter_code>stock.alias('Open', 'open')
stock.alias('High', 'high')
stock.alias('Low', 'low')
stock.alias('Close', 'close')
cross_up_upper = stock['high'].copy()

# `cross_up_upper` is the series of high prices each of which cross up the upper bollinger band.
cross_up_upper[
    ~ stock['column:high > boll.upper']
] = np.nan
# Set some items of the series to `np.nan` so that mplfinance will not draw markers for those items.

cross_down_lower = stock['low'].copy()

cross_down_lower[
    ~ stock['column:low < boll.lower']
] = np.nan
apds = [
    mpf.make_addplot(
        stock[
            [
                # The middle band
                'boll', 
                
                # The upper band
                # The default period of bollinger bands is 20 days. 
                # However, we could specify arguments for a command after `:`.
                'boll.upper:20',
                
                # The lower band
                # Which is a short cut for 'boll.lower'
                'boll.l'
            ]
        ]
    ),
    mpf.make_addplot(cross_up_upper, scatter=True, markersize=200, marker='v'),
    mpf.make_addplot(cross_down_lower, scatter=True, markersize=200, marker='^'),
]

# Go plotting! Oh yeah!
mpf.plot(stock, type='candle', addplot=apds, figscale=2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09837251356238698, 'fraction_numerical': 0.00976491862567812, 'mean_word_length': 3.4612903225806453, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '487107', 'license': 'MIT', 'n_tokens_mistral': 890, 'n_tokens_neox': 827, 'n_words': 281, 'path': 'example/bollinger_bands.ipynb', 'repo_name': 'kaelzhang/stock-pandas-example', 'size': '2765'}