<jupyter_start><jupyter_text>时机最重要<jupyter_code>import flynnBot.flynnBot as fbot
import pandas as pd
import matplotlib.pyplot as plt
sym = '000333'

start = '2011-01-01'
end = '2020-12-31'

bot = fbot.flynnBot(sym, 1000000, 0, start, end)
df = bot.fetch()
df.head(5)<jupyter_output><empty_output><jupyter_text>格式化<jupyter_code>dataSet = df.set_index(pd.to_datetime(df['date'])).copy()
dataSet.head(2)<jupyter_output><empty_output><jupyter_text>按照每年pivot分段<jupyter_code>ptbl = pd.pivot_table(dataSet, index=dataSet.index.month,
                     columns=dataSet.index.year,
                     values='adjClose',
                     aggfunc='sum')
ptbl
# 丢掉不全的年
ptbl.dropna(axis=1, inplace=True)
ptbl
for c in ptbl.columns:
    average = ptbl[c].sum() / 12
    ptbl['norm' + str(c)] = ptbl[c] / average

ptbl.filter(regex='norm')<jupyter_output><empty_output><jupyter_text>再对norm之后的月份进行一个汇总<jupyter_code>yearslis = list(ptbl.filter(regex='norm'))
yearslis
ptbl['sum'] = ptbl[yearslis].sum(axis=1)
ptbl
nyears = len(yearslis)
ptbl['finalIndex'] = ptbl['sum'] / nyears
ptbl
fig, (axup, axdown) = plt.subplots(2, figsize=(24, 24))

ptbl[yearslis].plot(grid=True, ax=axup)
ptbl['finalIndex'].plot(grid=True, ax=axdown)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15865384615384615, 'fraction_numerical': 0.032852564102564104, 'mean_word_length': 5.372448979591836, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '372557', 'license': 'MIT', 'n_tokens_mistral': 564, 'n_tokens_neox': 539, 'n_words': 72, 'path': 'lessions/08-timing-first/08-timing-first.ipynb', 'repo_name': 'FlynnMa/quantBob', 'size': '1248'}