or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdmomentum-indicators.mdothers-indicators.mdtrend-indicators.mdutilities.mdvolatility-indicators.mdvolume-indicators.mdwrapper-functions.md

others-indicators.mddocs/

0

# Others Indicators

1

2

Financial return calculation indicators that measure different aspects of price performance over time. These indicators help traders and analysts assess portfolio performance, risk metrics, and investment returns from various mathematical perspectives.

3

4

## Capabilities

5

6

### Daily Return (DR)

7

8

Calculates the simple percentage change in price from one period to the next, representing the daily performance as a percentage.

9

10

```python { .api }

11

class DailyReturnIndicator:

12

def __init__(self, close, fillna=False):

13

"""

14

Daily Return (DR).

15

16

Parameters:

17

- close (Series): Dataset 'Close' column

18

- fillna (bool): If True, fill NaN values with 0 (default: False)

19

"""

20

21

def daily_return(self):

22

"""Returns: Series with daily return values (percentage)"""

23

24

def daily_return(close, fillna=False):

25

"""Functional interface for Daily Return"""

26

```

27

28

**Calculation:** `((Price_t / Price_t-1) - 1) * 100`

29

30

**Use Cases:**

31

- Portfolio performance measurement

32

- Risk analysis and volatility estimation

33

- Backtesting trading strategies

34

- Comparing performance across different assets

35

36

### Daily Log Return (DLR)

37

38

Calculates the logarithmic return, which is more appropriate for continuous compounding and has better statistical properties for financial analysis.

39

40

```python { .api }

41

class DailyLogReturnIndicator:

42

def __init__(self, close, fillna=False):

43

"""

44

Daily Log Return (DLR).

45

46

Parameters:

47

- close (Series): Dataset 'Close' column

48

- fillna (bool): If True, fill NaN values with 0 (default: False)

49

"""

50

51

def daily_log_return(self):

52

"""Returns: Series with daily log return values (percentage)"""

53

54

def daily_log_return(close, fillna=False):

55

"""Functional interface for Daily Log Return"""

56

```

57

58

**Calculation:** `ln(Price_t / Price_t-1) * 100`

59

60

**Use Cases:**

61

- Statistical analysis of returns (normal distribution assumption)

62

- Risk modeling and Value at Risk (VaR) calculations

63

- Portfolio optimization

64

- Academic research and quantitative analysis

65

66

**Advantages over Simple Returns:**

67

- Time-additive (log returns can be summed over time)

68

- Better statistical properties for modeling

69

- Symmetric around zero

70

- More appropriate for continuous compounding

71

72

### Cumulative Return (CR)

73

74

Measures the total return from the beginning of the period to the current point, showing overall performance relative to the starting value.

75

76

```python { .api }

77

class CumulativeReturnIndicator:

78

def __init__(self, close, fillna=False):

79

"""

80

Cumulative Return (CR).

81

82

Parameters:

83

- close (Series): Dataset 'Close' column

84

- fillna (bool): If True, fill NaN values with -1 (default: False)

85

"""

86

87

def cumulative_return(self):

88

"""Returns: Series with cumulative return values (percentage)"""

89

90

def cumulative_return(close, fillna=False):

91

"""Functional interface for Cumulative Return"""

92

```

93

94

**Calculation:** `((Price_t / Price_0) - 1) * 100`

95

96

**Use Cases:**

97

- Long-term performance tracking

98

- Investment growth visualization

99

- Benchmark comparison

100

- Portfolio evaluation over entire holding periods

101

102

## Usage Examples

103

104

### Basic Return Calculations

105

106

```python

107

from ta.others import *

108

import pandas as pd

109

110

def calculate_returns(df):

111

# Calculate all return types

112

df['Daily_Return'] = daily_return(df['Close'])

113

df['Log_Return'] = daily_log_return(df['Close'])

114

df['Cumulative_Return'] = cumulative_return(df['Close'])

115

116

return df

117

118

# Apply return calculations

119

df_returns = calculate_returns(df)

120

```

121

122

### Return Analysis Workflow

123

124

```python

125

from ta.others import DailyReturnIndicator, DailyLogReturnIndicator, CumulativeReturnIndicator

126

127

# Create return indicators with class-based interface

128

daily_ret_indicator = DailyReturnIndicator(close=df['Close'], fillna=True)

129

log_ret_indicator = DailyLogReturnIndicator(close=df['Close'], fillna=True)

130

cum_ret_indicator = CumulativeReturnIndicator(close=df['Close'], fillna=True)

131

132

# Calculate return metrics

133

df['Daily_Return'] = daily_ret_indicator.daily_return()

134

df['Log_Return'] = log_ret_indicator.daily_log_return()

135

df['Cumulative_Return'] = cum_ret_indicator.cumulative_return()

136

137

# Calculate summary statistics

138

print(f"Average Daily Return: {df['Daily_Return'].mean():.4f}%")

139

print(f"Daily Return Volatility: {df['Daily_Return'].std():.4f}%")

140

print(f"Total Return: {df['Cumulative_Return'].iloc[-1]:.2f}%")

141

```

142

143

### Risk and Performance Analysis

144

145

