Skip to content

Commit c8c6e8b

Browse files
authored
Support benchmark create updates for v2 (#15)
1 parent 2f8cf31 commit c8c6e8b

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

src/commands/benchmarks/createBenchmark/BenchmarkCreateContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type BenchmarkCreateContext = AuthContext & {
99
benchmarkRealReturn?: number;
1010
benchmarkStdDev?: number;
1111
benchmarkDrawdownYears?: number;
12+
benchmarkRebalanceThresholdPct?: number;
1213

1314
benchmark?: Benchmark;
1415
};

src/commands/benchmarks/createBenchmark/BenchmarkCreateStep.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class BenchmarkCreateStep<T extends BenchmarkCreateContext> extends Execu
3232
real_return_pct: context.benchmarkRealReturn,
3333
std_dev_pct: context.benchmarkStdDev,
3434
drawdown_yrs: context.benchmarkDrawdownYears,
35+
rec_rebalance_threshold_pct: context.benchmarkRebalanceThresholdPct,
3536
is_deprecated: false,
3637
});
3738
if (response.error) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { l10n } from "vscode";
2+
import { PromptStep } from "../../../wizard/PromptStep";
3+
import { validationUtils } from "../../../utils/validationUtils";
4+
import { BenchmarkCreateContext } from "./BenchmarkCreateContext";
5+
6+
export class BenchmarkRebalanceThresholdStep<T extends BenchmarkCreateContext> extends PromptStep<T> {
7+
async prompt(context: T): Promise<void> {
8+
context.benchmarkRebalanceThresholdPct = Number((await context.ui.showInputBox({
9+
title: this.title,
10+
prompt: l10n.t('Enter benchmark\'s recommended rebalance threshold (%)'),
11+
validateInput: this.validateInput,
12+
})));
13+
}
14+
15+
shouldPrompt(context: T): boolean {
16+
return !context.benchmarkRebalanceThresholdPct;
17+
}
18+
19+
private validateInput(value: string): string | undefined {
20+
if (!validationUtils.hasValidCharLength(value)) {
21+
return validationUtils.getInvalidCharLengthMessage();
22+
}
23+
24+
const num: number = Number(value);
25+
if (isNaN(num) || !Number.isInteger(num)) {
26+
return l10n.t('Value must be a whole number.');
27+
}
28+
29+
if (num < 1 || num > 99) {
30+
return l10n.t('Value must be between 1 and 99.');
31+
}
32+
33+
return undefined;
34+
}
35+
}

src/commands/benchmarks/createBenchmark/createBenchmark.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { BenchmarkDrawdownYearsStep } from "./BenchmarkDrawdownYearsStep";
1414
import { BenchmarkAssetCategoriesStep } from "./BenchmarkAssetCategoriesStep";
1515
import { BenchmarkAssetAmountsStep } from "./BenchmarkAssetAmountsStep";
1616
import { BenchmarkCreateStep } from "./BenchmarkCreateStep";
17+
import { BenchmarkRebalanceThresholdStep } from "./BenchmarkRebalanceThresholdStep";
1718

1819
export async function createBenchmark(context: CommandContext, item: BenchmarksItem): Promise<void> {
1920
const wizardContext: BenchmarkCreateContext = {
@@ -29,6 +30,7 @@ export async function createBenchmark(context: CommandContext, item: BenchmarksI
2930
new BenchmarkDescriptionStep(),
3031
new BenchmarkAssetCategoriesStep(),
3132
new BenchmarkAssetAmountsStep(),
33+
new BenchmarkRebalanceThresholdStep(),
3234
new BenchmarkRealReturnStep(),
3335
new BenchmarkStdDevStep(),
3436
new BenchmarkDrawdownYearsStep(),

0 commit comments

Comments
 (0)