当前位置: 首页>>代码示例>>Python>>正文


Python FigureFactory.create_ohlc方法代码示例

本文整理汇总了Python中plotly.tools.FigureFactory.create_ohlc方法的典型用法代码示例。如果您正苦于以下问题:Python FigureFactory.create_ohlc方法的具体用法?Python FigureFactory.create_ohlc怎么用?Python FigureFactory.create_ohlc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plotly.tools.FigureFactory的用法示例。


在下文中一共展示了FigureFactory.create_ohlc方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: readAssetReturnsCSV

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_ohlc [as 别名]
def readAssetReturnsCSV(asset):
    df = pandas.read_csv('../../Daily/' + asset + '.csv')
    df['Index'] = pandas.to_datetime(df['Index']) # convert dates to Datetime objects
    df = df.set_index('Index') # set Index
    df = df.sort_index() # sort by date

    # Will store the weekly data
    df_calcs = pandas.DataFrame(columns=['period_ended', 'open', 'high', 'low', 'close', 'volume',
                                         'adj.', 'weekly_return'])

    # compute weekly returns only across full trading weeks (Monday -> Friday)
    for index, row in df.iterrows():
         date = pandas.to_datetime(index)
         if date.weekday() == 4: # is Friday
             thur = date + datetime.timedelta(days=-1)
             wed = date + datetime.timedelta(days=-2)
             tues = date + datetime.timedelta(days=-3)
             mon = date + datetime.timedelta(days=-4)
             # trading occurred on corresponding Friday
             if thur in df.index and wed in df.index and tues in df.index and mon in df.index:
                 period_ended = date
                 open = df.loc[mon]['open']
                 close = row['close']
                 low = min(df.loc[mon]['low'], df.loc[tues]['low'], df.loc[wed]['low'], df.loc[thur]['low'],
                           row['close'])
                 high = max(df.loc[mon]['high'], df.loc[tues]['high'], df.loc[wed]['high'], df.loc[thur]['high'],
                           row['high'])
                 volume = df.loc[mon]['volume'] + df.loc[tues]['volume'] + df.loc[wed]['volume'] + \
                          df.loc[thur]['volume'] + row['volume']
                 adj = row['adj.']
                 weekly_return = (row['adj.'] - df.loc[mon]['adj.']) / df.loc[mon]['adj.']
                 #print(mon, '(', df.loc[mon]['adj.'], ') ->', date, '(', row['adj.'], '):', weekly_return*100, '%')
                 week = pandas.Series([period_ended, open, high, low, close, volume, adj, weekly_return])
                 week = week.rename({0: 'period_ended', 1: 'open', 2: 'high', 3: 'low', 4: 'close', 5: 'volume',
                                     6: 'adj.', 7: 'weekly_return'})
                 df_calcs = df_calcs.append(week, ignore_index=True)
    df_calcs = df_calcs.set_index('period_ended') # set index to period_ended

    # standardize weekly returns
    df_calcs['std_return'] = (df_calcs['weekly_return'] - df_calcs['weekly_return'].mean()) / \
                             df_calcs['weekly_return'].std()

    # save OHLC data
    ohlc = FF.create_ohlc(df_calcs.open, df_calcs.high, df_calcs.low, df_calcs.close, dates=df_calcs.index)

    return Asset.Asset(asset, df_calcs, ohlc)
开发者ID:ab4es,项目名称:google-trends,代码行数:48,代码来源:IOHandler.py

示例2: financialplots

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_ohlc [as 别名]
def financialplots(filename, plotkind):
    try:
        data = pd.read_csv(filename,index_col=0, parse_dates=True)
    except(FileNotFoundError, IOError):
        print('Wrong file or file path.')
        return None
    if plotkind == 'candlestick':
        fig = FF.create_candlestick(data['Opening Price'], data['Maximum Price'], data['Minimum Price'], data['Closing Price'],dates=data.index)
    elif plotkind == 'macd':
        fig = data['Closing Price'].ta_plot(study='macd', fast_period=12, slow_period=26, signal_period=9, asFigure=True)
    elif plotkind == 'boll':
        fig = data['Closing Price'].ta_plot(study='boll',asFigure=True)
    elif plotkind == 'ohlc':
        fig = FF.create_ohlc(data['Opening Price'], data['Maximum Price'], data['Minimum Price'], data['Closing Price'],dates=data.index)
    elif plotkind == 'sma':
        fig = data['Closing Price'].ta_plot(study='sma', asFigure=True)
    py.plot(fig,filename='../../plots/'+filename[:-4]+plotkind,validate=False,auto_open=False)
