(feat) format visualizations

This commit is contained in:
cardosofede
2024-07-16 18:36:50 +03:00
parent e7eba7ed09
commit f12357048f
8 changed files with 19 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
from plotly.subplots import make_subplots
from frontend.visualization.candles import get_bt_candlestick_trace, get_candlestick_trace
from frontend.visualization.candles import get_bt_candlestick_trace
from frontend.visualization.executors import add_executors_trace
from frontend.visualization.pnl import get_pnl_trace
from frontend.visualization.theme import get_default_layout

View File

@@ -38,6 +38,7 @@ def render_accuracy_metrics(summary_results):
st.metric(label="Accuracy Long", value=f"{accuracy_long:.2%}")
st.metric(label="Accuracy Short", value=f"{accuracy_short:.2%}")
def render_accuracy_metrics2(summary_results):
accuracy = summary_results.get('accuracy', 0)
total_long = summary_results.get('total_long', 0)

View File

@@ -1,5 +1,5 @@
import plotly.graph_objects as go
import pandas as pd
import plotly.graph_objects as go
from frontend.visualization import theme
@@ -11,7 +11,7 @@ def get_candlestick_trace(df):
low=df['low'],
close=df['close'],
name="Candlesticks",
increasing_line_color='#2ECC71', decreasing_line_color='#E74C3C',)
increasing_line_color='#2ECC71', decreasing_line_color='#E74C3C', )
def get_bt_candlestick_trace(df):

View File

@@ -1,6 +1,6 @@
from decimal import Decimal
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import frontend.visualization.theme as theme

View File

@@ -1,9 +1,11 @@
import numpy as np
import plotly.graph_objects as go
import frontend.visualization.theme as theme
def create_executors_distribution_traces(buy_spreads, sell_spreads, buy_amounts_pct, sell_amounts_pct, total_amount_quote):
def create_executors_distribution_traces(buy_spreads, sell_spreads, buy_amounts_pct, sell_amounts_pct,
total_amount_quote):
colors = theme.get_color_scheme()
buy_spread_distributions = [spread * 100 for spread in buy_spreads]

View File

@@ -24,7 +24,9 @@ def get_bbands_traces(df, bb_length, bb_std):
def get_volume_trace(df):
df.index = pd.to_datetime(df.timestamp, unit='s')
return go.Bar(x=df.index, y=df['volume'], name="Volume", marker_color=theme.get_color_scheme()["volume"], opacity=0.7)
return go.Bar(x=df.index, y=df['volume'], name="Volume", marker_color=theme.get_color_scheme()["volume"],
opacity=0.7)
def get_macd_traces(df, macd_fast, macd_slow, macd_signal):
tech_colors = theme.get_color_scheme()
@@ -38,7 +40,8 @@ def get_macd_traces(df, macd_fast, macd_slow, macd_signal):
go.Scatter(x=df.index, y=df[macd_s], line=dict(color=tech_colors['macd_signal']),
name='MACD Signal'),
go.Bar(x=df.index, y=df[macd_hist], name='MACD Histogram',
marker_color=df[f"MACDh_{macd_fast}_{macd_slow}_{macd_signal}"].apply(lambda x: '#FF6347' if x < 0 else '#32CD32'))
marker_color=df[f"MACDh_{macd_fast}_{macd_slow}_{macd_signal}"].apply(
lambda x: '#FF6347' if x < 0 else '#32CD32'))
]
return traces
@@ -79,4 +82,3 @@ def get_supertrend_traces(df, length, multiplier):
]
return traces

View File

@@ -1,6 +1,7 @@
from frontend.visualization import theme
import plotly.graph_objects as go
import pandas_ta as ta # noqa: F401
import plotly.graph_objects as go
from frontend.visualization import theme
def get_signal_traces(buy_signals, sell_signals):
@@ -15,6 +16,7 @@ def get_signal_traces(buy_signals, sell_signals):
]
return traces
def get_bollinger_v1_signal_traces(df, bb_length, bb_std, bb_long_threshold, bb_short_threshold):
# Add Bollinger Bands
candles = df.copy()
@@ -29,7 +31,6 @@ def get_bollinger_v1_signal_traces(df, bb_length, bb_std, bb_long_threshold, bb_
def get_macdbb_v1_signal_traces(df, bb_length, bb_std, bb_long_threshold, bb_short_threshold, macd_fast, macd_slow,
macd_signal):
tech_colors = theme.get_color_scheme()
# Add Bollinger Bands
df.ta.bbands(length=bb_length, std=bb_std, append=True)
# Add MACD