import type { PriceScaleMode } from 'lightweight-charts';
export enum SeasonalityViewType {
Chart = 'chart',
Table = 'table',
}
export type SeasonalityScale = PriceScaleMode.Normal | PriceScaleMode.Percentage;
export interface SeasonalityRange {
fromYear: number;
toYear: number;
}
export interface SeasonalityState extends SeasonalityRange {
displayMode: SeasonalityViewType;
status: 'idle' | 'loading' | 'ready' | 'empty' | 'error';
scale: SeasonalityScale;
showAverage: boolean;
symbolId: string;
minYear: number;
maxYear: number;
error: string | null;
tableRows: SeasonalityTableRow[];
}
export interface SeasonalityPoint {
date: string;
chartDate: string;
price: number;
percentage: number | null;
}
export interface SeasonalityYear {
year: number;
baselineDate: string;
baselinePrice: number;
points: SeasonalityPoint[];
}
export interface DailyClose {
date: string;
close: number;
}
export interface SeasonalityChange {
absolute: number;
percentage: number | null;
}
export interface SeasonalityTableRow {
year: number;
months: (SeasonalityChange | null)[];
total: SeasonalityChange | null;
}
import { PriceScaleMode } from 'lightweight-charts';
import { SeasonalityViewType } from '@src/types';
import type { SeasonalityState } from '@src/types';
export const DEFAULT_SEASONALITY_YEARS = 5;
export function createInitialSeasonalityState(): SeasonalityState {
const year = new Date().getUTCFullYear();
const fromYear = year - DEFAULT_SEASONALITY_YEARS + 1;
return {
displayMode: SeasonalityViewType.Chart,
status: 'idle',
scale: PriceScaleMode.Normal,
showAverage: false,
symbolId: '',
error: null,
minYear: fromYear,
maxYear: year,
fromYear,
toYear: year,
tableRows: [],
};
}