fix benchmark return baseline
This commit is contained in:
@@ -75,6 +75,7 @@ pub struct DailyEquityPoint {
|
||||
pub market_value: f64,
|
||||
pub total_equity: f64,
|
||||
pub benchmark_close: f64,
|
||||
pub benchmark_prev_close: f64,
|
||||
pub notes: String,
|
||||
pub diagnostics: String,
|
||||
}
|
||||
@@ -212,6 +213,12 @@ impl BacktestResult {
|
||||
|
||||
pub fn analyzer_monthly_returns(&self) -> Vec<AnalyzerMonthlyReturnRow> {
|
||||
let mut month_points = BTreeMap::<(i32, u32), (f64, f64, f64, f64)>::new();
|
||||
let mut previous_equity = self.metrics.initial_cash;
|
||||
let mut previous_benchmark = self
|
||||
.equity_curve
|
||||
.first()
|
||||
.map(|point| point.benchmark_prev_close)
|
||||
.unwrap_or_default();
|
||||
for point in &self.equity_curve {
|
||||
let key = (point.date.year(), point.date.month());
|
||||
month_points
|
||||
@@ -221,11 +228,13 @@ impl BacktestResult {
|
||||
*end_benchmark = point.benchmark_close;
|
||||
})
|
||||
.or_insert((
|
||||
point.total_equity,
|
||||
point.benchmark_close,
|
||||
previous_equity,
|
||||
previous_benchmark,
|
||||
point.total_equity,
|
||||
point.benchmark_close,
|
||||
));
|
||||
previous_equity = point.total_equity;
|
||||
previous_benchmark = point.benchmark_close;
|
||||
}
|
||||
month_points
|
||||
.into_iter()
|
||||
@@ -2423,6 +2432,7 @@ where
|
||||
market_value: aggregate_market_value,
|
||||
total_equity: aggregate_total_equity,
|
||||
benchmark_close: benchmark.close,
|
||||
benchmark_prev_close: benchmark.prev_close,
|
||||
notes,
|
||||
diagnostics,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user