is the compounded calculation correct?

import React from 'react';
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
import { Card, CardHeader, CardContent } from '@/components/ui/card';

const rawData = [
  { week: '08.10.2023', conservative: 1.3, ultraConservative: 2.3 },
  { week: '15.10.2023', conservative: 2.4, ultraConservative: 0.9 },
  { week: '22.10.2023', conservative: 9.2, ultraConservative: 6.2 },
  { week: '05.11.2023', conservative: 5.3, ultraConservative: 5.8 },
  { week: '12.11.2023', conservative: 15.3, ultraConservative: 6.3 },
  { week: '18.11.2023', conservative: 10, ultraConservative: 5.2 },
  { week: '26.11.2023', conservative: 9.8, ultraConservative: 3.8 },
  { week: '03.12.2023', conservative: 1.9, ultraConservative: 0.9 },
  { week: '11.12.2023', conservative: 7.3, ultraConservative: 6.6 },
  { week: '17.12.2023', conservative: 9.2, ultraConservative: 6.3 },
  { week: '24.12.2023', conservative: 4, ultraConservative: 2 },
  { week: '31.12.2023', conservative: 9.7, ultraConservative: 7.2 },
  { week: '07.01.2024', conservative: 6.8, ultraConservative: 5 },
  { week: '14.01.2024', conservative: 8.2, ultraConservative: 3.6 },
  { week: '21.01.2024', conservative: 0, ultraConservative: 3.7 },
  { week: '28.01.2024', conservative: 3.2, ultraConservative: 0.8 },
  { week: '04.02.2024', conservative: 0.5, ultraConservative: 0.1 },
  { week: '11.02.2024', conservative: 2.9, ultraConservative: 0.7 },
  { week: '18.02.2024', conservative: 6.9, ultraConservative: 2.7 },
  { week: '25.02.2024', conservative: 7.1, ultraConservative: 3.3 },
  { week: '03.03.2024', conservative: 21, ultraConservative: 17.3 },
  { week: '10.03.2024', conservative: 18.7, ultraConservative: 11.6 },
  { week: '17.03.2024', conservative: 0, ultraConservative: 3.3 },
  { week: '24.03.2024', conservative: 3.1, ultraConservative: 1.8 },
  { week: '31.03.2024', conservative: 9, ultraConservative: 3 },
  { week: '07.04.2024', conservative: 1.1, ultraConservative: 1.7 },
  { week: '14.04.2024', conservative: -12.7, ultraConservative: -2.5 },
  { week: '21.04.2024', conservative: 10.6, ultraConservative: 6.5 },
  { week: '28.04.2024', conservative: -1.1, ultraConservative: -0.6 },
  { week: '05.05.2024', conservative: -1.9, ultraConservative: -1 },
  { week: '12.05.2024', conservative: -0.8, ultraConservative: 0 },
  { week: '19.05.2024', conservative: 2.7, ultraConservative: 1.3 },
  { week: '26.05.2024', conservative: 3.2, ultraConservative: 2.8 },
  { week: '02.06.2024', conservative: 3, ultraConservative: 0.9 },
  { week: '09.06.2024', conservative: 1.9, ultraConservative: 1.9 },
  { week: '16.06.2024', conservative: 2.8, ultraConservative: 3.2 },
  { week: '23.06.2024', conservative: 2.9, ultraConservative: 3 },
  { week: '30.06.2024', conservative: -2, ultraConservative: -0.2 },
  { week: '07.07.2024', conservative: -13, ultraConservative: -6.4 },
  { week: '14.07.2024', conservative: 2.4, ultraConservative: 1.6 },
  { week: '21.07.2024', conservative: 4.2, ultraConservative: 1.7 },
  { week: '28.07.2024', conservative: 0, ultraConservative: 0.1 },
  { week: '04.08.2024', conservative: -2.7, ultraConservative: -0.2 },
  { week: '11.08.2024', conservative: -18.7, ultraConservative: -6.4 },
  { week: '18.08.2024', conservative: 2.2, ultraConservative: 0.6 },
  { week: '25.08.2024', conservative: 1.2, ultraConservative: 0.6 },
  { week: '01.09.2024', conservative: 2, ultraConservative: 1.6 },
  { week: '08.09.2024', conservative: 1.2, ultraConservative: 2.3 },
  { week: '15.09.2024', conservative: 0.3, ultraConservative: 0.1 },
  { week: '22.09.2024', conservative: 0.1, ultraConservative: 0.2 },
  { week: '29.09.2024', conservative: 1.3, ultraConservative: 0.4 },
];

