import { useState, useEffect } from 'react' import Head from 'next/head' import Navbar from '../components/Navbar' import Footer from '../components/Footer' import TimeRangePicker from '../components/TimeRangePicker' import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts' const usDebtData = [ { year: '2019', debt: 22.7, gdp: 21.4, debtToGdp: 106.1, interestToGdp: 1.8 }, { year: '2020', debt: 26.9, gdp: 20.9, debtToGdp: 128.7, interestToGdp: 1.6 }, { year: '2021', debt: 28.4, gdp: 23.0, debtToGdp: 123.5, interestToGdp: 1.5 }, { year: '2022', debt: 30.9, gdp: 25.4, debtToGdp: 121.6, interestToGdp: 1.6 }, { year: '2023', debt: 33.1, gdp: 26.9, debtToGdp: 123.0, interestToGdp: 1.9 }, { year: '2024', debt: 35.3, gdp: 28.5, debtToGdp: 123.9, interestToGdp: 2.1 }, { year: '2025', debt: 37.5, gdp: 30.2, debtToGdp: 124.2, interestToGdp: 2.3 }, { year: '2026', debt: 39.8, gdp: 31.9, debtToGdp: 124.8, interestToGdp: 2.5 } ] const chinaDebtData = [ { year: '2019', debt: 8.8, gdp: 14.3, debtToGdp: 61.5, interestToGdp: 1.9 }, { year: '2020', debt: 10.3, gdp: 14.7, debtToGdp: 70.1, interestToGdp: 1.8 }, { year: '2021', debt: 11.7, gdp: 16.1, debtToGdp: 72.7, interestToGdp: 1.7 }, { year: '2022', debt: 13.1, gdp: 17.9, debtToGdp: 73.2, interestToGdp: 1.6 }, { year: '2023', debt: 14.5, gdp: 19.4, debtToGdp: 74.7, interestToGdp: 1.6 }, { year: '2024', debt: 15.9, gdp: 21.0, debtToGdp: 75.7, interestToGdp: 1.5 }, { year: '2025', debt: 17.3, gdp: 22.8, debtToGdp: 75.9, interestToGdp: 1.5 }, { year: '2026', debt: 18.8, gdp: 24.7, debtToGdp: 76.1, interestToGdp: 1.4 } ] export default function Strategy() { const [selectedStrategy, setSelectedStrategy] = useState('us-debt-gdp') const [sh300ExchangeData, setSh300ExchangeData] = useState([]) const [sh300Loading, setSh300Loading] = useState(false) const [timeRange, setTimeRange] = useState('1m') const [startDate, setStartDate] = useState('') const [endDate, setEndDate] = useState('') const strategies = [ { id: 'us-debt-gdp', name: '美国政府债务/GDP' }, { id: 'china-debt-gdp', name: '中国政府债务/GDP' }, { id: 'sh300-exchange-rate', name: '沪深300与汇率对比' } ] const handleTimeRangeChange = (range, start, end) => { setTimeRange(range) setStartDate(start) setEndDate(end) } const fetchSh300ExchangeData = async () => { console.log('fetchSh300ExchangeData called') setSh300Loading(true) try { let sh300Url = '/api/sh300-index' let exchangeUrl = '/api/exchange-rate' const params = [] if (timeRange === 'custom' && startDate && endDate) { params.push(`startDate=${startDate}`) params.push(`endDate=${endDate}`) } else if (timeRange === '1m') { params.push('limit=30') } else if (timeRange === '3m') { params.push('limit=90') } else if (timeRange === '1y') { params.push('limit=365') } if (params.length > 0) { sh300Url += '?' + params.join('&') exchangeUrl += '?' + params.join('&') } console.log('Fetching from:', sh300Url, exchangeUrl) const [sh300Res, exchangeRes] = await Promise.all([ fetch(sh300Url), fetch(exchangeUrl) ]) console.log('Response status:', sh300Res.status, exchangeRes.status) const sh300Json = await sh300Res.json() const exchangeJson = await exchangeRes.json() console.log('Response data:', sh300Json, exchangeJson) if (sh300Json.success && exchangeJson.success) { const sh300Map = new Map(sh300Json.data.map(item => [item.date, item.close])) const exchangeMap = new Map(exchangeJson.data.map(item => [item.date, item.rate])) const allDates = [...new Set([...sh300Map.keys(), ...exchangeMap.keys()])].sort() const mergedData = allDates.map(date => ({ date, sh300: sh300Map.get(date) || null, exchangeRate: exchangeMap.get(date) || null })).filter(item => item.sh300 !== null && item.exchangeRate !== null) console.log('Merged data:', mergedData) setSh300ExchangeData(mergedData) } } catch (error) { console.error('获取数据失败:', error) } finally { setSh300Loading(false) } } useEffect(() => { if (selectedStrategy === 'sh300-exchange-rate') { fetchSh300ExchangeData() } }, [selectedStrategy, timeRange, startDate, endDate]) return (
策略 - iBoard

经济策略

按照经济理论组织的相关数据和图表的对比

策略列表

    {strategies.map((strategy) => (
  • setSelectedStrategy(strategy.id)} > {strategy.name}
  • ))}
{selectedStrategy === 'us-debt-gdp' && (

美国政府债务/GDP分析

分析美国政府债务、GDP、债务/GDP比率以及债务利息/GDP比率的走势

美国政府债务走势

美国GDP走势

美国政府债务/GDP走势

美国政府债务利息/GDP

详细数据

{usDebtData.map((row, index) => ( ))}
年份 政府债务(万亿美元) GDP(万亿美元) 债务/GDP(%) 债务利息/GDP(%)
{row.year} {row.debt.toFixed(1)} {row.gdp.toFixed(1)} {row.debtToGdp.toFixed(1)} {row.interestToGdp.toFixed(1)}
)} {selectedStrategy === 'china-debt-gdp' && (

中国政府债务/GDP分析

分析中国政府债务、GDP、债务/GDP比率以及债务利息/GDP比率的走势

中国政府债务走势

中国GDP走势

中国政府债务/GDP走势

中国政府债务利息/GDP

详细数据

{chinaDebtData.map((row, index) => ( ))}
年份 政府债务(万亿美元) GDP(万亿美元) 债务/GDP(%) 债务利息/GDP(%)
{row.year} {row.debt.toFixed(1)} {row.gdp.toFixed(1)} {row.debtToGdp.toFixed(1)} {row.interestToGdp.toFixed(1)}
)} {selectedStrategy === 'sh300-exchange-rate' && (

沪深300与汇率对比分析

对比沪深300指数收盘价与人民币兑美元汇率的走势关系

{sh300Loading ? (
加载中...
) : ( <>

沪深300与汇率对比(双Y轴)

value.toFixed(4)} />
)}
)}
) }