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

Commit

Permalink
Merge pull request #12 from wst24365888/feat/editor
Browse files Browse the repository at this point in the history
feat: add runtime backtest function
  • Loading branch information
ppodds authored Oct 11, 2022
2 parents 68ea941 + e3a793f commit 3f44128
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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 };

0 comments on commit 3f44128

Please sign in to comment.