Beispiel #1
0
def analyze_trade_pair(con, trade_pairs):
    line = kani.LineCharts()
    all_df = None
    for trade_pair in trade_pairs:
        company, magic = trade_pair
        sql = make_sql(company, magic)
        df = read_sql(sql, con)
        if df is not None and len(df) > 0:
            df.close_time.fillna(method='ffill', inplace=True)
            df.index = df.close_time
            df = df.reindex()
            df.sort_index(inplace=True)
            profit_cumsum = df["profit"].groupby(df.index).sum().cumsum()
            profit_plot = profit_cumsum.resample('T').last()
            profit_plot.fillna(method='ffill', inplace=True)
            if len(profit_plot) > 0:
                line.add_chart("%s:%d" % (company, magic), profit_plot)
            if all_df is not None:
                all_df = pd.concat([all_df, df], axis=0)
            else:
                all_df = df

    if len(all_df) > 0 and len(trade_pairs) >= 2:
        all_df.close_time.fillna(method='ffill', inplace=True)
        df = all_df.reindex()
        df.sort_index(inplace=True)
        profit_cumsum = df["profit"].groupby(df.index).sum().cumsum()
        profit_plot = profit_cumsum.resample('T').last()
        profit_plot.fillna(method='ffill', inplace=True)
        if len(profit_plot) > 0:
            line.add_chart("ALL", profit_plot)
    return line.plot(width=600)
Beispiel #2
0
def analyze_all(con, companies, from_time='2018-10-18'):
    df = None
    for company_name in companies:
        sql = "SELECT profit, close_time FROM bitcoin.%s_trade_history" % (
            company_name)
        sql += " where close_time > '%s' and position_status=5 and open_order_number is not null and close_order_number is not null" % (
            from_time)
        tempdf = read_sql(sql, con)
        tempdf.index = tempdf.close_time

        if df is None:
            df = tempdf
        else:
            df = pd.concat([df, tempdf], axis=0)
    line = kani.LineCharts(width=600)
    if len(df) > 0:
        df.close_time.fillna(method='ffill', inplace=True)
        df = df.reindex()
        df.sort_index(inplace=True)
        profit_cumsum = df["profit"].groupby(df.index).sum().cumsum()
        profit_plot = profit_cumsum.resample('T').last()
        profit_plot.fillna(method='ffill', inplace=True)
        if len(profit_plot) > 0:
            line.add_chart("ALL", profit_plot)
    return line.plot()
Beispiel #3
0
def plot_make(df, show_title=True):
    if show_title:
        display(Markdown('### All Make Logic'))
    make_df = df[df['is_making']].copy()
    make_df['cumprofit'] = make_df['profit'].cumsum()
    make_df.index = make_df['close_time']
    make = make_df['cumprofit'].resample('T').last()
    make.fillna(method='ffill', inplace=True)
    line = kani.LineCharts()
    line.add_chart('make', make)
    return line.plot(width=600)
Beispiel #4
0
    def testName(self):
        start = datetime.datetime(2012, 1, 1)
        end = datetime.datetime(2017, 12, 31)

        df = web.DataReader('SNE', 'morningstar', start, end)
        df.reset_index(level=0, inplace=True)

        candle = kani.CandlestickCharts()
        candle.add_chart('SNE', df)
        H = candle.plot()
        H.save_file('candle_chart')

        candle = kani.LineCharts()
        candle.add_chart('SNE', df['Open'])
        H = candle.plot()
        H.save_file('line_chart')