开发者ID:samshara,项目名称:Stock-Market-Analysis-and-Prediction,代码行数:19,代码来源:visualization.py

示例3: plotlyData

# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_ohlc [as 别名]
    def plotlyData(self, i_destDictKey, i_freq='d', i_debug=False, i_out=None):
        l_data = self.m_data[i_destDictKey]['data'][i_freq]
        l_data['Date_tmp'] = l_data['Date'].apply(lambda d: mdates.date2num(d.to_pydatetime()))

        # idxLocalMins = self.m_data[i_destDictKey]['analysis'][i_freq]['localMins']
        # idxLocalMaxs = self.m_data[i_destDictKey]['analysis'][i_freq]['localMaxs']
        minIdx = self.m_data[i_destDictKey]['analysis'][i_freq]['imin']
        maxIdx = self.m_data[i_destDictKey]['analysis'][i_freq]['imax']

        fig = FF.create_ohlc(l_data['Open'], l_data['High'], l_data['Low'], l_data['Close'], dates=l_data['Date'],
                             line=Line(color='black'))

        if self.m_data[i_destDictKey]['analysis'][i_freq]['trendType'] == 2:
            trend = 'Up-Trend'
        elif self.m_data[i_destDictKey]['analysis'][i_freq]['trendType'] == 1:
            trend = 'Down-Trend'
        else:
            trend = 'None'
        # Update the fig - all options here: https://plot.ly/python/reference/#Layout
        fig['layout'].update({
            # 'title': self.generalData['name'] + ' [' + trend + ']',
            'title': i_destDictKey + ' [' + trend + ']',
            'yaxis': {'title': 'Stock Price [$]'},
            'xaxis': {'title': 'Date'},
            # 'shapes': [{
            #     'x0': '2008-09-15', 'x1': '2008-09-15', 'type': 'line',
            #     'y0': 0, 'y1': 1, 'xref': 'x', 'yref': 'paper',
            #     'line': {'color': 'rgb(40,40,40)', 'width': 0.5}
            # }],
            # 'annotations': [{
            #     'text': "the fall of Lehman Brothers",
            #     'x': '2008-09-15', 'y': 1.02,
            #     'xref': 'x', 'yref': 'paper',
            #     'showarrow': False, 'xanchor': 'left'
            # }]
        })

        # plotly.offline.iplot(fig, filename='finance/aapl-recession-ohlc', validate=False)

        if len(self.m_data[i_destDictKey]['analysis'][i_freq]['ema34']) > len(l_data['Date']):
            idx = len(self.m_data[i_destDictKey]['analysis'][i_freq]['ema34']) - len(l_data['Date']) + 1

        add_mins = Scatter(
            x=l_data['Date'][minIdx],
            y=l_data['Low'][minIdx],
            name='min',
            mode='markers')
        add_maxs = Scatter(
            x=l_data['Date'][maxIdx],
            y=l_data['High'][maxIdx],
            name='max',
            mode='markers')
        add_ema34 = Scatter(
            x=l_data['Date'],
            y=self.m_data[i_destDictKey]['analysis'][i_freq]['ema34'][idx:],
            name='EMA-34',
            mode='line')
        add_ema14 = Scatter(
            x=l_data['Date'],
            y=self.m_data[i_destDictKey]['analysis'][i_freq]['ema14'][idx:],
            name='EMA-14',
            mode='line')
        add_ema200 = Scatter(
            x=l_data['Date'],
            y=self.m_data[i_destDictKey]['analysis'][i_freq]['ema200'][idx:],
            name='EMA-200',
            mode='line')
        add_ema50 = Scatter(
            x=l_data['Date'],
            y=self.m_data[i_destDictKey]['analysis'][i_freq]['ema50'][idx:],
            name='EMA-50',
            mode='line')

        fig['data'].extend([add_mins, add_maxs, add_ema34, add_ema14, add_ema200, add_ema50])
        plotly.offline.plot(fig, filename=str(i_destDictKey) + '.html')
开发者ID:tamirgz,项目名称:SectorwiseDailyStockAnalyzer,代码行数:77,代码来源:Stock.py


注:本文中的plotly.tools.FigureFactory.create_ohlc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。