Backtest
April 15, 2024 ยท View on GitHub
Backtesting is the method for seeing how well a strategy would have done. The following backtesting functions are provided for evaluating strategies.
Strategy Info
The StrategyInfo provides a strategy function with a name.
interface StrategyInfo {
name: string;
strategy: StrategyFunction;
}
It is used to define a new strategy for the backtest.
import {StrategyInfo} from 'indicatorts';
const strategyInfo: StrategyInfo = {
name: 'My Strategy',
strategy: (asset: Asset): Action[] => {
// Strategy Function
}
};
The strategy infos for all strategies are provided under STRATEGY_INFOS.
Strategy Result
The StrategyResult provides the result of a given strategy after the backtest.
interface StrategyResult {
info: StrategyInfo;
gain: number;
lastAction: Action;
}
The info is the Strategy Info, the gain is the result of the strategy at the end, and the lastAction is the last action provided by the given strategy.
Backtest Function
The backtest function takes an Asset, an array of StrategyInfo, and returns an array of StrategyResult.
import {bactest} from 'indicatorts';
const results = backtest(asset, STRATEGY_INFOS);
Company Info
The CompanyInfo provides the company information.
interface CompanyInfo {
symbol: string;
name: string;
sector: string;
subIndustry: string;
}
The SP500_COMPANIES are provided.
Company Result
The CompanyResult provides the company result.
interface CompanyResult {
companyInfo: CompanyInfo;
strategyResults: StrategyResult[];
}
The companyInfo is the CompanyInfo, and strategyResults is an array of StrategyResult.
Strategy Stats
The StrategyStats provides the stats for a given strategy.
interface StrategyStats {
strategyInfo: StrategyInfo;
score: number;
minGain: number;
maxGain: number;
averageGain: number;
}
The strategyInfo is the StrategyInfo of the given strategy, score is the total count of times this strategy generated the highest gain, the minGain is the minimum gain, maxGain is the maximum gain, and the averageGain is the average gain.
Compute Strategy Stats
The computeStrategyStats takes an array for CompanyResult, and returns an array of StrategyStats.
import {StrategyStats, computeStrategyStats} from 'indicatorts';
const stats = computeStrategyStats(companyResults);
Disclaimer
The information provided on this project is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.
License
Copyright (c) 2022 Onur Cinar. All Rights Reserved.
The source code is provided under MIT License.