const calculateCompoundedReturns = (data) => {
  let conservativeCompounded = 100;
  let ultraConservativeCompounded = 100;
  
  return data.map(week => {
    conservativeCompounded *= (1 + week.conservative / 100);
    ultraConservativeCompounded *= (1 + week.ultraConservative / 100);
    
    return {
      ...week,
      conservativeCompounded: conservativeCompounded - 100,
      ultraConservativeCompounded: ultraConservativeCompounded - 100
    };
  });
};

const data = calculateCompoundedReturns(rawData);

const calculateStats = (data, key) => {
  const values = data.map(item => item[key]);
  const compoundedValues = data.map(item => item[key + 'Compounded']);
  const totalCompounded = compoundedValues[compoundedValues.length - 1].toFixed(1);
  const avg = values.reduce((a, b) => a + b, 0) / values.length;
  const max = Math.max(...values);
  const min = Math.min(...values);
  const positiveWeeks = values.filter(v => v > 0).length;
  const negativeWeeks = values.filter(v => v < 0).length;

  return {
    totalCompounded,
    average: avg.toFixed(2),
    max: max.toFixed(1),
    min: min.toFixed(1),
    positiveWeeks,
    negativeWeeks,
  };
};

const statsConservative = calculateStats(data, 'conservative');
const statsUltraConservative = calculateStats(data, 'ultraConservative');

const TraderPerformanceAnalysis = () => {
  return (
    <div className="space-y-6">
      <Card>
        <CardHeader>Master Trader Performance Analysis (Compounded Returns)</CardHeader>
        <CardContent>
          <ResponsiveContainer width="100%" height={400}>
            <LineChart data={data}>
              <CartesianGrid strokeDasharray="3 3" />
              <XAxis dataKey="week" angle={-45} textAnchor="end" height={70} interval={4} />
              <YAxis />
              <Tooltip />
              <Legend />
              <Line type="monotone" dataKey="conservativeCompounded" stroke="#8884d8" name="Conservative (Compounded)" />
              <Line type="monotone" dataKey="ultraConservativeCompounded" stroke="#82ca9d" name="Ultra-conservative (Compounded)" />
            </LineChart>
          </ResponsiveContainer>
        </CardContent>
      </Card>

      <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
        <Card>
          <CardHeader>Conservative Strategy Statistics</CardHeader>
          <CardContent>
            <p>Total Compounded Return: {statsConservative.totalCompounded}%</p>
            <p>Average Weekly Return: {statsConservative.average}%</p>
            <p>Best Week: {statsConservative.max}%</p>
            <p>Worst Week: {statsConservative.min}%</p>
            <p>Positive Weeks: {statsConservative.positiveWeeks}</p>
            <p>Negative Weeks: {statsConservative.negativeWeeks}</p>
          </CardContent>
        </Card>

        <Card>
          <CardHeader>Ultra-conservative Strategy Statistics</CardHeader>
          <CardContent>
            <p>Total Compounded Return: {statsUltraConservative.totalCompounded}%</p>
            <p>Average Weekly Return: {statsUltraConservative.average}%</p>
            <p>Best Week: {statsUltraConservative.max}%</p>
            <p>Worst Week: {statsUltraConservative.min}%</p>
            <p>Positive Weeks: {statsUltraConservative.positiveWeeks}</p>
            <p>Negative Weeks: {statsUltraConservative.negativeWeeks}</p>
          </CardContent>
        </Card>
      </div>
    </div>
  );
};

export default TraderPerformanceAnalysis;