Skip to content

Commit

Permalink
docs: update BaseFigure documentation
Browse files Browse the repository at this point in the history
- Move name and title from required attributes to required methods
- Clarify @Property decorator requirement for name and title methods
- Keep consistent documentation structure in both README and README_EN
  • Loading branch information
Xuan Ronaldo committed Dec 13, 2024
1 parent 8cae4da commit ac8bbfb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 20 deletions.
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,13 @@ from positionbt import (
class DrawdownFigure(BaseFigure):
"""Drawdown visualization figure"""

name = "drawdown" # Unique identifier for the figure
title = "Strategy Drawdown" # Display title for the figure
@property
def name(self) -> str:
return "drawdown"

@property
def title(self) -> str:
return "Strategy Drawdown"

def create(self) -> go.Figure:
"""Create drawdown figure
Expand Down Expand Up @@ -378,13 +383,19 @@ BacktestVisualizer(
#### BaseFigure
可视化图表的基类,用于自定义新的图表类型。

**必须实现的属性:**
- `name`: 图表唯一标识符
- `title`: 图表显示标题

**必须实现的方法:**
- `name(self) -> str`: 返回图表唯一标识符(需使用 @property 装饰器)
- `title(self) -> str`: 返回图表显示标题(需使用 @property 装饰器)
- `create(self) -> go.Figure`: 创建并返回 Plotly 图表对象

**初始化参数:**
- `results`: BacktestResult 对象,包含回测结果数据

**可用属性:**
- `results`: 回测结果对象
- `funding_curve`: 净值曲线数据
- `_fig`: 基础图表对象(包含默认布局设置)

### 注册器

#### indicator_registry
Expand Down
23 changes: 17 additions & 6 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,13 @@ from positionbt import (
class DrawdownFigure(BaseFigure):
"""Drawdown visualization figure"""

name = "drawdown" # Unique identifier for the figure
title = "Strategy Drawdown" # Display title for the figure
@property
def name(self) -> str:
return "drawdown"

@property
def title(self) -> str:
return "Strategy Drawdown"

def create(self) -> go.Figure:
"""Create drawdown figure
Expand Down Expand Up @@ -375,13 +380,19 @@ Base class for indicator calculation, used for custom performance indicators.
#### BaseFigure
Base class for visualization charts, used for custom chart types.

**Required Attributes:**
- `name`: Unique chart identifier
- `title`: Chart display title

**Required Methods:**
- `name(self) -> str`: Return chart unique identifier (requires @property decorator)
- `title(self) -> str`: Return chart display title (requires @property decorator)
- `create(self) -> go.Figure`: Create and return Plotly figure object

**Initialization Parameters:**
- `results`: BacktestResult object containing backtest data

**Available Attributes:**
- `results`: Backtest result object
- `funding_curve`: NAV curve data
- `_fig`: Base figure object (with default layout settings)

### Registries

#### indicator_registry
Expand Down
9 changes: 7 additions & 2 deletions examples/custom/custom_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@
class DrawdownFigure(BaseFigure):
"""Drawdown visualization figure"""

name = "drawdown" # Unique identifier for the figure
title = "Strategy Drawdown" # Display title for the figure
@property
def name(self) -> str:
return "drawdown"

@property
def title(self) -> str:
return "Strategy Drawdown"

def create(self) -> go.Figure:
"""Create drawdown figure
Expand Down
12 changes: 10 additions & 2 deletions src/positionbt/visualization/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
class BaseFigure(ABC):
"""Base class for visualization figures"""

name: str = "" # Unique identifier for the figure
title: str = "" # Display title for the figure
@property
@abstractmethod
def name(self) -> str:
pass

@property
@abstractmethod
def title(self) -> str:
pass

def __init__(self, results: BacktestResult):
"""Initialize base figure
Expand Down Expand Up @@ -45,6 +52,7 @@ def _create_base_figure(self) -> go.Figure:
fig = go.Figure()
fig.update_layout(
title=self.title,
template="plotly_white",
showlegend=True,
hovermode="x unified",
plot_bgcolor="white",
Expand Down
18 changes: 14 additions & 4 deletions src/positionbt/visualization/figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
class FundingCurveFigure(BaseFigure):
"""Funding curve visualization figure"""

name = "funding_curve" # Unique identifier for the figure
title = "Funding Curve" # Display title for the figure
@property
def name(self) -> str:
return "funding_curve"

@property
def title(self) -> str:
return "Funding Curve"

def create(self) -> go.Figure:
"""Create funding curve figure
Expand Down Expand Up @@ -107,8 +112,13 @@ def _add_max_drawdown_visualization(
class MonthlyReturnsFigure(BaseFigure):
"""Monthly returns distribution figure"""

name = "monthly_returns" # Unique identifier for the figure
title = "Monthly Returns Distribution" # Display title for the figure
@property
def name(self) -> str:
return "monthly_returns"

@property
def title(self) -> str:
return "Monthly Returns Distribution"

def create(self) -> go.Figure:
"""Create monthly returns distribution figure
Expand Down

0 comments on commit ac8bbfb

Please sign in to comment.