Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

feat: add runtime backtest function #12

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion plugins/blockly/blocks/backtest/backtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ Blockly.JavaScript["backtest"] = function (block) {
"STRATEGY_INFO",
Blockly.JavaScript.ORDER_ATOMIC,
);
const code = `indicatorts.backtest(stock, [${value_strategy_info}])`;
const code = `runtime.fn.backtest(stock, [${value_strategy_info}])`;
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
14 changes: 14 additions & 0 deletions plugins/blockly/runtime/fn/backtest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as indicatorts from "indicatorts";
import { StrategyInfo, StrategyResult } from "indicatorts";
import { Stock } from "~~/stock/stock";

export function backtest(
stock: Stock,
strategyInfos: StrategyInfo[],
): StrategyResult[] {
const result = indicatorts.backtest(stock, strategyInfos);

console.log(result);

return result;
}
3 changes: 2 additions & 1 deletion plugins/blockly/runtime/fn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { applyFirstMatch } from "./apply_first_match";
import { compare } from "./compare";
import { booleanAlgebra } from "./boolean_algebra";
import { cross } from "./cross";
import { backtest } from "./backtest";

export default { applyFirstMatch, compare, booleanAlgebra, cross };
export default { applyFirstMatch, compare, booleanAlgebra, cross, backtest };