```python

146

import numpy as np

147

from ta.others import daily_return, daily_log_return, cumulative_return

148

149

def comprehensive_return_analysis(df, risk_free_rate=0.02):

150

# Calculate returns

151

df['Daily_Return'] = daily_return(df['Close'])

152

df['Log_Return'] = daily_log_return(df['Close'])

153

df['Cumulative_Return'] = cumulative_return(df['Close'])

154

155

# Performance metrics

156

total_return = df['Cumulative_Return'].iloc[-1]

157

avg_daily_return = df['Daily_Return'].mean()

158

volatility = df['Daily_Return'].std()

159

160

# Risk-adjusted metrics

161

annualized_return = avg_daily_return * 252 # Assuming 252 trading days

162

annualized_volatility = volatility * np.sqrt(252)

163

sharpe_ratio = (annualized_return - risk_free_rate) / annualized_volatility

164

165

# Downside metrics

166

negative_returns = df['Daily_Return'][df['Daily_Return'] < 0]

167

downside_deviation = negative_returns.std() * np.sqrt(252)

168

169

# Maximum drawdown

170

cumulative_max = (1 + df['Cumulative_Return'] / 100).cummax()

171

drawdown = (1 + df['Cumulative_Return'] / 100) / cumulative_max - 1

172

max_drawdown = drawdown.min() * 100

173

174

metrics = {

175

'Total Return (%)': total_return,

176

'Annualized Return (%)': annualized_return,

177

'Annualized Volatility (%)': annualized_volatility,

178

'Sharpe Ratio': sharpe_ratio,

179

'Max Drawdown (%)': max_drawdown,

180

'Downside Deviation (%)': downside_deviation

181

}

182

183

return df, metrics

184

185

# Perform comprehensive analysis

186

df_analyzed, performance_metrics = comprehensive_return_analysis(df)

187

188

for metric, value in performance_metrics.items():

189

print(f"{metric}: {value:.4f}")

190

```

191

192

### Comparative Return Analysis

193

194

```python

195

from ta.others import *

196

197

def compare_return_types(df):

198

# Calculate different return types

199

df['Simple_Return'] = daily_return(df['Close'])

200

df['Log_Return'] = daily_log_return(df['Close'])

201

202

# Compare cumulative effects

203

df['Cumulative_Simple'] = (1 + df['Simple_Return'] / 100).cumprod() - 1

204

df['Cumulative_Log'] = df['Log_Return'].cumsum() / 100

205

206

# Calculate differences

207

df['Return_Difference'] = df['Simple_Return'] - df['Log_Return']

208

df['Cumulative_Difference'] = df['Cumulative_Simple'] - df['Cumulative_Log']

209

210

return df

211

212

# Compare return methodologies

213

df_comparison = compare_return_types(df)

214

215

# Analyze the differences

216

print("Return Type Analysis:")

217

print(f"Average Simple Return: {df_comparison['Simple_Return'].mean():.4f}%")

218

print(f"Average Log Return: {df_comparison['Log_Return'].mean():.4f}%")

219

print(f"Average Difference: {df_comparison['Return_Difference'].mean():.6f}%")

220

```

221

222

### Rolling Return Analysis

223

224

```python

225

from ta.others import daily_return, cumulative_return

226

227

def rolling_return_analysis(df, windows=[30, 60, 90, 252]):

228

# Calculate daily returns

229

df['Daily_Return'] = daily_return(df['Close'])

230

231

# Calculate rolling returns for different periods

232

for window in windows:

233

# Rolling annualized return

234

rolling_mean = df['Daily_Return'].rolling(window=window).mean()

235

df[f'Rolling_{window}d_Return'] = rolling_mean * 252

236

237

# Rolling volatility (annualized)

238

rolling_std = df['Daily_Return'].rolling(window=window).std()

239

df[f'Rolling_{window}d_Volatility'] = rolling_std * np.sqrt(252)

240

241

# Rolling Sharpe ratio

242

df[f'Rolling_{window}d_Sharpe'] = (

243

df[f'Rolling_{window}d_Return'] / df[f'Rolling_{window}d_Volatility']

244

)

245

246

return df

247

248

# Perform rolling analysis

249

df_rolling = rolling_return_analysis(df)

250

251

# Display recent rolling metrics

252

recent_metrics = df_rolling[['Rolling_30d_Return', 'Rolling_60d_Return',

253

'Rolling_90d_Return', 'Rolling_252d_Return']].tail(1)

254

print("Recent Rolling Returns (Annualized):")

255

print(recent_metrics)

256

```

257

258

## Key Differences and When to Use Each

259

260

### Daily Return vs Daily Log Return

261

- **Daily Return**: Intuitive percentage change, better for short-term analysis

262

- **Log Return**: Better statistical properties, time-additive, preferred for modeling

263

264

### Use Case Guidelines

265

- **Daily Return**: Day-to-day performance tracking, simple return calculations

266

- **Daily Log Return**: Risk modeling, statistical analysis, academic research

267

- **Cumulative Return**: Long-term performance evaluation, investment tracking

268

269

### Statistical Properties

270

- **Log Returns**: Approximately normally distributed, suitable for parametric tests

271

- **Simple Returns**: May exhibit skewness, especially during volatile periods

272

- **Cumulative Returns**: Show compounding effects and long-term trends