mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-09 08:18:07 +00:00
feat: 添加布林带宽度计算功能及相关配置项,优化趋势引擎以支持布林带宽度过滤
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getPosition, getSMA } from "../src/utils/strategy";
|
||||
import { computeBollingerBandwidth, getPosition, getSMA } from "../src/utils/strategy";
|
||||
import type { AsterAccountSnapshot, AsterKline } from "../src/exchanges/types";
|
||||
|
||||
const mockSnapshot = (positions: Array<{ symbol: string; amt: number; entry: number; pnl: number }> = []): AsterAccountSnapshot => ({
|
||||
@@ -55,4 +55,17 @@ describe("strategy utils", () => {
|
||||
const data = mockKlines(Array.from({ length: 30 }, (_, i) => i + 1));
|
||||
expect(getSMA(data, 30)).toBe(15.5);
|
||||
});
|
||||
|
||||
it("returns null Bollinger bandwidth when data insufficient", () => {
|
||||
const klines = mockKlines([100, 101, 102]);
|
||||
expect(computeBollingerBandwidth(klines, 20, 2)).toBeNull();
|
||||
});
|
||||
|
||||
it("computes Bollinger bandwidth ratio", () => {
|
||||
const closes = [...Array(19).fill(100), 110];
|
||||
const klines = mockKlines(closes);
|
||||
const bandwidth = computeBollingerBandwidth(klines, 20, 2);
|
||||
expect(bandwidth).not.toBeNull();
|
||||
expect(bandwidth ?? 0).toBeCloseTo(0.0867443, 5);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user