Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions src/v1/simulator/simulator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,42 @@ export class SimulatorService {
};

// adjust low range start price
if (
new Decimal(inputData.low_range_low_price).lessThan(usdPrices[0].low) &&
new Decimal(usdPrices[0].low).lessThan(inputData.low_range_high_price)
) {
inputData.low_range_start_price = usdPrices[0].low.toString();
}

// adjust high range start price
if (
new Decimal(inputData.high_range_low_price).lessThan(usdPrices[0].high) &&
new Decimal(usdPrices[0].high).lessThan(inputData.high_range_high_price)
) {
inputData.high_range_start_price = usdPrices[0].high.toString();
// Check if strategy is concentrated (price ranges are within 1% of each other)
const isConcentrated =
new Decimal(buyMin)
.div(new Decimal(sellMin))
.toDecimalPlaces(2) // Round to 2 decimal places
.times(1 + 0.01) // Apply 1% buffer above
.gte(new Decimal(buyMax).div(new Decimal(sellMax)).toDecimalPlaces(2)) &&
new Decimal(buyMin)
.div(new Decimal(sellMin))
.toDecimalPlaces(2) // Round to 2 decimal places
.times(1 - 0.01) // Apply 1% buffer below
.lte(new Decimal(buyMax).div(new Decimal(sellMax)).toDecimalPlaces(2));

if (isConcentrated) {
// For concentrated strategies, use existing logic
if (
new Decimal(inputData.low_range_low_price).lessThan(usdPrices[0].low) &&
new Decimal(usdPrices[0].low).lessThan(inputData.low_range_high_price)
) {
inputData.low_range_start_price = usdPrices[0].low.toString();
}

if (
new Decimal(inputData.high_range_low_price).lessThan(usdPrices[0].high) &&
new Decimal(usdPrices[0].high).lessThan(inputData.high_range_high_price)
) {
inputData.high_range_start_price = usdPrices[0].high.toString();
}
} else {
// For non-concentrated strategies, check budget and update start prices accordingly
if (new Decimal(inputData.portfolio_risk_value).equals(0)) {
inputData.low_range_start_price = buyMin.toString();
}
if (new Decimal(inputData.portfolio_cash_value).equals(0)) {
inputData.high_range_start_price = sellMax.toString();
}
}

// Create folder if it doesn't exist
Expand Down