Spaces:
Sleeping
Sleeping
File size: 1,873 Bytes
a1bf219 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
"""
Timeframe selector component.
Provides dropdown for selecting analysis timeframe.
"""
from typing import List, Tuple
import gradio as gr
# Available timeframes with descriptions
TIMEFRAMES = [
("1 Day", "1d"),
("1 Week", "1w"),
("1 Month", "1mo"),
("3 Months", "3mo"),
("1 Year", "1y"),
("5 Years", "5y"),
]
def create_timeframe_selector() -> gr.Dropdown:
"""
Create timeframe selector component.
Returns:
Gradio Dropdown component for timeframe selection
"""
return gr.Dropdown(
label="Timeframe",
choices=TIMEFRAMES,
value="1w", # Default to weekly for long-term investment focus
info="Select analysis timeframe. Daily/weekly for swing trading, monthly to multi-year for long-term investing.",
)
def get_recommended_timeframe(trading_style: str) -> str:
"""
Get recommended timeframe for trading style.
Args:
trading_style: Trading style (scalping, day_trading, swing_trading, position_trading)
Returns:
Recommended timeframe code
"""
recommendations = {
"scalping": "1m",
"day_trading": "5m",
"swing_trading": "1h",
"position_trading": "1d",
}
return recommendations.get(trading_style, "1d")
def validate_timeframe(timeframe: str) -> bool:
"""
Validate timeframe selection.
Args:
timeframe: Timeframe code
Returns:
True if valid
"""
valid_timeframes = [tf[1] for tf in TIMEFRAMES]
return timeframe in valid_timeframes
def get_timeframe_description(timeframe: str) -> str:
"""
Get human-readable description of timeframe.
Args:
timeframe: Timeframe code
Returns:
Description string
"""
for label, code in TIMEFRAMES:
if code == timeframe:
return label
return timeframe
|