Pharos
TAMath transform

LOG10 - 常用对数

函数说明

计算数组中每个元素的常用对数(以10为底)。

语法

python
result = TA.LOG10(records)

参数

参数名类型说明
recordsarray数值数组,所有元素必须>0

返回值

返回常用对数数组

计算方法

对输入数组的每个元素x(x > 0),返回 log10(x)

使用场景

  1. 数量级分析
  2. 对数坐标图表
  3. 价格范围压缩
  4. 科学计数转换

基础示例

python
import math

def main():
    # 分析价格数量级
    prices = [1, 10, 100, 1000, 10000]
    log_prices = [math.log10(p) for p in prices]
    # 结果: [0, 1, 2, 3, 4]
    
    Log(f"价格跨越 {log_prices[-1] - log_prices[0]} 个数量级")

高级应用

1. 价格范围归一化

python
def normalize_by_magnitude():
    records = exchange.GetRecords()
    prices = [r['Close'] for r in records[-100:]]
    
    # 使用log10压缩价格范围
    log_prices = [math.log10(p) for p in prices]
    
    # 归一化到0-1
    min_log = min(log_prices)
    max_log = max(log_prices)
    normalized = [(lp - min_log) / (max_log - min_log) for lp in log_prices]
    
    return normalized

2. 成交量数量级分析

python
def volume_magnitude():
    records = exchange.GetRecords()
    volumes = [r['Volume'] for r in records[-100:]]
    
    # 计算平均数量级
    log_volumes = [math.log10(v) if v > 0 else 0 for v in volumes]
    avg_magnitude = sum(log_volumes) / len(log_volumes)
    
    # 检测异常放量
    current_log_vol = math.log10(volumes[-1]) if volumes[-1] > 0 else 0
    
    if current_log_vol > avg_magnitude + 0.5:  # 超过3倍(10^0.5≈3.16)
        Log("异常放量!")
        return True
    
    return False

注意事项

  • 输入值必须 > 0
  • log10(10) = 1, log10(100) = 2
  • 适合处理跨多个数量级的数据
  • Python中可使用 math.log10() 替代
  • 量化交易中较少使用,更多用ln

相关函数

  • LN - 自然对数(更常用)
  • EXP - 指数函数