quant-zero
Version:
Node-Quant is a powerful Node.js package for developing and testing quantitative trading strategies in cryptocurrency markets, offering tools for backtesting and performance analysis.
12 lines (10 loc) • 314 B
text/typescript
import { PositionType } from '@/types'
export function calcPL(
currentClose: number,
openPrice: number,
positionType: PositionType,
): number {
return positionType === PositionType.LONG
? 100 * ((currentClose - openPrice) / openPrice)
: 100 * ((openPrice - currentClose) / openPrice)
}