numpy Python -什么是最好的图表,我可以通过提供3条信息创建,日期,RSI,交易状态[关闭]

rt4zxlrg  于 11个月前  发布在  Python
关注(0)|答案(1)|浏览(96)

**已关闭。**此问题不符合Stack Overflow guidelines。目前不接受回答。

这个问题似乎与help center中定义的范围内的编程无关。
昨天就关门了。
Improve this question
有人能给予我建议我可以建立什么图表来表示RSI和交易状态吗?我有一个研究项目,我正在使用yahoo_fin来检索交易数据,Pandas数据框包含如下3条信息

DateTime             RSI        Signal
2023-11-15 12:15:00  67.854002  HOLD
2023-11-15 12:20:00  67.854002  HOLD
2023-11-15 12:25:00  73.494992  SELL
2023-11-15 12:30:00  68.330019  HOLD
2023-11-15 12:35:00  63.522484  HOLD
2023-11-15 12:40:00  66.091706  HOLD
2023-11-15 12:45:00  68.330019  HOLD
2023-11-15 12:50:00  63.522484  HOLD
2023-11-15 12:55:00  66.091706  HOLD
2023-11-15 13:00:00  66.091706  BUY
2023-11-15 13:05:00  66.091706  HOLD

字符串
我可以通过提供上述信息来创建 Jmeter 图吗?我使用的是Python。如果您能提供一个示例,我将非常感激。
我正在尝试执行以下操作

col_names = ['Date', 'RSI', 'Signal']
df.columns = col_names

print(df)

fig = go.Figure(go.Indicator(
    mode = "gauge+number",
    value = "BUY",
    domain = {'x': df['Date'], 'y': df['Signle']},
    title = {'text': "Trading Signal"}))

It returns the following error:
(0) The 'x[0]' property is a number and may be specified as:
      - An int or float in the interval [0, 1]

ivqmmu1c

ivqmmu1c1#

不清楚你要什么,但先给予例子,安装图
运行

pip install plotly

字符串
运行代码以查看示例结果

import plotly.graph_objects as go
import pandas as pd

data = {
    'DateTime': ['2023-11-15 12:15:00', '2023-11-15 12:20:00', '2023-11-15 12:25:00',
                 '2023-11-15 12:30:00', '2023-11-15 12:35:00', '2023-11-15 12:40:00',
                 '2023-11-15 12:45:00', '2023-11-15 12:50:00', '2023-11-15 12:55:00',
                 '2023-11-15 13:00:00', '2023-11-15 13:05:00'],
    'RSI': [67.854002, 67.854002, 73.494992, 68.330019, 63.522484, 66.091706,
            68.330019, 63.522484, 66.091706, 66.091706, 66.091706],
    'Status': ['HOLD', 'HOLD', 'SELL', 'HOLD', 'HOLD', 'HOLD', 'HOLD', 'HOLD', 'HOLD', 'BUY', 'HOLD']
}

df = pd.DataFrame(data)
df['DateTime'] = pd.to_datetime(df['DateTime'])
fig = go.Figure(go.Indicator(
    mode="gauge+number",
    value=df['RSI'][0],
    title={'text': "RSI"},
    domain={'x': [0, 1], 'y': [0, 1]},
    gauge={'axis': {'range': [0, 100]},
           'bar': {'color': "lightgray"},
           'steps': [
               {'range': [0, 30], 'color': "red"},
               {'range': [30, 70], 'color': "yellow"},
               {'range': [70, 100], 'color': "green"}],
           'threshold': {
               'line': {'color': "black", 'width': 4},
               'thickness': 0.75,
               'value': df['RSI'][0]}
           }
))

fig.add_annotation(
    go.layout.Annotation(
        text=df['Status'][0],
        align='center',
        showarrow=False,
        x=0.5,
        y=0.5
    )
)

def update_chart(trace, points, selector):
    index = points.point_inds[0]
    trace.value = df['RSI'][index]
    fig.layout.annotations[0].text = df['Status'][index]

fig.update_layout(updatemenus=[{'type': 'buttons',
                                'showactive': False,
                                'buttons': [{'label': 'Play',
                                             'method': 'animate',
                                             'args': [None, {'frame': {'duration': 1000, 'redraw': True},
                                                              'fromcurrent': True}]}]}],
                  sliders=[{'yanchor': 'top',
                            'xanchor': 'left',
                            'currentvalue': {'font': {'size': 20},
                                             'visible': True,
                                             'prefix': 'Timestamp: ',
                                             'suffix': ' UTC'},
                            'transition': {'duration': 300, 'easing': 'cubic-in-out'},
                            'steps': [{'args': [[f'{timestamp}'], {'frame': {'duration': 300, 'redraw': True},
                                                                   'mode': 'immediate',
                                                                   'transition': {'duration': 300}}],
                                       'label': f'{timestamp}',
                                       'method': 'animate'} for timestamp in df['DateTime'].dt.strftime('%Y-%m-%d %H:%M:%S')]},
                           ])

fig.update_geos(projection_type="natural earth")
fig.show()

相关问题